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