Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • b383306/libcdi
  • mpim-sw/libcdi
  • m214007/libcdi
3 results
Show changes
Commits on Source (9)
......@@ -2,6 +2,20 @@
* Version 2.5.1 released
2025-02-01 Uwe Schulzweida
* Added support for READ_CELL_CENTER=false
2025-01-30 Uwe Schulzweida
* Added CDI_KEY_CHUNKSIZE_DIMX
* Added CDI_KEY_CHUNKSIZE_DIMY
2025-01-29 Uwe Schulzweida
* Added CDI_KEY_CHUNKSIZE_DIMZ
* Added CDI_KEY_CHUNKSIZE_DIMT
2025-01-14 Uwe Schulzweida
* NetCDF: Fix error in scanning coordinates attribute
......
......@@ -200,7 +200,7 @@ static void
cdfCloseFile(int fileID)
{
if (CDF_Debug) Message( "Closing cdf file: %d", fileID);
if (CDF_Debug) Message("Closing cdf file: %d", fileID);
cdf_close(fileID);
}
......@@ -209,6 +209,7 @@ cdfClose(int fileID)
{
cdfCloseFile(fileID);
}
#endif
/*
* Local Variables:
......
......@@ -150,7 +150,6 @@ void
cdf_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp)
{
int status = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp);
if (CDF_Debug || status != NC_NOERR)
Message("ncid=%d ndims=%d nvars=%d ngatts=%d unlimid=%d", ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);
......@@ -161,9 +160,7 @@ void
cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp)
{
int status = nc_def_dim(ncid, name, len, dimidp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d name=%s len=%zu", ncid, name, len);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -171,9 +168,7 @@ void
cdf_inq_dimid(int ncid, const char *name, int *dimidp)
{
int status = nc_inq_dimid(ncid, name, dimidp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d name=%s dimid=%d", ncid, name, *dimidp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -181,9 +176,7 @@ void
cdf_inq_dim(int ncid, int dimid, char *name, size_t *lengthp)
{
int status = nc_inq_dim(ncid, dimid, name, lengthp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d dimid=%d length=%zu name=%s", ncid, dimid, *lengthp, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -191,9 +184,7 @@ void
cdf_inq_dimname(int ncid, int dimid, char *name)
{
int status = nc_inq_dimname(ncid, dimid, name);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d dimid=%d name=%s", ncid, dimid, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -201,9 +192,7 @@ void
cdf_inq_dimlen(int ncid, int dimid, size_t *lengthp)
{
int status = nc_inq_dimlen(ncid, dimid, lengthp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d dimid=%d length=%zu", ncid, dimid, *lengthp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -233,9 +222,7 @@ void
cdf_inq_varid(int ncid, const char *name, int *varidp)
{
int status = nc_inq_varid(ncid, name, varidp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d name=%s varid=%d", ncid, name, *varidp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -243,9 +230,7 @@ void
cdf_inq_nvars(int ncid, int *nvarsp)
{
int status = nc_inq_nvars(ncid, nvarsp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d nvars=%d", ncid, *nvarsp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -253,7 +238,6 @@ void
cdf_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp, int dimids[], int *nattsp)
{
int status = nc_inq_var(ncid, varid, name, xtypep, ndimsp, dimids, nattsp);
if (CDF_Debug || status != NC_NOERR)
Message("ncid=%d varid=%d ndims=%d xtype=%d natts=%d name=%s", ncid, varid, *ndimsp, *xtypep, *nattsp, name);
......@@ -264,9 +248,7 @@ void
cdf_inq_varname(int ncid, int varid, char *name)
{
int status = nc_inq_varname(ncid, varid, name);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d name=%s", ncid, varid, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -274,9 +256,7 @@ void
cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
{
int status = nc_inq_vartype(ncid, varid, xtypep);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d xtype=%s", ncid, varid, *xtypep);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -284,9 +264,7 @@ void
cdf_inq_varndims(int ncid, int varid, int *ndimsp)
{
int status = nc_inq_varndims(ncid, varid, ndimsp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -294,9 +272,7 @@ void
cdf_inq_vardimid(int ncid, int varid, int dimids[])
{
int status = nc_inq_vardimid(ncid, varid, dimids);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -304,9 +280,7 @@ void
cdf_inq_varnatts(int ncid, int varid, int *nattsp)
{
int status = nc_inq_varnatts(ncid, varid, nattsp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d nattsp=%d", ncid, varid, *nattsp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -314,9 +288,7 @@ void
cdf_put_var_text(int ncid, int varid, const char *tp)
{
int status = nc_put_var_text(ncid, varid, tp);
if (CDF_Debug || status != NC_NOERR) Message("%d %d %s", ncid, varid, tp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -324,9 +296,7 @@ void
cdf_put_var_short(int ncid, int varid, const short *sp)
{
int status = nc_put_var_short(ncid, varid, sp);
if (CDF_Debug || status != NC_NOERR) Message("%d %d %hd", ncid, varid, *sp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -334,9 +304,7 @@ void
cdf_put_var_int(int ncid, int varid, const int *ip)
{
int status = nc_put_var_int(ncid, varid, ip);
if (CDF_Debug || status != NC_NOERR) Message("%d %d %d", ncid, varid, *ip);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -344,9 +312,7 @@ void
cdf_put_var_long(int ncid, int varid, const long *lp)
{
int status = nc_put_var_long(ncid, varid, lp);
if (CDF_Debug || status != NC_NOERR) Message("%d %d %ld", ncid, varid, *lp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -354,9 +320,7 @@ void
cdf_put_var_float(int ncid, int varid, const float *fp)
{
int status = nc_put_var_float(ncid, varid, fp);
if (CDF_Debug || status != NC_NOERR) Message("%d %d %f", ncid, varid, *fp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -419,7 +383,6 @@ void
cdf_put_vara_double(int ncid, int varid, const size_t start[], const size_t count[], const double *dp)
{
int status = nc_put_vara_double(ncid, varid, start, count, dp);
if (CDF_Debug || status != NC_NOERR)
{
char name[256];
......@@ -442,7 +405,6 @@ void
cdf_put_vara_float(int ncid, int varid, const size_t start[], const size_t count[], const float *fp)
{
int status = nc_put_vara_float(ncid, varid, start, count, fp);
if (CDF_Debug || status != NC_NOERR)
{
char name[256];
......@@ -465,9 +427,7 @@ void
cdf_put_vara(int ncid, int varid, const size_t start[], const size_t count[], const void *cp)
{
int status = nc_put_vara(ncid, varid, start, count, cp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -475,9 +435,7 @@ void
cdf_get_vara(int ncid, int varid, const size_t start[], const size_t count[], void *cp)
{
int status = nc_get_vara(ncid, varid, start, count, cp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -485,9 +443,7 @@ void
cdf_get_vara_int(int ncid, int varid, const size_t start[], const size_t count[], int *dp)
{
int status = nc_get_vara_int(ncid, varid, start, count, dp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -495,9 +451,7 @@ void
cdf_get_vara_double(int ncid, int varid, const size_t start[], const size_t count[], double *dp)
{
int status = nc_get_vara_double(ncid, varid, start, count, dp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d start[0]=%zu count[0]=%zu", ncid, varid, start[0], count[0]);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -505,9 +459,7 @@ void
cdf_get_vara_float(int ncid, int varid, const size_t start[], const size_t count[], float *fp)
{
int status = nc_get_vara_float(ncid, varid, start, count, fp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d start[0]=%zu count[0]=%zu", ncid, varid, start[0], count[0]);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -515,9 +467,7 @@ void
cdf_get_vara_text(int ncid, int varid, const size_t start[], const size_t count[], char *tp)
{
int status = nc_get_vara_text(ncid, varid, start, count, tp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -525,9 +475,7 @@ void
cdf_get_vara_uchar(int ncid, int varid, const size_t start[], const size_t count[], unsigned char *tp)
{
int status = nc_get_vara_uchar(ncid, varid, start, count, tp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -535,9 +483,7 @@ void
cdf_put_var_double(int ncid, int varid, const double *dp)
{
int status = nc_put_var_double(ncid, varid, dp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d val0=%f", ncid, varid, *dp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -545,9 +491,7 @@ void
cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp)
{
int status = nc_get_var1_text(ncid, varid, index, tp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -555,9 +499,7 @@ void
cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
{
int status = nc_get_var1_double(ncid, varid, index, dp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -565,9 +507,7 @@ void
cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
{
int status = nc_put_var1_double(ncid, varid, index, dp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d val=%f", ncid, varid, *dp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -575,9 +515,7 @@ void
cdf_get_var_text(int ncid, int varid, char *tp)
{
int status = nc_get_var_text(ncid, varid, tp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -585,9 +523,7 @@ void
cdf_get_var_short(int ncid, int varid, short *sp)
{
int status = nc_get_var_short(ncid, varid, sp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -595,9 +531,7 @@ void
cdf_get_var_int(int ncid, int varid, int *ip)
{
int status = nc_get_var_int(ncid, varid, ip);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -605,9 +539,7 @@ void
cdf_get_var_long(int ncid, int varid, long *lp)
{
int status = nc_get_var_long(ncid, varid, lp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -615,9 +547,7 @@ void
cdf_get_var_float(int ncid, int varid, float *fp)
{
int status = nc_get_var_float(ncid, varid, fp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d", ncid, varid);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -625,9 +555,7 @@ void
cdf_get_var_double(int ncid, int varid, double *dp)
{
int status = nc_get_var_double(ncid, varid, dp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d val[0]=%f", ncid, varid, *dp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -635,9 +563,7 @@ void
cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out)
{
int status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
if (CDF_Debug || status != NC_NOERR) Message("%d %d %s %d %d", ncid_in, varid_out, name, ncid_out, varid_out);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -645,9 +571,7 @@ void
cdf_put_att_text(int ncid, int varid, const char *name, size_t len, const char *tp)
{
int status = nc_put_att_text(ncid, varid, name, len, tp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s text='%.*s'", ncid, varid, name, (int) len, tp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -655,11 +579,8 @@ void
cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype, size_t len, const int *ip)
{
int status = nc_put_att_int(ncid, varid, name, xtype, len, ip);
if (status == NC_ERANGE) status = NC_NOERR;
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s val=%d", ncid, varid, name, *ip);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -667,9 +588,7 @@ void
cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype, size_t len, const float *dp)
{
int 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));
}
......@@ -677,9 +596,7 @@ void
cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype, size_t len, const double *dp)
{
int status = nc_put_att_double(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));
}
......@@ -687,9 +604,7 @@ void
cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
{
int status = nc_get_att_text(ncid, varid, name, tp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d name=%s", ncid, varid, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -698,9 +613,7 @@ cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
{
#ifdef HAVE_NETCDF4
int status = nc_get_att_string(ncid, varid, name, tp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d name=%s", ncid, varid, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
#endif
}
......@@ -709,11 +622,8 @@ void
cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
{
int status = nc_get_att_int(ncid, varid, name, ip);
if (status == NC_ERANGE) status = NC_NOERR;
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s val=%d", ncid, varid, name, *ip);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -722,11 +632,8 @@ cdf_get_att_longlong(int ncid, int varid, const char *name, long long *llp)
{
#ifdef HAVE_NETCDF4
int status = nc_get_att_longlong(ncid, varid, name, llp);
if (status == NC_ERANGE) status = NC_NOERR;
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s val=%lld", ncid, varid, name, *llp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
#endif
}
......@@ -735,9 +642,7 @@ void
cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
{
int 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);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -745,9 +650,7 @@ void
cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
{
int status = nc_inq_att(ncid, varid, name, xtypep, lenp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s", ncid, varid, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -755,9 +658,7 @@ void
cdf_inq_atttype(int ncid, int varid, const char *name, nc_type *xtypep)
{
int status = nc_inq_atttype(ncid, varid, name, xtypep);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s", ncid, varid, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -765,9 +666,7 @@ void
cdf_inq_attlen(int ncid, int varid, const char *name, size_t *lenp)
{
int status = nc_inq_attlen(ncid, varid, name, lenp);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s len=%zu", ncid, varid, name, *lenp);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -775,9 +674,7 @@ void
cdf_inq_attname(int ncid, int varid, int attnum, char *name)
{
int status = nc_inq_attname(ncid, varid, attnum, name);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d attnum=%d att=%s", ncid, varid, attnum, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -785,9 +682,7 @@ void
cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
{
int status = nc_inq_attid(ncid, varid, name, attnump);
if (CDF_Debug || status != NC_NOERR) Message("ncid=%d varid=%d att=%s", ncid, varid, name);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
......@@ -796,10 +691,34 @@ void
cdf_def_var_chunking(int ncid, int varid, int storage, const size_t *chunksizesp)
{
int status = nc_def_var_chunking(ncid, varid, storage, chunksizesp);
if (CDF_Debug || status != NC_NOERR)
Message("chunks=%zu/%zu/%zu/%zu", chunksizesp[0], chunksizesp[1], chunksizesp[2], chunksizesp[3]);
if (status != NC_NOERR) Error("%s", nc_strerror(status));
}
#endif
size_t
cdf_xtype_to_numbytes(nc_type xtype)
{
size_t numBytes = 8;
// clang-format off
if (xtype == NC_BYTE ) numBytes = 1;
else if (xtype == NC_CHAR ) numBytes = 1;
else if (xtype == NC_SHORT ) numBytes = 2;
else if (xtype == NC_INT ) numBytes = 4;
else if (xtype == NC_FLOAT ) numBytes = 4;
#ifdef HAVE_NETCDF4
else if (xtype == NC_UBYTE ) numBytes = 1;
else if (xtype == NC_USHORT) numBytes = 2;
else if (xtype == NC_LONG ) numBytes = 4;
else if (xtype == NC_UINT ) numBytes = 4;
#endif
// clang-format on
return numBytes;
}
#endif
/*
* Local Variables:
......
......@@ -99,6 +99,9 @@ int cdi_nc_enddef_serial(int ncid, int streamID);
int cdi_nc__enddef_serial(int ncid, int streamID, size_t hdr_pad, size_t v_align, size_t v_minfree, size_t r_align);
typedef int (*cdi_nc_enddef_funcp)(int ncid, int streamID);
typedef int (*cdi_nc__enddef_funcp)(int ncid, int streamID, size_t hdr_pad, size_t v_align, size_t v_minfree, size_t r_align);
size_t cdf_xtype_to_numbytes(nc_type xtype);
#endif
#endif /* CDF_INT_H */
......
......@@ -42,7 +42,7 @@ static void
cdfLazyGridDelete(grid_t *grid)
{
struct cdfLazyGrid *cdfGrid = (struct cdfLazyGrid *) grid;
void (*baseDestroy)(grid_t * grid) = cdfGrid->baseVtable->destroy;
void (*baseDestroy)(grid_t *grid) = cdfGrid->baseVtable->destroy;
cdfLazyGridDestroy(cdfGrid);
baseDestroy(grid);
}
......@@ -194,7 +194,7 @@ cdfLazyGridInqXVal(grid_t *grid, SizeType index)
{
struct cdfLazyGrid *lazyGrid = (struct cdfLazyGrid *) grid;
lock_lazy_load(lazyGrid);
const double rv = cdfLazyGridInqXYVal(grid, (size_t) index, &lazyGrid->xValsGet, grid->x.vals, grid->vtable->inqXValsPtr);
double rv = cdfLazyGridInqXYVal(grid, (size_t) index, &lazyGrid->xValsGet, grid->x.vals, grid->vtable->inqXValsPtr);
unlock_lazy_load(lazyGrid);
return rv;
}
......@@ -204,7 +204,7 @@ cdfLazyGridInqYVal(grid_t *grid, SizeType index)
{
struct cdfLazyGrid *lazyGrid = (struct cdfLazyGrid *) grid;
lock_lazy_load(lazyGrid);
const double rv = cdfLazyGridInqXYVal(grid, (size_t) index, &lazyGrid->yValsGet, grid->y.vals, grid->vtable->inqYValsPtr);
double rv = cdfLazyGridInqXYVal(grid, (size_t) index, &lazyGrid->yValsGet, grid->y.vals, grid->vtable->inqYValsPtr);
unlock_lazy_load(lazyGrid);
return rv;
}
......@@ -315,10 +315,10 @@ cdfLazyGridCopyScalarFields(grid_t *gridptrOrig, grid_t *gridptrDup)
static void
cdfLazyGridCopyArrayFields(grid_t *gridptrOrig, grid_t *gridptrDup)
{
const size_t reducedPointsSize = (size_t) gridptrOrig->reducedPointsSize;
const size_t gridsize = gridptrOrig->size;
const int gridtype = gridptrOrig->type;
const int irregular = (gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED);
size_t reducedPointsSize = (size_t) gridptrOrig->reducedPointsSize;
size_t gridsize = gridptrOrig->size;
int gridtype = gridptrOrig->type;
int irregular = (gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED);
if (reducedPointsSize)
{
......@@ -328,28 +328,28 @@ cdfLazyGridCopyArrayFields(grid_t *gridptrOrig, grid_t *gridptrDup)
if (gridptrOrig->x.vals != NULL && gridptrOrig->x.vals != cdfPendingLoad)
{
const size_t size = irregular ? gridsize : gridptrOrig->x.size;
size_t size = irregular ? gridsize : gridptrOrig->x.size;
gridptrDup->x.vals = (double *) Malloc(size * sizeof(double));
memcpy(gridptrDup->x.vals, gridptrOrig->x.vals, size * sizeof(double));
}
if (gridptrOrig->y.vals != NULL && gridptrOrig->y.vals != cdfPendingLoad)
{
const size_t size = irregular ? gridsize : gridptrOrig->y.size;
size_t size = irregular ? gridsize : gridptrOrig->y.size;
gridptrDup->y.vals = (double *) Malloc(size * sizeof(double));
memcpy(gridptrDup->y.vals, gridptrOrig->y.vals, size * sizeof(double));
}
if (gridptrOrig->x.bounds != NULL && gridptrOrig->x.bounds != cdfPendingLoad)
{
const size_t size = (irregular ? gridsize : gridptrOrig->x.size) * (size_t) gridptrOrig->nvertex;
size_t size = (irregular ? gridsize : gridptrOrig->x.size) * (size_t) gridptrOrig->nvertex;
gridptrDup->x.bounds = (double *) Malloc(size * sizeof(double));
memcpy(gridptrDup->x.bounds, gridptrOrig->x.bounds, size * sizeof(double));
}
if (gridptrOrig->y.bounds != NULL && gridptrOrig->y.bounds != cdfPendingLoad)
{
const size_t size = (irregular ? gridsize : gridptrOrig->y.size) * (size_t) gridptrOrig->nvertex;
size_t size = (irregular ? gridsize : gridptrOrig->y.size) * (size_t) gridptrOrig->nvertex;
gridptrDup->y.bounds = (double *) Malloc(size * sizeof(double));
memcpy(gridptrDup->y.bounds, gridptrOrig->y.bounds, size * sizeof(double));
}
......@@ -357,7 +357,7 @@ cdfLazyGridCopyArrayFields(grid_t *gridptrOrig, grid_t *gridptrDup)
{
if (gridptrOrig->area != NULL && gridptrOrig->area != cdfPendingLoad)
{
const size_t size = gridsize;
size_t size = gridsize;
gridptrDup->area = (double *) Malloc(size * sizeof(double));
memcpy(gridptrDup->area, gridptrOrig->area, size * sizeof(double));
}
......@@ -365,14 +365,14 @@ cdfLazyGridCopyArrayFields(grid_t *gridptrOrig, grid_t *gridptrDup)
if (gridptrOrig->mask != NULL)
{
const size_t size = gridsize;
size_t size = gridsize;
gridptrDup->mask = (mask_t *) Malloc(size * sizeof(mask_t));
memcpy(gridptrDup->mask, gridptrOrig->mask, size * sizeof(mask_t));
}
if (gridptrOrig->mask_gme != NULL)
{
const size_t size = gridsize;
size_t size = gridsize;
gridptrDup->mask_gme = (mask_t *) Malloc(size * sizeof(mask_t));
memcpy(gridptrDup->mask_gme, gridptrOrig->mask_gme, size * sizeof(mask_t));
}
......
......@@ -747,8 +747,9 @@ calc_chunksize_x(int chunkType, long chunkSize, size_t xsize, bool isReg2dGrid)
static int
cdfDefineDimsAndChunks(const stream_t *streamptr, int varID, int xid, int yid, int zid, size_t gridsize, const int dimorder[3],
int dims[4], bool useChunks, size_t chunks[4], char axis[5], size_t *piax)
int dims[4], bool useChunks, size_t chunks[4], char axis[5], size_t *piax, size_t *pchunkCacheSize)
{
size_t chunkCacheSize = 1;
int fileID = streamptr->fileID;
int vlistID = streamptr->vlistID;
......@@ -757,18 +758,22 @@ cdfDefineDimsAndChunks(const stream_t *streamptr, int varID, int xid, int yid, i
for (int i = 0; i < 4; ++i) chunks[i] = 0;
size_t xsize = 0, ysize = 0;
size_t xsize = 0, ysize = 0, zsize = 0;
if (xid != CDI_UNDEFID) cdf_inq_dimlen(fileID, xid, &xsize);
if (yid != CDI_UNDEFID) cdf_inq_dimlen(fileID, yid, &ysize);
if (zid != CDI_UNDEFID) cdf_inq_dimlen(fileID, zid, &zsize);
int timetype = vlistInqVarTimetype(vlistID, varID);
if (vlistHasTime(vlistID) && timetype != TIME_CONSTANT)
{
int chunkSizeDimT = 0;
cdiInqKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMT, &chunkSizeDimT);
int tid = streamptr->basetime.ncdimid;
if (tid == CDI_UNDEFID) Error("Internal problem, time undefined!");
axis[iax++] = 'T';
chunks[ndims] = 1;
chunks[ndims] = (chunkSizeDimT > 0) ? chunkSizeDimT : 1;
dims[ndims] = tid;
chunkCacheSize *= chunks[ndims];
ndims++;
}
......@@ -789,21 +794,35 @@ cdfDefineDimsAndChunks(const stream_t *streamptr, int varID, int xid, int yid, i
{
if (dimorder[id] == 3 && zid != CDI_UNDEFID)
{
int chunkSizeDimZ = 0;
cdiInqKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMZ, &chunkSizeDimZ);
if (chunkSizeDimZ == -1) chunkSizeDimZ = zsize;
axis[iax++] = 'Z';
chunks[ndims] = 1;
chunks[ndims] = (chunkSizeDimZ > 0) ? chunkSizeDimZ : 1;
dims[ndims] = zid;
chunkCacheSize *= (chunkCacheSize > 1) ? zsize : chunks[ndims];
ndims++;
}
else if (dimorder[id] == 2 && yid != CDI_UNDEFID)
{
chunks[ndims] = calc_chunksize_y(chunkType, gridsize, xsize, ysize);
int chunkSizeDimY = 0;
cdiInqKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMY, &chunkSizeDimY);
if (chunkSizeDimY == -1) chunkSizeDimY = ysize;
if (chunkSizeDimY == 0) chunkSizeDimY = calc_chunksize_y(chunkType, gridsize, xsize, ysize);
chunks[ndims] = chunkSizeDimY;
dims[ndims] = yid;
chunkCacheSize *= ysize;
ndims++;
}
else if (dimorder[id] == 1 && xid != CDI_UNDEFID)
{
chunks[ndims] = calc_chunksize_x(chunkType, chunkSize, xsize, isReg2dGrid);
int chunkSizeDimX = 0;
cdiInqKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMX, &chunkSizeDimX);
if (chunkSizeDimX == -1) chunkSizeDimX = xsize;
if (chunkSizeDimX == 0) chunkSizeDimX = calc_chunksize_x(chunkType, chunkSize, xsize, isReg2dGrid);
chunks[ndims] = chunkSizeDimX;
dims[ndims] = xid;
chunkCacheSize *= xsize;
ndims++;
}
}
......@@ -812,6 +831,7 @@ cdfDefineDimsAndChunks(const stream_t *streamptr, int varID, int xid, int yid, i
fprintf(stderr, "useChunks %d chunkType %d chunkSize %d chunks %zu %zu %zu %zu\n", useChunks, chunkType, chunkSize, chunks[0],
chunks[1], chunks[2], chunks[3]);
*pchunkCacheSize = chunkCacheSize;
*piax = iax;
return ndims;
}
......@@ -921,14 +941,15 @@ cdfGenVarname(int fileID, char name[CDI_MAX_NAME], int pnum, int pcat, int *pdis
}
static void
cdfDefVarChunkCache(int fileID, int ncvarID)
cdfDefVarChunkCache(int fileID, int ncvarID, size_t chunkCacheSize)
{
size_t size = 0;
size_t nelems = 0;
float preemption = 0;
if (CDI_Chunk_Cache > 0 && nc_get_var_chunk_cache(fileID, ncvarID, &size, &nelems, &preemption) == NC_NOERR)
if (nc_get_var_chunk_cache(fileID, ncvarID, &size, &nelems, &preemption) == NC_NOERR)
{
size = (size_t) CDI_Chunk_Cache;
if (chunkCacheSize > size) size = chunkCacheSize;
if (CDI_Chunk_Cache > 0) size = (size_t) CDI_Chunk_Cache;
}
nc_set_var_chunk_cache(fileID, ncvarID, size, nelems, preemption);
......@@ -979,8 +1000,9 @@ cdfDefVar(stream_t *streamptr, int varID)
char axis[5];
int dims[4];
size_t chunks[4];
int ndims
= cdfDefineDimsAndChunks(streamptr, varID, xid, yid, zid, (size_t) gridsize, dimorder, dims, useChunks, chunks, axis, &iax);
size_t chunkCacheSize = 1;
int ndims = cdfDefineDimsAndChunks(streamptr, varID, xid, yid, zid, (size_t) gridsize, dimorder, dims, useChunks, chunks, axis,
&iax, &chunkCacheSize);
char name[CDI_MAX_NAME];
int length = CDI_MAX_NAME;
......@@ -1003,19 +1025,20 @@ cdfDefVar(stream_t *streamptr, int varID)
else
cdfGenVarname(fileID, name, pnum, pcat, &pdis, &code);
int dtype = vlistInqVarDatatype(vlistID, varID);
nc_type xtype = cdfDefDatatype(dtype, streamptr);
if (streamptr->ncmode == 2)
{
cdf_redef(fileID);
streamptr->ncmode = 1;
}
int dtype = vlistInqVarDatatype(vlistID, varID);
nc_type xtype = cdfDefDatatype(dtype, streamptr);
int ncvarID = -1;
cdf_def_var(fileID, name, xtype, ndims, dims, &ncvarID);
cdfDefVarChunkCache(fileID, ncvarID);
chunkCacheSize *= cdf_xtype_to_numbytes(xtype);
cdfDefVarChunkCache(fileID, ncvarID, chunkCacheSize);
#ifdef HAVE_NETCDF4
#ifdef NC_QUANTIZE_BITROUND
......
......@@ -846,6 +846,10 @@ SizeType gridInqYCvals(int gridID, char *ycvals[]);
#define CDI_KEY_NLEV 964 // GRIB2 nlev
#define CDI_KEY_CHUNKTYPE 965 // ChunkType: CDI_CHUNK_AUTO/CDI_CHUNK_GRID/CDI_CHUNK_LINES
#define CDI_KEY_CHUNKSIZE 966 // ChunkSize
#define CDI_KEY_CHUNKSIZE_DIMT 967 // ChunkSize time dimension
#define CDI_KEY_CHUNKSIZE_DIMZ 968 // ChunkSize zaxis dimension
#define CDI_KEY_CHUNKSIZE_DIMY 969 // ChunkSize yaxis dimension
#define CDI_KEY_CHUNKSIZE_DIMX 970 // ChunkSize xaxis dimension
// Floating point keys
#define CDI_KEY_MISSVAL 701 // Missing value
......
......@@ -5,8 +5,6 @@
#include "config.h"
#endif
extern int cdi_fdb_dummy;
#ifdef HAVE_LIBFDB5
#include <fdb5/api/fdb_c.h>
......
......@@ -41,12 +41,14 @@ int CDI_Inventory_Mode = 1;
int CDI_Version_Info = 1;
int CDI_Query_Abort = 1;
int CDI_Convert_Cubesphere = 1;
int CDI_Read_Cell_Center = 1;
int CDI_Read_Cell_Corners = 1;
int CDI_CMOR_Mode = 0;
int CDI_Reduce_Dim = 0;
int CDI_Shuffle = 0;
int CDI_Test = 0;
size_t CDI_Netcdf_Hdr_Pad = 0UL;
bool CDI_CopyChunkSpec = false;
bool CDI_Chunk_Cache_Info = false;
long CDI_Chunk_Cache = -1L;
size_t CDI_Chunk_Cache_Max = 0UL;
......@@ -347,6 +349,9 @@ cdiInitialize(void)
value = cdi_getenv_int("CDI_LOCK_IO");
if (value >= 0) CDI_Lock_IO = (bool) value;
value = cdi_getenv_int("CDI_READ_CELL_CENTER");
if (value >= 0) CDI_Read_Cell_Center = (int) value;
value = cdi_getenv_int("CDI_READ_CELL_CORNERS");
if (value >= 0) CDI_Read_Cell_Corners = (int) value;
......@@ -368,6 +373,9 @@ cdiInitialize(void)
value = cdi_getenv_int("CDI_NETCDF_HDR_PAD");
if (value >= 0) CDI_Netcdf_Hdr_Pad = (size_t) value;
value = cdi_getenv_int("CDI_COPY_CHUNKSPEC");
if (value >= 0) CDI_CopyChunkSpec = (value > 0);
value = cdi_getenv_int("CDI_CHUNK_CACHE_INFO");
if (value > 0) CDI_Chunk_Cache_Info = true;
......@@ -515,6 +523,7 @@ cdiDefGlobal(const char *string, int value)
else if (str_is_equal(string, "SORTNAME")) cdiSortName = value;
else if (str_is_equal(string, "HAVE_MISSVAL")) cdiHaveMissval = value;
else if (str_is_equal(string, "NC_CHUNKSIZEHINT")) CDI_Netcdf_Chunksizehint = value;
else if (str_is_equal(string, "READ_CELL_CENTER")) CDI_Read_Cell_Center = value;
else if (str_is_equal(string, "READ_CELL_CORNERS")) CDI_Read_Cell_Corners = value;
else if (str_is_equal(string, "CMOR_MODE")) CDI_CMOR_Mode = value;
else if (str_is_equal(string, "REDUCE_DIM")) CDI_Reduce_Dim = value;
......
......@@ -417,11 +417,13 @@ extern int CDI_Inventory_Mode;
extern int CDI_Query_Abort;
extern int CDI_Version_Info;
extern int CDI_Convert_Cubesphere;
extern int CDI_Read_Cell_Center;
extern int CDI_Read_Cell_Corners;
extern int CDI_CMOR_Mode;
extern int CDI_Reduce_Dim;
extern int CDI_Shuffle;
extern size_t CDI_Netcdf_Hdr_Pad;
extern bool CDI_CopyChunkSpec;
extern bool CDI_Chunk_Cache_Info;
extern long CDI_Chunk_Cache;
extern size_t CDI_Chunk_Cache_Max;
......
......@@ -68,7 +68,7 @@ find_key(cdi_keys_t *keysp, int key)
if (keysp->nelems == 0) return NULL;
for (size_t keyid = 0; keyid < keysp->nelems; keyid++)
for (uint16_t keyid = 0; keyid < keysp->nelems; keyid++)
{
cdi_key_t *keyp = &(keysp->value[keyid]);
if (keyp->key == key) return keyp; // Normal return
......@@ -84,7 +84,7 @@ find_key_const(const cdi_keys_t *keysp, int key)
if (keysp->nelems == 0) return NULL;
for (size_t keyid = 0; keyid < keysp->nelems; keyid++)
for (uint16_t keyid = 0; keyid < keysp->nelems; keyid++)
{
const cdi_key_t *keyp = &(keysp->value[keyid]);
if (keyp->key == key) return keyp; // Normal return
......@@ -96,10 +96,11 @@ find_key_const(const cdi_keys_t *keysp, int key)
static cdi_keys_t *
cdi_get_keysp(int objID, int varID)
{
if (reshGetTxCode(objID) == GRID) return grid_get_keysp(grid_to_pointer(objID), varID);
if (reshGetTxCode(objID) == DIST_GRID) return grid_get_keysp(grid_to_pointer(objID), varID);
if (reshGetTxCode(objID) == ZAXIS) return zaxis_get_keysp(zaxis_to_pointer(objID), varID);
if (reshGetTxCode(objID) == VLIST) return vlist_get_keysp(vlist_to_pointer(objID), varID);
int reshID = reshGetTxCode(objID);
if (reshID == GRID) return grid_get_keysp(grid_to_pointer(objID), varID);
if (reshID == DIST_GRID) return grid_get_keysp(grid_to_pointer(objID), varID);
if (reshID == ZAXIS) return zaxis_get_keysp(zaxis_to_pointer(objID), varID);
if (reshID == VLIST) return vlist_get_keysp(vlist_to_pointer(objID), varID);
return NULL;
}
......@@ -114,9 +115,9 @@ cdi_key_compare(cdi_keys_t *keyspa, cdi_keys_t *keyspb, int keynum)
if (keypa->type != keypb->type) return 1;
if (keypa->length != keypb->length) return 1;
if (keypa->type == KEY_BYTES) return (memcmp(keypa->v.s, keypb->v.s, (size_t) keypa->length) != 0);
if (keypa->type == KEY_FLOAT) return (IS_NOT_EQUAL(keypa->v.d, keypb->v.d));
if (keypa->type == KEY_INT) return (keypa->v.i != keypb->v.i);
if (keypa->type == KeyBytes) return (memcmp(keypa->v.s, keypb->v.s, (size_t) keypa->length) != 0);
if (keypa->type == KeyFloat) return (IS_NOT_EQUAL(keypa->v.d, keypb->v.d));
if (keypa->type == KeyInt) return (keypa->v.i != keypb->v.i);
return 0;
}
......@@ -127,16 +128,16 @@ cdi_delete_key(cdi_key_t *keyp)
if (keyp != NULL && keyp->length) // key in use
{
keyp->length = 0;
if (keyp->type == KEY_BYTES)
if (keyp->type == KeyBytes)
{
if (keyp->v.s) Free(keyp->v.s);
keyp->v.s = NULL;
}
else if (keyp->type == KEY_FLOAT)
else if (keyp->type == KeyFloat)
{
keyp->v.d = 0.0;
}
else if (keyp->type == KEY_INT)
else if (keyp->type == KeyInt)
{
keyp->v.i = 0;
}
......@@ -146,8 +147,8 @@ cdi_delete_key(cdi_key_t *keyp)
void
cdiDeleteVarKeys(cdi_keys_t *keysp)
{
int nelems = keysp ? (int) keysp->nelems : 0;
for (int keyid = 0; keyid < nelems; keyid++)
uint16_t nelems = keysp ? keysp->nelems : 0;
for (uint16_t keyid = 0; keyid < nelems; keyid++)
{
cdi_delete_key(&(keysp->value[keyid]));
}
......@@ -167,20 +168,20 @@ cdiDeleteKeys(int cdiID, int varID)
void
cdiPrintVarKeys(cdi_keys_t *keysp)
{
int nelems = keysp ? (int) keysp->nelems : 0;
for (int keyid = 0; keyid < nelems; keyid++)
uint16_t nelems = keysp ? (int) keysp->nelems : 0;
for (uint16_t keyid = 0; keyid < nelems; keyid++)
{
cdi_key_t *keyp = &(keysp->value[keyid]);
if (keyp->length == 0) continue;
if (keyp->type == KEY_BYTES)
if (keyp->type == KeyBytes)
{
fprintf(stdout, "%d key %d length %d value %s\n", keyid + 1, keyp->key, keyp->length, keyp->v.s);
}
else if (keyp->type == KEY_FLOAT)
else if (keyp->type == KeyFloat)
{
fprintf(stdout, "%d key %d value %g\n", keyid + 1, keyp->key, keyp->v.d);
}
else if (keyp->type == KEY_INT)
else if (keyp->type == KeyInt)
{
fprintf(stdout, "%d key %d value %d\n", keyid + 1, keyp->key, keyp->v.i);
}
......@@ -219,9 +220,9 @@ static void
cdi_define_key(const cdi_key_t *keyp, cdi_keys_t *keysp)
{
// clang-format off
if (keyp->type == KEY_INT) cdiDefVarKeyInt(keysp, keyp->key, keyp->v.i);
else if (keyp->type == KEY_FLOAT) cdiDefVarKeyFloat(keysp, keyp->key, keyp->v.d);
else if (keyp->type == KEY_BYTES) cdiDefVarKeyBytes(keysp, keyp->key, keyp->v.s, keyp->length);
if (keyp->type == KeyInt) cdiDefVarKeyInt(keysp, keyp->key, keyp->v.i);
else if (keyp->type == KeyFloat) cdiDefVarKeyFloat(keysp, keyp->key, keyp->v.d);
else if (keyp->type == KeyBytes) cdiDefVarKeyBytes(keysp, keyp->key, keyp->v.s, keyp->length);
// clang-format on
}
......@@ -241,7 +242,7 @@ cdiDeleteKey(int cdiID, int varID, int key)
void
cdiCopyVarKeys(const cdi_keys_t *keysp1, cdi_keys_t *keysp2)
{
for (size_t keyid = 0; keyid < keysp1->nelems; keyid++)
for (uint16_t keyid = 0; keyid < keysp1->nelems; keyid++)
{
const cdi_key_t *keyp = &(keysp1->value[keyid]);
if (keyp->length > 0) cdi_define_key(keyp, keysp2);
......@@ -299,7 +300,7 @@ cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value)
{
// if ( keyp->v.i != value )
{
keyp->type = KEY_INT;
keyp->type = KeyInt;
keyp->v.i = value;
keyp->length = 1;
}
......@@ -370,7 +371,7 @@ cdiInqKeyInt(int cdiID, int varID, int key, int *value)
const cdi_key_t *keyp = find_key_const(keysp, key);
if (keyp != NULL && keyp->length == 1) // key in use
{
if (keyp->type == KEY_INT)
if (keyp->type == KeyInt)
{
*value = keyp->v.i;
status = CDI_NOERR;
......@@ -386,7 +387,7 @@ cdiInqVarKeyInt(const cdi_keys_t *keysp, int key)
int value = 0;
const cdi_key_t *keyp = find_key_const(keysp, key);
if (keyp && keyp->type == KEY_INT) value = keyp->v.i;
if (keyp && keyp->type == KeyInt) value = keyp->v.i;
return value;
}
......@@ -399,7 +400,7 @@ cdiDefVarKeyFloat(cdi_keys_t *keysp, int key, double value)
if (keyp != NULL)
{
keyp->type = KEY_FLOAT;
keyp->type = KeyFloat;
keyp->v.d = value;
keyp->length = 1;
}
......@@ -469,7 +470,7 @@ cdiInqKeyFloat(int cdiID, int varID, int key, double *value)
const cdi_key_t *keyp = find_key_const(keysp, key);
if (keyp != NULL && keyp->length == 1) // key in use
{
if (keyp->type == KEY_FLOAT)
if (keyp->type == KeyFloat)
{
*value = keyp->v.d;
status = CDI_NOERR;
......@@ -500,7 +501,7 @@ cdiDefVarKeyBytes(cdi_keys_t *keysp, int key, const unsigned char *bytes, int le
}
memcpy(keyp->v.s, bytes, length_);
keyp->type = KEY_BYTES;
keyp->type = KeyBytes;
}
}
......@@ -546,7 +547,7 @@ cdiInqVarKeyBytes(const cdi_keys_t *keysp, int key, unsigned char *bytes, int *l
int val_len;
if (keyp != NULL && (val_len = keyp->length) > 0) // key in use
{
if (keyp->type == KEY_BYTES)
if (keyp->type == KeyBytes)
{
if (val_len < *length)
*length = val_len;
......@@ -702,7 +703,7 @@ cdiInqVarKeyStringPtr(const cdi_keys_t *keysp, int key)
const cdi_key_t *keyp = find_key_const(keysp, key);
if (keyp != NULL) // key in use
{
if (keyp->type == KEY_BYTES) return (const char *) keyp->v.s;
if (keyp->type == KeyBytes) return (const char *) keyp->v.s;
}
return NULL;
......@@ -713,7 +714,7 @@ cdiInitKeys(cdi_keys_t *keysp)
{
keysp->nalloc = MAX_KEYS;
keysp->nelems = 0;
for (int i = 0; i < MAX_KEYS; ++i) keysp->value[i].length = 0;
for (uint16_t i = 0; i < MAX_KEYS; ++i) keysp->value[i].length = 0;
}
/*
......
......@@ -2,14 +2,15 @@
#define CDI_KEY_H
#include <stdio.h>
#include <stdint.h>
#include "cdi_limits.h"
// CDI key
typedef struct
{
int key; // CDI key
int type; // KEY_INT, KEY_FLOAT, KEY_BYTES
int length; // number of bytes in v.s
uint16_t key; // CDI key
uint16_t type; // KEY_INT, KEY_FLOAT, KEY_BYTES
int length; // number of bytes in v.s
union
{
int i;
......@@ -20,16 +21,16 @@ typedef struct
typedef struct
{
size_t nalloc; // number allocated >= nelems
size_t nelems; // length of the array
uint16_t nalloc; // number allocated >= nelems
uint16_t nelems; // length of the array
cdi_key_t value[MAX_KEYS];
} cdi_keys_t;
enum
{
KEY_INT = 1,
KEY_FLOAT,
KEY_BYTES
KeyInt = 1,
KeyFloat,
KeyBytes
};
void cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value);
......
......@@ -111,7 +111,8 @@ grib1_unzip_record(void *gribbuffer, size_t *gribsize)
typedef struct JobArgsGRB
{
int recID, tsID, *outZip, filetype, memType, datatype, unreduced;
int *outZip;
int recID, tsID, filetype, memType, datatype, unreduced;
void *cgribexp, *gribbuffer, *data;
size_t recsize, gridsize, numMissVals;
double missval;
......
......@@ -42,16 +42,16 @@ serializeKeysGetPackSize(const cdi_keys_t *keysp, void *context)
int type = keyp->type;
packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context); // key
packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context); // type
if (type == KEY_BYTES)
if (type == KeyBytes)
{
int length = keyp->length;
packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context) + serializeGetSize(length, CDI_DATATYPE_TXT, context);
}
else if (type == KEY_INT)
else if (type == KeyInt)
{
packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context);
}
else if (type == KEY_FLOAT)
else if (type == KeyFloat)
{
packBuffSize += serializeGetSize(1, CDI_DATATYPE_FLT64, context);
}
......@@ -74,18 +74,18 @@ serializeKeysPack(const cdi_keys_t *keysp, void *buf, int buf_size, int *positio
int type = keyp->type;
serializePack(&key, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
serializePack(&type, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
if (type == KEY_BYTES)
if (type == KeyBytes)
{
int length = keyp->length;
serializePack(&length, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
serializePack(keyp->v.s, length, CDI_DATATYPE_TXT, buf, buf_size, position, context);
d ^= cdiCheckSum(CDI_DATATYPE_TXT, length, keyp->v.s);
}
else if (type == KEY_INT)
else if (type == KeyInt)
{
serializePack(&keyp->v.i, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
}
else if (type == KEY_FLOAT)
else if (type == KeyFloat)
{
serializePack(&keyp->v.d, 1, CDI_DATATYPE_FLT64, buf, buf_size, position, context);
}
......@@ -108,7 +108,7 @@ serializeKeysUnpack(const void *buf, int buf_size, int *position, cdi_keys_t *ke
int key, type;
serializeUnpack(buf, buf_size, position, &key, 1, CDI_DATATYPE_INT, context);
serializeUnpack(buf, buf_size, position, &type, 1, CDI_DATATYPE_INT, context);
if (type == KEY_BYTES)
if (type == KeyBytes)
{
int length;
serializeUnpack(buf, buf_size, position, &length, 1, CDI_DATATYPE_INT, context);
......@@ -121,13 +121,13 @@ serializeKeysUnpack(const void *buf, int buf_size, int *position, cdi_keys_t *ke
cdiDefVarKeyBytes(keysp, key, (unsigned char *) buffer, length);
d2 ^= cdiCheckSum(CDI_DATATYPE_TXT, length, buffer);
}
else if (type == KEY_INT)
else if (type == KeyInt)
{
int ival;
serializeUnpack(buf, buf_size, position, &ival, 1, CDI_DATATYPE_INT, context);
cdiDefVarKeyInt(keysp, key, ival);
}
else if (type == KEY_FLOAT)
else if (type == KeyFloat)
{
double dval;
serializeUnpack(buf, buf_size, position, &dval, 1, CDI_DATATYPE_FLT64, context);
......
......@@ -52,6 +52,7 @@ typedef struct
typedef struct
{
int cdiVarID;
int ncid;
int varStatus;
bool ignoreVar;
......@@ -551,7 +552,7 @@ cdf_time_dimid(int fileID, int ndims, ncdim_t *ncdims, int nvars, ncvar_t *ncvar
check_dimids[dimid0] = true;
char sbuf[CDI_MAX_NAME];
for (int iatt = 0; iatt < ncvar->nattsNC; ++iatt)
for (int iatt = 0, n = ncvar->nattsNC; iatt < n; ++iatt)
{
sbuf[0] = 0;
cdf_inq_attname(fileID, varid, iatt, sbuf);
......@@ -588,6 +589,7 @@ init_ncvars(int nvars, ncvar_t *ncvars, int ncid)
for (int varid = 0; varid < nvars; varid++)
{
ncvar_t *ncvar = &ncvars[varid];
ncvar->cdiVarID = CDI_UNDEFID;
ncvar->ncid = ncid;
ncvar->varStatus = UndefVar;
ncvar->ignoreVar = false;
......@@ -1248,10 +1250,9 @@ set_vars_timetype(int nvars, ncvar_t *ncvars, int timedimid)
}
else
{
int nvdims = ncvar->ndims;
for (int vdimid = 1; vdimid < nvdims; vdimid++)
for (int i = 1, n = ncvar->ndims; i < n; i++)
{
if (timedimid == ncvar->dimids[vdimid])
if (timedimid == ncvar->dimids[i])
{
Warning("Time must be the first dimension! Unsupported array structure, skipped variable %s!", ncvar->name);
ncvar->varStatus = CoordVar;
......@@ -1644,15 +1645,15 @@ scan_vars_attr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int model
static void
cdf_set_chunk_info(stream_t *streamptr, int nvars, ncvar_t *ncvars)
{
int vlistID = streamptr->vlistID;
CdfInfo *cdfInfo = &(streamptr->cdfInfo);
for (int ncvarid = 0; ncvarid < nvars; ncvarid++)
{
ncvar_t *ncvar = &ncvars[ncvarid];
if (ncvar->varStatus == DataVar)
int varID = ncvar->cdiVarID;
if (ncvar->varStatus == DataVar && ncvar->isChunked && varID != CDI_UNDEFID)
{
int ndims = ncvar->ndims;
ncvar->isChunked = true;
for (int i = 0; i < ndims; ++i)
for (int i = 0, n = ncvar->ndims; i < n; ++i)
{
size_t chunkSize = ncvar->chunks[i];
if (chunkSize > 1)
......@@ -1661,6 +1662,14 @@ cdf_set_chunk_info(stream_t *streamptr, int nvars, ncvar_t *ncvars)
// clang-format off
if (dimType == T_AXIS && chunkSize > cdfInfo->chunkSizeTdim) cdfInfo->chunkSizeTdim = chunkSize;
else if (dimType == Z_AXIS && chunkSize > cdfInfo->chunkSizeZdim) cdfInfo->chunkSizeZdim = chunkSize;
if (CDI_CopyChunkSpec)
{
if (dimType == T_AXIS) cdiDefKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMT, chunkSize);
else if (dimType == Z_AXIS) cdiDefKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMZ, chunkSize);
else if (dimType == Y_AXIS) cdiDefKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMY, chunkSize);
else if (dimType == X_AXIS) cdiDefKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE_DIMX, chunkSize);
}
// clang-format on
}
}
......@@ -1692,9 +1701,9 @@ verify_vars_attr(int nvars, ncvar_t *ncvars, ncdim_t *ncdims)
cdf_inq_atttype(ncid, ncvarid, attname, &atttype);
size_t attstringsize = sizeof(attstring);
bool isText = xtypeIsText(atttype);
// bool isNumber = (xtypeIsFloat(atttype) || xtypeIsInt(atttype));
bool isText = xtypeIsText(atttype);
if (isText)
{
cdfGetAttText(ncid, ncvarid, attname, sizeof(attstring), attstring);
......@@ -1721,8 +1730,7 @@ find_dimtypes(ncvar_t *ncvars, ncvar_t *ncvar, bool *plxdim, bool *plydim, bool
{
bool lxdim = false, lydim = false, lzdim = false /*, ltdim = false */;
int lcdim = 0;
int ndims = ncvar->ndims;
for (int i = 0; i < ndims; i++)
for (int i = 0, n = ncvar->ndims; i < n; i++)
{
int dimtype = ncvar->dimtypes[i];
lxdim |= (dimtype == X_AXIS);
......@@ -1749,8 +1757,7 @@ cdf_set_dimtype(int nvars, ncvar_t *ncvars, ncdim_t *ncdims)
ncvar_t *ncvar = &ncvars[varid];
if (ncvar->varStatus == DataVar)
{
int ndims = ncvar->ndims;
for (int i = 0; i < ndims; i++)
for (int i = 0, n = ncvar->ndims; i < n; i++)
{
int ncdimid = ncvar->dimids[i];
int dimtype = ncdims[ncdimid].dimtype;
......@@ -1760,7 +1767,7 @@ cdf_set_dimtype(int nvars, ncvar_t *ncvars, ncdim_t *ncdims)
if (CDI_Debug)
{
Message("var %d %s", varid, ncvar->name);
for (int i = 0; i < ndims; i++) printf(" dim%d type=%d ", i, ncvar->dimtypes[i]);
for (int i = 0, n = ncvar->ndims; i < n; i++) printf(" dim%d type=%d ", i, ncvar->dimtypes[i]);
printf("\n");
}
}
......@@ -1801,8 +1808,7 @@ cdf_set_dimtype(int nvars, ncvar_t *ncvars, ncdim_t *ncdims)
for (int varid = 0; varid < nvars; varid++)
{
ncvar_t *ncvar = &ncvars[varid];
int ndims = ncvar->ndims;
for (int i = 0; i < ndims; i++)
for (int i = 0, n = ncvar->ndims; i < n; i++)
{
if (ncvar->dimtypes[i] == CDI_UNDEFID)
{
......@@ -2287,6 +2293,12 @@ cdf_get_xydimid(int ndims, int *dimids, int *dimtypes, int *xdimid, int *ydimid)
static void
cdf_check_gridtype(int *gridtype, bool isLon, bool isLat, size_t xsize, size_t ysize, grid_t *grid)
{
if (grid->y.vals == NULL)
{
*gridtype = GRID_GENERIC;
return;
}
if (isLat && (isLon || xsize == 0))
{
double yinc = 0.0;
......@@ -2391,8 +2403,10 @@ cdf_read_xcoord(stream_t *streamptr, struct cdfLazyGrid *lazyGrid, ncdim_t *ncdi
grid->x.clength = size / (*xsize);
#endif
}
else
cdf_load_vals(size, ndims, xvarid, axisvar, &grid->x.vals, &lazyGrid->xValsGet, hasTimeDim, readPart, start, count);
else if (CDI_Read_Cell_Center)
{
cdf_load_vals(size, ndims, xvarid, axisvar, &grid->x.vals, &lazyGrid->xValsGet, hasTimeDim, readPart, start, count);
}
cdf_copy_grid_axis_attr(axisvar, &grid->x);
......@@ -2473,8 +2487,10 @@ cdf_read_ycoord(stream_t *streamptr, struct cdfLazyGrid *lazyGrid, ncdim_t *ncdi
grid->y.clength = size / (*ysize);
#endif
}
else
cdf_load_vals(size, ndims, yvarid, axisvar, &grid->y.vals, &lazyGrid->yValsGet, hasTimeDim, readPart, start, count);
else if (CDI_Read_Cell_Center)
{
cdf_load_vals(size, ndims, yvarid, axisvar, &grid->y.vals, &lazyGrid->yValsGet, hasTimeDim, readPart, start, count);
}
cdf_copy_grid_axis_attr(axisvar, &grid->y);
......@@ -3533,28 +3549,6 @@ cdf_define_institut_and_model_id(int vlistID, int varID)
if (varTableID != CDI_UNDEFID) vlistDefVarTable(vlistID, varID, varTableID);
}
static size_t
cdf_xtype_to_numbytes(int xtype)
{
size_t numBytes = 8;
// clang-format off
if (xtype == NC_BYTE ) numBytes = 1;
else if (xtype == NC_CHAR ) numBytes = 1;
else if (xtype == NC_SHORT ) numBytes = 2;
else if (xtype == NC_INT ) numBytes = 4;
else if (xtype == NC_FLOAT ) numBytes = 4;
#ifdef HAVE_NETCDF4
else if (xtype == NC_UBYTE ) numBytes = 1;
else if (xtype == NC_USHORT) numBytes = 2;
else if (xtype == NC_LONG ) numBytes = 4;
else if (xtype == NC_UINT ) numBytes = 4;
#endif
// clang-format on
return numBytes;
}
static inline size_t
size_of_dim_chunks(size_t n, size_t c)
{
......@@ -3623,6 +3617,7 @@ cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID, i
stream_new_var(streamptr, gridID, zaxisID, CDI_UNDEFID);
int varID = vlistDefVar(vlistID, gridID, zaxisID, ncvar->timetype);
ncvar->cdiVarID = varID;
#ifdef HAVE_NETCDF4
if (ncvar->hasFilter) cdiDefKeyString(vlistID, varID, CDI_KEY_FILTERSPEC_IN, ncvar->filterSpec);
......@@ -4739,8 +4734,7 @@ cdfInqContents(stream_t *streamptr)
if (status < 0) return status;
// verify vars
cdfVerifyVars(nvars, ncvars //, ncdims
);
cdfVerifyVars(nvars, ncvars);
// select vars
int nvarsData = 0;
......
......@@ -1342,6 +1342,22 @@ vlistGridIndex(int vlistID, int gridID)
return index;
}
static void
delete_chunks(int vlistID, int varID)
{
int chunkKeys[4] = { CDI_KEY_CHUNKSIZE_DIMX, CDI_KEY_CHUNKSIZE_DIMY, CDI_KEY_CHUNKSIZE_DIMZ, CDI_KEY_CHUNKSIZE_DIMT };
for (int i = 0; i < 4; ++i)
{
int chunkSize = 0;
cdiInqKeyInt(vlistID, varID, chunkKeys[i], &chunkSize);
if (chunkSize != 0) cdiDeleteKey(vlistID, varID, chunkKeys[i]);
}
int chunkSize = 0;
cdiInqKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE, &chunkSize);
if (chunkSize > 0) cdiDeleteKey(vlistID, varID, CDI_KEY_CHUNKSIZE);
}
void
vlistChangeGridIndex(int vlistID, int index, int gridID)
{
......@@ -1357,9 +1373,7 @@ vlistChangeGridIndex(int vlistID, int index, int gridID)
if (vlistptr->vars[varID].gridID == gridIDold)
{
vlistptr->vars[varID].gridID = gridID;
int chunkSize = 0;
cdiInqKeyInt(vlistID, varID, CDI_KEY_CHUNKSIZE, &chunkSize);
if (chunkSize > 0) cdiDeleteKey(vlistID, varID, CDI_KEY_CHUNKSIZE);
delete_chunks(vlistID, varID);
if (gridInqXsize(gridIDold) == 0 && gridInqXsize(gridID) > 0 && vlistInqVarXYZ(vlistID, varID) != 0)
vlistDefVarXYZ(vlistID, varID, 0);
}
......@@ -1385,7 +1399,11 @@ vlistChangeGrid(int vlistID, int gridID1, int gridID2)
}
int nvars = vlistptr->nvars;
for (int varID = 0; varID < nvars; varID++)
if (vlistptr->vars[varID].gridID == gridID1) vlistptr->vars[varID].gridID = gridID2;
if (vlistptr->vars[varID].gridID == gridID1)
{
vlistptr->vars[varID].gridID = gridID2;
delete_chunks(vlistID, varID);
}
reshSetStatus(vlistID, &vlistOps, RESH_DESYNC_IN_USE);
}
}
......
......@@ -1139,7 +1139,7 @@ static inline void
zaxisCopyKeyStr(zaxis_t *zaxisptr1, zaxis_t *zaxisptr2, int key)
{
cdi_key_t *keyp = find_key(&zaxisptr1->keys, key);
if (keyp && keyp->type == KEY_BYTES)
if (keyp && keyp->type == KeyBytes)
cdiDefVarKeyBytes(&zaxisptr2->keys, key, (const unsigned char *) keyp->v.s, (int) keyp->length);
}
......