Commit 69ddc399 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function streamGrbChangeParameterIdentification() (patch from Michal Koutek, KMNI).

parent f433e9fe
......@@ -2,6 +2,10 @@
* Version 1.8.1 released
2017-03-07 Uwe Schulzweida
* Added function streamGrbChangeParameterIdentification() (patch from Michal Koutek, KMNI)
2017-02-27 Uwe Schulzweida
* Added function gridDefUvRelativeToGrid()
......
......@@ -12,7 +12,6 @@
#include "stream_gribapi.h"
#include "file.h"
#include "cgribex.h" /* gribZip gribGetZip gribGinfo */
#include "gribapi.h"
#include "namespace.h"
......
......@@ -12,7 +12,6 @@
#include "stream_gribapi.h"
#include "file.h"
#include "cgribex.h" /* gribZip gribGetZip gribGinfo */
#include "gribapi.h"
#include "namespace.h"
......@@ -116,6 +115,28 @@ void grbCopyRecord(stream_t * streamptr2, stream_t * streamptr1)
size_t nbytes = recsize;
if ( filetype == CDI_FILETYPE_GRB )
{
extern int GribChangeParameterIdentification;
if ( GribChangeParameterIdentification == 1 )
{
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);
cgribex_handle_delete(gh);
#elif defined HAVE_LIBGRIB_API
grib_handle *gh = grib_handle_new_from_message(NULL, (void*) gribbuffer, recsize);
gribapiChangeParameterIdentification(gh, GribChangeParID_code, GribChangeParID_ltype, GribChangeParID_lev);
grib_handle_delete(gh);
#endif
GribChangeParameterIdentification = -1; // after grib attributes have been changed turn it off again
}
}
if ( filetype == CDI_FILETYPE_GRB )
{
size_t unzipsize;
......
......@@ -2104,6 +2104,67 @@ size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridI
size_t nbytes = (size_t)iword * sizeof(int);
return nbytes;
}
typedef struct
{
void *gribbuffer;
size_t gribbuffersize;
unsigned char *pds;
unsigned char *gds;
unsigned char *bms;
unsigned char *bds;
} cgribex_handle;
int grib1Sections(unsigned char *gribbuffer, long gribbufsize, unsigned char **pdsp,
unsigned char **gdsp, unsigned char **bmsp, unsigned char **bdsp, long *gribrecsize);
void *cgribex_handle_new_from_meassage(void *gribbuffer, size_t gribbuffersize)
{
cgribex_handle *gh = (cgribex_handle*) Malloc(sizeof(cgribex_handle));
gh->gribbuffer = NULL;
gh->gribbuffersize = 0;
gh->pds = NULL;
if ( gribbuffersize && gribbuffer )
{
unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL;
long gribrecsize;
int status = grib1Sections((unsigned char *)gribbuffer, (long)gribbuffersize, &pds, &gds, &bms, &bds, &gribrecsize);
if ( status >= 0 )
{
gh->gribbuffer = gribbuffer;
gh->gribbuffersize = gribbuffersize;
gh->pds = pds;
gh->gds = gds;
gh->bms = bms;
gh->bds = bds;
}
}
return (void*)gh;
}
void cgribex_handle_delete(void *gh)
{
if ( gh ) Free(gh);
}
void cgribexChangeParameterIdentification(void *gh, int code, int ltype, int lev)
{
if ( !gh ) return;
unsigned char *pds = ((cgribex_handle*)gh)->pds;
if ( !pds ) return;
pds[8] = (unsigned char) code;
pds[9] = (unsigned char) ltype;
pds[10] = (unsigned char) lev;
}
#endif
/*
* Local Variables:
......
......@@ -12,6 +12,11 @@ size_t cgribexEncode(int memtype, int varID, int levelID, int vlistID, int gridI
int vdate, int vtime, int tsteptype, int numavg,
long datasize, const void *data, int nmiss, void *gribbuffer, size_t gribbuffersize);
void *cgribex_handle_new_from_meassage(void *gribbuffer, size_t recsize);
void cgribex_handle_delete(void *gh);
void cgribexChangeParameterIdentification(void *gh, int code, int ltype, int lev);
#endif /* _STREAM_CGRIBEX_H */
/*
* Local Variables:
......
......@@ -9,7 +9,28 @@
#include "stream_gribapi.h"
#include "file.h"
#include "cgribex.h" /* gribZip gribGetZip gribGinfo */
#include "gribapi.h"
// 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;
// Used only in CDO
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;
}
int grib1ltypeToZaxisType(int grib_ltype)
......
......@@ -2691,6 +2691,20 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
return recsize;
}
void gribapiChangeParameterIdentification(grib_handle *gh, int code, int ltype, int lev)
{
long indicatorOfParameter, indicatorOfTypeOfLevel, level; // timeRangeIndicator: could be included later
indicatorOfParameter = code;
indicatorOfTypeOfLevel = ltype;
level = lev;
if (indicatorOfParameter!=-1) GRIB_CHECK(my_grib_set_long(gh, "indicatorOfParameter", indicatorOfParameter), 0);
if (indicatorOfTypeOfLevel!=-1) GRIB_CHECK(my_grib_set_long(gh, "indicatorOfTypeOfLevel", indicatorOfTypeOfLevel), 0);
if (level!=-1) GRIB_CHECK(my_grib_set_long(gh, "level", level), 0);
}
#endif
/*
......
#ifndef _STREAM_GRIBAPI_H
#define _STREAM_GRIBAPI_H
#include "gribapi.h"
int gribapiScanTimestep1(stream_t * streamptr);
int gribapiScanTimestep2(stream_t * streamptr);
int gribapiScanTimestep(stream_t * streamptr);
......@@ -13,6 +15,8 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
long datasize, const double *data, int nmiss, void **gribbuffer, size_t *gribbuffersize,
int ljpeg, void *gribContainer);
void gribapiChangeParameterIdentification(grib_handle *gh, int code, int ltype, int lev);
#endif /* _STREAM_GRIBAPI_H */
/*
* Local Variables:
......
Markdown is supported
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