stream_cdf.c 141 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
5

Uwe Schulzweida's avatar
Uwe Schulzweida committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>

#include "dmemory.h"

#include "cdi.h"
#include "basetime.h"
#include "util.h"  /* gaussaw */
#include "stream_int.h"
#include "stream_cdf.h"
#include "cdf_int.h"
#include "varscan.h"
#include "vlist.h"


#if  defined  (HAVE_LIBNETCDF)
#  include "netcdf.h"
#endif

#undef  UNDEFID
#define UNDEFID  CDI_UNDEFID


void cdfDefTime(int streamID);
void cdfDefGlobalAtts(int streamID);
void cdfDefLocalAtts(int streamID);

#define  MAXNAMELEN  256

#define  X_AXIS  1
#define  Y_AXIS  2
#define  Z_AXIS  3
#define  T_AXIS  4

typedef struct {
  int     ncvarid;
  int     dimtype;
  size_t  len;
  char    name[MAXNAMELEN];
}
NCDIM;

typedef struct {
  int      vartype;
  int      isvar;
  int      islon;
  int      islat;
  int      islev;
  int      warn;
  int      timeID;
  int      code;
  int      bounds;
  int      gridID;
  int      zaxisID;
  int      gridtype;
  int      zaxistype;
  int      xdim;
  int      ydim;
  int      zdim;
  int      xvarid;
  int      yvarid;
  int      zvarid;
  int      tvarid;
72
73
  int      ncoordvars;
  int      coordvarids[4];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
74
75
76
77
78
79
80
81
82
83
84
  int      cellarea;
  int      calendar;
  int      tableID;
  int      truncation;
  int      defmiss;
  int      xtype;
  int      ndims;
  int      gmapid;
  int      positive;
  int      dimids[8];
  int      dimtype[8];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
85
86
  int      natts;
  int     *atts;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  size_t   vlen;
  double  *vdata;
  double   missval;
  double   addoffset;
  double   scalefactor;
  char     name[MAXNAMELEN];
  char     longname[MAXNAMELEN];
  char     stdname[MAXNAMELEN];
  char     units[MAXNAMELEN];
}
NCVAR;


static int splitBasetime(char *timeunits, TAXIS *taxis)
{
  static char func[] = "splitBasetime";
103
  int len, i;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
104
105
106
107
108
109
110
111
  char *ptu;
  int year, month, day;
  int hour = 0, minute = 0, second = 0;
  int timetype = TAXIS_ABSOLUTE;
  int rdate = -1, rtime = -1;
  int timeunit = -1;

  ptu = timeunits;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
112
  len = (int) strlen(timeunits);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
113

114
115
  for ( i = 0; i < len; i++ ) ptu[i] = tolower((int) ptu[i]);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
117
118
119
120
121
122
123
124
125
126
  (*taxis).type = timetype;

  if      ( strncmp(ptu, "sec",    3) == 0 ) timeunit = TUNIT_SECOND;
  else if ( strncmp(ptu, "minute", 6) == 0 ) timeunit = TUNIT_MINUTE;
  else if ( strncmp(ptu, "hour",   4) == 0 ) timeunit = TUNIT_HOUR;
  else if ( strncmp(ptu, "day",    3) == 0 ) timeunit = TUNIT_DAY;
  else if ( strncmp(ptu, "month",  5) == 0 ) timeunit = TUNIT_MONTH;
  else if ( strncmp(ptu, "calendar_month", 14) == 0 ) timeunit = TUNIT_MONTH;
  else if ( strncmp(ptu, "year",   4) == 0 ) timeunit = TUNIT_YEAR;
  else
    {
127
      Message(func, "Unsupported TIMEUNIT: %s!", ptu);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
      return (1);
    }

  while ( ! isspace(*ptu) && *ptu != 0 ) ptu++;
  if ( *ptu )
    {
      while (   isspace(*ptu) ) ptu++;

      if ( strncmp(ptu, "as", 2) == 0 )
	timetype = TAXIS_ABSOLUTE;
      else if ( strncmp(ptu, "since", 5) == 0 )
	timetype = TAXIS_RELATIVE;

      while ( ! isspace(*ptu) && *ptu != 0 ) ptu++;
      if ( *ptu )
	{
	  while (   isspace(*ptu) ) ptu++;

	  if ( timetype == TAXIS_ABSOLUTE )
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
	      if ( strncmp(ptu, "%y%m%d.%f", 9) != 0 && timeunit == TUNIT_DAY )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
149
150
151
152
		{
		  Message(func, "Unsupported format %s for TIMEUNIT day!", ptu);
		  timeunit = -1;
		}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
153
	      else if ( strncmp(ptu, "%y%m.%f", 7) != 0 && timeunit == TUNIT_MONTH )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154
155
156
157
158
159
160
161
		{
		  Message(func, "Unsupported format %s for TIMEUNIT month!", ptu);
		  timeunit = -1;
		}
	    }
	  else if ( timetype == TAXIS_RELATIVE )
	    {
	      year = atoi(ptu);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
162
	      if ( year < 0 ) ptu++;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
	      while ( isdigit((int) *ptu) ) ptu++;
	      month = atoi(++ptu);
	      while ( isdigit((int) *ptu) ) ptu++;
	      day = atoi(++ptu);
	      while ( isdigit((int) *ptu) ) ptu++;

	      while ( isspace((int) *ptu) ) ptu++;

	      if ( *ptu )
		{
		  while ( ! isdigit((int) *ptu) ) ptu++;

		  hour = atoi(ptu);
		  while ( isdigit((int) *ptu) ) ptu++;
		  if ( *ptu == ':' )
		    {
		      ptu++;
		      minute = atoi(ptu);
		      while ( isdigit((int) *ptu) ) ptu++;
		      if ( *ptu == ':' )
			{
			  ptu++;
			  second = atoi(ptu);
			  if ( second != 0 )
			    Message(func, "Seconds not supported in time units!");
			}
		    }
		}

192
193
	      rdate = encode_date(year, month, day);
	      rtime = encode_time(hour, minute);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
194
195
	      (*taxis).rdate = rdate;
	      (*taxis).rtime = rtime;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196
197
198

	      if ( CDI_Debug )
		Message(func, "rdate = %d  rtime = %d", rdate, rtime);	      
Uwe Schulzweida's avatar
Uwe Schulzweida committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
	    }
	}
    }

  (*taxis).type = timetype;
  (*taxis).unit = timeunit;

  if ( CDI_Debug )
    Message(func, "timetype = %d  unit = %d", timetype, timeunit);

  return (0);
}


#if  defined  (HAVE_LIBNETCDF)
214
static void cdfGetAttInt(int fileID, int ncvarid, char *attname, int attlen, int *attint)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
215
216
{
  static char func[] = "cdfGetAttInt";
217
  size_t nc_attlen;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
218
219
  int *pintatt;

220
  cdf_inq_attlen(fileID, ncvarid, attname, &nc_attlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
221

222
223
  if ( (int)nc_attlen > attlen )
    pintatt = (int *) malloc(nc_attlen*sizeof(int));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
224
  else
225
    pintatt = attint;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
226
227
228

  cdf_get_att_int(fileID, ncvarid, attname, pintatt);

229
230
231
232
233
  if ( (int)nc_attlen > attlen )
    {
      memcpy(attint, pintatt, attlen*sizeof(int));
      free(pintatt);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
234
235
236
237
}
#endif

#if  defined  (HAVE_LIBNETCDF)
238
static void cdfGetAttDouble(int fileID, int ncvarid, char *attname, int attlen, double *attdouble)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
239
{
240
241
  static char func[] = "cdfGetAttDouble";
  size_t nc_attlen;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
243
  double *pdoubleatt;

244
  cdf_inq_attlen(fileID, ncvarid, attname, &nc_attlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
245

246
247
  if ( (int)nc_attlen > attlen )
    pdoubleatt = (double *) malloc(nc_attlen*sizeof(double));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
248
  else
249
    pdoubleatt = attdouble;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
251
252

  cdf_get_att_double(fileID, ncvarid, attname, pdoubleatt);

253
254
255
256
257
  if ( (int)nc_attlen > attlen )
    {
      memcpy(attdouble, pdoubleatt, attlen*sizeof(double));
      free(pdoubleatt);
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
259
260
261
}
#endif

#if  defined  (HAVE_LIBNETCDF)
262
static void cdfGetAttText(int fileID, int ncvarid, char *attname, int attlen, char *atttext)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
263
{
264
  size_t nc_attlen;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
265
266
  char attbuf[65636];

267
  cdf_inq_attlen(fileID, ncvarid, attname, &nc_attlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
268

269
  if ( nc_attlen < sizeof(attbuf) )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
270
271
272
    {
      cdf_get_att_text(fileID, ncvarid, attname, attbuf);

273
      attbuf[nc_attlen++] = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
274

275
276
      if ( (int) nc_attlen > attlen ) nc_attlen = attlen;
      memcpy(atttext, attbuf, nc_attlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
277
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
279
280
281
  else
    {
      atttext[0] = 0;
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
282
283
284
285
286
287
288
289
}
#endif

#if  defined  (HAVE_LIBNETCDF)
int cdfInqDatatype(int xtype)
{
  int datatype;

290
291
292
293
294
  if      ( xtype == NC_BYTE  )  datatype = DATATYPE_INT8;
  else if ( xtype == NC_SHORT )  datatype = DATATYPE_INT16;
  else if ( xtype == NC_INT   )  datatype = DATATYPE_INT32;
  else if ( xtype == NC_FLOAT )  datatype = DATATYPE_FLT32;
  else                           datatype = DATATYPE_FLT64;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
295
296
297
298
299
300
301
302
303
304

  return (datatype);
}
#endif

#if  defined  (HAVE_LIBNETCDF)
int cdfDefDatatype(int datatype)
{
  int xtype;

305
  if      ( datatype == DATATYPE_INT8  )  xtype = NC_BYTE;
306
307
  else if ( datatype == DATATYPE_INT16 )  xtype = NC_SHORT;
  else if ( datatype == DATATYPE_INT32 )  xtype = NC_INT;
308
  else if ( datatype == DATATYPE_FLT64 )  xtype = NC_DOUBLE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
309
310
311
312
313
314
315
  else                                    xtype = NC_FLOAT;

  return (xtype);
}
#endif


Uwe Schulzweida's avatar
Uwe Schulzweida committed
316
317
318
#if  defined  (HAVE_LIBNETCDF)
void defineAttributes(int vlistID, int varID, int fileID, int ncvarID)
{
319
  static char func[] = "defineAttributes";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
320
  int natts, iatt;
321
  int atttype, attlen;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
322
  size_t len;
323
324
  char attname[1024];
  char atttxt[8192];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
325
326
327
328
329

  vlistInqNatts(vlistID, varID, &natts);

  for ( iatt = 0; iatt < natts; iatt++ )
    {
330
      vlistInqAtt(vlistID, varID, iatt, attname, &atttype, &attlen);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
331

332
      if ( atttype == DATATYPE_TXT )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
333
	{
334
	  vlistInqAttTxt(vlistID, varID, attname, sizeof(atttxt), atttxt);
335
336
	  len = attlen;
	  cdf_put_att_text(fileID, ncvarID, attname, len, atttxt);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
337
	}
338
      else if ( atttype == DATATYPE_INT )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
339
	{
340
341
342
343
344
345
	  int *attint;
	  attint = (int *) malloc(attlen*sizeof(int));
	  vlistInqAttInt(vlistID, varID, attname, attlen, &attint[0]);
	  len = attlen;
	  cdf_put_att_int(fileID, ncvarID, attname, NC_INT, len, attint);
	  free(attint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
346
	}
347
      else if ( atttype == DATATYPE_FLT )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
348
	{
349
350
351
352
353
354
	  double *attflt;
	  attflt = (double *) malloc(attlen*sizeof(double));
	  vlistInqAttFlt(vlistID, varID, attname, attlen, attflt);
	  len = attlen;
	  cdf_put_att_double(fileID, ncvarID, attname, NC_DOUBLE, len, attflt);
	  free(attflt);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
355
356
357
358
359
360
	}
    }
}
#endif


Uwe Schulzweida's avatar
Uwe Schulzweida committed
361
int cdfCopyRecord(int streamID2, int streamID1)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
362
363
364
{
  static char func[] = "cdfCopyRecord";
  double *data;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
365
  int datasize;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
  int tsID1, tsID2, recID1, recID2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
367
368
369
  int ivarID, gridID;
  int nmiss;
  int ierr = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
370
371
372
  int vlistID1, vlistID2;
  STREAM *streamptr1;
  STREAM *streamptr2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
373

Uwe Schulzweida's avatar
Uwe Schulzweida committed
374
375
  streamptr1 = stream_to_pointer(streamID1);
  streamptr2 = stream_to_pointer(streamID2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
376

Uwe Schulzweida's avatar
Uwe Schulzweida committed
377
378
  stream_check_ptr(func, streamptr1);
  stream_check_ptr(func, streamptr2);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379

Uwe Schulzweida's avatar
Uwe Schulzweida committed
380
381
  vlistID1 = streamptr1->vlistID;
  vlistID2 = streamptr2->vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
382

Uwe Schulzweida's avatar
Uwe Schulzweida committed
383
384
  tsID1 = streamptr1->curTsID;
  tsID2 = streamptr2->curTsID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
385

Uwe Schulzweida's avatar
Uwe Schulzweida committed
386
387
  recID1 = streamptr1->tsteps[tsID1].curRecID;
  recID2 = streamptr2->tsteps[tsID2].curRecID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
388

Uwe Schulzweida's avatar
Uwe Schulzweida committed
389
390
391
  ivarID = streamptr1->tsteps[tsID1].records[recID1].varID;

  gridID = vlistInqVarGrid(vlistID1, ivarID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392
393
394
395
396
397
398

  datasize = gridInqSize(gridID);      
  /* bug fix for constant netCDF fields */
  if ( datasize < 1048576 ) datasize = 1048576;

  data = (double *) malloc(datasize*sizeof(double));

Uwe Schulzweida's avatar
Uwe Schulzweida committed
399
400
  streamReadRecord(streamID1, data, &nmiss);
  streamWriteRecord(streamID2, data, nmiss);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
401
402
403
404
405

  free(data);

  return (ierr);
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
406

Uwe Schulzweida's avatar
Uwe Schulzweida committed
407
408
409
410
411
/* not used
int cdfInqRecord(int streamID, int *varID, int *levelID)
{
  static char func[] = "cdfInqRecord";
  int tsID, recID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
412
413
414
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
415

Uwe Schulzweida's avatar
Uwe Schulzweida committed
416
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
417

Uwe Schulzweida's avatar
Uwe Schulzweida committed
418
419
420
  recID = streamptr->tsteps[0].curRecID++;
  printf("cdfInqRecord recID %d %d\n", recID, streamptr->tsteps[0].curRecID);
  printf("cdfInqRecord tsID %d\n", streamptr->curTsID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
421

Uwe Schulzweida's avatar
Uwe Schulzweida committed
422
423
  if ( streamptr->tsteps[0].curRecID >= 
       streamptr->tsteps[0].nrecs )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
424
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
      streamptr->tsteps[0].curRecID = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
426
427
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
428
429
  *varID   = streamptr->tsteps[0].records[recID].varID;
  *levelID = streamptr->tsteps[0].records[recID].levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
430

Uwe Schulzweida's avatar
Uwe Schulzweida committed
431
432
  streamptr->record->varID   = *varID;
  streamptr->record->levelID = *levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
433
434
435
436
437
438
439
440
441
442
443

  if ( CDI_Debug )
    Message(func, "recID = %d  varID = %d  levelID = %d", recID, *varID, *levelID);
  
  return (recID+1);
}
*/
int cdfDefRecord(int streamID)
{
  static char func[] = "cdfDefRecord";
  int ierr = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
444
445
446
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
447
448
449
450

  if ( CDI_Debug )
    Message(func, "streamID = %d", streamID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
451
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
452
453
454
455
456
457
458
459
460
461
462
463

  return (ierr);
}

void cdfWriteGridTraj(int streamID, int gridID)
{
#if  defined  (HAVE_LIBNETCDF)
  int tsID, fileID;
  int lonID, latID, gridindex;
  size_t index;
  double xlon, xlat;
  int vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
464
465
466
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
467
468
469
470
471

  vlistID = streamInqVlist(streamID);
  fileID  = streamInqFileID(streamID);

  gridindex = vlistGridIndex(vlistID, gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
472
473
  lonID = streamptr->xdimID[gridindex];
  latID = streamptr->ydimID[gridindex];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
474
475
476

  xlon = gridInqXval(gridID, 0);
  xlat = gridInqYval(gridID, 0);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
477
  tsID = streamptr->curTsID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
  index = tsID;

  cdf_put_var1_double(fileID, lonID, &index, &xlon);
  cdf_put_var1_double(fileID, latID, &index, &xlat);
#endif
}


void cdfReadGridTraj(int streamID, int gridID)
{
#if  defined  (HAVE_LIBNETCDF)
  int tsID, fileID;
  int lonID, latID, gridindex;
  size_t index;
  double xlon, xlat;
  int vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
494
495
496
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
497
498
499
500
501

  vlistID = streamInqVlist(streamID);
  fileID  = streamInqFileID(streamID);

  gridindex = vlistGridIndex(vlistID, gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
502
503
  lonID = streamptr->xdimID[gridindex];
  latID = streamptr->ydimID[gridindex];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
504

Uwe Schulzweida's avatar
Uwe Schulzweida committed
505
  tsID = streamptr->curTsID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
  index = tsID;

  cdf_get_var1_double(fileID, lonID, &index, &xlon);
  cdf_get_var1_double(fileID, latID, &index, &xlat);

  gridDefXvals(gridID, &xlon);
  gridDefYvals(gridID, &xlat);
#endif
}


void cdfDefMissval(int streamID, int varID, int dtype)
{
#if  defined  (HAVE_LIBNETCDF)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520
521
522
523
524
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);

  if ( streamptr->vars[varID].defmiss == FALSE )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
525
526
527
528
529
530
531
532
533
    {
      int fileID;
      int ncvarid;
      double missval;
      int vlistID;
      int xtype;

      vlistID = streamInqVlist(streamID);
      fileID  = streamInqFileID(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
534
      ncvarid = streamptr->vars[varID].ncvarid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
535
      missval = vlistInqVarMissval(vlistID, varID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
536
      if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
537
538
539
540

      xtype = cdfDefDatatype(dtype);

      cdf_put_att_double(fileID, ncvarid, "_FillValue", (nc_type) xtype, 1L, &missval);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
541
542
543

      if ( cdiNcMissingValue == 1 )
	cdf_put_att_double(fileID, ncvarid, "missing_value", (nc_type) xtype, 1L, &missval);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
544

Uwe Schulzweida's avatar
Uwe Schulzweida committed
545
      if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
546

Uwe Schulzweida's avatar
Uwe Schulzweida committed
547
      streamptr->vars[varID].defmiss = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
548
549
550
551
552
553
554
555
556
557
    }
#endif
}

void cdfWriteRecord(int streamID, double *data, int nmiss)
{
#if  defined  (HAVE_LIBNETCDF)
  static char func[] = "cdfWriteRecord";
  int varID;
  int levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
558
559
560
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
561

Uwe Schulzweida's avatar
Uwe Schulzweida committed
562
563
  varID   = streamptr->record->varID;
  levelID = streamptr->record->levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
564
565
566
567
568
569
570
571
572
573
574
575
576

  if ( CDI_Debug )
    Message(func, "streamID = %d  varID = %d", streamID, varID);

  cdfWriteVarSliceDP(streamID, varID, levelID, data, nmiss);
#endif
}

int cdfReadRecord(int streamID, double *data, int *nmiss)
{
  static char func[] = "cdfReadRecord";
  int ierr = 0;
  int levelID, varID, tsID, recID, vrecID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
577
578
579
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
580
581
582

  if ( CDI_Debug ) Message(func, "streamID = %d", streamID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
583
584
585
586
587
  tsID    = streamptr->curTsID;
  vrecID  = streamptr->tsteps[tsID].curRecID;
  recID   = streamptr->tsteps[tsID].recIDs[vrecID];
  varID   = streamptr->tsteps[tsID].records[recID].varID;
  levelID = streamptr->tsteps[tsID].records[recID].levelID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

  cdfReadVarSliceDP(streamID, varID, levelID, data, nmiss);

  return (ierr);
}


void cdfDefTimeValue(int streamID, int tsID)
{
#if  defined  (HAVE_LIBNETCDF)
  static char func[] = "cdfDefTimeValue";
  int fileID;
  double timevalue;
  int ncvarid;
  size_t index;
  TAXIS *taxis;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
604
605
606
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
607
608
609
610
611
612

  fileID = streamInqFileID(streamID);

  if ( CDI_Debug )
    Message(func, "streamID = %d, fileID = %d", streamID, fileID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
613
  taxis = &streamptr->tsteps[tsID].taxis;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
614

Uwe Schulzweida's avatar
Uwe Schulzweida committed
615
  if ( streamptr->ncmode == 1 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
616
617
    {
      cdf_enddef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
618
      streamptr->ncmode = 2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
619
620
621
622
    }

  index = tsID;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
623
  timevalue = encode_timeval(taxis->vdate, taxis->vtime, &streamptr->tsteps[0].taxis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
624
625
  if ( CDI_Debug ) Message(func, "tsID = %d  timevalue = %f", tsID, timevalue);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
626
  ncvarid = streamptr->basetime.ncvarid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
627
628
629
630
631
632
  cdf_put_var1_double(fileID, ncvarid, &index, &timevalue);

  if ( taxis->has_bounds )
    {
      size_t start[2], count[2];

Uwe Schulzweida's avatar
Uwe Schulzweida committed
633
      ncvarid = streamptr->basetime.ncvarboundsid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
634

Uwe Schulzweida's avatar
Uwe Schulzweida committed
635
      timevalue = encode_timeval(taxis->vdate_lb, taxis->vtime_lb, &streamptr->tsteps[0].taxis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
636
637
638
      start[0] = tsID; count[0] = 1; start[1] = 0; count[1] = 1;
      cdf_put_vara_double(fileID, ncvarid, start, count, &timevalue);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
639
      timevalue = encode_timeval(taxis->vdate_ub, taxis->vtime_ub, &streamptr->tsteps[0].taxis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
      start[0] = tsID; count[0] = 1; start[1] = 1; count[1] = 1;
      cdf_put_vara_double(fileID, ncvarid, start, count, &timevalue);
    }
  /*
printf("fileID = %d %d %d %f\n", fileID, time_varid, index, timevalue);
  */
#endif
}


void cdfDefTimestep(int streamID, int tsID)
{
  int vlistID;

  vlistID = streamInqVlist(streamID);

  if ( vlistHasTime(vlistID) ) cdfDefTime(streamID);

  cdfDefTimeValue(streamID, tsID);
}


void cdfDefTime(int streamID)
{
#if  defined  (HAVE_LIBNETCDF)
  int fileID;
  int time_varid;
  int time_bndsid;
  int dims[2];
  int year, month, day, hour, minute;
  char unitstr[80];
  char calstr[80];
  size_t len;
  TAXIS *taxis;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
674
675
676
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
677

Uwe Schulzweida's avatar
Uwe Schulzweida committed
678
  if ( streamptr->basetime.ncvarid != UNDEFID ) return;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
679
680
681

  fileID = streamInqFileID(streamID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
682
  if ( streamptr->ncmode == 0 ) streamptr->ncmode = 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
683

Uwe Schulzweida's avatar
Uwe Schulzweida committed
684
  if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
685

Uwe Schulzweida's avatar
Uwe Schulzweida committed
686
  cdf_def_dim(fileID, "time", NC_UNLIMITED, &streamptr->basetime.ncdimid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
687

Uwe Schulzweida's avatar
Uwe Schulzweida committed
688
  dims[0] = streamptr->basetime.ncdimid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
689
690
  cdf_def_var(fileID, "time", NC_DOUBLE, 1, dims, &time_varid);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
691
  streamptr->basetime.ncvarid = time_varid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
692

Uwe Schulzweida's avatar
Uwe Schulzweida committed
693
  taxis = &streamptr->tsteps[0].taxis;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
694
695
696
697
698
699
700
701

  if ( taxis->has_bounds )
    {
      /* fprintf(stderr, "time has bounds\n"); */

      cdf_def_dim(fileID, "tbnds", 2, &dims[1]);
      cdf_def_var(fileID, "time_bnds", NC_DOUBLE, 2, dims, &time_bndsid);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
702
      streamptr->basetime.ncvarboundsid = time_bndsid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
703
704
705
706
707

      cdf_put_att_text(fileID, time_varid, "bounds", 9, "time_bnds");
    }

  unitstr[0] = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
708
  if ( streamptr->tsteps[0].taxis.type == TAXIS_ABSOLUTE )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
709
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
710
      if ( streamptr->tsteps[0].taxis.unit == TUNIT_MONTH )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
	sprintf(unitstr, "month as %s", "%Y%m.%f");
      else
	sprintf(unitstr, "day as %s", "%Y%m%d.%f");
    }
  else
    {
      int rdate, rtime;
      int timeunit;

      timeunit = taxis->unit;
      rdate    = taxis->rdate;
      rtime    = taxis->rtime;
      if ( rdate == -1 )
	{
	  rdate  = taxis->vdate;
	  rtime  = taxis->vtime;
	}
728
729
730
731

      decode_date(rdate, &year, &month, &day);
      decode_time(rtime, &hour, &minute);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
      sprintf(unitstr, "%s since %d-%02d-%02d %02d:%02d",
	      tunitNamePtr(timeunit), year, month, day, hour, minute);
    }

  len = strlen(unitstr);
  if ( len )
    cdf_put_att_text(fileID, time_varid, "units", len, unitstr);

  if ( taxis->has_bounds )
    if ( len )
      cdf_put_att_text(fileID, time_bndsid, "units", len, unitstr);

  if ( taxis->calendar != -1 )
    {
      calstr[0] = 0;

      if      ( taxis->calendar == CALENDAR_NONE )      strcpy(calstr, "none");
      else if ( taxis->calendar == CALENDAR_360DAYS )   strcpy(calstr, "360_day");
      else if ( taxis->calendar == CALENDAR_365DAYS )   strcpy(calstr, "365_day");
      else if ( taxis->calendar == CALENDAR_366DAYS )   strcpy(calstr, "366_day");
      else if ( taxis->calendar == CALENDAR_PROLEPTIC ) strcpy(calstr, "proleptic_gregorian");

      len = strlen(calstr);
      if ( len )
	cdf_put_att_text(fileID, time_varid, "calendar", len, calstr);

      if ( taxis->has_bounds )
	if ( len )
	  cdf_put_att_text(fileID, time_bndsid, "calendar", len, calstr);
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
763
  if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
#endif
}


void cdfDefComplex(int streamID, int gridID)
{
#if  defined  (HAVE_LIBNETCDF)
  char axisname[] = "complex";
  int index;
  int dimID = UNDEFID;
  int gridID0, gridtype0, gridindex;
  int ngrids;
  int fileID;
  int dimlen;
  int vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
779
780
781
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
782
783
784
785
786
787
788
789

  vlistID = streamInqVlist(streamID);
  fileID  = streamInqFileID(streamID);

  ngrids = vlistNgrids(vlistID);

  for ( index = 0; index < ngrids; index++ )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
790
      if ( streamptr->xdimID[index] != UNDEFID )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
791
792
793
794
795
	{
	  gridID0 = vlistGrid(vlistID, index);
	  gridtype0 = gridInqType(gridID0);
	  if ( gridtype0 == GRID_SPECTRAL )
	    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
796
	      dimID = streamptr->xdimID[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
797
798
799
800
801
802
803
804
805
	      break;
	    }
	}
    }

  if ( dimID == UNDEFID )
    {
      dimlen = 2;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
806
      if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807
808
809
810

      cdf_def_dim(fileID, axisname, dimlen, &dimID);

      cdf_enddef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
811
      streamptr->ncmode = 2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
812
813
814
    }

  gridindex = vlistGridIndex(vlistID, gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
815
  streamptr->xdimID[gridindex] = dimID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833

#endif
}

void cdfDefSpc(int streamID, int gridID)
{
#if  defined  (HAVE_LIBNETCDF)
  /*
  char longname[] = "Spherical harmonic coefficient";
  */
  char axisname[5] = "spcX";
  int index, iz = 0;
  int gridID0, gridtype0, gridindex;
  int dimID = UNDEFID;
  int ngrids;
  int fileID;
  int dimlen, dimlen0;
  int vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
834
835
836
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
837
838
839
840
841
842
843
844
845
846

  vlistID = streamInqVlist(streamID);
  fileID  = streamInqFileID(streamID);

  ngrids = vlistNgrids(vlistID);

  dimlen = gridInqSize(gridID)/2;

  for ( index = 0; index < ngrids; index++ )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
847
      if ( streamptr->ydimID[index] != UNDEFID )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
848
849
850
851
852
853
854
855
	{
	  gridID0 = vlistGrid(vlistID, index);
	  gridtype0 = gridInqType(gridID0);
	  if ( gridtype0 == GRID_SPECTRAL )
	    {
	      dimlen0 = gridInqSize(gridID0)/2;
	      if ( dimlen == dimlen0 )
		{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
856
		  dimID = streamptr->ydimID[index];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
857
858
859
860
861
862
863
864
865
866
867
868
869
		  break;
		}
	      else
		iz++;	
	    }
	}
    }

  if ( dimID == UNDEFID )
    {
      if ( iz == 0 ) axisname[3] = '\0';
      else           sprintf(&axisname[3], "%1d", iz+1);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
870
      if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
871
872
873
874

      cdf_def_dim(fileID, axisname, dimlen, &dimID);

      cdf_enddef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
875
      streamptr->ncmode = 2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
876
877
878
    }

  gridindex = vlistGridIndex(vlistID, gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
879
  streamptr->ydimID[gridindex] = dimID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899

#endif
}

void cdfDefTrajLon(int streamID, int gridID)
{
#if  defined  (HAVE_LIBNETCDF)
  static char func[] = "cdfDefTrajLon";
  char units[256];
  char longname[256];
  char stdname[256];
  char axisname[256];
  int gridtype, gridindex;
  int dimID = UNDEFID;
  int fileID;
  int dimlen;
  size_t len;
  int ncvarid;
  int vlistID;
  int xtype = NC_DOUBLE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
900
901
902
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
903

904
  if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
905
906
907
908
909
910
911
912
913

  vlistID = streamInqVlist(streamID);
  fileID  = streamInqFileID(streamID);

  gridtype = gridInqType(gridID);
  dimlen = gridInqXsize(gridID);
  if ( dimlen != 1 ) Error(func, "Xsize isn't 1 for %s grid!", gridNamePtr(gridtype));

  gridindex = vlistGridIndex(vlistID, gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
914
  ncvarid = streamptr->xdimID[gridindex];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
915
916
917
918
919
920
921
922

  gridInqXname(gridID, axisname);
  gridInqXlongname(gridID, longname);
  gridInqXstdname(gridID, stdname);
  gridInqXunits(gridID, units);

  if ( ncvarid == UNDEFID )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
923
      dimID = streamptr->basetime.ncvarid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
924

Uwe Schulzweida's avatar
Uwe Schulzweida committed
925
      if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
926
927
928
929
930
931
932
933
934
935

      cdf_def_var(fileID, axisname, (nc_type) xtype, 1, &dimID, &ncvarid);
      if ( (len = strlen(longname)) )
	cdf_put_att_text(fileID, ncvarid, "long_name", len, longname);
      if ( (len = strlen(units)) )
	cdf_put_att_text(fileID, ncvarid, "units", len, units);
      if ( (len = strlen(stdname)) )
	cdf_put_att_text(fileID, ncvarid, "standard_name", len, stdname);

      cdf_enddef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
936
      streamptr->ncmode = 2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
937
938
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
939
  streamptr->xdimID[gridindex] = ncvarid; /* var ID for trajectory !!! */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959

#endif
}

void cdfDefTrajLat(int streamID, int gridID)
{
#if  defined  (HAVE_LIBNETCDF)
  static char func[] = "cdfDefTrajLat";
  char units[] = "degrees_north";
  char longname[] = "latitude";
  char stdname[] = "latitude";
  char axisname[] = "tlat";
  int gridtype, gridindex;
  int dimID = UNDEFID;
  int fileID;
  int dimlen;
  size_t len;
  int ncvarid;
  int vlistID;
  int xtype = NC_DOUBLE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
960
961
962
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
963

964
  if ( gridInqPrec(gridID) == DATATYPE_FLT32 ) xtype = NC_FLOAT;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
965
966
967
968
969
970
971
972
973

  vlistID = streamInqVlist(streamID);
  fileID = streamInqFileID(streamID);

  gridtype = gridInqType(gridID);
  dimlen = gridInqYsize(gridID);
  if ( dimlen != 1 ) Error(func, "Ysize isn't 1 for %s grid!", gridNamePtr(gridtype));

  gridindex = vlistGridIndex(vlistID, gridID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
974
  ncvarid = streamptr->ydimID[gridindex];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
975
976
977
978
979
980
981
982

  gridInqYname(gridID, axisname);
  gridInqYlongname(gridID, longname);
  gridInqYstdname(gridID, stdname);
  gridInqYunits(gridID, units);

  if ( ncvarid == UNDEFID )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
983
      dimID = streamptr->basetime.ncvarid;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
984

Uwe Schulzweida's avatar
Uwe Schulzweida committed
985
      if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
986
987
988
989
990
991
992
993
994
995

      cdf_def_var(fileID, axisname, (nc_type) xtype, 1, &dimID, &ncvarid);
      if ( (len = strlen(longname)) )
	cdf_put_att_text(fileID, ncvarid, "long_name", len, longname);
      if ( (len = strlen(units)) )
	cdf_put_att_text(fileID, ncvarid, "units", len, units);
      if ( (len = strlen(stdname)) )
	cdf_put_att_text(fileID, ncvarid, "standard_name", len, stdname);

      cdf_enddef(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
996
      streamptr->ncmode = 2;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
997
998
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
999
  streamptr->ydimID[gridindex] = ncvarid; /* var ID for trajectory !!! */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1000

For faster browsing, not all history is shown. View entire blame