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

cdfWriteVar*: round integer field with NINT

parent f7d87d38
2006-09-?? Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using GRIB library version 1.0.1
* Version 1.0.1 released
* using GRIB library version 1.0.2
* cdfDefVar: set default datatype for addoffset and scalefactor to double
* cdfWriteVar*: round integer field with NINT [report: Etienne Tourigny]
* Version 1.0.2 released
2006-08-01 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
......@@ -11,7 +13,7 @@
* add DATATYPE PACK1 to PACK32
* change DATATYPE from byte to bit
* split GRIB level type 105 with env var SPLIT_LTYPE_105
* file.c: remove declaration of getpagesize (report: Mark Hadfield)
* file.c: remove declaration of getpagesize [report: Mark Hadfield]
* tableWrite: bug fix for undefined strings
* Version 1.0.1 released
......
/* Generated automatically from m214003 on Fri Aug 25 08:58:12 CEST 2006 */
/* Generated automatically from m214003 on Fri Aug 25 13:27:40 CEST 2006 */
#if defined (HAVE_CONFIG_H)
# include "config.h"
......@@ -6930,7 +6930,9 @@ int gribGinfo(long recpos, long recsize, unsigned char *gribbuffer,
if ( bms ) intnum[1] = bpos;
else intnum[1] = -999;
intnum[2] = BDS_NumBits;
fltnum[0] = 1.0;
/* fltnum[0] = 1.0; */
fltnum[0] = pow(10.0, (double)PDS_DecimalScale);
fltnum[1] = bsf;
fltnum[2] = BDS_RefValue;
/*
......@@ -7123,11 +7125,12 @@ void gribPrintBDS(int nrec, long recpos, long recsize, unsigned char *gribbuffer
int level, nerr;
unsigned char *pds = NULL, *gds = NULL, *bms = NULL, *bds = NULL;
double cr = 1;
double refval, scale;
if ( header )
{
fprintf(stdout,
" Rec : Code Level BDS Flag Scale RefValue Bits CR\n");
" Rec : Code Level BDS Flag Scale RefValue Bits CR\n");
/* ----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+ */
header = 0;
}
......@@ -7155,10 +7158,24 @@ void gribPrintBDS(int nrec, long recpos, long recsize, unsigned char *gribbuffer
cr = ((double)s1)/s2;
}
fprintf(stdout, "%5d :%4d%7d %7d %4d%5d%11.5g%4d %6.4g\n", nrec,
refval = BDS_RefValue;
if ( BDS_BinScale < 0 )
scale = 1.0/pow(2.0, (double) -BDS_BinScale);
else
scale = pow(2.0, (double) BDS_BinScale);
if ( PDS_DecimalScale )
{
double decscale;
decscale = pow(10.0, (double)-PDS_DecimalScale);
refval *= decscale;
scale *= decscale;
}
fprintf(stdout, "%5d :%4d%7d %7d %4d%8.5g%11.5g%4d %6.4g\n", nrec,
PDS_Parameter, level,
BDS_Len, BDS_Flag,
BDS_BinScale, BDS_RefValue, BDS_NumBits, cr);
BDS_Len, BDS_Flag, scale, refval, BDS_NumBits, cr);
}
/* #define SZTEST */
......@@ -7952,7 +7969,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
return (gribLen);
}
static const char grb_libvers[] = "1.0.2" " of ""Aug 25 2006"" ""08:58:12";
static const char grb_libvers[] = "1.0.2" " of ""Aug 25 2006"" ""13:27:40";
......
......@@ -293,8 +293,8 @@ int cdfDefDatatype(int datatype)
int xtype;
if ( datatype == DATATYPE_INT8 ) xtype = NC_BYTE;
else if ( datatype == DATATYPE_INT16 ) xtype = NC_SHORT;
else if ( datatype == DATATYPE_INT32 ) xtype = NC_INT;
else if ( datatype == DATATYPE_INT16 ) xtype = NC_SHORT;
else if ( datatype == DATATYPE_INT32 ) xtype = NC_INT;
else if ( datatype == DATATYPE_FLT64 ) xtype = NC_DOUBLE;
else xtype = NC_FLOAT;
......@@ -2136,17 +2136,27 @@ int cdfDefVar(int streamID, int varID)
{
int laddoffset, lscalefactor;
double addoffset, scalefactor;
int astype = NC_DOUBLE;
addoffset = vlistInqVarAddoffset(vlistID, varID);
scalefactor = vlistInqVarScalefactor(vlistID, varID);
laddoffset = addoffset != 0.0;
lscalefactor = scalefactor != 1.0;
if ( laddoffset || lscalefactor )
{
if ( DBL_IS_EQUAL(addoffset, (double) ((float) addoffset)) &&
DBL_IS_EQUAL(scalefactor, (double) ((float) scalefactor)) )
{
astype = NC_FLOAT;
}
}
if ( laddoffset )
cdf_put_att_double(fileID, ncvarid, "add_offset", NC_FLOAT, 1L, &addoffset);
cdf_put_att_double(fileID, ncvarid, "add_offset", (nc_type) astype, 1L, &addoffset);
if ( lscalefactor )
cdf_put_att_double(fileID, ncvarid, "scale_factor", NC_FLOAT, 1L, &scalefactor);
cdf_put_att_double(fileID, ncvarid, "scale_factor", (nc_type) astype, 1L, &scalefactor);
}
streams[streamID].vars[varID].ncvarid = ncvarid;
......@@ -2268,8 +2278,8 @@ void cdfReadVarDP(int streamID, int varID, double *data, int *nmiss)
{
if ( !DBL_IS_EQUAL(data[i], missval) )
{
if ( lscalefactor ) data[i] = data[i] * scalefactor;
if ( laddoffset ) data[i] = data[i] + addoffset;
if ( lscalefactor ) data[i] *= scalefactor;
if ( laddoffset ) data[i] += addoffset;
}
}
}
......@@ -2277,8 +2287,8 @@ void cdfReadVarDP(int streamID, int varID, double *data, int *nmiss)
{
for ( i = 0; i < (int) size; i++ )
{
if ( lscalefactor ) data[i] = data[i] * scalefactor;
if ( laddoffset ) data[i] = data[i] + addoffset;
if ( lscalefactor ) data[i] *= scalefactor;
if ( laddoffset ) data[i] += addoffset;
}
}
}
......@@ -2383,6 +2393,7 @@ void cdfWriteVarDP(int streamID, int varID, double *data, int nmiss)
/* if ( dtype == DATATYPE_INT8 || dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 ) */
{
int nvals;
int laddoffset, lscalefactor;
double addoffset, scalefactor;
double missval;
......@@ -2392,32 +2403,37 @@ void cdfWriteVarDP(int streamID, int varID, double *data, int nmiss)
laddoffset = addoffset != 0.0;
lscalefactor = scalefactor != 1.0;
nvals = gridInqSize(gridID)*zaxisInqSize(zaxisID);
if ( laddoffset || lscalefactor )
{
gridID = vlistInqVarGrid(vlistID, varID);
size = gridInqSize(gridID)*zaxisInqSize(zaxisID);
missval = vlistInqVarMissval(vlistID, varID);
if ( nmiss > 0 )
{
for ( i = 0; i < (int) size; i++ )
for ( i = 0; i < nvals; i++ )
{
if ( !DBL_IS_EQUAL(data[i], missval) )
{
if ( laddoffset ) data[i] = data[i] - addoffset;
if ( lscalefactor ) data[i] = data[i] / scalefactor;
if ( laddoffset ) data[i] -= addoffset;
if ( lscalefactor ) data[i] /= scalefactor;
}
}
}
else
{
for ( i = 0; i < (int) size; i++ )
for ( i = 0; i < nvals; i++ )
{
if ( laddoffset ) data[i] = data[i] - addoffset;
if ( lscalefactor ) data[i] = data[i] / scalefactor;
if ( laddoffset ) data[i] -= addoffset;
if ( lscalefactor ) data[i] /= scalefactor;
}
}
}
if ( dtype == DATATYPE_INT8 || dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 )
{
for ( i = 0; i < nvals; i++ ) data[i] = NINT(data[i]);
}
}
cdf_put_vara_double(fileID, ncvarid, start, count, data);
......@@ -2586,8 +2602,8 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
{
if ( !DBL_IS_EQUAL(data[i], missval) )
{
if ( lscalefactor ) data[i] = data[i] * scalefactor;
if ( laddoffset ) data[i] = data[i] + addoffset;
if ( lscalefactor ) data[i] *= scalefactor;
if ( laddoffset ) data[i] += addoffset;
}
}
}
......@@ -2595,8 +2611,8 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
{
for ( i = 0; i < (int) size; i++ )
{
if ( lscalefactor ) data[i] = data[i] * scalefactor;
if ( laddoffset ) data[i] = data[i] + addoffset;
if ( lscalefactor ) data[i] *= scalefactor;
if ( laddoffset ) data[i] += addoffset;
}
}
}
......@@ -2696,6 +2712,7 @@ int cdfWriteVarSliceDP(int streamID, int varID, int levelID, double *data, int n
/* if ( dtype == DATATYPE_INT8 || dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 ) */
{
int nvals;
int laddoffset, lscalefactor;
double addoffset, scalefactor;
double missval;
......@@ -2705,32 +2722,37 @@ int cdfWriteVarSliceDP(int streamID, int varID, int levelID, double *data, int n
laddoffset = addoffset != 0.0;
lscalefactor = scalefactor != 1.0;
nvals = gridInqSize(gridID);
if ( laddoffset || lscalefactor )
{
gridID = vlistInqVarGrid(vlistID, varID);
size = gridInqSize(gridID);
missval = vlistInqVarMissval(vlistID, varID);
if ( nmiss > 0 )
{
for ( i = 0; i < (int) size; i++ )
for ( i = 0; i < nvals; i++ )
{
if ( !DBL_IS_EQUAL(data[i], missval) )
{
if ( laddoffset ) data[i] = data[i] - addoffset;
if ( lscalefactor ) data[i] = data[i] / scalefactor;
if ( laddoffset ) data[i] -= addoffset;
if ( lscalefactor ) data[i] /= scalefactor;
}
}
}
else
{
for ( i = 0; i < (int) size; i++ )
for ( i = 0; i < nvals; i++ )
{
if ( laddoffset ) data[i] = data[i] - addoffset;
if ( lscalefactor ) data[i] = data[i] / scalefactor;
if ( laddoffset ) data[i] -= addoffset;
if ( lscalefactor ) data[i] /= scalefactor;
}
}
}
if ( dtype == DATATYPE_INT8 || dtype == DATATYPE_INT16 || dtype == DATATYPE_INT32 )
{
for ( i = 0; i < nvals; i++ ) data[i] = NINT(data[i]);
}
}
cdf_put_vara_double(fileID, ncvarid, start, count, data);
......
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