@@ -127,9 +127,10 @@ static inline StatusCode search_indices_vertical_z(type_coord z, int zdim, float
127127 return SUCCESS ;
128128}
129129
130- static inline StatusCode search_indices_vertical_s (type_coord z , int xdim , int ydim , int zdim , float * zvals ,
131- int xi , int yi , int * zi , double xsi , double eta , double * zeta ,
132- int z4d , int ti , int tdim , double time , double t0 , double t1 , int interp_method )
130+ static inline StatusCode search_indices_vertical_s (double time , type_coord z ,
131+ int tdim , int zdim , int ydim , int xdim , float * zvals ,
132+ int ti , int * zi , int yi , int xi , double * zeta , double eta , double xsi ,
133+ int z4d , double t0 , double t1 , int interp_method )
133134{
134135 if (interp_method == BGRID_VELOCITY || interp_method == BGRID_W_VELOCITY || interp_method == BGRID_TRACER ){
135136 xsi = 1 ;
@@ -184,7 +185,7 @@ static inline StatusCode search_indices_vertical_s(type_coord z, int xdim, int y
184185 return SUCCESS ;
185186}
186187
187- static inline void reconnect_bnd_indices (int * xi , int * yi , int xdim , int ydim , int onlyX , int sphere_mesh )
188+ static inline void reconnect_bnd_indices (int * yi , int * xi , int ydim , int xdim , int onlyX , int sphere_mesh )
188189{
189190 if (* xi < 0 ){
190191 if (sphere_mesh )
@@ -211,10 +212,11 @@ static inline void reconnect_bnd_indices(int *xi, int *yi, int xdim, int ydim, i
211212}
212213
213214
214- static inline StatusCode search_indices_rectilinear (type_coord x , type_coord y , type_coord z , CStructuredGrid * grid , GridType gtype ,
215- int * xi , int * yi , int * zi , double * xsi , double * eta , double * zeta ,
216- int ti , double time , double t0 , double t1 , int interp_method ,
217- int gridindexingtype )
215+ static inline StatusCode search_indices_rectilinear (double time , type_coord z , type_coord y , type_coord x ,
216+ CStructuredGrid * grid , GridType gtype ,
217+ int ti , int * zi , int * yi , int * xi , double * zeta , double * eta , double * xsi ,
218+ double t0 , double t1 , int interp_method ,
219+ int gridindexingtype )
218220{
219221 int xdim = grid -> xdim ;
220222 int ydim = grid -> ydim ;
@@ -261,7 +263,7 @@ static inline StatusCode search_indices_rectilinear(type_coord x, type_coord y,
261263 ++ (* xi );
262264 else if (xvalsi > x )
263265 -- (* xi );
264- reconnect_bnd_indices (xi , yi , xdim , ydim , 1 , 1 );
266+ reconnect_bnd_indices (yi , xi , ydim , xdim , 1 , 1 );
265267 xvalsi = xvals [* xi ];
266268 if (xvalsi < x - 225 ) xvalsi += 360 ;
267269 if (xvalsi > x + 225 ) xvalsi -= 360 ;
@@ -294,9 +296,9 @@ static inline StatusCode search_indices_rectilinear(type_coord x, type_coord y,
294296 status = search_indices_vertical_z (z , zdim , zvals , zi , zeta , gridindexingtype );
295297 break ;
296298 case RECTILINEAR_S_GRID :
297- status = search_indices_vertical_s (z , xdim , ydim , zdim , zvals ,
298- * xi , * yi , zi , * xsi , * eta , zeta ,
299- z4d , ti , tdim , time , t0 , t1 , interp_method );
299+ status = search_indices_vertical_s (time , z , tdim , zdim , ydim , xdim , zvals ,
300+ ti , zi , * yi , * xi , zeta , * eta , * xsi ,
301+ z4d , t0 , t1 , interp_method );
300302 break ;
301303 default :
302304 status = ERRORINTERPOLATION ;
@@ -321,10 +323,12 @@ static inline StatusCode search_indices_rectilinear(type_coord x, type_coord y,
321323}
322324
323325
324- static inline StatusCode search_indices_curvilinear (type_coord x , type_coord y , type_coord z , CStructuredGrid * grid , GridType gtype ,
325- int * xi , int * yi , int * zi , double * xsi , double * eta , double * zeta ,
326- int ti , double time , double t0 , double t1 , int interp_method ,
327- int gridindexingtype )
326+ static inline StatusCode search_indices_curvilinear (double time , type_coord z , type_coord y , type_coord x ,
327+ CStructuredGrid * grid , GridType gtype ,
328+ int ti , int * zi , int * yi , int * xi ,
329+ double * zeta , double * eta , double * xsi ,
330+ double t0 , double t1 , int interp_method ,
331+ int gridindexingtype )
328332{
329333 int xi_old = * xi ;
330334 int yi_old = * yi ;
@@ -407,23 +411,23 @@ static inline StatusCode search_indices_curvilinear(type_coord x, type_coord y,
407411 (* yi )-- ;
408412 if (* eta > 1 + tol )
409413 (* yi )++ ;
410- reconnect_bnd_indices (xi , yi , xdim , ydim , 0 , sphere_mesh );
414+ reconnect_bnd_indices (yi , xi , ydim , xdim , 0 , sphere_mesh );
411415 it ++ ;
412416 if ( it > maxIterSearch ){
413- printf ("Correct cell not found for (%f, %f) after %d iterations\n" , x , y , maxIterSearch );
417+ printf ("Correct cell not found for (lat, lon) = ( %f, %f) after %d iterations\n" , y , x , maxIterSearch );
414418 printf ("Debug info: old particle indices: (yi, xi) %d %d\n" , yi_old , xi_old );
415419 printf (" new particle indices: (yi, xi) %d %d\n" , * yi , * xi );
416420 printf (" Mesh 2d shape: %d %d\n" , ydim , xdim );
417- printf (" Relative particle position: (xsi, eta ) %1.16e %1.16e\n" , * xsi , * eta );
421+ printf (" Relative particle position: (eta, xsi ) %1.16e %1.16e\n" , * eta , * xsi );
418422 return ERROROUTOFBOUNDS ;
419423 }
420424 }
421425 if ( (* xsi != * xsi ) || (* eta != * eta ) ){ // check if nan
422- printf ("Correct cell not found for (%f, %f))\n" , x , y );
426+ printf ("Correct cell not found for (lat, lon) = ( %f, %f))\n" , y , x );
423427 printf ("Debug info: old particle indices: (yi, xi) %d %d\n" , yi_old , xi_old );
424428 printf (" new particle indices: (yi, xi) %d %d\n" , * yi , * xi );
425429 printf (" Mesh 2d shape: %d %d\n" , ydim , xdim );
426- printf (" Relative particle position: (xsi, eta ) %1.16e %1.16e\n" , * xsi , * eta );
430+ printf (" Relative particle position: (eta, xsi ) %1.16e %1.16e\n" , * eta , * xsi );
427431 return ERROROUTOFBOUNDS ;
428432 }
429433 if (* xsi < 0 ) * xsi = 0 ;
@@ -438,9 +442,9 @@ static inline StatusCode search_indices_curvilinear(type_coord x, type_coord y,
438442 status = search_indices_vertical_z (z , zdim , zvals , zi , zeta , gridindexingtype );
439443 break ;
440444 case CURVILINEAR_S_GRID :
441- status = search_indices_vertical_s (z , xdim , ydim , zdim , zvals ,
442- * xi , * yi , zi , * xsi , * eta , zeta ,
443- z4d , ti , tdim , time , t0 , t1 , interp_method );
445+ status = search_indices_vertical_s (time , z , tdim , ydim , xdim , zdim , zvals ,
446+ ti , zi , * yi , * xi , zeta , * eta , * xsi ,
447+ z4d , t0 , t1 , interp_method );
444448 break ;
445449 default :
446450 status = ERRORINTERPOLATION ;
@@ -460,21 +464,23 @@ static inline StatusCode search_indices_curvilinear(type_coord x, type_coord y,
460464/* Local linear search to update grid index
461465 * params ti, sizeT, time. t0, t1 are only used for 4D S grids
462466 * */
463- static inline StatusCode search_indices (type_coord x , type_coord y , type_coord z , CStructuredGrid * grid ,
464- int * xi , int * yi , int * zi , double * xsi , double * eta , double * zeta ,
465- GridType gtype , int ti , double time , double t0 , double t1 , int interp_method ,
466- int gridindexingtype )
467+ static inline StatusCode search_indices (double time , type_coord z , type_coord y , type_coord x ,
468+ CStructuredGrid * grid ,
469+ int ti , int * zi , int * yi , int * xi ,
470+ double * zeta , double * eta , double * xsi ,
471+ GridType gtype , double t0 , double t1 , int interp_method ,
472+ int gridindexingtype )
467473{
468474 switch (gtype ){
469475 case RECTILINEAR_Z_GRID :
470476 case RECTILINEAR_S_GRID :
471- return search_indices_rectilinear (x , y , z , grid , gtype , xi , yi , zi , xsi , eta , zeta ,
472- ti , time , t0 , t1 , interp_method , gridindexingtype );
477+ return search_indices_rectilinear (time , z , y , x , grid , gtype , ti , zi , yi , xi , zeta , eta , xsi ,
478+ t0 , t1 , interp_method , gridindexingtype );
473479 break ;
474480 case CURVILINEAR_Z_GRID :
475481 case CURVILINEAR_S_GRID :
476- return search_indices_curvilinear (x , y , z , grid , gtype , xi , yi , zi , xsi , eta , zeta ,
477- ti , time , t0 , t1 , interp_method , gridindexingtype );
482+ return search_indices_curvilinear (time , z , y , x , grid , gtype , ti , zi , yi , xi , zeta , eta , xsi ,
483+ t0 , t1 , interp_method , gridindexingtype );
478484 break ;
479485 default :
480486 printf ("Only RECTILINEAR_Z_GRID, RECTILINEAR_S_GRID, CURVILINEAR_Z_GRID and CURVILINEAR_S_GRID grids are currently implemented\n" );
0 commit comments