printinfo.h 19 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
// This file is used in CDI and CDO !!!

3
4
5
6
7
8
#if defined (HAVE_CONFIG_H)
#  include "../src/config.h"
#endif

#include <stdio.h>

9
10
11
#define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
#define TIME_FORMAT "%2.2d:%2.2d:%2.2d"

Uwe Schulzweida's avatar
Uwe Schulzweida committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void datetime2str(int date, int time, char *datetimestr, int maxlen)
{
  int year, month, day;
  cdiDecodeDate(date, &year, &month, &day);
  int hour, minute, second;
  cdiDecodeTime(time, &hour, &minute, &second);

  int len = sprintf(datetimestr, DATE_FORMAT "T" TIME_FORMAT, year, month, day, hour, minute, second);
  if ( len > ( maxlen-1) )
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
}


void date2str(int date, char *datestr, int maxlen)
26
27
28
29
{
  int year, month, day;
  cdiDecodeDate(date, &year, &month, &day);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
  int len = sprintf(datestr, DATE_FORMAT, year, month, day);
31
  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
32
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
33
34
35
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
void time2str(int time, char *timestr, int maxlen)
37
38
39
40
{
  int hour, minute, second;
  cdiDecodeTime(time, &hour, &minute, &second);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
41
  int len = sprintf(timestr, TIME_FORMAT, hour, minute, second);
42
  if ( len > ( maxlen-1) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
43
    fprintf(stderr, "Internal problem (%s): sizeof input string is too small!\n", __func__);
44
45
46
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
47
void printFiletype(int streamID, int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
48
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
49
  int filetype = streamInqFiletype(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
51
52
53
54
55
56
57
58
59

  switch ( filetype )
    {
    case FILETYPE_GRB:
      printf("GRIB");
      break;
    case FILETYPE_GRB2:
      printf("GRIB2");
      break;
    case FILETYPE_NC:
60
      printf("NetCDF");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
61
62
      break;
    case FILETYPE_NC2:
63
      printf("NetCDF2");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65
      break;
    case FILETYPE_NC4:
66
      printf("NetCDF4");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
67
      break;
68
    case FILETYPE_NC4C:
69
      printf("NetCDF4 classic");
70
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
71
72
73
74
75
76
77
78
79
80
81
    case FILETYPE_SRV:
      printf("SERVICE");
      break;
    case FILETYPE_EXT:
      printf("EXTRA");
      break;
    case FILETYPE_IEG:
      printf("IEG");
      break;
    default:
      printf("  File format: unsupported filetype %d" , filetype);
82
      break;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    }

  if ( filetype == FILETYPE_SRV || filetype == FILETYPE_EXT || filetype == FILETYPE_IEG )
    {
      switch ( streamInqByteorder(streamID) )
	{
	case CDI_BIGENDIAN:
	  printf("  BIGENDIAN"); break;
	case CDI_LITTLEENDIAN:
	  printf("  LITTLEENDIAN"); break;
	default:
	  printf("  byteorder: %d undefined", streamInqByteorder(streamID)); break;
	}
    }

98
  if ( filetype == FILETYPE_GRB || filetype == FILETYPE_NC4 || filetype == FILETYPE_NC4C )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
99
100
    {
      int nvars, varID;
101
      int comptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
102
103
104
105
106

      nvars = vlistNvars(vlistID);

      for ( varID = 0; varID < nvars; varID++ )
	{
107
108
	  comptype = vlistInqVarCompType(vlistID, varID);
	  if ( comptype )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
109
	    {
110
	      if ( comptype == COMPRESS_SZIP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
111
		printf(" SZIP");
112
	      else if ( comptype == COMPRESS_ZIP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113
114
115
116
117
118
119
		printf(" ZIP");

	      break;
	    }
	}
    }

120
121
  if ( filetype == FILETYPE_GRB2 )
    {
122
      int comptype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124
      int nvars = vlistNvars(vlistID);
      for ( int varID = 0; varID < nvars; varID++ )
125
	{
126
127
	  comptype = vlistInqVarCompType(vlistID, varID);
	  if ( comptype )
128
	    {
129
	      if ( comptype == COMPRESS_JPEG )
130
131
132
133
134
135
136
		printf(" JPEG");

	      break;
	    }
	}
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
138
139
  printf("\n");
}

Uwe Schulzweida's avatar
Uwe Schulzweida committed
140
141
static
void printGridInfo(int vlistID)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
142
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
143
  char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
144
  unsigned char uuidOfHGrid[CDI_UUID_SIZE];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145

146
147
  int ngrids = vlistNgrids(vlistID);
  for ( int index = 0; index < ngrids; index++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
    {
149
150
151
152
153
154
155
      int gridID   = vlistGrid(vlistID, index);
      int gridtype = gridInqType(gridID);
      int trunc    = gridInqTrunc(gridID);
      int gridsize = gridInqSize(gridID);
      int xsize    = gridInqXsize(gridID);
      int ysize    = gridInqYsize(gridID);
      int xysize   = xsize*ysize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
      // int prec     = gridInqPrec(gridID);
157

Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
159
      // int dig = (prec == DATATYPE_FLT64) ? 15 : 7;
      int dig = 7;
160

Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
162
163
164
165
      gridInqXname(gridID, xname);
      gridInqYname(gridID, yname);
      gridInqXunits(gridID, xunits);
      gridInqYunits(gridID, yunits);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
166
      fprintf(stdout, "  %4d : %-24s", index+1, gridNamePtr(gridtype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
167
168
169
170
171

      if ( gridtype == GRID_LONLAT   ||
	   gridtype == GRID_LCC2 ||
	   gridtype == GRID_LAEA ||
	   gridtype == GRID_SINUSOIDAL ||
172
	   gridtype == GRID_GENERIC ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
173
174
175
	   gridtype == GRID_GAUSSIAN ||
	   gridtype == GRID_GAUSSIAN_REDUCED )
	{
176
177
178
	  double yfirst = gridInqYval(gridID, 0);
	  double ylast  = gridInqYval(gridID, ysize-1);
	  double yinc   = gridInqYinc(gridID);
179

Uwe Schulzweida's avatar
Uwe Schulzweida committed
180
          fprintf(stdout, " : points=%d", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
181
	  if ( gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
182
183
184
	    fprintf(stdout, "  nlat=%d", ysize);
	  else if ( xysize )
	    fprintf(stdout, " (%dx%d)", xsize, ysize);
185

Uwe Schulzweida's avatar
Uwe Schulzweida committed
186
	  if ( gridtype == GRID_GAUSSIAN || gridtype == GRID_GAUSSIAN_REDUCED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
187
	    fprintf(stdout, "  np=%d", gridInqNP(gridID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
188
189

	  fprintf(stdout, "\n");
190

191
192
193
          bool lxcoord = true, lycoord = true;
          if ( gridInqXvals(gridID, NULL) == 0 ) lxcoord = false;
          if ( gridInqYvals(gridID, NULL) == 0 ) lycoord = false;
194
195

	  if ( xsize > 0 && lxcoord )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196
	    {
197
198
199
              double xfirst = gridInqXval(gridID, 0);
              double xlast  = gridInqXval(gridID, xsize-1);
              double xinc   = gridInqXinc(gridID);
200
              fprintf(stdout, "%33s : %.*g", xname, dig, xfirst);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
201
202
              if ( xsize > 1 )
                {
203
                  fprintf(stdout, " to %.*g", dig, xlast);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
204
                  if ( IS_NOT_EQUAL(xinc, 0) )
205
                    fprintf(stdout, " by %.*g", dig, xinc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
206
207
208
209
                }
              fprintf(stdout, " %s", xunits);
              if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
              fprintf(stdout, "\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
210
	    }
211

212
	  if ( ysize > 0 && lycoord )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
213
	    {
214
	      fprintf(stdout, "%33s : %.*g", yname, dig, yfirst);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
215
216
	      if ( ysize > 1 )
                {
217
                  fprintf(stdout, " to %.*g", dig, ylast);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
218
                  if ( IS_NOT_EQUAL(yinc, 0) && gridtype != GRID_GAUSSIAN && gridtype != GRID_GAUSSIAN_REDUCED )
219
                    fprintf(stdout, " by %.*g", dig, yinc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
220
221
                }
              fprintf(stdout, " %s", yunits);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
222
223
	      fprintf(stdout, "\n");
	    }
224

Uwe Schulzweida's avatar
Uwe Schulzweida committed
225
226
	  if ( gridIsRotated(gridID) )
	    {
227
228
229
	      double lonpole = gridInqXpole(gridID);
	      double latpole = gridInqYpole(gridID);
	      double angle   = gridInqAngle(gridID);
230
231
	      fprintf(stdout, "%33s : lon=%.*g  lat=%.*g", "northpole", dig, lonpole, dig, latpole);
	      if ( IS_NOT_EQUAL(angle, 0) ) fprintf(stdout, "  angle=%.*g", dig, angle);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
232
233
	      fprintf(stdout, "\n");
	    }
234

Uwe Schulzweida's avatar
Uwe Schulzweida committed
235
236
	  if ( gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
237
	      fprintf(stdout, "%33s :", "available");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
238
	      if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
239
	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
241
242
	      fprintf(stdout, "\n");
	    }
243

Uwe Schulzweida's avatar
Uwe Schulzweida committed
244
245
246
247
	  if ( gridtype == GRID_LAEA )
	    {
	      double a, lon_0, lat_0;
	      gridInqLaea(gridID, &a, &lon_0, &lat_0);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
248
	      fprintf(stdout, "%33s : a=%g  lon_0=%g  lat_0=%g\n", "projpar", a, lon_0, lat_0);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
	    }
250

Uwe Schulzweida's avatar
Uwe Schulzweida committed
251
252
253
254
	  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);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
255
256
	      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);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
257
258
259
260
	    }
	}
      else if ( gridtype == GRID_SPECTRAL )
	{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
261
262
263
	  fprintf(stdout, " : points=%d  nsp=%d  truncation=%d", gridsize, gridsize/2, trunc);
          if ( gridInqComplexPacking(gridID) ) fprintf(stdout, "  complexPacking");
          fprintf(stdout, "\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
264
	}
265
266
      else if ( gridtype == GRID_FOURIER )
	{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
267
	  fprintf(stdout, " : points=%d  nfc=%d  truncation=%d\n", gridsize, gridsize/2, trunc);
268
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
269
270
      else if ( gridtype == GRID_GME )
	{
271
272
	  int ni = gridInqGMEni(gridID);
	  int nd = gridInqGMEnd(gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273
	  fprintf(stdout, " : points=%d  nd=%d  ni=%d\n", gridsize, nd, ni);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
274
	}
275
      else if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
276
277
	{
	  if ( gridtype == GRID_CURVILINEAR )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
	    fprintf(stdout, " : points=%d (%dx%d)", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
279
	  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
280
	    fprintf(stdout, " : points=%d", gridsize);
281
282

          if ( gridtype == GRID_UNSTRUCTURED && gridInqNvertex(gridID) > 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
283
	    fprintf(stdout, "  nvertex=%d", gridInqNvertex(gridID));
284
285
286
287
288

          fprintf(stdout, "\n");

          if ( gridtype == GRID_UNSTRUCTURED )
            {
289
290
291
              int number   = gridInqNumber(gridID);
              int position = gridInqPosition(gridID);

292
293
              if ( number > 0 )
                {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
294
                  fprintf(stdout, "%33s : number=%d  position=%d\n", "grid", number, position);
295
296
297
298
299
300
                }

              if ( gridInqReference(gridID, NULL) )
                {
                  char reference_link[8192];
                  gridInqReference(gridID, reference_link);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
301
                  fprintf(stdout, "%33s : %s\n", "uri", reference_link);
302
303
                }
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
304
305
306

	  if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
	    {
307
308
	      double *xvals = (double*) malloc((size_t)gridsize*sizeof(double));
	      double *yvals = (double*) malloc((size_t)gridsize*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
309
310
311
312

	      gridInqXvals(gridID, xvals);
	      gridInqYvals(gridID, yvals);

313
314
315
316
317
	      double xfirst = xvals[0];
	      double xlast  = xvals[0];
	      double yfirst = yvals[0];
	      double ylast  = yvals[0];
	      for ( int i = 1; i < gridsize; i++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
318
319
		{
		  if ( xvals[i] < xfirst ) xfirst = xvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
320
		  if ( xvals[i] > xlast  ) xlast  = xvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
321
		  if ( yvals[i] < yfirst ) yfirst = yvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
322
		  if ( yvals[i] > ylast  ) ylast  = yvals[i];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
323
324
		}

325
	      fprintf(stdout, "%33s : %.*g to %.*g %s", xname, dig, xfirst, dig, xlast, xunits);
326
	      if ( gridIsCircular(gridID) ) fprintf(stdout, "  circular");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
327
	      fprintf(stdout, "\n");
328
	      fprintf(stdout, "%33s : %.*g to %.*g %s\n", yname, dig, yfirst, dig, ylast, yunits);
329

Uwe Schulzweida's avatar
Uwe Schulzweida committed
330
331
332
333
334
335
336
337
338
339
340
341
	      free(xvals);
	      free(yvals);
	    }
	}
      else if ( gridtype == GRID_LCC )
	{
	  double originLon, originLat, lonParY, lat1, lat2, xincm, yincm;
	  int projflag, scanflag;

	  gridInqLCC(gridID, &originLon, &originLat, &lonParY, &lat1, &lat2, &xincm, &yincm,
		     &projflag, &scanflag);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
342
	  fprintf(stdout, " : points=%d (%dx%d)  ", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
343
344
345
346
	  if ( (projflag&128) == 0 )
	    fprintf(stdout, "North Pole\n");
	  else
	    fprintf(stdout, "South Pole\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
347
348
349

	  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);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
350
351
352
353
	}
      else /* if ( gridtype == GRID_GENERIC ) */
	{
	  if ( ysize == 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
354
	    fprintf(stdout, " : points=%d\n", gridsize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
355
	  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
356
            fprintf(stdout, " : points=%d (%dx%d)\n", gridsize, xsize, ysize);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
357
358
	}

359
      if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
360
	{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
361
	  if ( gridHasArea(gridID) ||
Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
363
	       gridInqXbounds(gridID, NULL) || gridInqYbounds(gridID, NULL) )
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
364
	      fprintf(stdout, "%33s :", "available");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
365
	      if ( gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL) ) fprintf(stdout, " cellbounds");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
	      if ( gridHasArea(gridID) )          fprintf(stdout, " area");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
	      if ( gridInqMask(gridID, NULL) )    fprintf(stdout, " mask");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
369
370
	      fprintf(stdout, "\n");
	    }
	}
371
372

      gridInqUUID(gridID, uuidOfHGrid);
Thomas Jahns's avatar
Thomas Jahns committed
373
      if ( !cdiUUIDIsNull(uuidOfHGrid) )
374
375
        {
          char uuidOfHGridStr[37];
376
          cdiUUID2Str(uuidOfHGrid, uuidOfHGridStr);
377
378
          if ( uuidOfHGridStr[0] != 0  && strlen(uuidOfHGridStr) == 36 )
            {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379
380
381
382
383
384
385
386
387
388
389
	      fprintf(stdout, "%33s : %s\n", "uuid", uuidOfHGridStr);
            }
        }
    }
}

static
void printZaxisInfo(int vlistID)
{
  char zaxisname[CDI_MAX_NAME], zname[CDI_MAX_NAME], zunits[CDI_MAX_NAME];

390
  int nzaxis = vlistNzaxis(vlistID);
391
  for ( int index = 0; index < nzaxis; index++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392
    {
393
394
395
396
397
      double zinc = 0;
      int zaxisID   = vlistZaxis(vlistID, index);
      int zaxistype = zaxisInqType(zaxisID);
      int ltype     = zaxisInqLtype(zaxisID);
      int levelsize = zaxisInqSize(zaxisID);
398
399
400
401
      int prec      = zaxisInqPrec(zaxisID);

      int dig = (prec == DATATYPE_FLT64) ? 15 : 7;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
402
403
404
405
406
407
408
409
410
411
412
413
414
      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");

415
      double *levels = (double*) malloc((size_t)levelsize*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
416
417
418
419
      zaxisInqLevels(zaxisID, levels);

      if ( !(zaxistype == ZAXIS_SURFACE && levelsize == 1 && !(fabs(levels[0]) > 0)) )
        {
420
421
          double zfirst = levels[0];
          double zlast  = levels[levelsize-1];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
422
423
          if ( levelsize > 2 )
            {
424
              int levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
426
427
428
429
430
431
              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;
            }

432
          fprintf(stdout, "%33s : %.*g", zname, dig, zfirst);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
433
434
          if ( levelsize > 1 )
            {
435
              fprintf(stdout, " to %.*g", dig, zlast);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
436
              if ( IS_NOT_EQUAL(zinc, 0) )
437
                fprintf(stdout, " by %.*g", dig, zinc);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
438
439
440
441
442
443
444
445
446
447
448
449
450
451
            }
          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);
452
          fprintf(stdout, "%.*g-%.*g", dig, level1, dig, level2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
453
454
455
456
          if ( levelsize > 1 )
            {
              level1 = zaxisInqLbound(zaxisID, levelsize-1);
              level2 = zaxisInqUbound(zaxisID, levelsize-1);
457
              fprintf(stdout, " to %.*g-%.*g", dig, level1, dig, level2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
458
              if ( IS_NOT_EQUAL(zinc, 0) )
459
                fprintf(stdout, " by %.*g", dig, zinc);
460
            }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
461
462
          fprintf(stdout, " %s", zunits);
          fprintf(stdout, "\n");
463
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
464

Uwe Schulzweida's avatar
Uwe Schulzweida committed
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
      if ( zaxistype == ZAXIS_HYBRID )
        {
          char psname[CDI_MAX_NAME];
          psname[0] = 0;
          zaxisInqPsName(zaxisID, psname);
          int vctsize = zaxisInqVctSize(zaxisID);
          if ( vctsize || psname[0] )
            {
	      fprintf(stdout, "%33s :", "available");
              if ( vctsize   ) fprintf(stdout, " vct");
              if ( psname[0] ) fprintf(stdout, "  ps: %s", psname);
              fprintf(stdout, "\n");
            }
        }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
480
481
482
483
484
485
486
487
488
489
      if ( zaxistype == ZAXIS_REFERENCE )
        {
          int number   = zaxisInqNumber(zaxisID);

          if ( number > 0 )
            {
              fprintf(stdout, "%33s : ", "zaxis");
              fprintf(stdout, "number = %d\n", number);
            }

490
          unsigned char uuidOfVGrid[CDI_UUID_SIZE];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
491
          zaxisInqUUID(zaxisID, uuidOfVGrid);
Thomas Jahns's avatar
Thomas Jahns committed
492
          if ( !cdiUUIDIsNull(uuidOfVGrid) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
493
494
            {
              char uuidOfVGridStr[37];
495
              cdiUUID2Str(uuidOfVGrid, uuidOfVGridStr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
496
497
498
499
500
501
502
503
504
505
              if ( uuidOfVGridStr[0] != 0  && strlen(uuidOfVGridStr) == 36 )
                {
                  fprintf(stdout, "%33s : ", "uuid");
                  fprintf(stdout, "%s\n", uuidOfVGridStr);
                }
            }
        }
    }
}

506
507
508
509
510
511
512
513
514
515
516
517
518
519
static
void printSubtypeInfo(int vlistID)
{
  int nsubtypes = vlistNsubtypes(vlistID);
  for ( int index = 0; index < nsubtypes; index++)
    {
      int subtypeID = vlistSubtype(vlistID, index);
      int subtypesize = subtypeInqSize(subtypeID);
      // subtypePrint(subtypeID);
      fprintf(stdout, "  %4d : %-24s :", vlistSubtypeIndex(vlistID, subtypeID)+1, "tiles");
      fprintf(stdout, " ntiles=%d", subtypesize);
      fprintf(stdout, "\n");
    }
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563

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)++;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
564
  return ndotout;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
565
566
567
}

static
568
void printTimesteps(int streamID, int taxisID, int verbose)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
{
  int nrecs;
  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;
588

589
590
591
#ifdef CDO
  dtlist_type *dtlist = dtlist_new();
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
592
593
  while ( (nrecs = streamInqTimestep(streamID, tsID)) )
    {
594
595
596
597
598
599
600
601
#ifdef CDO
      dtlist_taxisInqTimestep(dtlist, taxisID, 0);
      int vdate = dtlist_get_vdate(dtlist, 0);
      int vtime = dtlist_get_vtime(dtlist, 0);
#else
      int vdate = taxisInqVdate(taxisID);
      int vtime = taxisInqVtime(taxisID);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
602

603
      if ( verbose || tsID < NUM_TIMESTEP )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
	{
	  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++;
    }

629
630
631
#ifdef CDO
  dtlist_delete(dtlist);
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
632
633
634
635
636
  if ( nvdatetime )
    {
      fprintf(stdout, "\n");

      ntimeout = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
637
638
639
640
641
642
643
      int toff = 0;
      if ( tsID > 2*NUM_TIMESTEP )
        {
          toff = tsID%4;
          if ( toff > 0 ) toff = 4 - toff;
          for ( int i = 0; i < toff; ++i ) next_vdatetime = next_vdatetime->next;
        }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
644
645
      for ( int i = toff; i < nvdatetime; ++i )
	{
646
647
	  int vdate = next_vdatetime->vdate;
	  int vtime = next_vdatetime->vtime;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
648
649
650
	  ntimeout = printDateTime(ntimeout, vdate, vtime);
	  next_vdatetime = next_vdatetime->next;
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
651
652
    }
}
653
654
655
656
657
658
659
660
661
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */