Commit 5c646e59 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

check dimension order (bug fix)

parent c5e8959c
......@@ -2695,15 +2695,8 @@ int cdfDefVar(int streamID, int varID)
cdiDecodeParam(param, &pnum, &pcat, &pdis);
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 ) lchunk = FALSE;
gridsize = gridInqSize(gridID);
if ( gridsize > 1 ) lchunk = TRUE;
gridtype = gridInqType(gridID);
......@@ -2719,11 +2712,23 @@ int cdfDefVar(int streamID, int varID)
zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
zid = streamptr->zaxisID[zaxisindex];
dimorder[0] = ixyz/100;
dimorder[1] = (ixyz-dimorder[0]*100)/10;
dimorder[2] = (ixyz-dimorder[0]*100-dimorder[1]*10);
if ( dimorder[0] == 3 ) lchunk = FALSE; /* ZYX and ZXY */
if ( ((dimorder[0]>0)+(dimorder[1]>0)+(dimorder[2]>0)) < ((xid!=UNDEFID)+(yid!=UNDEFID)+(zid!=UNDEFID)) )
{
printf("xyz=%d zid=%d yid=%d xid=%d\n", ixyz, zid, yid, xid);
Error("Internal problem, dimension order missing!");
}
tid = streamptr->basetime.ncdimid;
if ( timeID == TIME_VARIABLE )
{
if ( tid == UNDEFID ) Error("Internal problem! Time undefined.");
if ( tid == UNDEFID ) Error("Internal problem, time undefined!");
chunks[ndims] = 1;
dims[ndims++] = tid;
axis[iax++] = 'T';
......@@ -3393,19 +3398,8 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
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);
......@@ -3432,6 +3426,16 @@ int cdfReadVarSliceDP(int streamID, int varID, int levelID, double *data, int *n
/*
printf("2 %d %d %d %s\n", streamID, zaxisindex, streamptr->zaxisID[zaxisindex], vlistInqVarNamePtr(vlistID, varID));
*/
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) && xid != UNDEFID && yid != UNDEFID ) swapxy = TRUE;
/*
printf("swapxy %d\n", swapxy);
printf("ixyz %d\n", ixyz);
printf("dimorder: %d %d %d\n", dimorder[0], dimorder[1], dimorder[2]);
*/
if ( timeID == TIME_VARIABLE )
{
......@@ -3572,19 +3576,8 @@ int cdfWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
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]);
*/
gridindex = vlistGridIndex(vlistID, gridID);
if ( gridInqType(gridID) == GRID_TRAJECTORY )
{
......@@ -3599,6 +3592,17 @@ int cdfWriteVarSliceDP(int streamID, int varID, int levelID, const double *data,
zaxisindex = vlistZaxisIndex(vlistID, zaxisID);
zid = streamptr->zaxisID[zaxisindex];
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) && xid != UNDEFID && yid != UNDEFID ) swapxy = TRUE;
/*
printf("swapxy %d\n", swapxy);
printf("ixyz %d\n", ixyz);
printf("dimorder: %d %d %d\n", dimorder[0], dimorder[1], dimorder[2]);
*/
if ( timeID == TIME_VARIABLE )
{
start[ndims] = ntsteps - 1;
......
......@@ -1540,6 +1540,31 @@ void vlistDefVarXYZ(int vlistID, int varID, int xyz)
vlistCheckVarID(__func__, vlistID, varID);
/* check xyz dimension order */
{
int dimorder[3];
int dimx = 0, dimy = 0, dimz = 0;
int posx = -1, posy = -1, posz = -1;
dimorder[0] = xyz/100;
dimorder[1] = (xyz-dimorder[0]*100)/10;
dimorder[2] = (xyz-dimorder[0]*100-dimorder[1]*10);
for ( int id = 0; id < 3; ++id )
{
if ( dimorder[id] == 3 ) { dimz++; posz=id; }
else if ( dimorder[id] == 2 ) { dimy++; posy=id; }
else if ( dimorder[id] == 1 ) { dimx++; posx=id; }
}
if ( dimz > 1 || dimy > 1 || dimx > 1 ) xyz = 321; // ZYX
else
{
int lchanged = 0;
if ( dimz == 0 ) for ( int id = 0; id < 3; ++id ) if ( dimorder[id] == 0 ) {dimorder[id] = 3; lchanged++; break;}
if ( dimy == 0 ) for ( int id = 0; id < 3; ++id ) if ( dimorder[id] == 0 ) {dimorder[id] = 2; lchanged++; break;}
if ( dimx == 0 ) for ( int id = 0; id < 3; ++id ) if ( dimorder[id] == 0 ) {dimorder[id] = 1; lchanged++; break;}
if ( lchanged ) xyz = dimorder[0]*100 + dimorder[1]*10 + dimorder[2];
}
}
vlistptr->vars[varID].xyz = xyz;
}
......
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