cdf_int.c 19.9 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
6
7
8
9
10
11
12
13
#if defined (HAVE_CONFIG_H)
#  include "config.h"
#endif

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>

#include "cdi.h"
#include "stream_int.h"
#include "cdf_int.h"

14
15
16
17
18
19
20
21
22
#ifdef USE_MPI
#include "namespace.h"
#include "pio.h"
#include "pio_comm.h"
#include "pio_util.h"
#ifdef HAVE_NETCDF_PAR_H
#include <netcdf_par.h>
#endif
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
23
24
25
26
27
28

extern int CDF_Fatal;
extern int CDF_Verbose;
extern int CDF_Debug;

#if  defined  (HAVE_LIBNETCDF)
29
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
30
31
32
33
34
#if ! defined (MIN_BUF_SIZE)
#  define  MIN_BUF_SIZE  131072L
#endif

static size_t ChunkSizeMin = MIN_BUF_SIZE;
35
*/
36
37
38
39
40
#if USE_MPI && !defined (HAVE_PARALLEL_NC4)
/* When in PIO mode without a parallel netcdf library, each file is
 * actually opened on only one host */
extern int *cdiOpenFileMap, *cdiOpenFileCounts;
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
41
42
43
44
45

void cdf_create(const char *path, int cmode, int *ncidp)
{
  int status;
  int oldfill;
46
47
  size_t initialsz = 0, chunksizehint = 0;
  /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
48
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
49
  struct stat filestat;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
50
51
52
53
54
55
56
57
  char basename[1024];
  char *pend;

  pend = strrchr(path, '/');
  if ( pend == 0 )
    strcpy(basename, "./");
  else
    {
58
      memcpy(basename, path, pend-path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
59
60
61
62
      basename[pend-path] = 0;
    }

  if ( stat(basename, &filestat) != 0 )
63
    SysError(basename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65

  chunksizehint = (size_t) filestat.st_blksize * 4;
66
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
67

Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
  if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
69
70
71
72
  */
#if defined(__SX__) || defined(ES)
  chunksizehint = 16777216; /* 16 MB */
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
73

74
75
  if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#if USE_MPI
#if defined (HAVE_NETCDF4) && defined (HAVE_PARALLEL_NC4)
  if (cmode & NC_NETCDF4
      && namespaceHasLocalFile(namespaceGetActive())
      && commInqIOMode() != PIO_NONE)
    {
      cmode |= NC_MPIPOSIX;
      status = nc_create_par(path, cmode, commInqCommColl(),
                             MPI_INFO_NULL, ncidp);
    }
  else if (cmode & (NC_64BIT_OFFSET | NC_CLASSIC_MODEL)
           && namespaceHasLocalFile(namespaceGetActive())
           && commInqIOMode() != PIO_NONE)
    {
      /* FIXME: improve handling of pnetcdf here */
      abort();
    }
  else
    status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
#else
  /* FIXME: Only open netcdf file on one task */
  status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
#endif
#else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
100
  status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
101
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
102
103

  if ( CDF_Debug || status != NC_NOERR )
104
    Message("ncid = %d  mode = %d  file = %s", *ncidp, cmode, path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
105
106

  if ( CDF_Debug || status != NC_NOERR )
107
    Message("chunksizehint %d", chunksizehint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
108

109
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
111
112

  status = nc_set_fill(*ncidp, NC_NOFILL, &oldfill);

113
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
114
115
116
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
int cdf_open(const char *path, int omode, int *ncidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
119
  int status = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
120
121
  int dapfile = FALSE;
  struct stat filestat;
122
  size_t chunksizehint = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123
124

#if  defined  (HAVE_LIBNC_DAP)
125
  if ( memcmp(path, "http:", 5) == 0 ) dapfile = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
126
127
128
129
130
131
132
133
#endif

  if ( dapfile )
    {
      status = nc_open(path, omode, ncidp);
    }
  else
    {
134
      if ( stat(path, &filestat) != 0 ) SysError(path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
135

136
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
137
      chunksizehint = (size_t) filestat.st_blksize * 4;
138
#endif
139
      /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
140
      if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
141
      */
142
143
      if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;

144
      /* FIXME: parallel part missing */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
145
146
      status = nc__open(path, omode, &chunksizehint, ncidp);

147
      if ( CDF_Debug ) Message("chunksizehint %d", chunksizehint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
149
    }

150
  if ( CDF_Debug )
151
    Message("ncid = %d  mode = %d  file = %s", *ncidp, omode, path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152

153
  if ( CDF_Debug && status != NC_NOERR ) Message("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
154
155

  return (status);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
156
157
158
159
160
161
162
163
164
}


void cdf_close(int ncid)
{
  int status;

  status = nc_close(ncid);

165
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
166
167
168
169
170
171
172
173
174
}


void cdf_redef(int ncid)
{
  int status;

  status = nc_redef(ncid);

175
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
176
177
178
179
180
181
182
183
184
}


void cdf_enddef(int ncid)
{
  int status;

  status = nc_enddef(ncid);

185
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
186
187
188
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
190
191
192
193
194
void cdf_sync(int ncid)
{
  int status;

  status = nc_sync(ncid);

195
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
196
197
198
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
199
200
201
202
203
204
205
void cdf_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp)
{
  int status;

  status = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp);

  if ( CDF_Debug || status != NC_NOERR )
206
    Message("ncid = %d ndims = %d nvars = %d ngatts = %d unlimid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
207
208
	    ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);

209
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
210
211
212
213
214
215
216
217
218
219
}


void cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp)
{
  int status;

  status = nc_def_dim(ncid, name, len, dimidp);

  if ( CDF_Debug || status != NC_NOERR )
220
    Message("ncid = %d  name = %s  len = %d", ncid, name, len);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
221

222
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
223
224
}

225
226

void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
227
228
229
230
231
{
  int status;

  status = nc_inq_dimid(ncid, name, dimidp);

232
  if ( CDF_Debug || status != NC_NOERR )
233
    Message("ncid = %d  name = %s  dimid= %d", ncid, name, *dimidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
234

235
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
236
237
}

238
239

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
240
241
242
243
244
245
{
  int status;

  status = nc_inq_dim(ncid, dimid, name, lengthp);

  if ( CDF_Debug || status != NC_NOERR )
246
    Message("ncid = %d  dimid = %d  length = %d name = %s", ncid, dimid, *lengthp, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
247

248
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
249
250
}

251
252

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
254
255
256
257
258
{
  int status;

  status = nc_inq_dimname(ncid, dimid, name);

  if ( CDF_Debug || status != NC_NOERR )
259
    Message("ncid = %d  dimid = %d  name = %s", ncid, dimid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
260

261
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
262
263
}

264
265

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
266
267
268
269
270
271
{
  int status;

  status = nc_inq_dimlen(ncid, dimid, lengthp);

  if ( CDF_Debug || status != NC_NOERR )
272
    Message("ncid = %d dimid = %d length = %d", ncid, dimid, *lengthp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
273

274
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
275
276
}

277
278

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
279
280
281
282
283
284
285
	    const int dimids[], int *varidp)
{
  int status;

  status = nc_def_var(ncid, name, xtype, ndims, dimids, varidp);

  if ( CDF_Debug || status != NC_NOERR )
286
    Message("ncid = %d  name = %s  xtype = %d  ndims = %d  varid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
287
288
289
	    ncid, name, xtype, ndims, *varidp);

  if ( status != NC_NOERR )
290
    Error("%s", nc_strerror(status));
291
292
293
294
295
296
297
298
299
300
301
302
303
304

#if USE_MPI
#if defined (HAVE_NETCDF4) && defined (HAVE_PARALLEL_NC4)
  if (namespaceHasLocalFile(namespaceGetActive())
      && commInqIOMode() != PIO_NONE)
    {
      xdebug("%s", "calling nc_var_par_access");
      status = nc_var_par_access(ncid, *varidp, NC_COLLECTIVE);
      if ( status != NC_NOERR )
        Error("%s", nc_strerror(status));
    }
#endif
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
305
306
}

307

Uwe Schulzweida's avatar
Uwe Schulzweida committed
308
309
310
311
312
313
314
void cdf_inq_varid(int ncid, const char *name, int *varidp)
{
  int status;

  status = nc_inq_varid(ncid, name, varidp);

  if ( CDF_Debug || status != NC_NOERR )
315
    Message("ncid = %d  name = %s  varid = %d ", ncid, name, *varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
316

317
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
318
}
319
320
321


void cdf_inq_nvars(int ncid, int *nvarsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
322
323
324
325
326
327
{
  int status;

  status = nc_inq_nvars(ncid, nvarsp);

  if ( CDF_Debug || status != NC_NOERR )
328
    Message("ncid = %d  nvars = %d", ncid, *nvarsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
329

330
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
331
332
}

333
334
335

void cdf_inq_var(int ncid, int varid, char *name, nc_type *xtypep, int *ndimsp,
		 int dimids[], int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
336
337
338
339
340
341
{
  int status;

  status = nc_inq_var(ncid, varid, name, xtypep, ndimsp, dimids, nattsp);

  if ( CDF_Debug || status != NC_NOERR )
342
    Message("ncid = %d varid = %d ndims = %d xtype = %d natts = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
343
344
	    ncid, varid, *ndimsp, *xtypep, *nattsp, name);

345
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
346
347
}

348
349

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
350
351
352
353
354
355
{
  int status;

  status = nc_inq_varname(ncid, varid, name);

  if ( CDF_Debug || status != NC_NOERR )
356
    Message("ncid = %d varid = %d name = %s", ncid, varid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
357

358
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
359
360
}

361
362

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
363
364
365
366
367
368
{
  int status;

  status = nc_inq_vartype(ncid, varid, xtypep);

  if ( CDF_Debug || status != NC_NOERR )
369
    Message("ncid = %d varid = %d xtype = %s", ncid, varid, *xtypep);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
370

371
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
372
373
}

374
375

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
376
377
378
379
380
381
{
  int status;

  status = nc_inq_varndims(ncid, varid, ndimsp);

  if ( CDF_Debug || status != NC_NOERR )
382
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
383

384
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
385
386
}

387
388

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
389
390
391
392
393
394
{
  int status;

  status = nc_inq_vardimid(ncid, varid, dimids);

  if ( CDF_Debug || status != NC_NOERR )
395
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
396

397
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
398
399
}

400
401

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
402
403
404
405
406
{
  int status;

  status = nc_inq_varnatts(ncid, varid, nattsp);

407
  if ( CDF_Debug || status != NC_NOERR )
408
    Message("ncid = %d varid = %d nattsp = %d", ncid, varid, *nattsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
409

410
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
411
412
}

413
414

void cdf_put_var_text(int ncid, int varid, const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
415
416
417
418
419
{
  int status;

  status = nc_put_var_text(ncid, varid, tp);

420
421
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %s", ncid, varid, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
422

423
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
424
425
426
}


427
void cdf_put_var_short(int ncid, int varid, const short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
428
429
430
431
432
{
  int status;

  status = nc_put_var_short(ncid, varid, sp);

433
434
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %hd", ncid, varid, *sp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
435

436
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
437
438
}

439
440

void cdf_put_var_int(int ncid, int varid, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
441
442
443
444
445
{
  int status;

  status = nc_put_var_int(ncid, varid, ip);

446
447
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %d", ncid, varid, *ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
448

449
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
450
451
}

452
453

void cdf_put_var_long(int ncid, int varid, const long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
454
455
456
457
458
{
  int status;

  status = nc_put_var_long(ncid, varid, lp);

459
460
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %ld", ncid, varid, *lp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
461

462
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
463
464
}

465
466

void cdf_put_var_float(int ncid, int varid, const float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
467
468
469
470
471
{
  int status;

  status = nc_put_var_float(ncid, varid, fp);

472
473
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %f", ncid, varid, *fp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
474

475
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
476
477
}

478

479
480
void cdf_put_vara_double(int ncid, int varid, const size_t start[],
                         const size_t count[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
481
482
483
484
485
486
{
  int status;

  status = nc_put_vara_double(ncid, varid, start, count, dp);

  if ( CDF_Debug || status != NC_NOERR )
487
    Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
488
489

  if ( status != NC_NOERR )
490
491
492
493
494
495
496
    {
      char name[256];
      nc_inq_varname(ncid, varid, name);
      Message("varname = %s", name);
    }

  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
497
498
}

499

500
501
502
503
504
505
506
507
508
509
void  cdf_put_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], const float *fp)
{
  int status;

  status = nc_put_vara_float(ncid, varid, start, count, fp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d val0 = %f", ncid, varid, *fp);

510
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
511
512
513
514
515
}


void  cdf_get_vara_int(int ncid, int varid, const size_t start[],
                       const size_t count[], int *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
516
517
518
519
520
521
{
  int status;

  status = nc_get_vara_int(ncid, varid, start, count, dp);

  if ( CDF_Debug || status != NC_NOERR )
522
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
523

524
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
525
526
}

527

528
529
void  cdf_get_vara_double(int ncid, int varid, const size_t start[],
                          const size_t count[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
530
531
532
533
534
535
{
  int status;

  status = nc_get_vara_double(ncid, varid, start, count, dp);

  if ( CDF_Debug || status != NC_NOERR )
536
537
    Message("ncid = %d varid = %d", ncid, varid);

538
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
539
540
541
}


542
543
544
545
546
547
548
549
550
551
void  cdf_get_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], float *fp)
{
  int status;

  status = nc_get_vara_float(ncid, varid, start, count, fp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d", ncid, varid);

552
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
553
554
555
}


556
557
558
559
560
561
562
563
564
void  cdf_get_vara_text(int ncid, int varid, const size_t start[],
			const size_t count[], char *tp)
{
  int status;

  status = nc_get_vara_text(ncid, varid, start, count, tp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
565

566
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
567
568
}

569

570
void cdf_put_var_double(int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
571
572
573
574
575
576
{
  int status;

  status = nc_put_var_double(ncid, varid, dp);

  if ( CDF_Debug || status != NC_NOERR )
577
578
    Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);

579
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
580
581
582
583
584
585
586
587
588
589
590
}


void cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp)
{
  int status;

  status = nc_get_var1_text(ncid, varid, index, tp);

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
591

592
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
593
594
}

595
596

void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
597
598
599
600
601
602
{
  int status;

  status = nc_get_var1_double(ncid, varid, index, dp);

  if ( CDF_Debug || status != NC_NOERR )
603
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
604

605
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
606
607
}

608
609

void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
610
611
612
613
614
615
{
  int status;

  status = nc_put_var1_double(ncid, varid, index, dp);

  if ( CDF_Debug || status != NC_NOERR )
616
    Message("ncid = %d varid = %d val = %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
617

618
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
619
620
}

621
622

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
623
624
625
626
627
628
{
  int status;

  status = nc_get_var_text(ncid, varid, tp);

  if ( CDF_Debug || status != NC_NOERR )
629
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
630

631
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
632
633
}

634
635

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
636
637
638
639
640
641
{
  int status;

  status = nc_get_var_short(ncid, varid, sp);

  if ( CDF_Debug || status != NC_NOERR )
642
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
643

644
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
645
646
}

647
648

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
649
650
651
652
653
654
{
  int status;

  status = nc_get_var_int(ncid, varid, ip);

  if ( CDF_Debug || status != NC_NOERR )
655
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
656

657
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
658
659
}

660
661

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
662
663
664
665
666
667
{
  int status;

  status = nc_get_var_long(ncid, varid, lp);

  if ( CDF_Debug || status != NC_NOERR )
668
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
669

670
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
671
672
}

673
674

void cdf_get_var_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
675
676
677
678
679
680
{
  int status;

  status = nc_get_var_float(ncid, varid, fp);

  if ( CDF_Debug || status != NC_NOERR )
681
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
682

683
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
684
685
}

686
687

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
688
689
690
691
692
{
  int status;

  status = nc_get_var_double(ncid, varid, dp);

693
  if ( CDF_Debug || status != NC_NOERR )
694
    Message("ncid = %d varid = %d val[0] = %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
695

696
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
697
698
}

699
700
701

void cdf_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out,
		  int varid_out)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
702
703
704
705
706
{
  int status;

  status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);

707
708
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %s %d %d", ncid_in, varid_out, name, ncid_out, varid_out);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
709

710
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
711
712
}

713
714
715

void cdf_put_att_text(int ncid, int varid, const char *name, size_t len,
		      const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
716
717
718
719
720
{
  int status;

  status = nc_put_att_text(ncid, varid, name, len, tp);

721
  if ( CDF_Debug || status != NC_NOERR )
722
    Message("ncid = %d varid = %d att = %s text = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
723
724
	    ncid, varid, name, tp);

725
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
726
727
}

728
729
730

void cdf_put_att_int(int ncid, int varid, const char *name, nc_type xtype,
		     size_t len, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
731
732
733
734
735
{
  int status;

  status = nc_put_att_int(ncid, varid, name, xtype, len, ip);

736
737
  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d att = %s val = %d", ncid, varid, name, *ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
738

739
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
740
741
}

742
743
744

void cdf_put_att_double(int ncid, int varid, const char *name, nc_type xtype,
			size_t len, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
745
746
747
748
749
{
  int status;

  status = nc_put_att_double(ncid, varid, name, xtype, len, dp);

750
751
  if ( CDF_Debug || status != NC_NOERR )
    Message("%d %d %f", ncid, varid, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
752

753
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
754
755
}

756
757

void cdf_get_att_text(int ncid, int varid, char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
758
759
760
761
762
{
  int status;

  status = nc_get_att_text(ncid, varid, name, tp);

763
  if ( CDF_Debug || status != NC_NOERR )
764
    Message("ncid = %d varid = %d name = %s", ncid, varid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
765

766
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
767
768
}

769
770

void cdf_get_att_int(int ncid, int varid, char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
771
772
773
774
775
{
  int status;

  status = nc_get_att_int(ncid, varid, name, ip);

776
777
  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d att = %s val = %d", ncid, varid, name, *ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
778

779
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
780
781
}

782

Uwe Schulzweida's avatar
Uwe Schulzweida committed
783
784
785
786
787
788
789
void cdf_get_att_double(int ncid, int varid, char *name, double *dp)
{
  int status;

  status = nc_get_att_double(ncid, varid, name, dp);

  if ( CDF_Debug || status != NC_NOERR )
790
    Message("ncid = %d varid = %d att = %s val = %.9g",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
791
792
	    ncid, varid, name, *dp);

793
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
795
}

796

Uwe Schulzweida's avatar
Uwe Schulzweida committed
797
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
798
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
799
800
801
802
803
804
{
  int status;

  status = nc_inq_att(ncid, varid, name, xtypep, lenp);

  if ( CDF_Debug || status != NC_NOERR )
805
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
806

807
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
808
809
}

810
811

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
812
813
814
815
816
817
{
  int status;

  status = nc_inq_atttype(ncid, varid, name, xtypep);

  if ( CDF_Debug || status != NC_NOERR )
818
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
819

820
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
821
822
}

823
824

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
825
826
827
828
829
{
  int status;

  status = nc_inq_attlen(ncid, varid, name, lenp);

830
831
  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d name = %s len = %d", ncid, varid, name, *lenp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
832

833
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
834
835
}

836
837

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
838
839
840
841
842
{
  int status;

  status = nc_inq_attname(ncid, varid, attnum, name);

843
844
  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d attnum = %d name = %s", ncid, varid, attnum, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
845

846
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
847
848
}

849
850

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
851
852
853
854
855
856
{
  int status;

  status = nc_inq_attid(ncid, varid, name, attnump);

  if ( CDF_Debug || status != NC_NOERR )
857
    Message("ncid = %d varid = %d", ncid, varid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
858

859
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
860
861
862
}

#endif
863
864
865
866
867
868
869
870
871
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */