Commit 4cd050ef authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

added interface function vlistDefVarXYZ to set the dimension order

parent 52dec846
2011-07-28 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* added interface function vlistDefVarXYZ to set the dimension order
2011-07-23 Pier Giuseppe Fogli <piergiuseppe.fogli@cmcc.it>
* added interface function zaxisInqVct to read the VCT
......@@ -9,7 +13,7 @@
2011-07-14 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* netcdf: added support for GRID_FOURIER (fourier coefficients)
2011-07-12 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* Version 1.5.1 released
......@@ -31,7 +35,7 @@
* gridGenYvals: changed delta eps to 0.002 for gaussian grids [report: John Lillibridge]
* ruby/python interface: changed GRID_CELL to GRID_UNSTRUCTURED [report: Tim Cera]
2011-05-12 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* grid::compareXYvals: bug fix for generic grids [report: Felicia Brisc]
......
......@@ -407,6 +407,9 @@ void vlistDefVarDatatype(int vlistID, int varID, int datatype);
/* vlistInqVarDatatype: Get the data type of a Variable */
int vlistInqVarDatatype(int vlistID, int varID);
void vlistDefVarXYZ(int vlistID, int varID, int xyz);
int vlistInqVarXYZ(int vlistID, int varID);
int vlistInqVarNumber(int vlistID, int varID);
void vlistDefVarInstitut(int vlistID, int varID, int instID);
......
......@@ -3333,10 +3333,8 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
int zaxisindex;
int vlistID;
int i, j;
int ndimsp;
int dimids[9];
int swapyxz = FALSE;
int swapyz = FALSE;
int dimorder[3];
int ixyz;
int swapxy = FALSE;
double missval;
int laddoffset, lscalefactor;
......@@ -3345,7 +3343,6 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
streamptr = stream_to_pointer(streamID);
if ( CDI_Debug )
Message("streamID = %d varID = %d levelID = %d", streamID, varID, levelID);
......@@ -3361,11 +3358,24 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
gridID = vlistInqVarGrid(vlistID, varID);
zaxisID = vlistInqVarZaxis(vlistID, varID);
timeID = vlistInqVarTime(vlistID, varID);
ixyz = vlistInqVarXYZ(vlistID, varID);
if ( ixyz == 0 ) ixyz = 321; // ZYX
dimorder[0] = ixyz/100;
dimorder[1] = (ixyz-dimorder[0]*100)/10;
dimorder[2] = (ixyz-dimorder[0]*100-dimorder[1]*10);
if ( dimorder[2] == 2 || dimorder[0] == 1 ) swapxy = TRUE;
/*
printf("swapxy %d\n", swapxy);
printf("ixyz %d\n", ixyz);
printf("dimorder: %d %d %d\n", dimorder[0], dimorder[1], dimorder[2]);
*/
gridsize = gridInqSize(gridID);
xsize = gridInqXsize(gridID);
ysize = gridInqYsize(gridID);
streamptr->numvals += gridsize;
gridindex = vlistGridIndex(vlistID, gridID);
......@@ -3396,145 +3406,28 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
ndims++;
}
cdf_inq_varndims(fileID, ncvarid, &ndimsp);
cdf_inq_vardimid(fileID, ncvarid, dimids);
// printf("xid %d, yid %d, zid %d\n", xid, yid, zid);
// printf("dimid2 %d, dimid3 %d, dimid4 %d\n", dimids[ndims], dimids[ndims+1], dimids[ndims+2]);
if ( zid != UNDEFID && yid != UNDEFID && xid != UNDEFID )
{
if ( yid == dimids[ndims] && xid == dimids[ndims+1] && zid == dimids[ndims+2] )
swapyxz = TRUE;
if ( zid == dimids[ndims] && xid == dimids[ndims+1] && yid == dimids[ndims+2] )
swapxy = TRUE;
}
if ( swapyxz == FALSE && swapxy == FALSE && zid != UNDEFID && yid != UNDEFID )
{
if ( zid == dimids[ndims] && yid == dimids[ndims+1] )
swapyz = FALSE;
else if ( yid == dimids[ndims] && zid == dimids[ndims+1] )
swapyz = TRUE;
else
{
char name[256];
vlistInqVarName(vlistID, varID, name);
Error("Unsupported array structure for: %s", name);
}
}
if ( swapyxz == FALSE && swapyz == FALSE && yid != UNDEFID && xid != UNDEFID )
{
if ( xid == dimids[ndimsp-1] && yid == dimids[ndimsp-2] )
swapxy = FALSE;
else if ( yid == dimids[ndimsp-1] && xid == dimids[ndimsp-2] )
swapxy = TRUE;
else
{
char name[256];
vlistInqVarName(vlistID, varID, name);
Error("Unsupported array structure for: %s", name);
}
}
if ( swapyz )
for ( int id = 0; id < 3; ++id )
{
if ( yid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqYsize(gridID); */
cdf_inq_dimlen(fileID, yid, &size);
count[ndims] = size;
ndims++;
}
if ( zid != UNDEFID )
if ( dimorder[id] == 3 && zid != UNDEFID )
{
start[ndims] = levelID;
count[ndims] = 1;
ndims++;
}
if ( xid != UNDEFID )
else if ( dimorder[id] == 2 && yid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqXsize(gridID); */
cdf_inq_dimlen(fileID, xid, &size);
count[ndims] = size;
ndims++;
}
}
else if ( swapyxz )
{
if ( yid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqYsize(gridID); */
cdf_inq_dimlen(fileID, yid, &size);
count[ndims] = size;
ndims++;
}
if ( xid != UNDEFID )
else if ( dimorder[id] == 1 && xid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqXsize(gridID); */
cdf_inq_dimlen(fileID, xid, &size);
count[ndims] = size;
ndims++;
}
if ( zid != UNDEFID )
{
start[ndims] = levelID;
count[ndims] = 1;
ndims++;
}
}
else
{
if ( zid != UNDEFID )
{
start[ndims] = levelID;
count[ndims] = 1;
ndims++;
}
if ( swapxy )
{
if ( xid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqXsize(gridID); */
cdf_inq_dimlen(fileID, xid, &size);
count[ndims] = size;
ndims++;
}
if ( yid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqYsize(gridID); */
cdf_inq_dimlen(fileID, yid, &size);
count[ndims] = size;
ndims++;
}
}
else
{
if ( yid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqYsize(gridID); */
cdf_inq_dimlen(fileID, yid, &size);
count[ndims] = size;
ndims++;
}
if ( xid != UNDEFID )
{
start[ndims] = 0;
/* count[ndims] = gridInqXsize(gridID); */
cdf_inq_dimlen(fileID, xid, &size);
count[ndims] = size;
ndims++;
}
}
}
if ( CDI_Debug )
......@@ -3670,7 +3563,6 @@ int cdfWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
{
start[ndims] = 0;
cdf_inq_dimlen(fileID, yid, &size);
/* count[ndims] = gridInqYsize(gridID); */
count[ndims] = size;
ndims++;
}
......@@ -3678,7 +3570,6 @@ int cdfWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
{
start[ndims] = 0;
cdf_inq_dimlen(fileID, xid, &size);
/* count[ndims] = gridInqXsize(gridID); */
count[ndims] = size;
ndims++;
}
......@@ -5033,7 +4924,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
{
ydimids[nydims] = ncvars[ncvarid].dimids[i];
nydims++;
}
}
}
if ( nxdims == 2 )
......@@ -5083,7 +4974,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
{
ydimid = ncvars[yvarid].dimids[0];
ysize = ncdims[ydimid].len;
}
}
}
if ( ncvars[ncvarid].gridtype == UNDEFID || ncvars[ncvarid].gridtype == GRID_GENERIC )
......@@ -5209,7 +5100,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
xinc = fabs(grid.xvals[0] - grid.xvals[1]);
for ( i = 2; i < (int) xsize; i++ )
if ( (fabs(grid.xvals[i-1] - grid.xvals[i]) - xinc) > (xinc/1000) ) break;
if ( i < (int) xsize ) xinc = 0;
}
}
......@@ -5282,7 +5173,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
yinc = fabs(grid.yvals[0] - grid.yvals[1]);
for ( i = 2; i < (int) ysize; i++ )
if ( (fabs(grid.yvals[i-1] - grid.yvals[i]) - yinc) > (yinc/1000) ) break;
if ( i < (int) ysize ) yinc = 0;
}
}
......@@ -5437,7 +5328,7 @@ void define_all_grids(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
{
proj.type = GRID_PROJECTION;
proj.name = strdup(attstring);
}
}
}
else if ( strcmp(attname, "earth_radius") == 0 )
{
......@@ -5615,13 +5506,13 @@ void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
}
if ( CDI_Debug ) Message("nlevs = %d", zsize);
zvar = (double *) malloc(zsize*sizeof(double));
zaxisType = UNDEFID;
if ( zvarid != UNDEFID ) zaxisType = ncvars[zvarid].zaxistype;
if ( zaxisType == UNDEFID ) zaxisType = ZAXIS_GENERIC;
zprec = DATATYPE_FLT64;
......@@ -5695,7 +5586,7 @@ void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
free(ubounds);
zaxisindex = vlistZaxisIndex(vlistID, ncvars[ncvarid].zaxisID);
streamptr->zaxisID[zaxisindex] = zdimid;
streamptr->zaxisID[zaxisindex] = zdimid;
if ( CDI_Debug )
Message("zaxisID %d %d %s", ncvars[ncvarid].zaxisID, ncvarid, ncvars[ncvarid].name);
......@@ -5725,7 +5616,7 @@ void define_all_zaxes(stream_t *streamptr, int fileID, int vlistID, ncdim_t *ncd
#if defined (HAVE_LIBNETCDF)
/* define all input variables */
/* define all input data variables */
static
void define_all_vars(int fileID, int streamID, int vlistID, int instID, int modelID, int tableID, int *varids, ncdim_t *ncdims, int nvars, ncvar_t *ncvars)
{
......@@ -5734,7 +5625,7 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode
stream_t *streamptr;
streamptr = stream_to_pointer(streamID);
stream_check_ptr(__func__, streamptr);
if ( streamptr->sortname )
......@@ -5812,6 +5703,39 @@ void define_all_vars(int fileID, int streamID, int vlistID, int instID, int mode
if ( CDI_Debug )
Message("varID = %d gridID = %d zaxisID = %d", varID,
vlistInqVarGrid(vlistID, varID), vlistInqVarZaxis(vlistID, varID));
int gridindex = vlistGridIndex(vlistID, gridID);
int xdimid = streamptr->xdimID[gridindex];
int ydimid = streamptr->ydimID[gridindex];
int zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
int zdimid = streamptr->zaxisID[zaxisindex];
int ndims = ncvars[ncvarid].ndims;
int iodim = 0;
int ixyz = 0;
int ipow10[4] = {1, 10, 100, 1000};
if ( ncvars[ncvarid].timeID == TIME_VARIABLE ) iodim++;
for ( int idim = iodim; idim < ndims; idim++ )
{
if ( xdimid == ncvars[ncvarid].dimids[idim] )
ixyz += 1*ipow10[(ndims-idim-1)];
else if ( ydimid == ncvars[ncvarid].dimids[idim] )
ixyz += 2*ipow10[(ndims-idim-1)];
else if ( zdimid == ncvars[ncvarid].dimids[idim] )
ixyz += 3*ipow10[(ndims-idim-1)];
}
vlistDefVarXYZ(vlistID, varID, ixyz);
/*
printf("ixyz %d\n", ixyz);
printf("ndims %d\n", ncvars[ncvarid].ndims);
for ( int i = 0; i < ncvars[ncvarid].ndims; ++i )
printf("dimids: %d %d\n", i, ncvars[ncvarid].dimids[i]);
printf("xdimid, ydimid %d %d\n", xdimid, ydimid);
*/
}
for ( varID = 0; varID < nvars; varID++ )
......@@ -6252,7 +6176,7 @@ int cdfInqContents(int streamID)
if ( ncvars[ncvarid].isvar == -1 && ncvars[ncvarid].ndims > 1 )
cdfSetVar(ncvars, ncvarid, TRUE);
if ( ncvars[ncvarid].isvar == -1 )
{
ncvars[ncvarid].isvar = 0;
......@@ -6541,7 +6465,7 @@ int cdfInqTimestep(int streamID, int tsID)
Message("streamID = %d tsID = %d", streamID, tsID);
stream_check_ptr(__func__, streamptr);
if ( tsID < 0 ) Error("unexpected tsID = %d", tsID);
if ( tsID < streamptr->ntsteps && streamptr->ntsteps > 0 )
......@@ -6774,7 +6698,7 @@ void cdfDefLocalAtts(int streamID)
}
}
}
if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
#endif
}
......
......@@ -61,6 +61,7 @@ typedef struct
int tsteptype; /* Time step type: TSTEP_INSTANT, TSTEP_AVG ... */
int timave;
int timaccu;
int xyz;
int missvalused; /* TRUE if missval is defined */
char *name;
char *longname;
......
......@@ -26,6 +26,7 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr->vars[varID].tsteptype = TSTEP_INSTANT;
vlistptr->vars[varID].timave = 0;
vlistptr->vars[varID].timaccu = 0;
vlistptr->vars[varID].xyz = 0;
vlistptr->vars[varID].gridID = CDI_UNDEFID;
vlistptr->vars[varID].zaxisID = CDI_UNDEFID;
vlistptr->vars[varID].instID = CDI_UNDEFID;
......@@ -1529,6 +1530,31 @@ int vlistInqVarCompLevel(int vlistID, int varID)
return (vlistptr->vars[varID].complevel);
}
void vlistDefVarXYZ(int vlistID, int varID, int xyz)
{
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(__func__, vlistID, varID);
vlistptr->vars[varID].xyz = xyz;
}
int vlistInqVarXYZ(int vlistID, int varID)
{
vlist_t *vlistptr;
vlistptr = vlist_to_pointer(vlistID);
vlistCheckVarID(__func__, vlistID, varID);
return (vlistptr->vars[varID].xyz);
}
/*
* Local Variables:
* c-file-style: "Java"
......
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