Commit f6a24e78 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge declaration and definition.

parent 1f094807
=======================================
Example 1: rotated_latitude_longitude
=======================================
rlon = 106 ;
rlat = 111 ;
float lon(rlat, rlon) ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:standard_name = "grid_longitude" ;
float lat(rlat, rlon) ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:standard_name = "grid_latitude" ;
float rlat(rlat) ;
rlat:standard_name = "grid_latitude" ;
rlat:long_name = "rotated latitude" ;
rlat:units = "degrees" ;
float rlon(rlon) ;
rlon:standard_name = "grid_longitude" ;
rlon:long_name = "rotated longitude" ;
rlon:units = "degrees" ;
char rotated_pole ;
rotated_pole:long_name = "coordinates of the rotated North Pole" ;
rotated_pole:grid_mapping_name = "rotated_latitude_longitude" ;
rotated_pole:grid_north_pole_latitude = 39.25f ;
rotated_pole:grid_north_pole_longitude = -162.f ;
float T_2M_AV(time, height_2m, rlat, rlon) ;
T_2M_AV:standard_name = "air_temperature" ;
T_2M_AV:units = "K" ;
T_2M_AV:coordinates = "lon lat" ;
gridtype = GRIB_CURVILINEAR
xsize = 106
ysize = 111
xname = lon
xvals = ...
yname = lat
yvals = ...
xdimname = rlon
ydimname = rlat
projection = rotated_latitude_longitude
pname = rotated_pole
pxvals = ....
pyvals = ....
grid_north_pole_latitude = 39.25f
grid_north_pole_longitude = -162.f
long_name = "coordinates of the rotated North Pole"
gridID = gridCreate(GRID_CURVILINEAR, size)
gridDefXsize(gridID, xsize)
gridDefYsize(gridID, ysize)
gridDefXvals(gridID, xvals)
gridDefYvals(gridID, yvals)
....
projID = gridCreate(GRIB_PROJECTION, size)
gridDefKeyStr(projID, CDI_KEY_MAPPINGNAME, len, string)
gridDefKeyStr(projID, CDI_KEY_PNAME, len, string)
gridDefXsize(projID, xsize)
gridDefYsize(projID, ysize)
gridDefXvals(projID, xvals)
gridDefYvals(projID, yvals)
gridDefAttStr(projID, NAME, len, string);
gridDefAttFlt(projID, NAME, len, array);
....
gridDefProjection(gridID, projID);
=======================================
Example 2: lambert_azimuthal_equal_area
=======================================
x = 334 ;
y = 334 ;
double x(x) ;
x:standard_name = "projection_x_coordinate" ;
x:units = "m" ;
x:axis = "X" ;
double y(y) ;
y:standard_name = "projection_y_coordinate" ;
y:units = "m" ;
y:axis = "Y" ;
char laea ;
laea:grid_mapping_name = "lambert_azimuthal_equal_area" ;
laea:earth_radius = 6370997. ;
laea:longitude_of_projection_origin = 0. ;
laea:latitude_of_projection_origin = 90. ;
float CFC_FC_F(time, y, x) ;
CFC_FC_F:grid_mapping = "laea" ;
gridtype = GRIB_CURVILINEAR
xsize = 334
ysize = 334
projection = lambert_azimuthal_equal_area
pxvals = ....
pyvals = ....
earth_radius = 6370997.
longitude_of_projection_origin = 0.
latitude_of_projection_origin = 90.
cdo gen_geoloc ifile ofile
//cdo del_geoloc ifile ofile
gridtype = GRIB_CURVILINEAR
xsize = 334
ysize = 334
xvals = ....
yvals = ....
xbounds = ....
ybounds = ....
projection = lambert_azimuthal_equal_area
pxvals = ....
pyvals = ....
earth_radius = 6370997.
longitude_of_projection_origin = 0.
latitude_of_projection_origin = 90.
cdo del_proj ifile ofile
gridtype = GRIB_CURVILINEAR
xsize = 334
ysize = 334
xvals = ....
yvals = ....
xbounds = ....
ybounds = ....
=======================================
Example 3: Latitude and longitude on a spherical Earth
=======================================
dimensions:
lat = 18 ;
lon = 36 ;
variables:
double lat(lat) ;
double lon(lon) ;
float temp(lat, lon) ;
temp:long_name = "temperature" ;
temp:units = "K" ;
temp:grid_mapping = "crs" ;
int crs ;
crs:grid_mapping_name = "latitude_longitude"
crs:semi_major_axis = 6371000.0 ;
crs:inverse_flattening = 0 ;
LONLAT grid with projection parameter
GENERIC grid "
CURVILINEAR grid "
UNSTRUCTURED grid "
......@@ -314,18 +314,12 @@ void transpose2dArrayDP(size_t inWidth, size_t inHeight, double *data)
*/
for ( size_t yBlock = 0; yBlock < inHeight; yBlock += cacheBlockSize )
{
for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
{
for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
{
for ( size_t x = xBlock, xEnd = min_size(xBlock + cacheBlockSize, inWidth); x < xEnd; x++ )
{
out[x][y] = temp[y][x];
}
}
}
}
for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
for ( size_t x = xBlock, xEnd = min_size(xBlock + cacheBlockSize, inWidth); x < xEnd; x++ )
{
out[x][y] = temp[y][x];
}
Free(temp[0]);
}
......@@ -355,18 +349,12 @@ void transpose2dArraySP(size_t inWidth, size_t inHeight, float *data)
*/
for ( size_t yBlock = 0; yBlock < inHeight; yBlock += cacheBlockSize )
{
for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
{
for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
{
for ( size_t x = xBlock, xEnd = min_size(xBlock + cacheBlockSize, inWidth); x < xEnd; x++ )
{
out[x][y] = temp[y][x];
}
}
}
}
for ( size_t xBlock = 0; xBlock < inWidth; xBlock += cacheBlockSize )
for ( size_t y = yBlock, yEnd = min_size(yBlock + cacheBlockSize, inHeight); y < yEnd; y++ )
for ( size_t x = xBlock, xEnd = min_size(xBlock + cacheBlockSize, inWidth); x < xEnd; x++ )
{
out[x][y] = temp[y][x];
}
Free(temp);
}
......
......@@ -19,7 +19,7 @@
void cdfDefVarDeflate(int ncid, int ncvarid, int deflate_level)
{
#if defined (HAVE_NETCDF4)
#if defined(HAVE_NETCDF4)
int retval;
/* Set chunking, shuffle, and deflate. */
int shuffle = 1;
......@@ -27,15 +27,15 @@ void cdfDefVarDeflate(int ncid, int ncvarid, int deflate_level)
if ( deflate_level < 1 || deflate_level > 9 ) deflate_level = 1;
if ((retval = nc_def_var_deflate(ncid, ncvarid, shuffle, deflate, deflate_level)))
if ( (retval = nc_def_var_deflate(ncid, ncvarid, shuffle, deflate, deflate_level)) )
{
Error("nc_def_var_deflate failed, status = %d", retval);
}
#else
static int lwarn = TRUE;
static bool lwarn = true;
if ( lwarn )
{
lwarn = FALSE;
lwarn = false;
Warning("Deflate compression failed, NetCDF4 not available!");
}
#endif
......@@ -84,7 +84,7 @@ int cdfDefDatatype(int datatype, int filetype)
static
void cdfDefVarMissval(stream_t *streamptr, int varID, int dtype, int lcheck)
{
if ( streamptr->vars[varID].defmiss == FALSE )
if ( streamptr->vars[varID].defmiss == false )
{
int vlistID = streamptr->vlistID;
int fileID = streamptr->fileID;
......@@ -102,7 +102,7 @@ void cdfDefVarMissval(stream_t *streamptr, int varID, int dtype, int lcheck)
if ( lcheck && streamptr->ncmode == 2 ) cdf_enddef(fileID);
streamptr->vars[varID].defmiss = TRUE;
streamptr->vars[varID].defmiss = true;
}
}
......@@ -155,7 +155,7 @@ void cdfDefSource(stream_t *streamptr)
static inline
void *resizeBuf(void **buf, size_t *bufSize, size_t reqSize)
{
if (reqSize > *bufSize)
if ( reqSize > *bufSize )
{
*buf = Realloc(*buf, reqSize);
*bufSize = reqSize;
......@@ -324,7 +324,6 @@ int cdfDefVar(stream_t *streamptr, int varID)
size_t xsize = 0, ysize = 0;
char varname[CDI_MAX_NAME];
int dims[4];
int lchunk = FALSE;
size_t chunks[4] = {0,0,0,0};
int ndims = 0;
int tablenum;
......@@ -356,7 +355,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
vlistInqVarDimorder(vlistID, varID, &dimorder);
int gridsize = gridInqSize(gridID);
if ( gridsize > 1 ) lchunk = TRUE;
bool lchunk = (gridsize > 1);
int gridtype = gridInqType(gridID);
int gridindex = nc_grid_index(streamptr, gridID);
if ( gridtype != GRID_TRAJECTORY )
......@@ -372,7 +371,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
bool zaxis_is_scalar = false;
if ( zid == UNDEFID ) zaxis_is_scalar = zaxisInqScalar(zaxisID) > 0;
if ( dimorder[0] != 3 ) lchunk = FALSE; /* ZYX and ZXY */
if ( dimorder[0] != 3 ) lchunk = false; /* ZYX and ZXY */
if ( ((dimorder[0]>0)+(dimorder[1]>0)+(dimorder[2]>0)) < ((xid!=UNDEFID)+(yid!=UNDEFID)+(zid!=UNDEFID)) )
{
......@@ -441,24 +440,17 @@ int cdfDefVar(stream_t *streamptr, int varID)
if ( units == NULL ) units = tableInqParUnitsPtr(tableID, code);
if ( name )
{
int checkname;
int iz;
int status;
sprintf(varname, "%s", name);
checkname = TRUE;
iz = 0;
bool checkname = true;
int iz = 0;
while ( checkname )
{
if ( iz ) sprintf(varname, "%s_%d", name, iz+1);
status = nc_inq_varid(fileID, varname, &ncvarid);
if ( status != NC_NOERR )
{
checkname = FALSE;
}
int status = nc_inq_varid(fileID, varname, &ncvarid);
if ( status != NC_NOERR ) checkname = false;
if ( checkname ) iz++;
......@@ -487,7 +479,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
char *varname2 = varname+strlen(varname);
int checkname = TRUE;
bool checkname = true;
int iz = 0;
while ( checkname )
......@@ -495,7 +487,7 @@ int cdfDefVar(stream_t *streamptr, int varID)
if ( iz ) sprintf(varname2, "_%d", iz+1);
int status = nc_inq_varid(fileID, varname, &ncvarid);
if ( status != NC_NOERR ) checkname = FALSE;
if ( status != NC_NOERR ) checkname = false;
if ( checkname ) iz++;
......@@ -536,11 +528,10 @@ int cdfDefVar(stream_t *streamptr, int varID)
{
if ( lchunk )
{
static int lwarn = TRUE;
static bool lwarn = true;
if ( lwarn )
{
lwarn = FALSE;
lwarn = false;
Warning("Deflate compression is only available for NetCDF4!");
}
}
......@@ -554,22 +545,20 @@ int cdfDefVar(stream_t *streamptr, int varID)
#if defined (NC_SZIP_NN_OPTION_MASK)
cdfDefVarSzip(fileID, ncvarid);
#else
static int lwarn = TRUE;
static bool lwarn = true;
if ( lwarn )
{
lwarn = FALSE;
lwarn = false;
Warning("NetCDF4/SZIP compression not available!");
}
#endif
}
else
{
static int lwarn = TRUE;
static bool lwarn = true;
if ( lwarn )
{
lwarn = FALSE;
lwarn = false;
Warning("SZIP compression is only available for NetCDF4!");
}
}
......@@ -816,7 +805,7 @@ void cdfWriteGridTraj(stream_t *streamptr, int gridID)
static
void cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dtype, size_t nvals, size_t xsize, size_t ysize,
int swapxy, size_t *start, size_t *count, int memtype, const void *data, int nmiss)
bool swapxy, size_t *start, size_t *count, int memtype, const void *data, int nmiss)
{
const double *pdata_dp = (const double *) data;
double *mdata_dp = NULL;
......@@ -944,9 +933,8 @@ void cdf_write_var_data(int fileID, int vlistID, int varID, int ncvarid, int dty
if ( CDF_Debug && memtype != MEMTYPE_FLOAT )
{
double fmin, fmax;
fmin = 1.0e200;
fmax = -1.0e200;
double fmin = 1.0e200;
double fmax = -1.0e200;
for ( size_t i = 0; i < nvals; ++i )
{
if ( !DBL_IS_EQUAL(pdata_dp[i], missval) )
......@@ -1001,7 +989,7 @@ void cdf_write_var(stream_t *streamptr, int varID, int memtype, const void *data
size_t size;
size_t start[5];
size_t count[5];
int swapxy = FALSE;
bool swapxy = false;
int ndims = 0;
int idim;
......@@ -1097,7 +1085,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
size_t xsize = 0, ysize = 0;
size_t start[5];
size_t count[5];
int swapxy = FALSE;
bool swapxy = false;
int ndims = 0;
int idim;
int streamID = streamptr->self;
......@@ -1232,7 +1220,7 @@ void cdf_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
int zid = streamptr->zaxisID[zaxisindex];
int swapxy = (dimorder[2] == 2 || dimorder[0] == 1) && xid != UNDEFID && yid != UNDEFID;
bool swapxy = (dimorder[2] == 2 || dimorder[0] == 1) && xid != UNDEFID && yid != UNDEFID;
size_t ndims = 0;
if ( tsteptype != TSTEP_CONSTANT )
......
......@@ -357,9 +357,9 @@ const char *streamFilesuffix(int filetype);
off_t streamNvals(int streamID);
int streamInqNvars ( int streamID );
int streamInqNvars(int streamID);
/* STREAM var I/O routines */
/* STREAM var I/O routines (random access) */
/* streamWriteVar: Write a variable */
void streamWriteVar(int streamID, int varID, const double data[], int nmiss);
......@@ -380,7 +380,7 @@ void streamReadVarSliceF(int streamID, int varID, int levelID, float data[],
void streamWriteVarChunk(int streamID, int varID, const int rect[3][2], const double data[], int nmiss);
/* STREAM record I/O routines */
/* STREAM record I/O routines (sequential access) */
void streamDefRecord(int streamID, int varID, int levelID);
void streamInqRecord(int streamID, int *varID, int *levelID);
......
......@@ -188,14 +188,14 @@ typedef struct {
typedef struct {
int ncvarid;
int subtypeSize;
sleveltable_t *recordTable; /* record IDs for each subtype */
int defmiss; /* TRUE if missval is defined in file */
sleveltable_t *recordTable; // record IDs for each subtype
bool defmiss; // true: if missval is defined in file
bool isUsed;
int isUsed;
int gridID;
int zaxisID;
int tsteptype; /* TSTEP_* */
int subtypeID; /* subtype ID, e.g. for tile-related meta-data (currently for GRIB-API only). */
int tsteptype; // TSTEP_*
int subtypeID; // subtype ID, e.g. for tile-related meta-data (currently for GRIB-API only).
}
svarinfo_t;
......
......@@ -81,7 +81,7 @@ int grbUnzipRecord(void *gribbuffer, size_t *gribsize)
if ( unzipsize < (long) igribsize )
{
fprintf(stderr, "Decompressed size smaller than compressed size (in %ld; out %ld)!\n", (long)igribsize, unzipsize);
return (0);
return 0;
}
if ( itmpbuffersize < igribsize )
......
......@@ -193,8 +193,7 @@ void grb_write_var_slice(stream_t *streamptr, int varID, int levelID, int memtyp
if ( filetype == FILETYPE_GRB && streamptr->comptype == CDI_COMPRESS_SZIP )
nbytes = grbSzip(filetype, gribbuffer, nbytes);
size_t (*myFileWrite)(int fileID, const void *restrict buffer,
size_t len, int tsID)
size_t (*myFileWrite)(int fileID, const void *restrict buffer, size_t len, int tsID)
= (size_t (*)(int, const void *restrict, size_t, int))
namespaceSwitchGet(NSSWITCH_FILE_WRITE).func;
size_t nwrite = myFileWrite(fileID, gribbuffer, nbytes, tsID);
......
......@@ -2933,7 +2933,7 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
vlistDefVarChunkType(vlistID, varID, ncvars[ncvarid].chunktype);
#endif
streamptr->vars[varID1].defmiss = 0;
streamptr->vars[varID1].defmiss = false;
streamptr->vars[varID1].ncvarid = ncvarid;
vlistDefVarName(vlistID, varID, ncvars[ncvarid].name);
......
......@@ -2,10 +2,7 @@
# include "config.h"
#endif
#include <string.h>
#include "dmemory.h"
#include "error.h"
#include "cdi.h"
#include "cdi_int.h"
......@@ -23,7 +20,7 @@ static
void streamvar_init_entry(stream_t *streamptr, int varID)
{
streamptr->vars[varID].ncvarid = CDI_UNDEFID;
streamptr->vars[varID].defmiss = 0;
streamptr->vars[varID].defmiss = false;
streamptr->vars[varID].subtypeSize = 0;
streamptr->vars[varID].recordTable = NULL;
......@@ -38,30 +35,24 @@ static
int streamvar_new_entry(stream_t *streamptr)
{
int varID = 0;
int streamvarSize;
svarinfo_t *streamvar;
streamvarSize = streamptr->varsAllocated;
streamvar = streamptr->vars;
int streamvarSize = streamptr->varsAllocated;
svarinfo_t *streamvar = streamptr->vars;
/*
Look for a free slot in streamvar.
(Create the table the first time through).
*/
if ( ! streamvarSize )
{
int i;
streamvarSize = 2;
streamvar
= (svarinfo_t *) Malloc((size_t)streamvarSize * sizeof(svarinfo_t));
streamvar = (svarinfo_t *) Malloc((size_t)streamvarSize * sizeof(svarinfo_t));
if ( streamvar == NULL )
{
Message("streamvarSize = %d", streamvarSize);
SysError("Allocation of svarinfo_t failed");
}
for ( i = 0; i < streamvarSize; i++ )
streamvar[i].isUsed = FALSE;
for ( int i = 0; i < streamvarSize; i++ )
streamvar[i].isUsed = false;
}
else
{
......@@ -76,11 +67,8 @@ int streamvar_new_entry(stream_t *streamptr)
*/
if ( varID == streamvarSize )
{
int i;
streamvarSize = 2*streamvarSize;
streamvar
= (svarinfo_t *) Realloc(streamvar,
streamvar = (svarinfo_t *) Realloc(streamvar,
(size_t)streamvarSize * sizeof (svarinfo_t));
if ( streamvar == NULL )
{
......@@ -89,8 +77,8 @@ int streamvar_new_entry(stream_t *streamptr)
}
varID = streamvarSize/2;
for ( i = varID; i < streamvarSize; i++ )
streamvar[i].isUsed = FALSE;
for ( int i = varID; i < streamvarSize; i++ )
streamvar[i].isUsed = false;
}
streamptr->varsAllocated = streamvarSize;
......@@ -98,8 +86,9 @@ int streamvar_new_entry(stream_t *streamptr)
streamvar_init_entry(streamptr, varID);
streamptr->vars[varID].isUsed = TRUE;
return (varID);
streamptr->vars[varID].isUsed = true;
return varID;
}
......@@ -109,7 +98,7 @@ allocate_record_table_entry(stream_t *streamptr, int varID, int subID, int nlevs
int *level = (int *) Malloc((size_t)nlevs * sizeof (int));
int *lindex = (int *) Malloc((size_t)nlevs * sizeof (int));
for (int levID = 0; levID < nlevs; levID++ )
for ( int levID = 0; levID < nlevs; levID++ )
{
level[levID] = CDI_UNDEFID;
lindex[levID] = levID;
......@@ -154,7 +143,7 @@ int stream_new_var(stream_t *streamptr, int gridID, int zaxisID, int tilesetID)
streamptr->vars[varID].subtypeID = tilesetID;
return (varID);
return varID;
}
/*
* Local Variables:
......
......@@ -105,8 +105,7 @@ The values are converted to the external data type of the variable, if necessary
*/
void streamWriteVar(int streamID, int varID, const double *data, int nmiss)
{
void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype,
const void *data, int nmiss)
void (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype, const void *data, int nmiss)
= (void (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
......@@ -131,8 +130,7 @@ The values are converted to the external data type of the variable, if necessary
*/
void streamWriteVarF(int streamID, int varID, const float *data, int nmiss)
{
int (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype,
const void *data, int nmiss)
int (*myCdiStreamWriteVar_)(int streamID, int varID, int memtype, const void *data, int nmiss)
= (int (*)(int, int, int, const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_).func;
......@@ -275,22 +273,19 @@ void streamWriteVarSliceF(int streamID, int varID, int levelID, const float *dat
}
void
streamWriteVarChunk(int streamID, int varID,
const int rect[][2], const double *data, int nmiss)
void streamWriteVarChunk(int streamID, int varID,
const int rect[][2], const double *data, int nmiss)
{
void (*myCdiStreamWriteVarChunk_)(int streamID, int varID, int memtype,
const int rect[][2], const void *data,
int nmiss)
const int rect[][2], const void *data, int nmiss)
= (void (*)(int, int, int, const int [][2], const void *, int))
namespaceSwitchGet(NSSWITCH_STREAM_WRITE_VAR_CHUNK_).func;
myCdiStreamWriteVarChunk_(streamID, varID, MEMTYPE_DOUBLE, rect, data, nmiss);
}
/* single image implementation */
void
cdiStreamWriteVarChunk_(int streamID, int varID, int memtype,