Commit 909fe487 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cdi: short info update

parent c907ff8b
......@@ -301,18 +301,11 @@ void printShortinfo(int streamID, int vlistID, int vardis)
int varID;
int gridsize = 0;
int gridID, zaxisID, param;
int zaxistype, ltype;
int vdate, vtime;
int nrecs, nvars, nzaxis, ntsteps;
int levelID, levelsize;
int tsID, ntimeout;
int nvars, ntsteps;
int levelsize;
int tsteptype, taxisID;
int nbyte, nbyte0;
int index;
char varname[CDI_MAX_NAME];
char longname[CDI_MAX_NAME];
char units[CDI_MAX_NAME];
double level;
char *modelptr, *instptr;
int datatype;
int year, month, day, hour, minute, second;
......@@ -413,83 +406,15 @@ void printShortinfo(int streamID, int vlistID, int vardis)
fprintf(stdout, "\n");
}
fprintf(stdout, " Grid coordinates :\n");
fprintf(stdout, " Grid coordinates");
fprintf(stdout, " :\n");
printGridInfo(vlistID);
nzaxis = vlistNzaxis(vlistID);
fprintf(stdout, " Vertical coordinates :\n");
for ( index = 0; index < nzaxis; index++)
{
zaxisID = vlistZaxis(vlistID, index);
zaxistype = zaxisInqType(zaxisID);
ltype = zaxisInqLtype(zaxisID);
levelsize = zaxisInqSize(zaxisID);
/* zaxisInqLongname(zaxisID, longname); */
zaxisName(zaxistype, longname);
longname[18] = 0;
zaxisInqUnits(zaxisID, units);
units[12] = 0;
if ( zaxistype == ZAXIS_GENERIC && ltype != 0 )
nbyte0 = fprintf(stdout, " %4d : %-11s (ltype=%3d) : ", vlistZaxisIndex(vlistID, zaxisID)+1, longname, ltype);
else
nbyte0 = fprintf(stdout, " %4d : %-18s %5s : ", vlistZaxisIndex(vlistID, zaxisID)+1, longname, units);
nbyte = nbyte0;
for ( levelID = 0; levelID < levelsize; levelID++ )
{
if ( nbyte > MAXCHARS )
{
fprintf(stdout, "\n");
fprintf(stdout, "%*s", nbyte0, "");
nbyte = nbyte0;
}
level = zaxisInqLevel(zaxisID, levelID);
nbyte += fprintf(stdout, "%.9g ", level);
}
fprintf(stdout, "\n");
if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
{
double level1, level2;
nbyte = nbyte0;
fprintf(stdout, "%33s : ", "bounds");
for ( levelID = 0; levelID < levelsize; levelID++ )
{
if ( nbyte > MAXCHARS )
{
fprintf(stdout, "\n");
fprintf(stdout, "%*s", nbyte0, "");
nbyte = nbyte0;
}
level1 = zaxisInqLbound(zaxisID, levelID);
level2 = zaxisInqUbound(zaxisID, levelID);
nbyte += fprintf(stdout, "%.9g-%.9g ", level1, level2);
}
fprintf(stdout, "\n");
}
fprintf(stdout, " Vertical coordinates");
fprintf(stdout, " :\n");
if ( zaxistype == ZAXIS_REFERENCE )
{
int number = zaxisInqNumber(zaxisID);
if ( number > 0 )
{
fprintf(stdout, "%33s : ", "zaxis");
fprintf(stdout, "number = %d\n", number);
}
char uuidOfVGrid[17];
zaxisInqUUID(zaxisID, uuidOfVGrid);
if ( uuidOfVGrid[0] != 0 )
{
char uuidOfVGridStr[37];
uuid2str(uuidOfVGrid, uuidOfVGridStr);
if ( uuidOfVGridStr[0] != 0 && strlen(uuidOfVGridStr) == 36 )
{
fprintf(stdout, "%33s : ", "uuid");
fprintf(stdout, "%s\n", uuidOfVGridStr);
}
}
}
}
printZaxisInfo(vlistID);
taxisID = vlistInqTaxis(vlistID);
ntsteps = vlistNtsteps(vlistID);
......@@ -531,27 +456,8 @@ void printShortinfo(int streamID, int vlistID, int vardis)
fprintf(stdout, " YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss\n");
ntimeout = 0;
tsID = 0;
while ( (nrecs = streamInqTimestep(streamID, tsID)) )
{
if ( ntimeout == 4 )
{
ntimeout = 0;
fprintf(stdout, "\n");
}
printTimesteps(streamID, taxisID);
vdate = taxisInqVdate(taxisID);
vtime = taxisInqVtime(taxisID);
cdiDecodeDate(vdate, &year, &month, &day);
cdiDecodeTime(vtime, &hour, &minute, &second);
fprintf(stdout, " %5.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
year, month, day, hour, minute, second);
ntimeout++;
tsID++;
}
fprintf(stdout, "\n");
}
}
......
......@@ -134,7 +134,6 @@ void printGridInfo(int vlistID)
{
int ngrids, index;
int gridID, gridtype, trunc, gridsize, xsize, ysize, xysize;
int nbyte0;
char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
char uuidOfHGrid[17];
......@@ -153,7 +152,7 @@ void printGridInfo(int vlistID)
gridInqXunits(gridID, xunits);
gridInqYunits(gridID, yunits);
nbyte0 = fprintf(stdout, " %4d : %-12s ", index+1, gridNamePtr(gridtype));
fprintf(stdout, " %4d : %-24s", index+1, gridNamePtr(gridtype));
if ( gridtype == GRID_LONLAT ||
gridtype == GRID_LCC2 ||
......@@ -172,7 +171,7 @@ void printGridInfo(int vlistID)
ylast = gridInqYval(gridID, ysize-1);
yinc = gridInqYinc(gridID);
fprintf(stdout, " : points=%d", gridsize);
fprintf(stdout, " : points=%d", gridsize);
if ( gridtype == GRID_GAUSSIAN_REDUCED )
fprintf(stdout, " nlat=%d", ysize);
else if ( xysize )
......@@ -188,35 +187,24 @@ void printGridInfo(int vlistID)
if ( xsize > 0 && lxcoord )
{
if ( gridtype == GRID_GAUSSIAN_REDUCED )
{
fprintf(stdout, " : points=%d nlat=%d\n", gridsize, ysize);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "longitude : reduced\n");
}
else
{
xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, xsize-1);
xinc = gridInqXinc(gridID);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "%-9s : %g", xname, xfirst);
if ( xsize > 1 )
{
fprintf(stdout, " to %g", xlast);
if ( IS_NOT_EQUAL(xinc, 0) )
fprintf(stdout, " by %g", xinc);
}
fprintf(stdout, " %s", xunits);
if ( gridIsCircular(gridID) ) fprintf(stdout, " circular");
fprintf(stdout, "\n");
}
xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, xsize-1);
xinc = gridInqXinc(gridID);
fprintf(stdout, "%33s : %g", xname, xfirst);
if ( xsize > 1 )
{
fprintf(stdout, " to %g", xlast);
if ( IS_NOT_EQUAL(xinc, 0) )
fprintf(stdout, " by %g", xinc);
}
fprintf(stdout, " %s", xunits);
if ( gridIsCircular(gridID) ) fprintf(stdout, " circular");
fprintf(stdout, "\n");
}
if ( ysize > 0 && lycoord )
{
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "%-9s : %g", yname, yfirst);
fprintf(stdout, "%33s : %g", yname, yfirst);
if ( ysize > 1 )
{
fprintf(stdout, " to %g", ylast);
......@@ -233,16 +221,14 @@ void printGridInfo(int vlistID)
lonpole = gridInqXpole(gridID);
latpole = gridInqYpole(gridID);
angle = gridInqAngle(gridID);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "northpole : lon=%g lat=%g", lonpole, latpole);
fprintf(stdout, "%33s : lon=%g lat=%g", "northpole", lonpole, latpole);
if ( angle > 0 ) fprintf(stdout, " angle=%g", angle);
fprintf(stdout, "\n");
}
if ( gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
{
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "available :");
fprintf(stdout, "%33s :", "available");
if ( gridInqXbounds(gridID, NULL) ) fprintf(stdout, " xbounds");
if ( gridInqYbounds(gridID, NULL) ) fprintf(stdout, " ybounds");
if ( gridHasArea(gridID) ) fprintf(stdout, " area");
......@@ -254,42 +240,40 @@ void printGridInfo(int vlistID)
{
double a, lon_0, lat_0;
gridInqLaea(gridID, &a, &lon_0, &lat_0);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "projpar : a=%g lon_0=%g lat_0=%g\n", a, lon_0, lat_0);
fprintf(stdout, "%33s : a=%g lon_0=%g lat_0=%g\n", "projpar", a, lon_0, lat_0);
}
if ( gridtype == GRID_LCC2 )
{
double a, lon_0, lat_0, lat_1, lat_2;
gridInqLcc2(gridID, &a, &lon_0, &lat_0, &lat_1, &lat_2);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "projpar : a=%7.0f lon_0=%g lat_0=%g lat_1=%g lat_2=%g\n",
a, lon_0, lat_0, lat_1, lat_2);
fprintf(stdout, "%33s : a=%7.0f lon_0=%g lat_0=%g lat_1=%g lat_2=%g\n",
"projpar", a, lon_0, lat_0, lat_1, lat_2);
}
}
else if ( gridtype == GRID_SPECTRAL )
{
fprintf(stdout, " : points=%d nsp=%d truncation=%d\n", gridsize, gridsize/2, trunc);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, " complexPacking=%d\n", gridInqComplexPacking(gridID));
fprintf(stdout, " : points=%d nsp=%d truncation=%d", gridsize, gridsize/2, trunc);
if ( gridInqComplexPacking(gridID) ) fprintf(stdout, " complexPacking");
fprintf(stdout, "\n");
}
else if ( gridtype == GRID_FOURIER )
{
fprintf(stdout, " : points=%d nfc=%d truncation=%d\n", gridsize, gridsize/2, trunc);
fprintf(stdout, " : points=%d nfc=%d truncation=%d\n", gridsize, gridsize/2, trunc);
}
else if ( gridtype == GRID_GME )
{
int ni, nd;
ni = gridInqGMEni(gridID);
nd = gridInqGMEnd(gridID);
fprintf(stdout, " : points=%d nd=%d ni=%d\n", gridsize, nd, ni);
fprintf(stdout, " : points=%d nd=%d ni=%d\n", gridsize, nd, ni);
}
else if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED )
{
if ( gridtype == GRID_CURVILINEAR )
fprintf(stdout, " : points=%d (%dx%d)", gridsize, xsize, ysize);
fprintf(stdout, " : points=%d (%dx%d)", gridsize, xsize, ysize);
else
fprintf(stdout, " : points=%d", gridsize);
fprintf(stdout, " : points=%d", gridsize);
if ( gridtype == GRID_UNSTRUCTURED && gridInqNvertex(gridID) > 0 )
fprintf(stdout, " nvertex=%d", gridInqNvertex(gridID));
......@@ -303,16 +287,14 @@ void printGridInfo(int vlistID)
if ( number > 0 )
{
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "grid : number=%d position=%d\n", number, position);
fprintf(stdout, "%33s : number=%d position=%d\n", "grid", number, position);
}
if ( gridInqReference(gridID, NULL) )
{
char reference_link[8192];
gridInqReference(gridID, reference_link);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "uri : %s\n", reference_link);
fprintf(stdout, "%33s : %s\n", "uri", reference_link);
}
}
......@@ -339,12 +321,10 @@ void printGridInfo(int vlistID)
if ( yvals[i] > ylast ) ylast = yvals[i];
}
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "%-9s : %g to %g %s", xname, xfirst, xlast, xunits);
fprintf(stdout, "%33s : %g to %g %s", xname, xfirst, xlast, xunits);
if ( gridIsCircular(gridID) ) fprintf(stdout, " circular");
fprintf(stdout, "\n");
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "%-9s : %g to %g %s\n", yname, yfirst, ylast, yunits);
fprintf(stdout, "%33s : %g to %g %s\n", yname, yfirst, ylast, yunits);
free(xvals);
free(yvals);
......@@ -358,24 +338,21 @@ void printGridInfo(int vlistID)
gridInqLCC(gridID, &originLon, &originLat, &lonParY, &lat1, &lat2, &xincm, &yincm,
&projflag, &scanflag);
fprintf(stdout, " : points=%d (%dx%d) ", gridsize, xsize, ysize);
fprintf(stdout, " : points=%d (%dx%d) ", gridsize, xsize, ysize);
if ( (projflag&128) == 0 )
fprintf(stdout, "North Pole\n");
else
fprintf(stdout, "South Pole\n");
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, " originLon=%g originLat=%g lonParY=%g\n",
originLon, originLat, lonParY);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, " lat1=%g lat2=%g xinc=%g m yinc=%g m\n",
lat1, lat2, xincm, yincm);
fprintf(stdout, "%33s : originLon=%g originLat=%g lonParY=%g\n", " ", originLon, originLat, lonParY);
fprintf(stdout, "%33s : lat1=%g lat2=%g xinc=%g m yinc=%g m\n", " ", lat1, lat2, xincm, yincm);
}
else /* if ( gridtype == GRID_GENERIC ) */
{
if ( ysize == 0 )
fprintf(stdout, " : points=%d\n", gridsize);
fprintf(stdout, " : points=%d\n", gridsize);
else
fprintf(stdout, " : points=%d (%dx%d)\n", gridsize, xsize, ysize);
fprintf(stdout, " : points=%d (%dx%d)\n", gridsize, xsize, ysize);
}
if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC )
......@@ -383,8 +360,7 @@ void printGridInfo(int vlistID)
if ( gridInqXvals(gridID, NULL) || gridInqYvals(gridID, NULL) || gridHasArea(gridID) ||
gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
{
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "available :");
fprintf(stdout, "%33s :", "available");
if ( gridInqXvals(gridID, NULL) ) fprintf(stdout, " xvals");
if ( gridInqYvals(gridID, NULL) ) fprintf(stdout, " yvals");
if ( gridInqXbounds(gridID, NULL) ) fprintf(stdout, " xbounds");
......@@ -402,10 +378,234 @@ void printGridInfo(int vlistID)
uuid2str(uuidOfHGrid, uuidOfHGridStr);
if ( uuidOfHGridStr[0] != 0 && strlen(uuidOfHGridStr) == 36 )
{
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "uuid : %s\n", uuidOfHGridStr);
fprintf(stdout, "%33s : %s\n", "uuid", uuidOfHGridStr);
}
}
}
}
static
void printZaxisInfo(int vlistID)
{
int nzaxis, index;
int zaxisID, zaxistype, levelsize, levelID;
int ltype;
double *levels = NULL;
char zaxisname[CDI_MAX_NAME], zname[CDI_MAX_NAME], zunits[CDI_MAX_NAME];
nzaxis = vlistNzaxis(vlistID);
for ( index = 0; index < nzaxis; index++)
{
double zfirst = 0, zlast = 0, zinc = 0;
zaxisID = vlistZaxis(vlistID, index);
zaxistype = zaxisInqType(zaxisID);
ltype = zaxisInqLtype(zaxisID);
levelsize = zaxisInqSize(zaxisID);
zaxisName(zaxistype, zaxisname);
zaxisInqName(zaxisID, zname);
zaxisInqUnits(zaxisID, zunits);
zunits[12] = 0;
if ( zaxistype == ZAXIS_GENERIC && ltype != 0 )
fprintf(stdout, " %4d : %-12s (ltype=%3d) :", vlistZaxisIndex(vlistID, zaxisID)+1, zaxisname, ltype);
else
fprintf(stdout, " %4d : %-24s :", vlistZaxisIndex(vlistID, zaxisID)+1, zaxisname);
fprintf(stdout, " levels=%d", levelsize);
fprintf(stdout, "\n");
levels = (double*) malloc(levelsize*sizeof(double));
zaxisInqLevels(zaxisID, levels);
if ( !(zaxistype == ZAXIS_SURFACE && levelsize == 1 && !(fabs(levels[0]) > 0)) )
{
zfirst = levels[0];
zlast = levels[levelsize-1];
if ( levelsize > 2 )
{
zinc = (levels[levelsize-1] - levels[0]) / (levelsize-1);
for ( levelID = 2; levelID < levelsize; ++levelID )
if ( fabs(fabs(levels[levelID] - levels[levelID-1]) - zinc) > 0.001*zinc ) break;
if ( levelID < levelsize ) zinc = 0;
}
fprintf(stdout, "%33s : %g", zname, zfirst);
if ( levelsize > 1 )
{
fprintf(stdout, " to %g", zlast);
if ( IS_NOT_EQUAL(zinc, 0) )
fprintf(stdout, " by %g", zinc);
}
fprintf(stdout, " %s", zunits);
fprintf(stdout, "\n");
}
free(levels);
if ( zaxisInqLbounds(zaxisID, NULL) && zaxisInqUbounds(zaxisID, NULL) )
{
double level1, level2;
fprintf(stdout, "%33s : ", "bounds");
level1 = zaxisInqLbound(zaxisID, 0);
level2 = zaxisInqUbound(zaxisID, 0);
fprintf(stdout, "%.9g-%.9g", level1, level2);
if ( levelsize > 1 )
{
level1 = zaxisInqLbound(zaxisID, levelsize-1);
level2 = zaxisInqUbound(zaxisID, levelsize-1);
fprintf(stdout, " to %.9g-%.9g", level1, level2);
if ( IS_NOT_EQUAL(zinc, 0) )
fprintf(stdout, " by %g", zinc);
}
fprintf(stdout, " %s", zunits);
fprintf(stdout, "\n");
}
if ( zaxistype == ZAXIS_REFERENCE )
{
int number = zaxisInqNumber(zaxisID);
if ( number > 0 )
{
fprintf(stdout, "%33s : ", "zaxis");
fprintf(stdout, "number = %d\n", number);
}
char uuidOfVGrid[17];
zaxisInqUUID(zaxisID, uuidOfVGrid);
if ( uuidOfVGrid[0] != 0 )
{
char uuidOfVGridStr[37];
uuid2str(uuidOfVGrid, uuidOfVGridStr);
if ( uuidOfVGridStr[0] != 0 && strlen(uuidOfVGridStr) == 36 )
{
fprintf(stdout, "%33s : ", "uuid");
fprintf(stdout, "%s\n", uuidOfVGridStr);
}
}
}
}
}
static
int printDateTime(int ntimeout, int vdate, int vtime)
{
char vdatestr[32], vtimestr[32];
if ( ntimeout == 4 )
{
ntimeout = 0;
fprintf(stdout, "\n");
}
date2str(vdate, vdatestr, sizeof(vdatestr));
time2str(vtime, vtimestr, sizeof(vtimestr));
fprintf(stdout, " %s %s", vdatestr, vtimestr);
return (++ntimeout);
}
#define NUM_TIMESTEP 60
#define MAX_DOTS 80
static
int printDot(int ndotout, int *nfact, int *ncout)
{
//printf("ncout %d %d %d\n",*ncout, (*ncout)%(*nfact), *nfact);
if ( (*ncout)%(*nfact) == 0 )
{
if ( ndotout == MAX_DOTS )
{
*ncout = 0;
ndotout = 0;
fprintf(stdout, "\n ");
(*nfact) *= 10;
}
fprintf(stdout, ".");
fflush(stdout);
ndotout++;
}
(*ncout)++;
return (ndotout);
}
static
void printTimesteps(int streamID, int taxisID)
{
int nrecs;
int vdate, vtime;
struct datetime {
int vdate;
int vtime;
struct datetime *next;
};
struct datetime vdatetime[NUM_TIMESTEP];
struct datetime *next_vdatetime = vdatetime;
for ( int i = 0; i < NUM_TIMESTEP-1; ++i ) vdatetime[i].next = &vdatetime[i+1];
vdatetime[NUM_TIMESTEP-1].next = &vdatetime[0];
int ntimeout = 0;
int ndotout = 0;
int nvdatetime = 0;
int ncout = 0;
int nfact = 1;
int tsID = 0;
while ( (nrecs = streamInqTimestep(streamID, tsID)) )
{
vdate = taxisInqVdate(taxisID);
vtime = taxisInqVtime(taxisID);
if ( tsID < NUM_TIMESTEP )
{
ntimeout = printDateTime(ntimeout, vdate, vtime);
}
else
{
if ( tsID == 2*NUM_TIMESTEP ) fprintf(stdout, "\n ");
if ( tsID >= 2*NUM_TIMESTEP ) ndotout = printDot(ndotout, &nfact, &ncout);
if ( nvdatetime < NUM_TIMESTEP )
{
vdatetime[nvdatetime].vdate = vdate;
vdatetime[nvdatetime].vtime = vtime;
nvdatetime++;
}
else
{
next_vdatetime->vdate = vdate;
next_vdatetime->vtime = vtime;
next_vdatetime = next_vdatetime->next;
}
}
tsID++;
}
if ( nvdatetime )
{
fprintf(stdout, "\n");
ntimeout = 0;
int toff = tsID%4;
if ( toff > 0 ) toff = 4 - toff;
for ( int i = 0; i < toff; ++i ) next_vdatetime = next_vdatetime->next;
for ( int i = toff; i < nvdatetime; ++i )
{
vdate = next_vdatetime->vdate;
vtime = next_vdatetime->vtime;
ntimeout = printDateTime(ntimeout, vdate, vtime);
next_vdatetime = next_vdatetime->next;
}
}
}
/*
......
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