Commit fce198f9 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

merged trunk into cdi_conversion-c++

parents 82fd5583 0415ce02
......@@ -14,8 +14,8 @@
m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],,
[m4_warning([this file was generated for autoconf 2.68.
m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
[m4_warning([this file was generated for autoconf 2.69.
You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])
......
This diff is collapsed.
......@@ -721,6 +721,20 @@ void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype,
}
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype,
size_t len, const float *dp)
{
int status;
status = nc_put_att_float(ncid, varid, name, xtype, len, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype,
size_t len, const double *dp)
{
......@@ -729,7 +743,7 @@ void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype,
status = nc_put_att_double(ncid, varid, name, xtype, len, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("%d %d %f", ncid, varid, *dp);
Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......@@ -782,8 +796,7 @@ void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
status = nc_get_att_double(ncid, varid, name, dp);
if ( CDF_Debug || status != NC_NOERR )
Message("ncid = %d varid = %d att = %s val = %.9g",
ncid, varid, name, *dp);
Message("ncid = %d varid = %d att = %s val = %.9g", ncid, varid, name, *dp);
if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
}
......
......@@ -68,6 +68,7 @@ void cdf_put_vara_float(int ncid, int varid, const size_t start[], const size_t
void cdf_put_att_text(int ncid, int varid, const char *name, size_t len, const char *tp);
void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype, size_t len, const int *ip);
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype, size_t len, const float *dp);
void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype, size_t len, const double *dp);
void cdf_get_att_string(int ncid, int varid, const char *name, char **tp);
......
......@@ -36,6 +36,7 @@ int cdiSplitLtype105 = CDI_UNDEFID;
int cdiIgnoreAttCoordinates = FALSE;
int cdiIgnoreValidRange = FALSE;
int cdiSkipRecords = 0;
int cdiConvention = CDI_CONVENTION_ECHAM;
int cdiInventoryMode = 1;
size_t CDI_netcdf_hdr_pad = 0UL;
......@@ -336,6 +337,17 @@ void cdiInitialize(void)
cdiSkipRecords = cdiSkipRecords > 0 ? cdiSkipRecords : 0;
}
envString = getenv("CDI_CONVENTION");
if ( envString )
{
if ( strcmp(envString, "CF") == 0 )
{
cdiConvention = CDI_CONVENTION_CF;
if ( CDI_Debug )
Message("CDI convention was set to CF!");
}
}
envString = getenv("CDI_INVENTORY_MODE");
if ( envString )
{
......
......@@ -2,7 +2,7 @@
#define _CDI_INT_H
#if defined (HAVE_CONFIG_H)
# include "config.h"
#include "config.h"
#endif
#include <assert.h>
......@@ -264,6 +264,7 @@ stream_t;
/* Length of optional keyword/value pair list */
#define MAX_OPT_GRIB_ENTRIES 500
enum cdi_convention {CDI_CONVENTION_ECHAM, CDI_CONVENTION_CF};
/* Data type specification for optional key/value pairs (GRIB) */
typedef enum {
......
......@@ -255,6 +255,11 @@
# endif
#endif
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
......
......@@ -620,7 +620,14 @@ void defineAttributes(int vlistID, int varID, int fileID, int ncvarID)
double *attflt = (double *)resizeBuf(&attBuf, &attBufSize, attSize);
vlistInqAttFlt(vlistID, varID, attname, attlen, attflt);
len = (size_t)attlen;
cdf_put_att_double(fileID, ncvarID, attname, atttype == DATATYPE_FLT32 ? NC_FLOAT : NC_DOUBLE, len, attflt);
if ( atttype == DATATYPE_FLT32 )
{
float attflt_sp[len];
for ( size_t i = 0; i < len; ++i ) attflt_sp[i] = attflt[i];
cdf_put_att_float(fileID, ncvarID, attname, NC_FLOAT, len, attflt_sp);
}
else
cdf_put_att_double(fileID, ncvarID, attname, NC_DOUBLE, len, attflt);
}
}
free(attBuf);
......@@ -2366,6 +2373,114 @@ void cdfDefVCT(stream_t *streamptr, int zaxisID)
}
}
static
void cdfDefZaxisHybridEcham(stream_t *streamptr, int type, int ncvarid, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
{
char tmpname[CDI_MAX_NAME];
int fileID = streamptr->fileID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
cdf_def_dim(fileID, axisname, dimlen, dimID);
cdf_def_var(fileID, axisname, (nc_type) xtype, 1, dimID, &ncvarid);
strcpy(tmpname, "hybrid_sigma_pressure");
cdf_put_att_text(fileID, ncvarid, "standard_name", strlen(tmpname), tmpname);
if ( type == ZAXIS_HYBRID )
{
strcpy(tmpname, "hybrid level at layer midpoints");
cdf_put_att_text(fileID, ncvarid, "long_name", strlen(tmpname), tmpname);
strcpy(tmpname, "hyam hybm (mlev=hyam+hybm*aps)");
cdf_put_att_text(fileID, ncvarid, "formula", strlen(tmpname), tmpname);
strcpy(tmpname, "ap: hyam b: hybm ps: aps");
cdf_put_att_text(fileID, ncvarid, "formula_terms", strlen(tmpname), tmpname);
}
else
{
strcpy(tmpname, "hybrid level at layer interfaces");
cdf_put_att_text(fileID, ncvarid, "long_name", strlen(tmpname), tmpname);
strcpy(tmpname, "hyai hybi (ilev=hyai+hybi*aps)");
cdf_put_att_text(fileID, ncvarid, "formula", strlen(tmpname), tmpname);
strcpy(tmpname, "ap: hyai b: hybi ps: aps");
cdf_put_att_text(fileID, ncvarid, "formula_terms", strlen(tmpname), tmpname);
}
strcpy(tmpname, "level");
cdf_put_att_text(fileID, ncvarid, "units", strlen(tmpname), tmpname);
strcpy(tmpname, "down");
cdf_put_att_text(fileID, ncvarid, "positive", strlen(tmpname), tmpname);
cdf_enddef(fileID);
streamptr->ncmode = 2;
cdf_put_var_double(fileID, ncvarid, zaxisInqLevelsPtr(zaxisID));
cdfDefVCT(streamptr, zaxisID);
if ( *dimID == UNDEFID )
{
if ( type == ZAXIS_HYBRID )
streamptr->zaxisID[zaxisindex] = streamptr->vct.mlevID;
else
streamptr->zaxisID[zaxisindex] = streamptr->vct.ilevID;
}
}
static
void cdfDefZaxisHybridCF(stream_t *streamptr, int type, int ncvarid, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
{
char tmpname[CDI_MAX_NAME];
int fileID = streamptr->fileID;
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
cdf_def_dim(fileID, axisname, dimlen, dimID);
cdf_def_var(fileID, axisname, (nc_type) xtype, 1, dimID, &ncvarid);
strcpy(tmpname, "atmosphere_hybrid_sigma_pressure_coordinate");
cdf_put_att_text(fileID, ncvarid, "standard_name", strlen(tmpname), tmpname);
strcpy(tmpname, "hybrid level at layer midpoints");
cdf_put_att_text(fileID, ncvarid, "long_name", strlen(tmpname), tmpname);
strcpy(tmpname, "p = ap + b*ps");
cdf_put_att_text(fileID, ncvarid, "formula", strlen(tmpname), tmpname);
strcpy(tmpname, "ap: ap b: b ps: ps");
cdf_put_att_text(fileID, ncvarid, "formula_terms", strlen(tmpname), tmpname);
strcpy(tmpname, "1");
cdf_put_att_text(fileID, ncvarid, "units", strlen(tmpname), tmpname);
strcpy(tmpname, "Z");
cdf_put_att_text(fileID, ncvarid, "axis", strlen(tmpname), tmpname);
strcpy(tmpname, "down");
cdf_put_att_text(fileID, ncvarid, "positive", strlen(tmpname), tmpname);
cdf_enddef(fileID);
streamptr->ncmode = 2;
cdf_put_var_double(fileID, ncvarid, zaxisInqLevelsPtr(zaxisID));
cdfDefVCT(streamptr, zaxisID);
if ( *dimID == UNDEFID )
{
if ( type == ZAXIS_HYBRID )
streamptr->zaxisID[zaxisindex] = streamptr->vct.mlevID;
else
streamptr->zaxisID[zaxisindex] = streamptr->vct.ilevID;
}
}
static
void cdfDefZaxisHybrid(stream_t *streamptr, int type, int ncvarid, int zaxisID, int zaxisindex, int xtype, size_t dimlen, int *dimID, char *axisname)
{
extern int cdiConvention;
if ( cdiConvention == CDI_CONVENTION_ECHAM || type == ZAXIS_HYBRID_HALF )
cdfDefZaxisHybridEcham(streamptr, type, ncvarid, zaxisID, zaxisindex, xtype, dimlen, dimID, axisname);
else
cdfDefZaxisHybridCF(streamptr, type, ncvarid, zaxisID, zaxisindex, xtype, dimlen, dimID, axisname);
}
static
void cdfDefZaxis(stream_t *streamptr, int zaxisID)
......@@ -2380,29 +2495,24 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
int zaxisID0;
int dimID = UNDEFID;
int dimIDs[2];
int fileID;
size_t len;
int ncvarid = UNDEFID, ncbvarid = UNDEFID;
int nvdimID = UNDEFID;
int type;
int nzaxis;
int ilevel = 0;
int vlistID;
int zaxisindex;
int xtype = NC_DOUBLE;
int positive;
if ( zaxisInqPrec(zaxisID) == DATATYPE_FLT32 ) xtype = NC_FLOAT;
vlistID = streamptr->vlistID;
fileID = streamptr->fileID;
int vlistID = streamptr->vlistID;
int fileID = streamptr->fileID;
zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
nzaxis = vlistNzaxis(vlistID);
int nzaxis = vlistNzaxis(vlistID);
size_t dimlen = (size_t)zaxisInqSize(zaxisID);
type = zaxisInqType(zaxisID);
int type = zaxisInqType(zaxisID);
if (dimlen == 1)
switch (type)
......@@ -2486,70 +2596,7 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
if ( type == ZAXIS_HYBRID || type == ZAXIS_HYBRID_HALF )
{
if ( type == ZAXIS_HYBRID )
{
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
cdf_def_dim(fileID, axisname, dimlen, &dimID);
cdf_def_var(fileID, axisname, (nc_type) xtype, 1, &dimID, &ncvarid);
strcpy(tmpname, "hybrid_sigma_pressure");
cdf_put_att_text(fileID, ncvarid, "standard_name", strlen(tmpname), tmpname);
strcpy(tmpname, "hybrid level at layer midpoints");
cdf_put_att_text(fileID, ncvarid, "long_name", strlen(tmpname), tmpname);
strcpy(tmpname, "level");
cdf_put_att_text(fileID, ncvarid, "units", strlen(tmpname), tmpname);
strcpy(tmpname, "down");
cdf_put_att_text(fileID, ncvarid, "positive", strlen(tmpname), tmpname);
strcpy(tmpname, "hyam hybm (mlev=hyam+hybm*aps)");
cdf_put_att_text(fileID, ncvarid, "formula", strlen(tmpname), tmpname);
strcpy(tmpname, "ap: hyam b: hybm ps: aps");
cdf_put_att_text(fileID, ncvarid, "formula_terms", strlen(tmpname), tmpname);
/*
strcpy(tmpname, "ilev");
cdf_put_att_text(fileID, ncvarid, "borders", strlen(tmpname), tmpname);
*/
cdf_enddef(fileID);
streamptr->ncmode = 2;
cdf_put_var_double(fileID, ncvarid, zaxisInqLevelsPtr(zaxisID));
}
if ( type == ZAXIS_HYBRID_HALF )
{
if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
cdf_def_dim(fileID, axisname, dimlen, &dimID);
cdf_def_var(fileID, axisname, (nc_type) xtype, 1, &dimID, &ncvarid);
strcpy(tmpname, "hybrid_sigma_pressure");
cdf_put_att_text(fileID, ncvarid, "standard_name", strlen(tmpname), tmpname);
strcpy(tmpname, "hybrid level at layer interfaces");
cdf_put_att_text(fileID, ncvarid, "long_name", strlen(tmpname), tmpname);
strcpy(tmpname, "level");
cdf_put_att_text(fileID, ncvarid, "units", strlen(tmpname), tmpname);
strcpy(tmpname, "down");
cdf_put_att_text(fileID, ncvarid, "positive", strlen(tmpname), tmpname);
strcpy(tmpname, "hyai hybi (ilev=hyai+hybi*aps)");
cdf_put_att_text(fileID, ncvarid, "formula", strlen(tmpname), tmpname);
strcpy(tmpname, "ap: hyai b: hybi ps: aps");
cdf_put_att_text(fileID, ncvarid, "formula_terms", strlen(tmpname), tmpname);
cdf_enddef(fileID);
streamptr->ncmode = 2;
cdf_put_var_double(fileID, ncvarid, zaxisInqLevelsPtr(zaxisID));
}
cdfDefVCT(streamptr, zaxisID);
if ( dimID == UNDEFID )
{
if ( type == ZAXIS_HYBRID )
streamptr->zaxisID[zaxisindex] = streamptr->vct.mlevID;
else
streamptr->zaxisID[zaxisindex] = streamptr->vct.ilevID;
}
cdfDefZaxisHybrid(streamptr, type, ncvarid, zaxisID, zaxisindex, xtype, dimlen, &dimID, axisname);
}
else
{
......@@ -2636,7 +2683,6 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
streamptr->zaxisID[zaxisindex] = dimID;
}
static
void cdfDefPole(stream_t *streamptr, int gridID)
{
......@@ -5844,6 +5890,13 @@ void verify_coordinate_vars_1(int ndims, ncdim_t *ncdims, ncvar_t *ncvars, int t
ncvars[ncvarid].zaxistype = ZAXIS_HEIGHT;
}
}
else
{
if ( (strcmp(ncvars[ncvarid].longname, "generalized_height") == 0 ||
strcmp(ncvars[ncvarid].longname, "generalized height") == 0) &&
strcmp(ncvars[ncvarid].stdname, "height") == 0 )
ncvars[ncvarid].zaxistype = ZAXIS_REFERENCE;
}
if ( ncvars[ncvarid].islon == FALSE && ncvars[ncvarid].longname[0] != 0 &&
ncvars[ncvarid].islat == FALSE && ncvars[ncvarid].longname[1] != 0 )
......@@ -6915,11 +6968,9 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
for ( int varID1 = 0; varID1 < nvars; varID1++ )
{
int gridID, zaxisID;
int ncvarid = varids[varID1];
gridID = ncvars[ncvarid].gridID;
zaxisID = ncvars[ncvarid].zaxisID;
int gridID = ncvars[ncvarid].gridID;
int zaxisID = ncvars[ncvarid].zaxisID;
stream_new_var(streamptr, gridID, zaxisID, CDI_UNDEFID);
int varID = vlistDefVar(vlistID, gridID, zaxisID, ncvars[ncvarid].tsteptype);
......@@ -7436,8 +7487,6 @@ int cdfInqContents(stream_t *streamptr)
int leadtime_id = UNDEFID;
int nvars_data;
int nvcth_id = UNDEFID, vcta_id = UNDEFID, vctb_id = UNDEFID;
size_t vctsize = 0;
double *vct = NULL;
int instID = UNDEFID;
int modelID = UNDEFID;
int taxisID;
......@@ -7526,7 +7575,7 @@ int cdfInqContents(stream_t *streamptr)
}
/* scan global attributes */
scan_global_attributes(fileID, vlistID, streamptr, ngatts, &instID, &modelID, &ucla_les,
scan_global_attributes(fileID, vlistID, streamptr, ngatts, &instID, &modelID, &ucla_les,
uuidOfHGrid, uuidOfVGrid, gridfile, &number_of_grid_used);
/* find time dim */
......@@ -7763,6 +7812,8 @@ int cdfInqContents(stream_t *streamptr)
/* read VCT */
size_t vctsize = 0;
double *vct = NULL;
if ( nvcth_id != UNDEFID && vcta_id != UNDEFID && vctb_id != UNDEFID )
{
vctsize = ncdims[nvcth_id].len;
......@@ -7775,10 +7826,9 @@ int cdfInqContents(stream_t *streamptr)
/* define all zaxes */
define_all_zaxes(streamptr, vlistID, ncdims, nvars, ncvars, vctsize, vct, uuidOfVGrid);
if ( vct ) free(vct);
/* select vars */
varids = (int *)xmalloc((size_t)nvars * sizeof (int));
nvarids = 0;
......
......@@ -54,7 +54,7 @@ ZaxistypeEntry[] = {
{ /* 22 */ 0, "sedimentbottomta", "sediment_bottom_ta", "", ""},
{ /* 23 */ 0, "sedimentbottomtw", "sediment_bottom_tw", "", ""},
{ /* 24 */ 0, "mixlayer", "mix_layer", "", ""},
{ /* 25 */ 0, "height", "generalized height", "height", ""},
{ /* 25 */ 0, "height", "generalized_height", "height", ""},
};
enum {
......@@ -1254,12 +1254,14 @@ void zaxisPrintKernel ( zaxis_t * zaxisptr, int index, FILE * fp )
if ( type == ZAXIS_REFERENCE )
{
const unsigned char *d;
zaxisInqUUID(zaxisID, uuid);
d = uuid;
fprintf(fp, "uuid = %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
if ( *uuid )
{
const unsigned char *d = uuid;
fprintf(fp, "uuid = %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
}
}
}
......
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