/*
cnode.c

I on node
*/

#include "oth.h"
#include "complex.h"
#include "oth_prototype.h"

void cnode(int f, int i, int j, int k, d_complex_t c[])
{
	assert((f >= 0) && (f < NFrequency));
	assert((i >= 0) && (i <= Nx) && (j >= 0) && (j <= Ny) && (k >= 0) && (k <= Nz));

	// Ix
	d_complex_t cxp = (i < Nx) ? cxyee(f, i,     j,     k    ) : cxyee(f, i - 1, j,     k    );
	d_complex_t cxm = (i >  0) ? cxyee(f, i - 1, j,     k    ) : cxyee(f, i,     j,     k    );
	c[0] = d_rmul(0.5, d_add(cxp, cxm));

	// Iy
	d_complex_t cyp = (j < Ny) ? cyyee(f, i,     j,     k    ) : cyyee(f, i,     j - 1, k    );
	d_complex_t cym = (j >  0) ? cyyee(f, i,     j - 1, k    ) : cyyee(f, i,     j,     k    );
	c[1] = d_rmul(0.5, d_add(cyp, cym));

	// Iz
	d_complex_t czp = (k < Nz) ? czyee(f, i,     j,     k    ) : czyee(f, i,     j,     k - 1);
	d_complex_t czm = (k >  0) ? czyee(f, i,     j,     k - 1) : czyee(f, i,     j,     k    );
	c[2] = d_rmul(0.5, d_add(czp, czm));
}
