stream.c 43.9 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#include <ctype.h>

#include "dmemory.h"
#include "cdi.h"
#include "stream_int.h"
#include "cdf.h"
#include "stream_grb.h"
#include "stream_cdf.h"
#include "stream_srv.h"
#include "stream_ext.h"
#include "stream_ieg.h"
#include "file.h"
#include "grib.h"
#include "cdf.h"
#include "service.h"
#include "extra.h"
#include "ieg.h"
#include "vlist.h"

24
25
26
27
#define  MAX_FNAMES  3

FILE *popen(const char *command, const char *type);
int pclose(FILE *stream);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

void cdiPrintDefaults(void)
{
  fprintf (stderr, "default instID     :  %d\n", cdiDefaultInstID); 
  fprintf (stderr, "default modelID    :  %d\n", cdiDefaultModelID); 
  fprintf (stderr, "default tableID    :  %d\n", cdiDefaultTableID); 
  fprintf (stderr, "default missval    :  %g\n", cdiDefaultMissval); 
}


void cdiDebug(int level)
{
  static char func[] = "cdiDebug";

  if ( level == 1 || level &  2 ) CDI_Debug = 1;

  if ( CDI_Debug ) Message(func, "debug level %d", level);

  if ( level == 1 || level &  4 ) memDebug(1);

  if ( level == 1 || level &  8 ) fileDebug(1);

  if ( level == 1 || level & 16 )
    {
#if  defined  (HAVE_LIBGRIB)
      gribSetDebug(1);
#endif
#if  defined  (HAVE_LIBNETCDF)
      cdfDebug(1);
#endif
#if  defined  (HAVE_LIBSERVICE)
      srvDebug(1);
#endif
#if  defined  (HAVE_LIBEXTRA)
      extDebug(1);
#endif
#if  defined  (HAVE_LIBIEG)
      iegDebug(1);
#endif
    }

  if ( CDI_Debug )
    {
      cdiPrintDefaults();
      cdiPrintDatatypes();
    }
}


#undef  IsBigendian
#define IsBigendian()  ( u_byteorder.c[sizeof(long) - 1] )


static int getByteorder(int byteswap)
{
  static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1};
  int byteorder = -1;

  if ( IsBigendian() )
    {
      if ( byteswap ) byteorder = CDI_LITTLEENDIAN;
      else            byteorder = CDI_BIGENDIAN;
    }
  else
    {
      if ( byteswap ) byteorder = CDI_BIGENDIAN;
      else            byteorder = CDI_LITTLEENDIAN;
    }

  return (byteorder);
}


static int getFiletype(const char *filename, int *byteorder)
{
  static char func[] = "getFiletype";
  int filetype = CDI_EUFTYPE;
  int fileID;
  int swap = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
107
  int version;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
108
  long recpos;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
109
  char buffer[8];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
111
112
113
114
115
116
117
118
119
120

  fileID = fileOpen(filename, "r");

  if ( fileID == CDI_UNDEFID )
    {
      if ( strncmp(filename, "http:", 5) == 0 )
	return (FILETYPE_NC);
      else
	return (CDI_ESYSTEM);
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
121
  if ( fileRead(fileID, buffer, 8) != 8 ) return (CDI_EUFTYPE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
122
123
124
125
126

  fileRewind(fileID);

  if ( strncmp(buffer, "GRIB", 4) == 0 )
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
127
128
129
130
      version = buffer[7];
      if ( version <= 1 )
	{
	  filetype = FILETYPE_GRB;
131
	  if ( CDI_Debug ) Message(func, "found GRIB file = %s, version %d", filename, version);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
132
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
133
134
135
136
137
138
139
140
141
142
143
144
145
    }
  else if ( strncmp(buffer, "CDF\001", 4) == 0 )
    {
      filetype = FILETYPE_NC;
      if ( CDI_Debug ) Message(func, "found CDF1 file = %s", filename);
    }
  else if ( strncmp(buffer, "CDF\002", 4) == 0 )
    {
      filetype = FILETYPE_NC2;
      if ( CDI_Debug ) Message(func, "found CDF2 file = %s", filename);
    }
  else if ( strncmp(buffer+1, "HDF", 3) == 0 )
    {
146
      filetype = FILETYPE_NC4;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
      if ( CDI_Debug ) Message(func, "found HDF file = %s", filename);
    }
#if  defined  (HAVE_LIBSERVICE)
  else if ( srvCheckFiletype(fileID, &swap) )
    {
      filetype = FILETYPE_SRV;
      if ( CDI_Debug ) Message(func, "found SRV file = %s", filename);
    }
#endif
#if  defined  (HAVE_LIBEXTRA)
  else if ( extCheckFiletype(fileID, &swap) )
    {
      filetype = FILETYPE_EXT;
      if ( CDI_Debug ) Message(func, "found EXT file = %s", filename);
    }
#endif
#if  defined  (HAVE_LIBIEG)
  else if ( iegCheckFiletype(fileID, &swap) )
    {
      filetype = FILETYPE_IEG;
      if ( CDI_Debug ) Message(func, "found IEG file = %s", filename);
    }
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
170
  else if ( gribCheckSeek(fileID, &recpos, &version) == 0 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
171
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
172
173
174
175
176
      if ( version <= 1 )
	{
	  filetype = FILETYPE_GRB;
	  if ( CDI_Debug ) Message(func, "found seek GRIB file = %s", filename);
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
177
178
179
180
181
182
183
184
185
186
    }

  fileClose(fileID);

  *byteorder = getByteorder(swap);

  return (filetype);
}


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
int _readline_(FILE *fp, char *line, int len)
{
  int ichar, ipos = 0;

  while ( (ichar = fgetc(fp)) != EOF )
    {
      if ( ichar == '\n' ) break;
      line[ipos++] = ichar;
      if ( ipos >= len )
        {
          fprintf(stderr, "readline Warning: end of line not found (maxlen = %d)!\n", len);
          break;
        }
    }
  line[ipos] = 0;

  if ( feof(fp) && ipos == 0 ) return (0);

  return (1);
}

#define  MAX_LINE  4096

int get_fnames(const char *argument, char *fnames[], int max_fnames)
{
  static char func[] = "get_fnames";
  int num_fnames = 0;
  int len;
  int nfiles = 0;
  int i, j;
  const char *pch;
  char line[MAX_LINE];

  len = (int) strlen(argument);
  for ( i = 0; i < len; ++i )
    if ( argument[i] == ':' ) break;

  if ( i < len )
    {
      pch = &argument[i+1];
      len -= (i+1);
      if ( len && ( strncmp(argument, "filelist:", i) == 0 || 
		    strncmp(argument, "flist:", i) == 0 ) )
	{
	  for ( i = 0; i < len; ++i ) if ( pch[i] == ',' ) nfiles++;

	  if ( nfiles == 0 )
	    {
	      FILE *fp;
	      fp = fopen(pch, "r");
	      if ( fp == NULL ) Error(func, "Open failed on %s", pch);

	      if ( CDI_Debug )
		Message(func, "Reading file names from %s", pch);

	      rewind(fp);

	      nfiles = 0;
	      while ( _readline_(fp, line, MAX_LINE) )
		{
		  if ( line[0] == '#' || line[0] == '\0' ||
		       line[0] == ' ' ) continue;
		  
		  if ( nfiles >= max_fnames )
		    {
		      Warning(func, "Too many input files (limit: %d)", max_fnames);
		      break;
		    }
		  fnames[nfiles] = strdupx(line);
		  nfiles++;
		}
	      
	      fclose(fp);

	      if ( nfiles == 0 ) Error(func, "No input file found in %s", pch);
	    }
	  else
	    {
	      char xline[65536];
	      	      
	      strcpy(xline, pch);
	      for ( i = 0; i < len; i++ ) if ( xline[i] == ',' ) xline[i] = 0;
	      
	      nfiles++;
	      if ( nfiles >= max_fnames )
		{
		  Warning(func, "Too many input files (limit: %d)", max_fnames);
		  nfiles = max_fnames;
		}

	      i = 0;
	      for ( j = 0; j < nfiles; j++ )
		{
		  fnames[j] = strdupx(&xline[i]);
		  i += strlen(&xline[i]) + 1;
		}
	    }
	}
      else if ( len && strncmp(argument, "ls:", i) == 0 )
	{
	  char command[4096];
	  FILE *pfp;
	  
	  strcpy(command, "ls ");
	  strcat(command, pch);

	  pfp = popen(command, "r");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
294
	  if ( pfp == NULL )
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	    SysError(func, "popen %s failed", command);
	  
	  nfiles = 0;
	  while ( _readline_(pfp, line, MAX_LINE) )
	    {
	      if ( nfiles >= max_fnames )
		{
		  Warning(func, "Too many input files (limit: %d)", max_fnames);
		  break;
		}
	      fnames[nfiles++] = strdupx(line);
	    }

	  pclose(pfp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
309
	  /*
310
311
	  for ( j = 0; j < nfiles; j++ )
	    fnames[j] = fnames[j];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
312
	  */
313
314
315
316
317
318
319
320
321
	}
    }

  num_fnames = nfiles;
  
  return (num_fnames);
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
322
323
324
325
326
327
/*
@Function  streamInqFiletype
@Title     Get the filetype

@Prototype int streamInqFiletype(int streamID)
@Parameter
328
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
329
330

@Description
331
The function @func{streamInqFiletype} returns the filetype of a stream.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
332
333

@Result
334
@func{streamInqFiletype} returns the type of the file format,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
335
one of the set of predefined CDI file format types.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
336
337
The valid CDI file format types are @func{FILETYPE_GRB}, @func{FILETYPE_NC}, @func{FILETYPE_NC2},
@func{FILETYPE_NC4}, @func{FILETYPE_SRV}, @func{FILETYPE_EXT} and @func{FILETYPE_IEG}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
338
339
340
341
342
343

@EndFunction
*/
int streamInqFiletype(int streamID)
{
  static char func[] = "streamInqFiletype";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
344
345
346
  STREAM *streamptr;

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
348
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
349

Uwe Schulzweida's avatar
Uwe Schulzweida committed
350
  return (streamptr->filetype);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
}


int getByteswap(int byteorder)
{
  static union {unsigned long l; unsigned char c[sizeof(long)];} u_byteorder = {1};
  int byteswap = 0;

  if ( IsBigendian() )
    {
      if ( byteorder == CDI_LITTLEENDIAN ) byteswap = TRUE;
    }
  else
    {
      if ( byteorder == CDI_BIGENDIAN ) byteswap = TRUE;
    }

  return (byteswap);
}


372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
@Function  streamDefByteorder
@Title     Define the byte order

@Prototype void streamDefByteorder(int streamID, int byteorder)
@Parameter
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
    @Item  byteorder The byte order of a dataset, one of the CDI constants @func{CDI_BIGENDIAN} and
                     @func{CDI_LITTLEENDIAN}.

@Description
The function @func{streamDefByteorder} defines the byte order of a binary dataset
with the file format type @func{FILETYPE_SRV}, @func{FILETYPE_EXT} or @func{FILETYPE_IEG}.

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
388
389
390
391
void streamDefByteorder(int streamID, int byteorder)
{
  static char func[] = "streamDefByteorder";
  int filetype, fileID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392
  STREAM *streamptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
393

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
396
397
398
399
400
  stream_check_ptr(func, streamptr);

  streamptr->byteorder = byteorder;
  filetype = streamptr->filetype;
  fileID   = streamptr->fileID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
401
402
403
404
405
406

  switch (filetype)
    {
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
407
	SRVREC *srvp = streamptr->record->srvp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
408
409
410
411
412
413
414
415
	srvp->byteswap = getByteswap(byteorder);

	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
416
	EXTREC *extp = streamptr->record->extp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
417
418
419
420
421
422
423
424
	extp->byteswap = getByteswap(byteorder);

	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
425
	IEGREC *iegp = streamptr->record->iegp;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
426
427
428
429
430
431
432
433
434
	iegp->byteswap = getByteswap(byteorder);

	break;
      }
#endif
    }
}


435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
@Function  streamInqByteorder
@Title     Get the byte order

@Prototype int streamInqByteorder(int streamID)
@Parameter
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}

@Description
The function @func{streamInqByteorder} returns the byte order of a binary dataset
with the file format type @func{FILETYPE_SRV}, @func{FILETYPE_EXT} or @func{FILETYPE_IEG}.

@Result
@func{streamInqByteorder} returns the type of the byte order.
The valid CDI byte order types are @func{CDI_BIGENDIAN} and @func{CDI_LITTLEENDIAN}

@EndFunction
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
453
454
455
int streamInqByteorder(int streamID)
{
  static char func[] = "streamInqByteorder";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
456
457
458
  STREAM *streamptr;

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
460
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
461

Uwe Schulzweida's avatar
Uwe Schulzweida committed
462
  return (streamptr->byteorder);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
463
464
465
466
467
}


char *streamFilesuffix(int filetype)
{
468
  static char *fileSuffix[] = {"", ".grb", ".g2", ".nc", ".nc2", ".nc4", ".srv", ".ext", ".h5", ".ieg"};
Uwe Schulzweida's avatar
Uwe Schulzweida committed
469
  int size = (int) (sizeof(fileSuffix)/sizeof(char *));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
470
471
472
473
474
475
476
477
478
479
480

  if ( filetype > 0 && filetype < size )
    return (fileSuffix[filetype]);
  else
    return (fileSuffix[0]);
}


char *streamFilename(int streamID)
{
  static char func[] = "streamFilename";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
481
  STREAM *streamptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
482

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
485
486
487
  stream_check_ptr(func, streamptr);

  return (streamptr->filename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
488
489
490
491
492
493
494
495
}


int cdiInqTimeSize(int streamID)
{
  static char func[] = "cdiInqTimeSize";
  int ntsteps;
  int tsID = 0, nrecs;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
496
497
498
  STREAM *streamptr;

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
500
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
501

Uwe Schulzweida's avatar
Uwe Schulzweida committed
502
  ntsteps = streamptr->ntsteps;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
503
504
505
506

  if ( ntsteps == CDI_UNDEFID )
    while ( (nrecs = streamInqTimestep(streamID, tsID++)) )

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

  return (ntsteps);
}


int cdiInqContents(int streamID)
{
  static char func[] = "cdiInqContents";
  int filetype;
  int vlistID;
  int taxisID;
  int status = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
520
521
522
  STREAM *streamptr;

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
524
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
525

Uwe Schulzweida's avatar
Uwe Schulzweida committed
526
  filetype = streamptr->filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        status = grbInqContents(streamID);
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        status = srvInqContents(streamID);
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        status = extInqContents(streamID);
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        status = iegInqContents(streamID);
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
    case FILETYPE_NC2:
561
    case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
562
563
564
565
566
567
568
569
      {
        status = cdfInqContents(streamID);
	break;
      }
#endif
    default:
      {
	if ( CDI_Debug )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
570
	  Message(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
571
572
573
574
575
576
577
578
579
580

	status = CDI_ELIBNAVAIL;
      }
    }

  if ( status == 0 )
    {
      vlistID = streamInqVlist(streamID);
      taxisID = vlistInqTaxis(vlistID);
      if ( taxisID != -1 )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
581
	ptaxisCopy(taxisPtr(taxisID), &streamptr->tsteps[0].taxis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
582
583
584
585
586
587
588
589
590
591
592
593
594
    }

  return (status);
}


int streamOpen(const char *filename, const char *filemode, int filetype)
{
  static char func[] = "streamOpen";
  int fileID = CDI_UNDEFID;
  int streamID = CDI_ESYSTEM;
  int status;
  Record *record = NULL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
595
  STREAM *streamptr = NULL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
596
597
598
599
600
601
602
603
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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653

  if ( CDI_Debug )
    Message(func, "Open %s mode %c file %s", strfiletype(filetype), (int) *filemode, filename);

  if ( ! filename || ! filemode || filetype < 0 ) return (CDI_EINVAL);

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        fileID = gribOpen(filename, filemode);
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        fileID = fileOpen(filename, filemode);
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	record->srvp   = srvNew();
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        fileID = fileOpen(filename, filemode);
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	record->extp   = extNew();
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        fileID = fileOpen(filename, filemode);
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	record->iegp   = iegNew();
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
      {
	fileID = cdfOpen(filename, filemode);
	break;
      }
    case FILETYPE_NC2:
      {
	fileID = cdfOpen64(filename, filemode);
	break;
      }
654
655
656
657
658
659
    case FILETYPE_NC4:
      {
	fileID = cdf4Open(filename, filemode);
	break;
      }
 #endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
660
661
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
	if ( CDI_Debug ) Message(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
663
664
665
666
667
668
669
670
671
672
	return (CDI_ELIBNAVAIL);
      }
    }

  if ( fileID < 0 )
    {
      streamID = fileID;
    }
  else
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
673
674
      streamptr = stream_new_entry();
      streamID = streamptr->self;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
675

Uwe Schulzweida's avatar
Uwe Schulzweida committed
676
677
678
679
680
      streamptr->record   = record;
      streamptr->filetype = filetype;
      streamptr->filemode = tolower(*filemode);
      streamptr->filename = strdupx(filename);
      streamptr->fileID   = fileID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
681

Uwe Schulzweida's avatar
Uwe Schulzweida committed
682
      if ( streamptr->filemode == 'r' )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
683
684
	{
	  VLIST *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
685
	  streamptr->vlistID = vlistCreate();
Uwe Schulzweida's avatar
Uwe Schulzweida committed
686
687
688
	  /* cdiReadByteorder(streamID); */
	  status = cdiInqContents(streamID);
	  if ( status < 0 ) return (status);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
689
	  vlistptr = vlist_to_pointer(streamptr->vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
	  vlistptr->ntsteps = streamNtsteps(streamID);
	}
    }
 
  return (streamID);
}


int streamOpenA(const char *filename, const char *filemode, int filetype)
{
  static char func[] = "streamOpenA";
  int fileID = CDI_UNDEFID;
  int streamID = CDI_ESYSTEM;
  int status;
  Record *record = NULL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
705
  STREAM *streamptr = NULL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
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
763

  if ( CDI_Debug )
    Message(func, "Open %s mode %c file %s", strfiletype(filetype), (int) *filemode, filename);

  if ( ! filename || ! filemode || filetype < 0 ) return (CDI_EINVAL);

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        fileID = gribOpen(filename, "r");
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        fileID = fileOpen(filename, "r");
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	record->srvp   = srvNew();
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        fileID = fileOpen(filename, "r");
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	record->extp   = extNew();
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        fileID = fileOpen(filename, "r");
	record = (Record *) malloc(sizeof(Record));
	record->buffer = NULL;
	record->iegp   = iegNew();
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
      {
	fileID = cdfOpen(filename, "r");
	break;
      }
    case FILETYPE_NC2:
      {
	fileID = cdfOpen64(filename, "r");
	break;
      }
764
765
766
767
768
    case FILETYPE_NC4:
      {
	fileID = cdf4Open(filename, "r");
	break;
      }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
769
770
771
#endif
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
772
	if ( CDI_Debug ) Message(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
773
774
775
776
777
778
779
780
781
782
783
784
	return (CDI_ELIBNAVAIL);
      }
    }

  if ( fileID == CDI_UNDEFID || fileID == CDI_ELIBNAVAIL )
    {
      streamID = fileID;
      return (streamID);
    }
  else
    {
      VLIST *vlistptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
785
786
      streamptr = stream_new_entry();
      streamID = streamptr->self;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
787

Uwe Schulzweida's avatar
Uwe Schulzweida committed
788
789
790
791
792
      streamptr->record   = record;
      streamptr->filetype = filetype;
      streamptr->filemode = tolower(*filemode);
      streamptr->filename = strdupx(filename);
      streamptr->fileID   = fileID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
793

Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
      streamptr->vlistID = vlistCreate();
Uwe Schulzweida's avatar
Uwe Schulzweida committed
795
796
797
      /* cdiReadByteorder(streamID); */
      status = cdiInqContents(streamID);
      if ( status < 0 ) return (status);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
798
      vlistptr = vlist_to_pointer(streamptr->vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
      vlistptr->ntsteps = cdiInqTimeSize(streamID);
    }
 
  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
      case FILETYPE_GRB:
	{
	  gribClose(fileID);
	  break;
	}
#endif
#if  defined  (HAVE_LIBSERVICE)
      case FILETYPE_SRV:
	{
	  fileClose(fileID);
	  break;
	}
#endif
#if  defined  (HAVE_LIBEXTRA)
      case FILETYPE_EXT:
	{
	  fileClose(fileID);
	  break;
	}
#endif
#if  defined  (HAVE_LIBIEG)
      case FILETYPE_IEG:
	{
	  fileClose(fileID);
	  break;
	}
#endif
#if  defined  (HAVE_LIBNETCDF)
      case FILETYPE_NC:
      case FILETYPE_NC2:
835
      case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
836
837
838
839
840
841
842
	{
	  cdfClose(fileID);
	  break;
	}
#endif
      default:
	{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
843
	  if ( CDI_Debug ) Message(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
	  return (CDI_ELIBNAVAIL);
	}
    }

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        fileID = gribOpen(filename, filemode);
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        fileID = fileOpen(filename, filemode);
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        fileID = fileOpen(filename, filemode);
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        fileID = fileOpen(filename, filemode);
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
      {
	fileID = cdfOpen(filename, filemode);
	break;
      }
    case FILETYPE_NC2:
      {
	fileID = cdfOpen64(filename, filemode);
	break;
      }
889
890
891
892
893
    case FILETYPE_NC4:
      {
	fileID = cdf4Open(filename, filemode);
	break;
      }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
894
895
896
#endif
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
897
	if ( CDI_Debug ) Message(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
898
899
900
901
902
903
904
	return (CDI_ELIBNAVAIL);
      }
    }

  if ( fileID == CDI_UNDEFID )
    streamID = CDI_UNDEFID;
  else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
905
    streamptr->fileID   = fileID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
906
907
908
909
910
911
912

  return (streamID);
}


/*
@Function  streamOpenRead
Uwe Schulzweida's avatar
Uwe Schulzweida committed
913
@Title     Open a dataset for reading
Uwe Schulzweida's avatar
Uwe Schulzweida committed
914

Uwe Schulzweida's avatar
Uwe Schulzweida committed
915
@Prototype int streamOpenRead(const char *path)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
916
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
917
    @Item  path  The name of the dataset to be read
Uwe Schulzweida's avatar
Uwe Schulzweida committed
918
919

@Description
920
The function @func{streamOpenRead} opens an existing dataset for reading.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
921
922

@Result
923
Upon successful completion @func{streamOpenRead} returns an identifier to the
Uwe Schulzweida's avatar
Uwe Schulzweida committed
924
925
926
927
928
929
930
open stream. Otherwise, a negative number with the error status is returned.

@Errors
@List
   @Item  CDI_ESYSTEM     Operating system error
   @Item  CDI_EINVAL      Invalid argument
   @Item  CDI_EUFILETYPE  Unsupported file type
Uwe Schulzweida's avatar
Uwe Schulzweida committed
931
   @Item  CDI_ELIBNAVAIL  Library support not compiled in
Uwe Schulzweida's avatar
Uwe Schulzweida committed
932
933
934
@EndList

@Example
935
936
Here is an example using @func{streamOpenRead} to open an existing netCDF
file named @func{foo.nc} for reading:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
937
938

@Source
Uwe Schulzweida's avatar
Uwe Schulzweida committed
939
#include "cdi.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
940
941
942
943
944
945
946
947
948
   ...
int streamID;
   ...
streamID = streamOpenRead("foo.nc");
if ( streamID < 0 ) handle_error(streamID);
   ...
@EndSource
@EndFunction
*/
949
int streamOpenRead(const char *filenames)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
950
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
951
  static char func[] = "streamOpenRead";
Uwe Schulzweida's avatar
Uwe Schulzweida committed
952
953
  int filetype, byteorder;
  int streamID;
954
955
956
  int num_fnames;
  char *fnames[MAX_FNAMES];
  const char *filename;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
957
  STREAM *streamptr = NULL;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
958

959
960
961
962
963
964
965
966
967
968
969
  num_fnames = get_fnames(filenames, fnames, MAX_FNAMES);

  if ( num_fnames == 0 )
    filename = filenames;
  else
    {
      int i; 
      for ( i = 0; i < num_fnames; ++i) printf("fnames: %d %s\n", i, fnames[i]);
      filename = fnames[0];
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
970
971
972
973
974
975
  filetype = getFiletype(filename, &byteorder);

  if ( filetype < 0 ) return (filetype);

  streamID = streamOpen(filename, "r", filetype);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
976
977
978
979
  if ( streamID >= 0 )
    {
      streamptr = stream_to_pointer(streamID);
      streamptr->byteorder = byteorder;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
980
981
982
983
984
985
986
987
988

      if ( num_fnames > 0 )
	{
	  int i;
	  streamptr->nfiles = num_fnames;
	  streamptr->fnames = (char **) malloc(num_fnames*sizeof(char *));
	  for ( i = 0; i < num_fnames; ++i )
	    streamptr->fnames[i] = fnames[i];
	}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
989
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
990
991
992
993
994
995
996
997
998

  return (streamID);
}


int streamOpenAppend(const char *filename)
{
  int filetype, byteorder;
  int streamID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
999
  STREAM *streamptr;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1000
1001
1002
1003
1004
1005
1006

  filetype = getFiletype(filename, &byteorder);

  if ( filetype < 0 ) return (filetype);

  streamID = streamOpenA(filename, "a", filetype);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1007
1008
1009
  streamptr = stream_to_pointer(streamID);

  streamptr->byteorder = byteorder;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1010
1011
1012
1013
1014
1015
1016

  return (streamID);
}


/*
@Function  streamOpenWrite
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1017
@Title     Create a new dataset
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1018

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1019
@Prototype int streamOpenWrite(const char *path, int filetype)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1020
@Parameter
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1021
    @Item  path      The name of the new dataset
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1022
    @Item  filetype  The type of the file format, one of the set of predefined CDI file format types.
1023
                     The valid CDI file format types are @func{FILETYPE_GRB}, @func{FILETYPE_NC},
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1024
1025
                     @func{FILETYPE_NC2}, @func{FILETYPE_NC4}, @func{FILETYPE_SRV},
                     @func{FILETYPE_EXT} and @func{FILETYPE_IEG}.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1026
1027

@Description
1028
The function @func{streamOpenWrite} creates a new datset.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1029
@Result
1030
Upon successful completion @func{streamOpenWrite} returns an identifier to the
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1031
1032
1033
1034
1035
1036
1037
open stream. Otherwise, a negative number with the error status is returned.

@Errors
@List
   @Item  CDI_ESYSTEM     Operating system error
   @Item  CDI_EINVAL      Invalid argument
   @Item  CDI_EUFILETYPE  Unsupported file type
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1038
   @Item  CDI_ELIBNAVAIL  Library support not compiled in
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1039
1040
1041
@EndList

@Example
1042
1043
Here is an example using @func{streamOpenWrite} to create a new netCDF file 
named @func{foo.nc} for writing:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1044
1045

@Source
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1046
#include "cdi.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
   ...
int streamID;
   ...
streamID = streamOpenWrite("foo.nc", FILETYPE_NC);
if ( streamID < 0 ) handle_error(streamID);
   ...
@EndSource
@EndFunction
*/
int streamOpenWrite(const char *filename, int filetype)
{
  return (streamOpen(filename, "w", filetype));
}


/*
@Function  streamClose
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1064
@Title     Close an open dataset
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1065
1066
1067

@Prototype  void streamClose(int streamID)
@Parameter
1068
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1069
1070

@Description
1071
The function @func{streamClose} closes an open dataset.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081

@EndFunction
*/
void streamClose(int streamID)
{
  static char func[] = "streamClose";
  int filetype;
  int fileID;
  int index;
  int vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1082
1083
1084
  STREAM *streamptr;

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1086
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1087
1088

  if ( CDI_Debug )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1089
    Message(func, "fileID = %d filename = %s", streamID, streamptr->filename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1090

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1091
1092
  fileID   = streamptr->fileID;
  filetype = streamptr->filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1093
1094
1095
  vlistID  = streamInqVlist(streamID);

  if ( fileID == CDI_UNDEFID )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1096
    Warning(func, "File %s not open!", streamptr->filename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
  else
    switch (filetype)
      {
#if  defined  (HAVE_LIBGRIB)
      case FILETYPE_GRB:
	{
	  gribClose(fileID);
	  break;
	}
#endif
#if  defined  (HAVE_LIBSERVICE)
      case FILETYPE_SRV:
	{
	  fileClose(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1111
	  srvDelete(streamptr->record->srvp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1112
1113
1114
1115
1116
1117
1118
	  break;
	}
#endif
#if  defined  (HAVE_LIBEXTRA)
      case FILETYPE_EXT:
	{
	  fileClose(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1119
	  extDelete(streamptr->record->extp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1120
1121
1122
1123
1124
1125
1126
	  break;
	}
#endif
#if  defined  (HAVE_LIBIEG)
      case FILETYPE_IEG:
	{
	  fileClose(fileID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1127
	  iegDelete(streamptr->record->iegp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1128
1129
1130
1131
1132
1133
	  break;
	}
#endif
#if  defined  (HAVE_LIBNETCDF)
      case FILETYPE_NC:
      case FILETYPE_NC2:
1134
      case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1135
1136
1137
1138
1139
1140
1141
	{
	  cdfClose(fileID);
	  break;
	}
#endif
      default:
	{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1142
	  Error(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1143
1144
1145
1146
	  break;
	}
      }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1147
  if ( streamptr->record )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1148
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1149
1150
      if ( streamptr->record->buffer )
	free(streamptr->record->buffer);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1151

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1152
      free(streamptr->record);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1153
1154
    }  

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1155
1156
  streamptr->filetype = 0;
  if ( streamptr->filename ) free(streamptr->filename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1157

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1158
  for ( index = 0; index < streamptr->nvars; index++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1159
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1160
1161
1162
1163
      if ( streamptr->vars[index].level )
	free(streamptr->vars[index].level);
      if ( streamptr->vars[index].lindex )
	free(streamptr->vars[index].lindex);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1164
    }
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1165
  free(streamptr->vars);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1166

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1167
  for ( index = 0; index < streamptr->ntsteps; ++index )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1168
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1169
1170
1171
1172
      if ( streamptr->tsteps[index].records )
	free(streamptr->tsteps[index].records);
      if ( streamptr->tsteps[index].recIDs )
	free(streamptr->tsteps[index].recIDs);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1173
1174
    }
    
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1175
  if ( streamptr->tsteps ) free(streamptr->tsteps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1176

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1177
1178
1179
1180
1181
1182
1183
1184
  if ( streamptr->nfiles > 0 )
    {
      for ( index = 0; index < streamptr->nfiles; ++index )
	free(streamptr->fnames[index]);

      free(streamptr->fnames);
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1185
  stream_delete_entry(streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1186

1187
1188
1189
1190
1191
  if ( vlistInqTaxis(vlistID) != -1 )
    {
      taxisDestroy(vlistInqTaxis(vlistID));
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1192
1193
  if ( vlistID != -1 )
    {
1194
      vlistDestroy(vlistID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1195
1196
1197
1198
1199
1200
    }
}


/*
@Function  streamDefTimestep
1201
@Title     Define time step
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1202
1203
1204

@Prototype int streamDefTimestep(int streamID, int tsID)
@Parameter
1205
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1206
1207
1208
    @Item  tsID      Timestep identifier

@Description
1209
The function @func{streamDefTimestep} defines the time step of a stream.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1210
1211

@Result
1212
@func{streamDefTimestep} returns the number of records of the time step.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1213
1214
1215
1216
1217
1218
1219
1220
1221

@EndFunction
*/
int streamDefTimestep(int streamID, int tsID)
{
  static char func[] = "streamDefTimestep";
  int newtsID;
  int taxisID;
  int vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1222
1223
1224
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1225
1226
1227
1228

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1229
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1230
1231
1232
1233
1234
1235

  vlistID = streamInqVlist(streamID);
  taxisID = vlistInqTaxis(vlistID);
  if ( taxisID == CDI_UNDEFID )
    {
      Warning(func, "taxisID undefined for fileID = %d! Using absolute time axis.", streamID);
1236
      taxisID = taxisCreate(TAXIS_ABSOLUTE);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1237
1238
1239
1240
1241
1242
1243
1244
      vlistDefTaxis(vlistID, taxisID);
    }

  newtsID = tstepsNewEntry(streamID);

  if ( tsID != newtsID )
    Error(func, "Internal problem: tsID = %d newtsID = %d", tsID, newtsID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1245
  streamptr->curTsID = tsID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1246

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1247
  ptaxisCopy(&streamptr->tsteps[tsID].taxis, taxisPtr(taxisID));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1248

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1249
  streamptr->ntsteps = tsID + 1;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1250

1251
1252
1253
  if ( (streamptr->filetype == FILETYPE_NC  ||
	streamptr->filetype == FILETYPE_NC2 ||
	streamptr->filetype == FILETYPE_NC4)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1254
1255
1256
1257
1258
       && vlistHasTime(vlistID) )
    cdfDefTimestep(streamID, tsID);

  cdiCreateRecords(streamID, tsID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1259
  return (streamptr->ntsteps);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1260
1261
1262
1263
1264
}


/*
@Function  streamInqTimestep
1265
@Title     Get time step
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1266
1267
1268

@Prototype int streamInqTimestep(int streamID, int tsID)
@Parameter
1269
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1270
1271
1272
    @Item  tsID      Timestep identifier

@Description
1273
The function @func{streamInqTimestep} returns the time step of a stream.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1274
1275

@Result
1276
@func{streamInqTimestep} returns the number of records of the time step.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286

@EndFunction
*/
int streamInqTimestep(int streamID, int tsID)
{
  static char func[] = "streamInqTimestep";
  int filetype;
  int nrecs = 0;
  int taxisID;
  int vlistID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1287
1288
1289
  STREAM *streamptr;

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1291
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1292
1293
1294

  vlistID = streamInqVlist(streamID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1295
  if ( tsID < streamptr->rtsteps )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1296
    {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1297
1298
1299
      streamptr->curTsID = tsID;
      nrecs = streamptr->tsteps[tsID].nrecs;
      streamptr->tsteps[tsID].curRecID = CDI_UNDEFID;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1300
1301
1302
      taxisID = vlistInqTaxis(vlistID);
      if ( taxisID == -1 )
	Error(func, "Timestep undefined for fileID = %d", streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1303
      ptaxisCopy(taxisPtr(taxisID), &streamptr->tsteps[tsID].taxis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1304
1305
1306
1307

      return (nrecs);
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1308
  if ( tsID >= streamptr->ntsteps && streamptr->ntsteps != CDI_UNDEFID )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1309
1310
1311
1312
    {
      return (0);
    }

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1313
  filetype = streamptr->filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350

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

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        nrecs = grbInqTimestep(streamID, tsID);
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        nrecs = srvInqTimestep(streamID, tsID);
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        nrecs = extInqTimestep(streamID, tsID);
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        nrecs = iegInqTimestep(streamID, tsID);
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
    case FILETYPE_NC2:
1351
    case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1352
1353
1354
1355
1356
1357
1358
      {
        nrecs = cdfInqTimestep(streamID, tsID);
	break;
      }
#endif
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1359
	Error(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1360
1361
1362
1363
1364
1365
1366
1367
	break;
      }
    }

  taxisID = vlistInqTaxis(vlistID);
  if ( taxisID == -1 )
    Error(func, "Timestep undefined for fileID = %d", streamID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1368
  ptaxisCopy(taxisPtr(taxisID), &streamptr->tsteps[tsID].taxis);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379

  return (nrecs);
}


/*
@Function  streamReadVar
@Title     Read a variable

@Prototype void streamReadVar(int streamID, int varID, double *data, int *nmiss)
@Parameter
1380
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1381
    @Item  varID     Variable identifier
1382
    @Item  data      Pointer to the location into which the data value is read
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1383
1384
    @Item  nmiss     Number of missing values

1385
1386
1387
@Description
The function streamReadVar reads all the values of one time step of a variable
from an open dataset.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1388
1389
1390
1391
1392
1393
@EndFunction
*/
void streamReadVar(int streamID, int varID, double *data, int *nmiss)
{
  static char func[] = "streamReadVar";
  int filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1394
1395
1396
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1397
1398
1399
1400

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1401
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1402

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1403
  filetype = streamptr->filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439

  *nmiss = 0;

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        grbReadVarDP(streamID, varID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        srvReadVarDP(streamID, varID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        extReadVarDP(streamID, varID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        iegReadVarDP(streamID, varID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
    case FILETYPE_NC2:
1440
    case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1441
1442
1443
1444
1445
1446
1447
      {
        cdfReadVarDP(streamID, varID, data, nmiss);
	break;
      }
#endif
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1448
	Error(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
	break;
      }
    }
}


/*
@Function  streamWriteVar
@Title     Write a variable

@Prototype void streamWriteVar(int streamID, int varID, double *data, int nmiss)
@Parameter
1461
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1462
    @Item  varID     Variable identifier
1463
    @Item  data      Pointer to a block of data values to be written
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1464
1465
    @Item  nmiss     Number of missing values

1466
1467
1468
@Description
The function streamWriteVar writes the values of one time step of a variable 
to an open dataset.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1469
1470
1471
1472
1473
1474
@EndFunction
*/
void streamWriteVar(int streamID, int varID, double *data, int nmiss)
{
  static char func[] = "streamWriteVar";
  int filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1475
1476
1477
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1478
1479
1480
1481

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1482
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1483
1484
1485

  streamDefineTaxis(streamID);

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1486
  filetype = streamptr->filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        grbWriteVarDP(streamID, varID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        srvWriteVarDP(streamID, varID, data);
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        extWriteVarDP(streamID, varID, data);
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        iegWriteVarDP(streamID, varID, data);
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
    case FILETYPE_NC2:
1521
    case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1522
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1523
	if ( streamptr->accessmode == 0 ) cdfEndDef(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1524
1525
1526
1527
1528
1529
        cdfWriteVarDP(streamID, varID, data, nmiss);
	break;
      }
#endif
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1530
	Error(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
	break;
      }
    }
}


/*
@Function  streamReadVarSlice
@Title     Read a horizontal slice of a variable

@Prototype void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int *nmiss)
@Parameter
1543
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1544
1545
    @Item  varID     Variable identifier
    @Item  levelID   Level identifier
1546
    @Item  data      Pointer to the location into which the data value is read
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1547
1548
    @Item  nmiss     Number of missing values

1549
1550
1551
@Description
The function streamReadVar reads all the values of a horizontal slice of a variable
from an open dataset.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1552
1553
1554
1555
1556
1557
1558
@EndFunction
*/
void streamReadVarSlice(int streamID, int varID, int levelID, double *data, int *nmiss)
{
  static char func[] = "streamReadVarSlice";
  int filetype;
  int ierr = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1559
1560
1561
  STREAM *streamptr;

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1563
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1564

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1565
  filetype = streamptr->filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601

  *nmiss = 0;

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        grbReadVarSliceDP(streamID, varID, levelID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        srvReadVarSliceDP(streamID, varID, levelID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        extReadVarSliceDP(streamID, varID, levelID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        iegReadVarSliceDP(streamID, varID, levelID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
    case FILETYPE_NC2:
1602
    case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1603
1604
1605
1606
1607
1608
1609
      {
        ierr = cdfReadVarSliceDP(streamID, varID, levelID, data, nmiss);
	break;
      }
#endif
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1610
	Error(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
	break;
      }
    }
}


/*
@Function  streamWriteVarSlice
@Title     Write a horizontal slice of a variable

@Prototype void streamWriteVarSlice(int streamID, int varID, int levelID, double *data, int nmiss)
@Parameter
1623
    @Item  streamID  Stream ID, from a previous call to @fref{streamOpenRead} or @fref{streamOpenWrite}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1624
1625
    @Item  varID     Variable identifier
    @Item  levelID   Level identifier
1626
    @Item  data      Pointer to a block of data values to be written
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1627
1628
    @Item  nmiss     Number of missing values

1629
1630
1631
@Description
The function streamWriteVarSlice writes the values of a horizontal slice of a 
variable to an open dataset.
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1632
1633
1634
1635
1636
1637
1638
@EndFunction
*/
void streamWriteVarSlice(int streamID, int varID, int levelID, double *data, int nmiss)
{
  static char func[] = "streamWriteVarSlice";
  int filetype;
  int ierr = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1639
1640
1641
  STREAM *streamptr;

  streamptr = stream_to_pointer(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1642
1643
1644
1645

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1646
  stream_check_ptr(func, streamptr);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1647

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1648
  filetype = streamptr->filetype;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682

  switch (filetype)
    {
#if  defined  (HAVE_LIBGRIB)
    case FILETYPE_GRB:
      {
        grbWriteVarSliceDP(streamID, varID, levelID, data, nmiss);
	break;
      }
#endif
#if  defined  (HAVE_LIBSERVICE)
    case FILETYPE_SRV:
      {
        srvWriteVarSliceDP(streamID, varID, levelID, data);
	break;
      }
#endif
#if  defined  (HAVE_LIBEXTRA)
    case FILETYPE_EXT:
      {
        extWriteVarSliceDP(streamID, varID, levelID, data);
	break;
      }
#endif
#if  defined  (HAVE_LIBIEG)
    case FILETYPE_IEG:
      {
        iegWriteVarSliceDP(streamID, varID, levelID, data);
	break;
      }
#endif
#if  defined  (HAVE_LIBNETCDF)
    case FILETYPE_NC:
    case FILETYPE_NC2:
1683
    case FILETYPE_NC4:
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1684
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1685
	if ( streamptr->accessmode == 0 ) cdfEndDef(streamID);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1686
1687
1688
1689
1690
1691
        ierr = cdfWriteVarSliceDP(streamID, varID, levelID, data, nmiss);
	break;
      }
#endif
    default:
      {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1692
	Error(func, "%s support not compiled in!", strfiletype(filetype));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1693