cdf_int.c 18.8 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
5
6
7
8
9
10
#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"
11
#include "cdi_int.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
12
#include "cdf_int.h"
13
#include "namespace.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
14
15
16
17
18
19

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

#if  defined  (HAVE_LIBNETCDF)
20
/*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
21
22
23
24
25
#if ! defined (MIN_BUF_SIZE)
#  define  MIN_BUF_SIZE  131072L
#endif

static size_t ChunkSizeMin = MIN_BUF_SIZE;
26
*/
Uwe Schulzweida's avatar
Uwe Schulzweida committed
27
28
29
30
void cdf_create(const char *path, int cmode, int *ncidp)
{
  int status;
  int oldfill;
31
32
  size_t initialsz = 0, chunksizehint = 0;
  /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
33
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
34
  struct stat filestat;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
35
36
37
38
39
40
41
42
  char basename[1024];
  char *pend;

  pend = strrchr(path, '/');
  if ( pend == 0 )
    strcpy(basename, "./");
  else
    {
43
      memcpy(basename, path, pend-path);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
44
45
46
47
      basename[pend-path] = 0;
    }

  if ( stat(basename, &filestat) != 0 )
48
    SysError(basename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
49
50

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
53
  if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
54
55
56
57
  */
#if defined(__SX__) || defined(ES)
  chunksizehint = 16777216; /* 16 MB */
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
58

59
60
  if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;

61
62
63
  cdi_nc__create_funcp my_nc__create =
    namespaceSwitchGet(NSSWITCH_NC__CREATE);
  status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65

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

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

71
  if ( status != NC_NOERR ) Error("%s: %s", path, nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
72
73
74

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

75
  if ( status != NC_NOERR ) Error("%s: %s", path, nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
76
77
78
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
79
int cdf_open(const char *path, int omode, int *ncidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
80
{
Uwe Schulzweida's avatar
Uwe Schulzweida committed
81
  int status = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
82
83
  int dapfile = FALSE;
  struct stat filestat;
84
  size_t chunksizehint = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
85
86

#if  defined  (HAVE_LIBNC_DAP)
87
  if ( memcmp(path, "http:", 5) == 0 ) dapfile = TRUE;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
88
89
90
91
92
93
94
95
#endif

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

98
#if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
99
      chunksizehint = (size_t) filestat.st_blksize * 4;
100
#endif
101
      /*
Uwe Schulzweida's avatar
Uwe Schulzweida committed
102
      if ( chunksizehint < ChunkSizeMin ) chunksizehint = ChunkSizeMin;
103
      */
104
105
      if ( cdiNcChunksizehint != CDI_UNDEFID ) chunksizehint = cdiNcChunksizehint;

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

109
      if ( CDF_Debug ) Message("chunksizehint %d", chunksizehint);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
110
111
    }

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

115
  if ( CDF_Debug && status != NC_NOERR ) Message("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
116
117

  return (status);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
118
119
120
121
122
123
124
125
126
}


void cdf_close(int ncid)
{
  int status;

  status = nc_close(ncid);

127
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
128
129
130
131
132
133
134
135
136
}


void cdf_redef(int ncid)
{
  int status;

  status = nc_redef(ncid);

137
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
138
139
140
141
142
143
144
145
146
}


void cdf_enddef(int ncid)
{
  int status;

  status = nc_enddef(ncid);

147
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
148
149
150
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
151
152
153
154
155
156
void cdf_sync(int ncid)
{
  int status;

  status = nc_sync(ncid);

157
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
158
159
160
}


Uwe Schulzweida's avatar
Uwe Schulzweida committed
161
162
163
164
165
166
167
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 )
168
    Message("ncid = %d ndims = %d nvars = %d ngatts = %d unlimid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
169
170
	    ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);

171
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
172
173
174
175
176
177
178
179
180
181
}


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 )
182
    Message("ncid = %d  name = %s  len = %d", ncid, name, len);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
183

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

187
188

void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
189
190
191
192
193
{
  int status;

  status = nc_inq_dimid(ncid, name, dimidp);

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

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

200
201

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
202
203
204
205
206
207
{
  int status;

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

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

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

213
214

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
215
216
217
218
219
220
{
  int status;

  status = nc_inq_dimname(ncid, dimid, name);

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

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

226
227

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
228
229
230
231
232
233
{
  int status;

  status = nc_inq_dimlen(ncid, dimid, lengthp);

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

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

239
240

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
241
                 const int dimids[], int *varidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
242
{
243
244
245
246
  cdi_cdf_def_var_funcp my_cdf_def_var
    = namespaceSwitchGet(NSSWITCH_CDF_DEF_VAR);
  my_cdf_def_var(ncid, name, xtype, ndims, dimids, varidp);
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
247

248
249
250
251
252
void
cdf_def_var_serial(int ncid, const char *name, nc_type xtype, int ndims,
                   const int dimids[], int *varidp)
{
  int status = nc_def_var(ncid, name, xtype, ndims, dimids, varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
253
254

  if ( CDF_Debug || status != NC_NOERR )
255
    Message("ncid = %d  name = %s  xtype = %d  ndims = %d  varid = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
256
257
258
	    ncid, name, xtype, ndims, *varidp);

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

262

263

Uwe Schulzweida's avatar
Uwe Schulzweida committed
264
265
266
267
268
269
270
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 )
271
    Message("ncid = %d  name = %s  varid = %d ", ncid, name, *varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
272

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


void cdf_inq_nvars(int ncid, int *nvarsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
279
280
281
282
283
{
  int status;

  status = nc_inq_nvars(ncid, nvarsp);

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

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

289
290
291

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
292
293
294
295
296
297
{
  int status;

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

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

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

304
305

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
306
307
308
309
310
311
{
  int status;

  status = nc_inq_varname(ncid, varid, name);

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

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

317
318

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
319
320
321
322
323
324
{
  int status;

  status = nc_inq_vartype(ncid, varid, xtypep);

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

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

330
331

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
332
333
334
335
336
337
{
  int status;

  status = nc_inq_varndims(ncid, varid, ndimsp);

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

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

343
344

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
345
346
347
348
349
350
{
  int status;

  status = nc_inq_vardimid(ncid, varid, dimids);

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

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

356
357

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
358
359
360
361
362
{
  int status;

  status = nc_inq_varnatts(ncid, varid, nattsp);

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

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

369
370

void cdf_put_var_text(int ncid, int varid, const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
371
372
373
374
375
{
  int status;

  status = nc_put_var_text(ncid, varid, tp);

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

379
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
380
381
382
}


383
void cdf_put_var_short(int ncid, int varid, const short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
384
385
386
387
388
{
  int status;

  status = nc_put_var_short(ncid, varid, sp);

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

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

395
396

void cdf_put_var_int(int ncid, int varid, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
397
398
399
400
401
{
  int status;

  status = nc_put_var_int(ncid, varid, ip);

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

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

408
409

void cdf_put_var_long(int ncid, int varid, const long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
410
411
412
413
414
{
  int status;

  status = nc_put_var_long(ncid, varid, lp);

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

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

421
422

void cdf_put_var_float(int ncid, int varid, const float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
423
424
425
426
427
{
  int status;

  status = nc_put_var_float(ncid, varid, fp);

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

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

434

435
436
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
437
438
439
440
441
442
{
  int status;

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

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

  if ( status != NC_NOERR )
446
447
448
449
450
451
452
    {
      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
453
454
}

455

456
457
458
459
460
461
462
463
464
465
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);

466
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
467
468
469
470
471
}


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
472
473
474
475
476
477
{
  int status;

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

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

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

483

484
485
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
486
487
488
489
490
491
{
  int status;

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

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

494
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
495
496
497
}


498
499
500
501
502
503
504
505
506
507
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);

508
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
509
510
511
}


512
513
514
515
516
517
518
519
520
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
521

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

525

526
void cdf_put_var_double(int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
527
528
529
530
531
532
{
  int status;

  status = nc_put_var_double(ncid, varid, dp);

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

535
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
536
537
538
539
540
541
542
543
544
545
546
}


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
547

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

551
552

void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
553
554
555
556
557
558
{
  int status;

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

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

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

564
565

void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
566
567
568
569
570
571
{
  int status;

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

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

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

577
578

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
579
580
581
582
583
584
{
  int status;

  status = nc_get_var_text(ncid, varid, tp);

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

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

590
591

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
592
593
594
595
596
597
{
  int status;

  status = nc_get_var_short(ncid, varid, sp);

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

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

603
604

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
605
606
607
608
609
610
{
  int status;

  status = nc_get_var_int(ncid, varid, ip);

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

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

616
617

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
618
619
620
621
622
623
{
  int status;

  status = nc_get_var_long(ncid, varid, lp);

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

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

629
630

void cdf_get_var_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
631
632
633
634
635
636
{
  int status;

  status = nc_get_var_float(ncid, varid, fp);

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

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

642
643

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
644
645
646
647
648
{
  int status;

  status = nc_get_var_double(ncid, varid, dp);

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

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

655
656
657

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
658
659
660
661
662
{
  int status;

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

663
664
  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
665

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

669
670
671

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
672
673
674
675
676
{
  int status;

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

677
  if ( CDF_Debug || status != NC_NOERR )
678
    Message("ncid = %d varid = %d att = %s text = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
679
680
	    ncid, varid, name, tp);

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

684
685
686

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
687
688
689
690
691
{
  int status;

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

692
693
  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
694

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

698
699
700

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
701
702
703
704
705
{
  int status;

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

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

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

712
713

void cdf_get_att_text(int ncid, int varid, char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
714
715
716
717
718
{
  int status;

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

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

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

725
726

void cdf_get_att_int(int ncid, int varid, char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
727
728
729
730
731
{
  int status;

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

732
733
  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
734

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

738

Uwe Schulzweida's avatar
Uwe Schulzweida committed
739
740
741
742
743
744
745
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 )
746
    Message("ncid = %d varid = %d att = %s val = %.9g",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
747
748
	    ncid, varid, name, *dp);

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

752

Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
754
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
755
756
757
758
759
760
{
  int status;

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

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

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

766
767

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
768
769
770
771
772
773
{
  int status;

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

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

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

779
780

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
781
782
783
784
785
{
  int status;

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

786
787
  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
788

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

792
793

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
794
795
796
797
798
{
  int status;

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

799
800
  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
801

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

805
806

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
807
808
809
810
811
812
{
  int status;

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

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

815
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
816
817
818
}

#endif
819
820
821
822
823
824
825
826
827
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */