mirror of https://github.com/ecmwf/eccodes.git
Refactoring and renaming
This commit is contained in:
parent
735f76d04b
commit
99259d2a4a
|
@ -34,8 +34,8 @@ or edit "iterator.class" and rerun ./make_class.pl
|
|||
|
||||
static void init_class (grib_iterator_class*);
|
||||
|
||||
static int init (grib_iterator* i,grib_handle*,grib_arguments*);
|
||||
static int next (grib_iterator* i, double *lat, double *lon, double *val);
|
||||
static int init (grib_iterator* iter,grib_handle*,grib_arguments*);
|
||||
static int next (grib_iterator* iter, double *lat, double *lon, double *val);
|
||||
|
||||
|
||||
typedef struct grib_iterator_latlon{
|
||||
|
@ -142,25 +142,25 @@ void unrotate(grib_handle* h,
|
|||
*outlon = ret_lon;
|
||||
}
|
||||
|
||||
static int next(grib_iterator* i, double *lat, double *lon, double *val)
|
||||
static int next(grib_iterator* iter, double *lat, double *lon, double *val)
|
||||
{
|
||||
/* GRIB-238: Support rotated lat/lon grids */
|
||||
|
||||
double ret_lat, ret_lon, ret_val;
|
||||
grib_iterator_latlon* self = (grib_iterator_latlon*)i;
|
||||
grib_iterator_latlon* self = (grib_iterator_latlon*)iter;
|
||||
|
||||
if((long)i->e >= (long)(i->nv-1)) return 0;
|
||||
if((long)iter->e >= (long)(iter->nv-1)) return 0;
|
||||
|
||||
i->e++;
|
||||
iter->e++;
|
||||
|
||||
ret_lat = self->las[(long)floor(i->e/self->nap)];
|
||||
ret_lon = self->los[(long)i->e%self->nap];
|
||||
ret_val = i->data[i->e];
|
||||
ret_lat = self->las[(long)floor(iter->e/self->nap)];
|
||||
ret_lon = self->los[(long)iter->e%self->nap];
|
||||
ret_val = iter->data[iter->e];
|
||||
|
||||
if (self->isRotated)
|
||||
{
|
||||
double new_lat = 0, new_lon = 0;
|
||||
unrotate(i->h, ret_lat, ret_lon,
|
||||
unrotate(iter->h, ret_lat, ret_lon,
|
||||
self->angleOfRotation, self->southPoleLat, self->southPoleLon,
|
||||
&new_lat, &new_lon);
|
||||
ret_lat = new_lat;
|
||||
|
@ -173,18 +173,18 @@ static int next(grib_iterator* i, double *lat, double *lon, double *val)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int init(grib_iterator* i,grib_handle* h,grib_arguments* args)
|
||||
static int init(grib_iterator* iter, grib_handle* h,grib_arguments* args)
|
||||
{
|
||||
grib_iterator_latlon* self = (grib_iterator_latlon*)i;
|
||||
grib_iterator_latlon* self = (grib_iterator_latlon*)iter;
|
||||
int ret = GRIB_SUCCESS;
|
||||
double jdir;
|
||||
double laf;
|
||||
double lat1;
|
||||
long jScansPositively;
|
||||
long lai;
|
||||
|
||||
const char* latofirst = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* jdirec = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_jScansPositively = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_lat1 = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_jdir = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_jScansPositively = grib_arguments_get_name(h,args,self->carg++);
|
||||
self->angleOfRotation = 0;
|
||||
self->isRotated = 0;
|
||||
self->southPoleLat = 0;
|
||||
|
@ -197,18 +197,18 @@ static int init(grib_iterator* i,grib_handle* h,grib_arguments* args)
|
|||
if ((ret = grib_get_double_internal(h,"longitudeOfSouthernPoleInDegrees", &self->southPoleLon))) return ret;
|
||||
}
|
||||
|
||||
if((ret = grib_get_double_internal(h,latofirst, &laf))) return ret;
|
||||
if((ret = grib_get_double_internal(h,jdirec, &jdir))) return ret;
|
||||
if((ret = grib_get_double_internal(h,s_lat1, &lat1))) return ret;
|
||||
if((ret = grib_get_double_internal(h,s_jdir, &jdir))) return ret;
|
||||
if((ret = grib_get_long_internal(h,s_jScansPositively,&jScansPositively)))
|
||||
return ret;
|
||||
|
||||
if (jScansPositively) jdir=-jdir;
|
||||
|
||||
for( lai = 0; lai < self->nam; lai++ ) {
|
||||
self->las[lai] = laf;
|
||||
laf -= jdir ;
|
||||
self->las[lai] = lat1;
|
||||
lat1 -= jdir ;
|
||||
}
|
||||
|
||||
i->e = -1;
|
||||
iter->e = -1;
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -134,42 +134,42 @@ static int init(grib_iterator* i,grib_handle* h,grib_arguments* args)
|
|||
grib_iterator_regular* self = (grib_iterator_regular*)i;
|
||||
int ret = GRIB_SUCCESS;
|
||||
|
||||
long nap; /* Number of points along a parallel = Ni */
|
||||
long nam; /* Number of points along a meridian = Nj */
|
||||
double idir, lof,lol;
|
||||
long Ni; /* Number of points along a parallel = Nx */
|
||||
long Nj; /* Number of points along a meridian = Ny */
|
||||
double idir, lon1,lon2;
|
||||
long loi;
|
||||
|
||||
const char* longoffirst = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* idirec = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* nalpar = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* nalmer = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* iScansNegatively = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_lon1 = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_idir = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_Ni = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_Nj = grib_arguments_get_name(h,args,self->carg++);
|
||||
const char* s_iScansNeg = grib_arguments_get_name(h,args,self->carg++);
|
||||
|
||||
if((ret = grib_get_double_internal(h,longoffirst, &lof))) return ret;
|
||||
if((ret = grib_get_double_internal(h,"longitudeOfLastGridPointInDegrees", &lol))) return ret;
|
||||
if((ret = grib_get_double_internal(h,idirec, &idir))) return ret;
|
||||
if((ret = grib_get_long_internal(h,nalpar, &nap))) return ret;
|
||||
if((ret = grib_get_long_internal(h,nalmer, &nam))) return ret;
|
||||
if((ret = grib_get_long_internal(h,iScansNegatively,&self->iScansNegatively)))
|
||||
if((ret = grib_get_double_internal(h, s_lon1, &lon1))) return ret;
|
||||
if((ret = grib_get_double_internal(h, "longitudeOfLastGridPointInDegrees", &lon2))) return ret;
|
||||
if((ret = grib_get_double_internal(h, s_idir, &idir))) return ret;
|
||||
if((ret = grib_get_long_internal(h, s_Ni, &Ni))) return ret;
|
||||
if((ret = grib_get_long_internal(h, s_Nj, &Nj))) return ret;
|
||||
if((ret = grib_get_long_internal(h, s_iScansNeg, &self->iScansNegatively)))
|
||||
return ret;
|
||||
|
||||
/* GRIB-801: Careful of case with a single point! nap==1 */
|
||||
if (nap > 1) {
|
||||
if (Ni > 1) {
|
||||
/* Note: If first and last longitudes are equal I assume you wanna go round the globe */
|
||||
if (self->iScansNegatively) {
|
||||
if (lof > lol){
|
||||
idir=(lof-lol)/(nap-1);
|
||||
if (lon1 > lon2){
|
||||
idir=(lon1-lon2)/(Ni-1);
|
||||
}
|
||||
else {
|
||||
idir=(lof+360.0-lol)/(nap-1);
|
||||
idir=(lon1+360.0-lon2)/(Ni-1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (lol > lof){
|
||||
idir=(lol-lof)/(nap-1);
|
||||
if (lon2 > lon1){
|
||||
idir=(lon2-lon1)/(Ni-1);
|
||||
}
|
||||
else {
|
||||
idir=(lol+360.0-lof)/(nap-1);
|
||||
idir=(lon2+360.0-lon1)/(Ni-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,22 +177,22 @@ static int init(grib_iterator* i,grib_handle* h,grib_arguments* args)
|
|||
idir=-idir;
|
||||
} else {
|
||||
const double epsilon = 1e-6;
|
||||
if (lof+(nap-2)*idir>360) lof-=360;
|
||||
else if ( (lof+(nap-1)*idir)-360 > epsilon ){
|
||||
if (lon1+(Ni-2)*idir>360) lon1-=360;
|
||||
else if ( (lon1+(Ni-1)*idir)-360 > epsilon ){
|
||||
/*See GRIB-396*/
|
||||
idir=360.0/(float)nap;
|
||||
idir=360.0/(float)Ni;
|
||||
}
|
||||
}
|
||||
|
||||
self->nap = nap;
|
||||
self->nam = nam;
|
||||
self->nap = Ni;
|
||||
self->nam = Nj;
|
||||
|
||||
self->las = (double*)grib_context_malloc(h->context,nam*sizeof(double));
|
||||
self->los = (double*)grib_context_malloc(h->context,nap*sizeof(double));
|
||||
self->las = (double*)grib_context_malloc(h->context,Nj*sizeof(double));
|
||||
self->los = (double*)grib_context_malloc(h->context,Ni*sizeof(double));
|
||||
|
||||
for( loi = 0; loi < nap; loi++ ) {
|
||||
self->los[loi] = lof;
|
||||
lof += idir ;
|
||||
for( loi = 0; loi < Ni; loi++ ) {
|
||||
self->los[loi] = lon1;
|
||||
lon1 += idir ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Reference in New Issue