Commit 45060c7b authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cdf_def_zaxis_hybrid_cf: added level bounds

parent 130c1fce
...@@ -2433,15 +2433,15 @@ void cdf_def_vct_cf(stream_t *streamptr, int zaxisID, int nclevID, int ncbndsID) ...@@ -2433,15 +2433,15 @@ void cdf_def_vct_cf(stream_t *streamptr, int zaxisID, int nclevID, int ncbndsID)
for ( int i = 0; i < mlev; ++i ) for ( int i = 0; i < mlev; ++i )
{ {
tarray[2*i ] = vctptr[i+1]; tarray[2*i ] = vctptr[i];
tarray[2*i+1] = vctptr[i]; tarray[2*i+1] = vctptr[i+1];
} }
cdf_put_var_double(fileID, hyaiid, tarray); cdf_put_var_double(fileID, hyaiid, tarray);
for ( int i = 0; i < mlev; ++i ) for ( int i = 0; i < mlev; ++i )
{ {
tarray[2*i ] = vctptr[ilev+i+1]; tarray[2*i ] = vctptr[ilev+i];
tarray[2*i+1] = vctptr[ilev+i]; tarray[2*i+1] = vctptr[ilev+i+1];
} }
cdf_put_var_double(fileID, hybiid, tarray); cdf_put_var_double(fileID, hybiid, tarray);
...@@ -2544,7 +2544,7 @@ void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int ncvarid, int zax ...@@ -2544,7 +2544,7 @@ void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int ncvarid, int zax
int ncbvarid = UNDEFID; int ncbvarid = UNDEFID;
int nvdimID = UNDEFID; int nvdimID = UNDEFID;
// if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) ) if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
{ {
int dimIDs[2]; int dimIDs[2];
size_t nvertex = 2; size_t nvertex = 2;
...@@ -2577,29 +2577,22 @@ void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int ncvarid, int zax ...@@ -2577,29 +2577,22 @@ void cdf_def_zaxis_hybrid_cf(stream_t *streamptr, int type, int ncvarid, int zax
streamptr->ncmode = 2; streamptr->ncmode = 2;
cdf_put_var_double(fileID, ncvarid, zaxisInqLevelsPtr(zaxisID)); cdf_put_var_double(fileID, ncvarid, zaxisInqLevelsPtr(zaxisID));
free(attflt);
if ( ncbvarid != UNDEFID ) if ( ncbvarid != UNDEFID )
{ {
double *lbounds = (double *) malloc(dimlen*sizeof(double)); double lbounds[dimlen], ubounds[dimlen], zbounds[2*dimlen];
double *ubounds = (double *) malloc(dimlen*sizeof(double));
double *zbounds = (double *) malloc(2*dimlen*sizeof(double));
// zaxisInqLbounds(zaxisID, lbounds); zaxisInqLbounds(zaxisID, lbounds);
// zaxisInqUbounds(zaxisID, ubounds); zaxisInqUbounds(zaxisID, ubounds);
zaxisInqLevels(zaxisID, lbounds);
for (size_t i = 0; i < dimlen; ++i ) ubounds[i] = lbounds[i] + 1;
for (size_t i = 0; i < dimlen; ++i ) for ( size_t i = 0; i < dimlen; ++i )
{ {
zbounds[2*i ] = lbounds[i]; zbounds[2*i ] = lbounds[i];
zbounds[2*i+1] = ubounds[i]; zbounds[2*i+1] = ubounds[i];
} }
cdf_put_var_double(fileID, ncbvarid, zbounds); cdf_put_var_double(fileID, ncbvarid, zbounds);
free(zbounds);
free(ubounds);
free(lbounds);
} }
cdf_def_vct_cf(streamptr, zaxisID, *dimID, nvdimID); cdf_def_vct_cf(streamptr, zaxisID, *dimID, nvdimID);
...@@ -2797,9 +2790,7 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID) ...@@ -2797,9 +2790,7 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
if ( ncbvarid != UNDEFID ) if ( ncbvarid != UNDEFID )
{ {
double *lbounds = (double *) malloc(dimlen*sizeof(double)); double lbounds[dimlen], ubounds[dimlen], zbounds[2*dimlen];
double *ubounds = (double *) malloc(dimlen*sizeof(double));
double *zbounds = (double *) malloc(2*dimlen*sizeof(double));
zaxisInqLbounds(zaxisID, lbounds); zaxisInqLbounds(zaxisID, lbounds);
zaxisInqUbounds(zaxisID, ubounds); zaxisInqUbounds(zaxisID, ubounds);
...@@ -2811,10 +2802,6 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID) ...@@ -2811,10 +2802,6 @@ void cdfDefZaxis(stream_t *streamptr, int zaxisID)
} }
cdf_put_var_double(fileID, ncbvarid, zbounds); cdf_put_var_double(fileID, ncbvarid, zbounds);
free(zbounds);
free(ubounds);
free(lbounds);
} }
} }
} }
...@@ -5126,7 +5113,7 @@ void scan_hybrid_formula(int ncid, int ncfvarid, int *apvarid, int *bvarid, int ...@@ -5126,7 +5113,7 @@ void scan_hybrid_formula(int ncid, int ncfvarid, int *apvarid, int *bvarid, int
else if ( strcmp(tagname, "b:") == 0 ) *bvarid = dimvarid; else if ( strcmp(tagname, "b:") == 0 ) *bvarid = dimvarid;
else if ( strcmp(tagname, "ps:") == 0 ) *psvarid = dimvarid; else if ( strcmp(tagname, "ps:") == 0 ) *psvarid = dimvarid;
} }
else else if ( strcmp(tagname, "ps:") != 0 )
{ {
Warning("%s - %s", nc_strerror(status), varname); Warning("%s - %s", nc_strerror(status), varname);
} }
...@@ -7087,18 +7074,16 @@ void define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva ...@@ -7087,18 +7074,16 @@ void define_all_zaxes(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
nvertex = (int)ncdims[ncvars[ncvars[zvarid].bounds].dimids[1]].len; nvertex = (int)ncdims[ncvars[ncvars[zvarid].bounds].dimids[1]].len;
if ( nlevel == zsize && nvertex == 2 ) if ( nlevel == zsize && nvertex == 2 )
{ {
double *zbounds;
with_bounds = TRUE; with_bounds = TRUE;
zbounds = (double *) malloc(2*(size_t)nlevel*sizeof(double));
lbounds = (double *) malloc((size_t)nlevel*sizeof(double)); lbounds = (double *) malloc((size_t)nlevel*sizeof(double));
ubounds = (double *) malloc((size_t)nlevel*sizeof(double)); ubounds = (double *) malloc((size_t)nlevel*sizeof(double));
double zbounds[2*nlevel];
cdf_get_var_double(ncvars[zvarid].ncid, ncvars[zvarid].bounds, zbounds); cdf_get_var_double(ncvars[zvarid].ncid, ncvars[zvarid].bounds, zbounds);
for ( i = 0; i < nlevel; ++i ) for ( i = 0; i < nlevel; ++i )
{ {
lbounds[i] = zbounds[i*2]; lbounds[i] = zbounds[i*2];
ubounds[i] = zbounds[i*2+1]; ubounds[i] = zbounds[i*2+1];
} }
free(zbounds);
} }
} }
} }
...@@ -7357,23 +7342,21 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID, ...@@ -7357,23 +7342,21 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
if ( attrtype == NC_SHORT || attrtype == NC_INT ) if ( attrtype == NC_SHORT || attrtype == NC_INT )
{ {
int *attint = (int *) malloc(attlen*sizeof(int)); int attint[attlen];
cdfGetAttInt(ncid, ncvarid, attname, (int)attlen, attint); cdfGetAttInt(ncid, ncvarid, attname, (int)attlen, attint);
if ( attrtype == NC_SHORT ) if ( attrtype == NC_SHORT )
vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT16, (int)attlen, attint); vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT16, (int)attlen, attint);
else else
vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT32, (int)attlen, attint); vlistDefAttInt(vlistID, varID, attname, DATATYPE_INT32, (int)attlen, attint);
free(attint);
} }
else if ( attrtype == NC_FLOAT || attrtype == NC_DOUBLE ) else if ( attrtype == NC_FLOAT || attrtype == NC_DOUBLE )
{ {
double *attflt = (double *) malloc(attlen*sizeof(double)); double attflt[attlen];
cdfGetAttDouble(ncid, ncvarid, attname, (int)attlen, attflt); cdfGetAttDouble(ncid, ncvarid, attname, (int)attlen, attflt);
if ( attrtype == NC_FLOAT ) if ( attrtype == NC_FLOAT )
vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT32, (int)attlen, attflt); vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT32, (int)attlen, attflt);
else else
vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT64, (int)attlen, attflt); vlistDefAttFlt(vlistID, varID, attname, DATATYPE_FLT64, (int)attlen, attflt);
free(attflt);
} }
else if ( xtypeIsText(attrtype) ) else if ( xtypeIsText(attrtype) )
{ {
...@@ -7568,26 +7551,22 @@ void scan_global_attributes(int fileID, int vlistID, stream_t *streamptr, int ng ...@@ -7568,26 +7551,22 @@ void scan_global_attributes(int fileID, int vlistID, stream_t *streamptr, int ng
} }
else else
{ {
int *attint; int attint[attlen];
attint = (int *) malloc(attlen*sizeof(int));
cdfGetAttInt(fileID, NC_GLOBAL, attname, (int)attlen, attint); cdfGetAttInt(fileID, NC_GLOBAL, attname, (int)attlen, attint);
if ( xtype == NC_SHORT ) if ( xtype == NC_SHORT )
vlistDefAttInt(vlistID, CDI_GLOBAL, attname, DATATYPE_INT16, (int)attlen, attint); vlistDefAttInt(vlistID, CDI_GLOBAL, attname, DATATYPE_INT16, (int)attlen, attint);
else else
vlistDefAttInt(vlistID, CDI_GLOBAL, attname, DATATYPE_INT32, (int)attlen, attint); vlistDefAttInt(vlistID, CDI_GLOBAL, attname, DATATYPE_INT32, (int)attlen, attint);
free(attint);
} }
} }
else if ( xtype == NC_FLOAT || xtype == NC_DOUBLE ) else if ( xtype == NC_FLOAT || xtype == NC_DOUBLE )
{ {
double *attflt; double attflt[attlen];
attflt = (double *) malloc(attlen*sizeof(double));
cdfGetAttDouble(fileID, NC_GLOBAL, attname, (int)attlen, attflt); cdfGetAttDouble(fileID, NC_GLOBAL, attname, (int)attlen, attflt);
if ( xtype == NC_FLOAT ) if ( xtype == NC_FLOAT )
vlistDefAttFlt(vlistID, CDI_GLOBAL, attname, DATATYPE_FLT32, (int)attlen, attflt); vlistDefAttFlt(vlistID, CDI_GLOBAL, attname, DATATYPE_FLT32, (int)attlen, attflt);
else else
vlistDefAttFlt(vlistID, CDI_GLOBAL, attname, DATATYPE_FLT64, (int)attlen, attflt); vlistDefAttFlt(vlistID, CDI_GLOBAL, attname, DATATYPE_FLT64, (int)attlen, attflt);
free(attflt);
} }
} }
} }
......
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