Commit 9bd7f004 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Move grib record copy clobbering data to COMMON segment.

* Initializing the controling variable to -1 prevents that.
* This change also reduces the number of globally visible symbols
  the feature introduces.
parent 50b39355
......@@ -117,23 +117,19 @@ void grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
if ( filetype == CDI_FILETYPE_GRB )
{
extern int GribChangeParameterIdentification;
if ( GribChangeParameterIdentification == 1 )
if ( cdiGribChangeParameterID.active )
{
extern int GribChangeParID_code;
extern int GribChangeParID_ltype;
extern int GribChangeParID_lev;
// Even if you are stream-copy records you might need to change a bit of grib-header !
#if defined HAVE_LIBCGRIBEX
void *gh = cgribex_handle_new_from_meassage((void*) gribbuffer, recsize);
cgribexChangeParameterIdentification(gh, GribChangeParID_code, GribChangeParID_ltype, GribChangeParID_lev);
cgribexChangeParameterIdentification(gh, cdiGribChangeParameterID.code, cdiGribChangeParameterID.ltype, cdiGribChangeParameterID.lev);
cgribex_handle_delete(gh);
#elif defined HAVE_LIBGRIB_API
void *gh = (void*)grib_handle_new_from_message(NULL, (void*) gribbuffer, recsize);
gribapiChangeParameterIdentification(gh, GribChangeParID_code, GribChangeParID_ltype, GribChangeParID_lev);
gribapiChangeParameterIdentification(gh, cdiGribChangeParameterID.code, cdiGribChangeParameterID.ltype, cdiGribChangeParameterID.lev);
grib_handle_delete(gh);
#endif
GribChangeParameterIdentification = -1; // after grib attributes have been changed turn it off again
cdiGribChangeParameterID.active = false; // after grib attributes have been changed turn it off again
}
}
......
......@@ -12,11 +12,8 @@
// Regarding operation to change parameter identification:
// -1: don't change; 1: change (GribChangeParID_code, GribChangeParID_ltype, GribChangeParID_lev)
int GribChangeParameterIdentification = -1;
int GribChangeParID_code;
int GribChangeParID_ltype;
int GribChangeParID_lev;
// change if cdiGribChangeParameterID.active
struct cdiGribParamChange cdiGribChangeParameterID;
// Used only in CDO
void streamGrbChangeParameterIdentification(int code, int ltype, int lev)
......@@ -24,12 +21,12 @@ void streamGrbChangeParameterIdentification(int code, int ltype, int lev)
// NOTE this is a "PROXY" function for gribapiChangeParameterIdentification();
// This just sets the globals. There are probably better solutions to this.
// The parameter change is done by function gribapiChangeParameterIdentification() in stream_gribapi.c
GribChangeParameterIdentification = 1;
// Setting this control variable to 1 will cause calling fnc. gribapiChangeParameterIdentification later.
// After grib attributes have been changed this variable goes to -1.
GribChangeParID_code = code;
GribChangeParID_ltype = ltype;
GribChangeParID_lev = lev;
// Setting this control variable to true will cause calling fnc. gribapiChangeParameterIdentification later.
// After grib attributes have been changed this variable goes to false.
cdiGribChangeParameterID.active = true;
cdiGribChangeParameterID.code = code;
cdiGribChangeParameterID.ltype = ltype;
cdiGribChangeParameterID.lev = lev;
}
......
......@@ -24,6 +24,16 @@ int grib2ltypeToZaxisType(int grib_ltype);
int zaxisTypeToGrib1ltype(int zaxistype);
int zaxisTypeToGrib2ltype(int zaxistype);
struct cdiGribParamChange
{
int code, ltype, lev;
bool active;
};
extern struct cdiGribParamChange cdiGribChangeParameterID;
void streamGrbChangeParameterIdentification(int code, int ltype, int lev);
#endif /* _STREAM_GRB_H */
/*
* Local Variables:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment