// File: TBody[P]atomicpp/atomicpp/Spline/BicubicSpline.cpp
// Function: atomicpp::BicubicSpline::calculate_grid_coeff()
std::vector<std::vector<interp_data>> BicubicSpline::calculate_grid_coeff(){

	int Lx = x_values.size();
	int Ly = y_values.size();

	std::vector<std::vector<interp_data>>
	grid_coeff(Lx,std::vector<interp_data>(Ly,default_interp_data));

	for(int i=0; i<Lx; ++i){
		for(int j=0; j<Ly; ++j){

			grid_coeff[i][j].coord = std::make_pair(i, j);
			grid_coeff[i][j].datapoint = std::make_pair(x_values[i], y_values[j]);

			// Set the function value
			grid_coeff[i][j].f = z_values[i][j];

			// Treat as though this is a unit grid -- i.e. assume unit spacing
			if((i != 0) and (i != (int)(x_values.size()-1))){
				// Central difference for dx (2 cells)
				grid_coeff[i][j].fdx = (z_values[i+1][j] - z_values[i-1][j])/2;

			} else if (i == 0) {
				// Forward difference for dx (1 cell)
				grid_coeff[i][j].fdx = z_values[i+1][j] - z_values[i][j];

			} else if (i == (int)(x_values.size()-1)){
				// Backward difference for dx (1 cell)
				grid_coeff[i][j].fdx = z_values[i][j] - z_values[i-1][j];
			}

			if((j != 0) and (j != (int)(y_values.size()-1))){
				// Central difference for dy
				grid_coeff[i][j].fdy = (z_values[i][j+1] - z_values[i][j-1])/2;

			} else if (j == 0) {
				// Forward difference for dy
				grid_coeff[i][j].fdy = z_values[i][j+1] - z_values[i][j];

			} else if (j == (int)(y_values.size()-1)){
				// Backward difference for dy
				grid_coeff[i][j].fdy = z_values[i][j] - z_values[i][j-1];	
			}

		}
	}

	//Now that all axial derivatives have been calculated, use these results to calculate the mixed derivatives

	for(int i=0; i<Lx; ++i){
		for(int j=0; j<Ly; ++j){

			if((i != 0) and (i != (int)(x_values.size()-1))){
				// Central difference for dxy
				grid_coeff[i][j].fdxdy = (grid_coeff[i+1][j].fdy - grid_coeff[i-1][j].fdy)/2;

			} else if (i == 0) {
				// Forward difference for dxy
				grid_coeff[i][j].fdxdy = grid_coeff[i+1][j].fdy - grid_coeff[i][j].fdy;

			} else if (i == (int)(x_values.size()-1)){
				// Backward difference for dxy
				grid_coeff[i][j].fdxdy = grid_coeff[i][j].fdy - grid_coeff[i-1][j].fdy;	
			}

			// std::printf("(%d, %d) = (%f, %f) -> [%f, %f, %f, %f]\n", i, j, x_values[i], y_values[j], grid_coeff[i][j].f, grid_coeff[i][j].fdx, grid_coeff[i][j].fdy, grid_coeff[i][j].fdxdy);
		}
	}

	return grid_coeff;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0xa8(%rbp)
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x1d4d0
movq -0x98(%rbp), %rdi
movl %eax, -0x14(%rbp)
addq $0x18, %rdi
callq 0x1d4d0
movl %eax, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x90(%rbp)
movslq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x26610
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rcx
leaq 0x29945(%rip), %rdx     # 0x4f378
leaq -0x38(%rbp), %rdi
callq 0x26630
jmp 0x25a3e
leaq -0x4d(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x266b0
movq -0xa8(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0xb0(%rbp), %rcx
leaq -0x38(%rbp), %rdx
callq 0x266d0
jmp 0x25a6e
leaq -0x4d(%rbp), %rdi
callq 0x26750
leaq -0x38(%rbp), %rdi
callq 0x26770
leaq -0x39(%rbp), %rdi
callq 0x267d0
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x260c0
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x260b0
leaq -0x54(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x26900
movq %rax, -0xb8(%rbp)
jmp 0x25ac5
movq -0xa8(%rbp), %rdi
movq -0xb8(%rbp), %rax
movq %rax, -0x60(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movq %rax, %rdi
leaq -0x60(%rbp), %rsi
callq 0x26970
movq -0x98(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x5950
movq -0x98(%rbp), %rdi
movq %rax, -0xd0(%rbp)
addq $0x18, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x269a0
movsd %xmm1, -0xc8(%rbp)
movsd %xmm0, -0xc0(%rbp)
jmp 0x25b44
movq -0xa8(%rbp), %rdi
movsd -0xc8(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm1
movsd %xmm1, -0x70(%rbp)
movsd %xmm0, -0x68(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movq %rax, %rdi
addq $0x8, %rdi
leaq -0x70(%rbp), %rsi
callq 0x269e0
movq -0x98(%rbp), %rdi
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movq -0xa8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xd8(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, 0x18(%rax)
cmpl $0x0, -0x54(%rbp)
je 0x25d0e
movq -0x98(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, -0xdc(%rbp)
callq 0x1d4d0
movq %rax, %rcx
movl -0xdc(%rbp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
je 0x25d0e
movq -0x98(%rbp), %rdi
addq $0x30, %rdi
movl -0x54(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xf0(%rbp)
addq $0x30, %rdi
movl -0x54(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movsd -0xf0(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd (%rax), %xmm0
movsd 0x12edc(%rip), %xmm1    # 0x38b60
divsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
jmp 0x25e67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x25ce3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x4d(%rbp), %rdi
callq 0x26750
leaq -0x38(%rbp), %rdi
callq 0x26770
leaq -0x39(%rbp), %rdi
callq 0x267d0
jmp 0x2634b
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x26880
jmp 0x2634b
cmpl $0x0, -0x54(%rbp)
jne 0x25dab
movq -0x98(%rbp), %rdi
addq $0x30, %rdi
movl -0x54(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movsd -0x100(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, -0xf8(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
jmp 0x25e65
movq -0x98(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, -0x104(%rbp)
callq 0x1d4d0
movq %rax, %rcx
movl -0x104(%rbp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
jne 0x25e63
movq -0x98(%rbp), %rdi
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
addq $0x30, %rdi
movl -0x54(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movsd -0x118(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movsd -0x110(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
jmp 0x25e65
jmp 0x25e67
cmpl $0x0, -0x58(%rbp)
je 0x25f43
movq -0x98(%rbp), %rdi
movl -0x58(%rbp), %eax
movl %eax, -0x11c(%rbp)
addq $0x18, %rdi
callq 0x1d4d0
movq %rax, %rcx
movl -0x11c(%rbp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
je 0x25f43
movq -0x98(%rbp), %rdi
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movl -0x58(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x5950
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x130(%rbp)
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movl -0x58(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x5950
movsd -0x130(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd (%rax), %xmm0
movsd 0x12c50(%rip), %xmm1    # 0x38b60
divsd %xmm1, %xmm0
movsd %xmm0, -0x128(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movsd -0x128(%rbp), %xmm0
movsd %xmm0, 0x28(%rax)
jmp 0x260a0
cmpl $0x0, -0x58(%rbp)
jne 0x25fe0
movq -0x98(%rbp), %rdi
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movl -0x58(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x5950
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movsd -0x140(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movsd -0x138(%rbp), %xmm0
movsd %xmm0, 0x28(%rax)
jmp 0x2609e
movq -0x98(%rbp), %rdi
movl -0x58(%rbp), %eax
movl %eax, -0x144(%rbp)
addq $0x18, %rdi
callq 0x1d4d0
movq %rax, %rcx
movl -0x144(%rbp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
jne 0x2609c
movq -0x98(%rbp), %rdi
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x5950
movq -0x98(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x158(%rbp)
addq $0x30, %rdi
movslq -0x54(%rbp), %rsi
callq 0x22870
movq %rax, %rdi
movl -0x58(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x5950
movsd -0x158(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, -0x150(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x26950
movsd -0x150(%rbp), %xmm0
movsd %xmm0, 0x28(%rax)
jmp 0x2609e
jmp 0x260a0
jmp 0x260a2
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x25aa3
jmp 0x260b2
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x25a90
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x26325
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x26315
cmpl $0x0, -0x74(%rbp)
je 0x261b8
movq -0x98(%rbp), %rdi
movl -0x74(%rbp), %eax
movl %eax, -0x15c(%rbp)
callq 0x1d4d0
movq %rax, %rcx
movl -0x15c(%rbp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
je 0x261b8
movq -0xa8(%rbp), %rdi
movl -0x74(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movq -0xa8(%rbp), %rdi
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x170(%rbp)
movl -0x74(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movsd -0x170(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd 0x28(%rax), %xmm0
movsd 0x129db(%rip), %xmm1    # 0x38b60
divsd %xmm1, %xmm0
movsd %xmm0, -0x168(%rbp)
movslq -0x74(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movsd -0x168(%rbp), %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0x26305
cmpl $0x0, -0x74(%rbp)
jne 0x2624f
movq -0xa8(%rbp), %rdi
movl -0x74(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movq -0xa8(%rbp), %rdi
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x180(%rbp)
movslq -0x74(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movsd -0x180(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd 0x28(%rax), %xmm0
movsd %xmm0, -0x178(%rbp)
movslq -0x74(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movsd -0x178(%rbp), %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0x26303
movq -0x98(%rbp), %rdi
movl -0x74(%rbp), %eax
movl %eax, -0x184(%rbp)
callq 0x1d4d0
movq %rax, %rcx
movl -0x184(%rbp), %eax
subq $0x1, %rcx
cmpl %ecx, %eax
jne 0x26301
movq -0xa8(%rbp), %rdi
movslq -0x74(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movq -0xa8(%rbp), %rdi
movsd 0x28(%rax), %xmm0
movsd %xmm0, -0x198(%rbp)
movl -0x74(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movsd -0x198(%rbp), %xmm0
movq -0xa8(%rbp), %rdi
subsd 0x28(%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
movslq -0x74(%rbp), %rsi
callq 0x26930
movq %rax, %rdi
movslq -0x78(%rbp), %rsi
callq 0x26950
movsd -0x190(%rbp), %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0x26303
jmp 0x26305
jmp 0x26307
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x260da
jmp 0x26317
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x260c7
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x2633b
movq -0xa8(%rbp), %rdi
callq 0x26880
movq -0xa0(%rbp), %rax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x45e0
nopw %cs:(%rax,%rax)