Refactoring and preparation for GRIB-70: take into account chemical and aerosol PDTNs

This commit is contained in:
Shahram Najm 2013-08-01 17:08:20 +01:00
parent 7e34d69386
commit 966ea699a8
4 changed files with 508 additions and 490 deletions

View File

@ -142,97 +142,94 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c) static void init(grib_accessor* a,const long l, grib_arguments* c)
{ {
grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a; grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a;
int n = 0; int n = 0;
self->productDefinitionTemplateNumber = grib_arguments_get_name(a->parent->h,c,n++);
self->type = grib_arguments_get_name(a->parent->h,c,n++);
self->stream = grib_arguments_get_name(a->parent->h,c,n++);
self->stepType = grib_arguments_get_name(a->parent->h,c,n++);
self->derivedForecast = grib_arguments_get_name(a->parent->h,c,n++);
self->productDefinitionTemplateNumber = grib_arguments_get_name(a->parent->h,c,n++);
self->type = grib_arguments_get_name(a->parent->h,c,n++);
self->stream = grib_arguments_get_name(a->parent->h,c,n++);
self->stepType = grib_arguments_get_name(a->parent->h,c,n++);
self->derivedForecast = grib_arguments_get_name(a->parent->h,c,n++);
} }
static int unpack_long (grib_accessor* a, long* val, size_t *len) static int unpack_long(grib_accessor* a, long* val, size_t *len)
{ {
grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a; grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a;
long productDefinitionTemplateNumber=0; long productDefinitionTemplateNumber=0;
grib_get_long(a->parent->h, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber); grib_get_long(a->parent->h, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber);
*val=0; *val=0;
if (productDefinitionTemplateNumber==1 || productDefinitionTemplateNumber==11) if (is_productDefinitionTemplateNumber_EPS(productDefinitionTemplateNumber))
*val=1; *val=1;
return GRIB_SUCCESS; return GRIB_SUCCESS;
} }
static int pack_long(grib_accessor* a, const long* val, size_t *len) static int pack_long(grib_accessor* a, const long* val, size_t *len)
{ {
grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a; grib_accessor_g2_eps* self = (grib_accessor_g2_eps*)a;
long productDefinitionTemplateNumber=-1; long productDefinitionTemplateNumber=-1;
long productDefinitionTemplateNumberNew=-1; long productDefinitionTemplateNumberNew=-1;
long type=-1; long type=-1;
long stream=-1; long stream=-1;
char stepType[15]={0,}; char stepType[15]={0,};
size_t slen=15; size_t slen=15;
int eps=*val; int eps=*val;
int isInstant=0; int isInstant=0;
long derivedForecast=-1; long derivedForecast=-1;
if (grib_get_long(a->parent->h, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber)!=GRIB_SUCCESS) if (grib_get_long(a->parent->h, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber)!=GRIB_SUCCESS)
return GRIB_SUCCESS; return GRIB_SUCCESS;
grib_get_long(a->parent->h, self->type,&type); grib_get_long(a->parent->h, self->type,&type);
grib_get_long(a->parent->h, self->stream,&stream); grib_get_long(a->parent->h, self->stream,&stream);
grib_get_string(a->parent->h, self->stepType,stepType,&slen); grib_get_string(a->parent->h, self->stepType,stepType,&slen);
if (!strcmp(stepType,"instant")) isInstant=1; if (!strcmp(stepType,"instant")) isInstant=1;
/* eps or enda or elda or ewla */ /* eps or stream=(enda or elda or ewla) */
if ( eps || stream==1030 || stream==1249 || stream==1250 ) { if ( eps || stream==1030 || stream==1249 || stream==1250 ) {
if (isInstant) { if (isInstant) {
/* type=em || type=es */ /* type=em || type=es */
if (type==17) { if (type==17) {
productDefinitionTemplateNumberNew=2; productDefinitionTemplateNumberNew=2;
derivedForecast=0; derivedForecast=0;
} else if (type==18) { } else if (type==18) {
productDefinitionTemplateNumberNew=2; productDefinitionTemplateNumberNew=2;
derivedForecast=4; derivedForecast=4;
} else { } else {
productDefinitionTemplateNumberNew=1; productDefinitionTemplateNumberNew=1;
} }
} else { } else {
/* type=em || type=es */ /* type=em || type=es */
if (type==17) { if (type==17) {
productDefinitionTemplateNumberNew=12; productDefinitionTemplateNumberNew=12;
derivedForecast=0; derivedForecast=0;
} else if (type==18) { } else if (type==18) {
productDefinitionTemplateNumberNew=12; productDefinitionTemplateNumberNew=12;
derivedForecast=4; derivedForecast=4;
} else { } else {
productDefinitionTemplateNumberNew=11; productDefinitionTemplateNumberNew=11;
} }
} }
} else { } else {
if (isInstant) { if (isInstant) {
productDefinitionTemplateNumberNew=0; productDefinitionTemplateNumberNew=0;
} else { } else {
productDefinitionTemplateNumberNew=8; productDefinitionTemplateNumberNew=8;
} }
} }
if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) {
grib_set_long(a->parent->h, self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew); grib_set_long(a->parent->h, self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew);
if (derivedForecast>=0) if (derivedForecast>=0)
grib_set_long(a->parent->h, self->derivedForecast,derivedForecast); grib_set_long(a->parent->h, self->derivedForecast,derivedForecast);
} }
return 0; return 0;
} }
static long value_count(grib_accessor* a) static long value_count(grib_accessor* a)
{ {
return 1; return 1;
} }

View File

@ -150,366 +150,366 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c) static void init(grib_accessor* a,const long l, grib_arguments* c)
{ {
grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a;
int n = 0; int n = 0;
self->index = grib_arguments_get_long(a->parent->h,c,n++); self->index = grib_arguments_get_long(a->parent->h,c,n++);
self->class = grib_arguments_get_name(a->parent->h,c,n++); self->class = grib_arguments_get_name(a->parent->h,c,n++);
self->type = grib_arguments_get_name(a->parent->h,c,n++); self->type = grib_arguments_get_name(a->parent->h,c,n++);
self->stream = grib_arguments_get_name(a->parent->h,c,n++); self->stream = grib_arguments_get_name(a->parent->h,c,n++);
self->expver = grib_arguments_get_name(a->parent->h,c,n++); self->expver = grib_arguments_get_name(a->parent->h,c,n++);
self->typeOfProcessedData = grib_arguments_get_name(a->parent->h,c,n++); self->typeOfProcessedData = grib_arguments_get_name(a->parent->h,c,n++);
self->productDefinitionTemplateNumber = grib_arguments_get_name(a->parent->h,c,n++); self->productDefinitionTemplateNumber = grib_arguments_get_name(a->parent->h,c,n++);
self->stepType = grib_arguments_get_name(a->parent->h,c,n++); self->stepType = grib_arguments_get_name(a->parent->h,c,n++);
self->derivedForecast = grib_arguments_get_name(a->parent->h,c,n++); self->derivedForecast = grib_arguments_get_name(a->parent->h,c,n++);
self->typeOfGeneratingProcess = grib_arguments_get_name(a->parent->h,c,n++); self->typeOfGeneratingProcess = grib_arguments_get_name(a->parent->h,c,n++);
} }
static int unpack_long (grib_accessor* a, long* val, size_t *len) static int unpack_long(grib_accessor* a, long* val, size_t *len)
{ {
grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a;
char* key=NULL; char* key=NULL;
switch (self->index) { switch (self->index) {
case 0: case 0:
key=(char*)self->class; key=(char*)self->class;
break; break;
case 1: case 1:
key=(char*)self->type; key=(char*)self->type;
break; break;
case 2: case 2:
key=(char*)self->stream; key=(char*)self->stream;
break; break;
default : default :
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR, grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"invalid first argument of g2_mars_labeling in %s",a->name); "invalid first argument of g2_mars_labeling in %s",a->name);
return GRIB_INTERNAL_ERROR; return GRIB_INTERNAL_ERROR;
break; break;
} }
return grib_get_long(a->parent->h, key,val); return grib_get_long(a->parent->h, key,val);
} }
static int unpack_string (grib_accessor* a, char* val, size_t *len) static int unpack_string(grib_accessor* a, char* val, size_t *len)
{ {
grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a;
char* key=NULL; char* key=NULL;
switch (self->index) { switch (self->index) {
case 0: case 0:
key=(char*)self->class; key=(char*)self->class;
break; break;
case 1: case 1:
key=(char*)self->type; key=(char*)self->type;
break; break;
case 2: case 2:
key=(char*)self->stream; key=(char*)self->stream;
break; break;
default : default :
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR, grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"invalid first argument of g2_mars_labeling in %s",a->name); "invalid first argument of g2_mars_labeling in %s",a->name);
return GRIB_INTERNAL_ERROR; return GRIB_INTERNAL_ERROR;
break; break;
} }
return grib_get_string(a->parent->h, key,val,len); return grib_get_string(a->parent->h, key,val,len);
} }
static int extra_set(grib_accessor* a,long val) { static int extra_set(grib_accessor* a,long val)
int ret=0; {
grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; int ret=0;
char stepType[30]={0,}; grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a;
size_t stepTypelen=30; char stepType[30]={0,};
long derivedForecast=-1; size_t stepTypelen=30;
long productDefinitionTemplateNumberNew=-1; long derivedForecast=-1;
long productDefinitionTemplateNumber; long productDefinitionTemplateNumberNew=-1;
long typeOfProcessedData=-1; long productDefinitionTemplateNumber;
long typeOfGeneratingProcess=-1; long typeOfProcessedData=-1;
long typeOfGeneratingProcess=-1;
switch (self->index) { switch (self->index) {
case 0: case 0:
/* class */ /* class */
return ret; return ret;
break; break;
case 1: case 1:
/* type */ /* type */
switch (val) { switch (val) {
case 0: /* Unknown (0) */ case 0: /* Unknown (0) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=255; typeOfGeneratingProcess=255;
break; break;
case 1: /* First guess (fg) */ case 1: /* First guess (fg) */
case 3: /* Initialised analysis (ia) */ case 3: /* Initialised analysis (ia) */
typeOfProcessedData=0; typeOfProcessedData=0;
typeOfGeneratingProcess=1; typeOfGeneratingProcess=1;
break; break;
case 2: /* Analysis (an) */ case 2: /* Analysis (an) */
case 4: /* Oi analysis (oi) */ case 4: /* Oi analysis (oi) */
case 5: /* 3d variational analysis (3v) */ case 5: /* 3d variational analysis (3v) */
case 6: /* 4d variational analysis (4v) */ case 6: /* 4d variational analysis (4v) */
case 7: /* 3d variational gradients (3g) */ case 7: /* 3d variational gradients (3g) */
case 8: /* 4d variational gradients (4g) */ case 8: /* 4d variational gradients (4g) */
typeOfProcessedData=0; typeOfProcessedData=0;
typeOfGeneratingProcess=0; typeOfGeneratingProcess=0;
break; break;
case 9: /* Forecast (fc) */ case 9: /* Forecast (fc) */
typeOfProcessedData=1; typeOfProcessedData=1;
typeOfGeneratingProcess=2; typeOfGeneratingProcess=2;
break; break;
case 10: /* Control forecast (cf) */ case 10: /* Control forecast (cf) */
typeOfProcessedData=3; typeOfProcessedData=3;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
case 11: /* Perturbed forecast (pf) */ case 11: /* Perturbed forecast (pf) */
typeOfProcessedData=4; typeOfProcessedData=4;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
case 12: /* Errors in first guess (ef) */ case 12: /* Errors in first guess (ef) */
case 13: /* Errors in analysis (ea) */ case 13: /* Errors in analysis (ea) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=7; typeOfGeneratingProcess=7;
break; break;
case 14: /* Cluster means (cm) */ case 14: /* Cluster means (cm) */
case 15: /* Cluster std deviations (cs) */ case 15: /* Cluster std deviations (cs) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
case 16: /* Forecast probability (fp) */ case 16: /* Forecast probability (fp) */
typeOfProcessedData=8; typeOfProcessedData=8;
typeOfGeneratingProcess=5; typeOfGeneratingProcess=5;
break; break;
case 17: /* Ensemble mean (em) */ case 17: /* Ensemble mean (em) */
derivedForecast=0; derivedForecast=0;
grib_get_string(a->parent->h,self->stepType,stepType,&stepTypelen); grib_get_string(a->parent->h,self->stepType,stepType,&stepTypelen);
if (!strcmp(stepType,"instant")) { if (!strcmp(stepType,"instant")) {
productDefinitionTemplateNumberNew=2; productDefinitionTemplateNumberNew=2;
} else { } else {
productDefinitionTemplateNumberNew=12; productDefinitionTemplateNumberNew=12;
} }
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
case 18: /* Ensemble standard deviation (es) */ case 18: /* Ensemble standard deviation (es) */
derivedForecast=4; derivedForecast=4;
grib_get_string(a->parent->h,self->stepType,stepType,&stepTypelen); grib_get_string(a->parent->h,self->stepType,stepType,&stepTypelen);
if (!strcmp(stepType,"instant")) { if (!strcmp(stepType,"instant")) {
productDefinitionTemplateNumberNew=2; productDefinitionTemplateNumberNew=2;
} else { } else {
productDefinitionTemplateNumberNew=12; productDefinitionTemplateNumberNew=12;
} }
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
case 19: /* Forecast accumulation (fa) */ case 19: /* Forecast accumulation (fa) */
case 20: /* Climatology (cl) */ case 20: /* Climatology (cl) */
case 21: /* Climate simulation (si) */ case 21: /* Climate simulation (si) */
case 22: /* Climate 30 days simulation (s3) */ case 22: /* Climate 30 days simulation (s3) */
case 23: /* Empirical distribution (ed) */ case 23: /* Empirical distribution (ed) */
case 24: /* Tubes (tu) */ case 24: /* Tubes (tu) */
case 25: /* Flux forcing realtime (ff) */ case 25: /* Flux forcing realtime (ff) */
case 26: /* Ocean forward (of) */ case 26: /* Ocean forward (of) */
case 27: /* Extreme forecast index (efi) */ case 27: /* Extreme forecast index (efi) */
case 28: /* Extreme forecast index control (efic)*/ case 28: /* Extreme forecast index control (efic)*/
case 29: /* Probability boundaries (pb) */ case 29: /* Probability boundaries (pb) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=255; typeOfGeneratingProcess=255;
break; break;
case 30: /* Event probability (ep) */ case 30: /* Event probability (ep) */
typeOfProcessedData=8; typeOfProcessedData=8;
typeOfGeneratingProcess=5; typeOfGeneratingProcess=5;
break; break;
case 31: /* Bias-corrected Forecast (bf) */ case 31: /* Bias-corrected Forecast (bf) */
typeOfProcessedData=1; typeOfProcessedData=1;
typeOfGeneratingProcess=3; typeOfGeneratingProcess=3;
break; break;
case 32: /* Climate distribution (cd) */ case 32: /* Climate distribution (cd) */
case 33: /* 4D analysis increments (4i) */ case 33: /* 4D analysis increments (4i) */
case 34: /* Gridded observations (go) */ case 34: /* Gridded observations (go) */
case 35: /* Model errors (me) */ case 35: /* Model errors (me) */
case 36: /* Probability distribution (pd) */ case 36: /* Probability distribution (pd) */
case 37: /* Cluster information (ci) */ case 37: /* Cluster information (ci) */
case 38: /* Shift of Tail (sot) */ case 38: /* Shift of Tail (sot) */
case 40: /* Images (im) */ case 40: /* Images (im) */
case 42: /* Simulated images (sim) */ case 42: /* Simulated images (sim) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=255; typeOfGeneratingProcess=255;
break; break;
case 43: /* Weighted ensemble mean (wem) */ case 43: /* Weighted ensemble mean (wem) */
case 44: /* Weighted ensemble standard deviation (wes) */ case 44: /* Weighted ensemble standard deviation (wes) */
case 45: /* Cluster representative (cr) */ case 45: /* Cluster representative (cr) */
case 46: /* Scaled ensemble standard deviation (ses) */ case 46: /* Scaled ensemble standard deviation (ses) */
case 47: /* Time average ensemble mean (taem) */ case 47: /* Time average ensemble mean (taem) */
case 48: /* Time average ensemble standard deviation (taes) */ case 48: /* Time average ensemble standard deviation (taes) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
case 50: /* Sensitivity gradient (sg) */ case 50: /* Sensitivity gradient (sg) */
case 52: /* Sensitivity forecast (sf) */ case 52: /* Sensitivity forecast (sf) */
case 60: /* Perturbed analysis (pa) */ case 60: /* Perturbed analysis (pa) */
case 61: /* Initial condition perturbation (icp) */ case 61: /* Initial condition perturbation (icp) */
case 62: /* Singular vector (sv) */ case 62: /* Singular vector (sv) */
case 63: /* Adjoint singular vector (as) */ case 63: /* Adjoint singular vector (as) */
case 64: /* Signal variance (svar) */ case 64: /* Signal variance (svar) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=255; typeOfGeneratingProcess=255;
break; break;
case 65: /* Calibration/Validation forecast (cv) */ case 65: /* Calibration/Validation forecast (cv) */
typeOfProcessedData=5; typeOfProcessedData=5;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
case 70: /* Ocean reanalysis (or) */ case 70: /* Ocean reanalysis (or) */
case 71: /* Flux forcing (fx) */ case 71: /* Flux forcing (fx) */
case 80: /* Forecast mean (fcmean) */ case 80: /* Forecast mean (fcmean) */
case 81: /* Forecast maximum (fcmax) */ case 81: /* Forecast maximum (fcmax) */
case 82: /* Forecast minimum (fcmin) */ case 82: /* Forecast minimum (fcmin) */
case 83: /* Forecast standard deviation (fcstdev) */ case 83: /* Forecast standard deviation (fcstdev) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=255; typeOfGeneratingProcess=255;
break; break;
case 84: /* Ensemble mean of temporal mean (emtm) */ case 84: /* Ensemble mean of temporal mean (emtm) */
case 85: /* Ensemble standard deviation of temporal mean (estdtm) */ case 85: /* Ensemble standard deviation of temporal mean (estdtm) */
typeOfProcessedData=255; typeOfProcessedData=255;
typeOfGeneratingProcess=4; typeOfGeneratingProcess=4;
break; break;
default : default :
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,"unknown mars.type %d",(int)val); grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,"unknown mars.type %d",(int)val);
return GRIB_ENCODING_ERROR; return GRIB_ENCODING_ERROR;
} }
case 2: case 2:
/* stream */ /* stream */
switch (val) { switch (val) {
case 1030: /* enda */ case 1030: /* enda */
case 1249: /* elda */ case 1249: /* elda */
case 1250: /* ewla */ case 1250: /* ewla */
grib_get_string(a->parent->h,self->stepType,stepType,&stepTypelen); grib_get_string(a->parent->h,self->stepType,stepType,&stepTypelen);
if (!strcmp(stepType,"instant")) { if (!strcmp(stepType,"instant")) {
productDefinitionTemplateNumberNew=1; productDefinitionTemplateNumberNew=1;
} else { } else {
productDefinitionTemplateNumberNew=11; productDefinitionTemplateNumberNew=11;
} }
break; break;
} }
break; break;
default : default :
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR, grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"invalid first argument of g2_mars_labeling in %s",a->name); "invalid first argument of g2_mars_labeling in %s",a->name);
return GRIB_INTERNAL_ERROR; return GRIB_INTERNAL_ERROR;
break; break;
} }
if (productDefinitionTemplateNumberNew>=0) { if (productDefinitionTemplateNumberNew>=0) {
grib_get_long(a->parent->h,self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber); grib_get_long(a->parent->h,self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber);
if (productDefinitionTemplateNumber!=productDefinitionTemplateNumberNew) if (productDefinitionTemplateNumber!=productDefinitionTemplateNumberNew)
grib_set_long(a->parent->h,self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew); grib_set_long(a->parent->h,self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew);
} }
if (derivedForecast>=0) { if (derivedForecast>=0) {
grib_set_long(a->parent->h,self->derivedForecast,derivedForecast); grib_set_long(a->parent->h,self->derivedForecast,derivedForecast);
} }
if (typeOfProcessedData>0) if (typeOfProcessedData>0)
grib_set_long(a->parent->h,self->typeOfProcessedData,typeOfProcessedData); grib_set_long(a->parent->h,self->typeOfProcessedData,typeOfProcessedData);
if (typeOfGeneratingProcess>0) if (typeOfGeneratingProcess>0)
grib_set_long(a->parent->h,self->typeOfGeneratingProcess,typeOfGeneratingProcess); grib_set_long(a->parent->h,self->typeOfGeneratingProcess,typeOfGeneratingProcess);
return ret; return ret;
} }
static int pack_string(grib_accessor* a, const char* val, size_t *len) static int pack_string(grib_accessor* a, const char* val, size_t *len)
{ {
grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a;
char* key=NULL; char* key=NULL;
int ret=0; int ret=0;
long lval=0; long lval=0;
switch (self->index) { switch (self->index) {
case 0: case 0:
key=(char*)self->class; key=(char*)self->class;
break; break;
case 1: case 1:
key=(char*)self->type; key=(char*)self->type;
break; break;
case 2: case 2:
key=(char*)self->stream; key=(char*)self->stream;
break; break;
default : default :
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR, grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"invalid first argument of g2_mars_labeling in %s",a->name); "invalid first argument of g2_mars_labeling in %s",a->name);
return GRIB_INTERNAL_ERROR; return GRIB_INTERNAL_ERROR;
break; break;
} }
ret=grib_set_string(a->parent->h, key,val,len); ret=grib_set_string(a->parent->h, key,val,len);
if (ret) return ret; if (ret) return ret; /* failed */
ret=grib_get_long(a->parent->h, key,&lval); ret=grib_get_long(a->parent->h, key,&lval);
if (ret) return ret; if (ret) return ret; /* failed */
return extra_set(a,lval); return extra_set(a,lval);
} }
static int pack_long(grib_accessor* a, const long* val, size_t *len) static int pack_long(grib_accessor* a, const long* val, size_t *len)
{ {
grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a;
char* key=NULL; char* key=NULL;
int ret=0; int ret=0;
switch (self->index) { switch (self->index) {
case 0: case 0:
key=(char*)self->class; key=(char*)self->class;
break; break;
case 1: case 1:
key=(char*)self->type; key=(char*)self->type;
break; break;
case 2: case 2:
key=(char*)self->stream; key=(char*)self->stream;
break; break;
default : default :
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR, grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"invalid first argument of g2_mars_labeling in %s",a->name); "invalid first argument of g2_mars_labeling in %s",a->name);
return GRIB_INTERNAL_ERROR; return GRIB_INTERNAL_ERROR;
break; break;
} }
ret=grib_set_long(a->parent->h, key,*val); ret=grib_set_long(a->parent->h, key,*val);
if (ret) return ret; if (ret) return ret; /* failed */
return extra_set(a,*val); return extra_set(a,*val);
} }
static long value_count(grib_accessor* a) static long value_count(grib_accessor* a)
{ {
return 1; return 1;
} }
static int get_native_type(grib_accessor* a) static int get_native_type(grib_accessor* a)
{ {
grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a; grib_accessor_g2_mars_labeling* self = (grib_accessor_g2_mars_labeling*)a;
char* key=NULL; char* key=NULL;
int ret=0; int ret=0;
int type=0; int type=0;
switch (self->index) { switch (self->index) {
case 0: case 0:
key=(char*)self->class; key=(char*)self->class;
break; break;
case 1: case 1:
key=(char*)self->type; key=(char*)self->type;
break; break;
case 2: case 2:
key=(char*)self->stream; key=(char*)self->stream;
break; break;
default : default :
grib_context_log(a->parent->h->context,GRIB_LOG_ERROR, grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"invalid first argument of g2_mars_labeling in %s",a->name); "invalid first argument of g2_mars_labeling in %s",a->name);
return GRIB_INTERNAL_ERROR; return GRIB_INTERNAL_ERROR;
break; break;
} }
ret=grib_get_native_type(a->parent->h,key,&type); ret=grib_get_native_type(a->parent->h,key,&type);
if (ret) grib_context_log(a->parent->h->context,GRIB_LOG_ERROR, if (ret) grib_context_log(a->parent->h->context,GRIB_LOG_ERROR,
"unable to get native type for %s",key); "unable to get native type for %s",key);
return type; return type;
} }

View File

@ -204,7 +204,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len)
if (!strcmp(stepType,"instant")) isInstant=1; if (!strcmp(stepType,"instant")) isInstant=1;
grib_get_long(a->parent->h, self->grib2LocalSectionNumber,&grib2LocalSectionNumber); grib_get_long(a->parent->h, self->grib2LocalSectionNumber,&grib2LocalSectionNumber);
if (productDefinitionTemplateNumber==1 || productDefinitionTemplateNumber==11) if (is_productDefinitionTemplateNumber_EPS(productDefinitionTemplateNumber))
eps=1; eps=1;
switch (localDefinitionNumber) { switch (localDefinitionNumber) {
@ -221,7 +221,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len)
case 36: /* MARS labelling for long window 4Dvar system */ case 36: /* MARS labelling for long window 4Dvar system */
case 40: /* MARS labeling with domain and model (for LAM) */ case 40: /* MARS labeling with domain and model (for LAM) */
if (isInstant) { if (isInstant) {
/* type=em || type=es */ /* type=em || type=es */
if (type==17) { if (type==17) {
productDefinitionTemplateNumberNew=2; productDefinitionTemplateNumberNew=2;
derivedForecast=0; derivedForecast=0;
@ -306,4 +306,3 @@ static long value_count(grib_accessor* a)
{ {
return 1; return 1;
} }

View File

@ -136,115 +136,137 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c) static void init(grib_accessor* a,const long l, grib_arguments* c)
{ {
grib_accessor_select_step_template* self = (grib_accessor_select_step_template*)a; grib_accessor_select_step_template* self = (grib_accessor_select_step_template*)a;
int n = 0; int n = 0;
self->productDefinitionTemplateNumber = grib_arguments_get_name(a->parent->h,c,n++);
self->instant = grib_arguments_get_long(a->parent->h,c,n++);
self->productDefinitionTemplateNumber = grib_arguments_get_name(a->parent->h,c,n++);
self->instant = grib_arguments_get_long(a->parent->h,c,n++);
} }
static int unpack_long (grib_accessor* a, long* val, size_t *len) static int unpack_long(grib_accessor* a, long* val, size_t *len)
{ {
*val=1; *val=1;
return GRIB_SUCCESS; return GRIB_SUCCESS;
} }
static int pack_long(grib_accessor* a, const long* val, size_t* len)
static int pack_long(grib_accessor* a, const long* val, size_t *len)
{ {
grib_accessor_select_step_template* self = (grib_accessor_select_step_template*)a; grib_accessor_select_step_template* self = (grib_accessor_select_step_template*)a;
long productDefinitionTemplateNumber=0; long productDefinitionTemplateNumber=0;
long productDefinitionTemplateNumberNew=0; long productDefinitionTemplateNumberNew=0;
grib_get_long(a->parent->h, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber); grib_get_long(a->parent->h, self->productDefinitionTemplateNumber,&productDefinitionTemplateNumber);
if (self->instant) { if (self->instant) {
switch (productDefinitionTemplateNumber) { /* Going from continuous or non-continuous interval to a point-in-time (instantaneous) */
case 8: switch (productDefinitionTemplateNumber) {
productDefinitionTemplateNumberNew=0; case 8:
break; productDefinitionTemplateNumberNew=0;
case 9: break;
productDefinitionTemplateNumberNew=5; case 9:
break; productDefinitionTemplateNumberNew=5;
case 10: break;
productDefinitionTemplateNumberNew=6; case 10:
break; productDefinitionTemplateNumberNew=6;
case 11: break;
productDefinitionTemplateNumberNew=1; case 11:
break; productDefinitionTemplateNumberNew=1;
case 12: break;
productDefinitionTemplateNumberNew=2; case 12:
break; productDefinitionTemplateNumberNew=2;
case 13: break;
productDefinitionTemplateNumberNew=3; case 13:
break; productDefinitionTemplateNumberNew=3;
case 14: break;
productDefinitionTemplateNumberNew=4; case 14:
break; productDefinitionTemplateNumberNew=4;
case 0: break;
case 1: case 42: /* non-EPS chemical */
case 2: productDefinitionTemplateNumberNew=40;
case 3: break;
case 4: case 43: /* EPS chemical */
case 5: productDefinitionTemplateNumberNew=41;
case 6: break;
case 7: case 46: /* non-EPS aerosol */
case 15: productDefinitionTemplateNumberNew=44;
productDefinitionTemplateNumberNew=productDefinitionTemplateNumber; break;
break; case 47: /* EPS aerosol */
default: productDefinitionTemplateNumberNew=45;
productDefinitionTemplateNumberNew=productDefinitionTemplateNumber; break;
break; case 0:
} case 1:
} else { case 2:
switch (productDefinitionTemplateNumber) { case 3:
case 0: case 4:
productDefinitionTemplateNumberNew=8; case 5:
break; case 6:
case 1: case 7:
productDefinitionTemplateNumberNew=11; case 15:
break; productDefinitionTemplateNumberNew=productDefinitionTemplateNumber;
case 2: break;
productDefinitionTemplateNumberNew=12; default:
break; productDefinitionTemplateNumberNew=productDefinitionTemplateNumber;
case 3: break;
productDefinitionTemplateNumberNew=13; }
break; } else {
case 4: /* Going from point-in-time (instantaneous) to continuous or non-continuous interval */
productDefinitionTemplateNumberNew=14; switch (productDefinitionTemplateNumber) {
break; case 0:
case 5: productDefinitionTemplateNumberNew=8;
productDefinitionTemplateNumberNew=9; break;
break; case 1:
case 6: productDefinitionTemplateNumberNew=11;
productDefinitionTemplateNumberNew=10; break;
break; case 2:
case 7: productDefinitionTemplateNumberNew=12;
case 8: break;
case 9: case 3:
case 10: productDefinitionTemplateNumberNew=13;
case 11: break;
case 12: case 4:
case 13: productDefinitionTemplateNumberNew=14;
case 14: break;
productDefinitionTemplateNumberNew=productDefinitionTemplateNumber; case 5:
break; productDefinitionTemplateNumberNew=9;
default: break;
productDefinitionTemplateNumberNew=productDefinitionTemplateNumber; case 6:
break; productDefinitionTemplateNumberNew=10;
} break;
case 40: /* non-EPS chemical */
productDefinitionTemplateNumberNew=42;
break;
case 41: /* EPS chemical */
productDefinitionTemplateNumberNew=43;
break;
case 44: /* non-EPS aerosol */
productDefinitionTemplateNumberNew=46;
break;
case 45: /* EPS aerosol */
productDefinitionTemplateNumberNew=47;
break;
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
productDefinitionTemplateNumberNew=productDefinitionTemplateNumber;
break;
default:
productDefinitionTemplateNumberNew=productDefinitionTemplateNumber;
break;
}
}
} if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew)
grib_set_long(a->parent->h, self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew);
if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) return 0;
grib_set_long(a->parent->h, self->productDefinitionTemplateNumber,productDefinitionTemplateNumberNew);
return 0;
} }
static long value_count(grib_accessor* a) static long value_count(grib_accessor* a)
{ {
return 1; return 1;
} }