cdf_int.c 18.6 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
#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"


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
31

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

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

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

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

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
62
63
64
  status = nc__create(path, cmode, initialsz, &chunksizehint, ncidp);

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

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

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

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

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


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

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

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

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

Uwe Schulzweida's avatar
Uwe Schulzweida committed
105
106
      status = nc__open(path, omode, &chunksizehint, ncidp);

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

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

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

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


void cdf_close(int ncid)
{
  int status;

  status = nc_close(ncid);

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


void cdf_redef(int ncid)
{
  int status;

  status = nc_redef(ncid);

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


void cdf_enddef(int ncid)
{
  int status;

  status = nc_enddef(ncid);

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


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

  status = nc_sync(ncid);

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


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

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


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

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

191
192

void cdf_inq_dimid(int ncid, const char *name, int *dimidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
193
194
195
196
197
198
{
  int status;

  status = nc_inq_dimid(ncid, name, dimidp);

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

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

205
206

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
207
208
209
210
211
212
{
  int status;

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

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

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

220
221

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
222
223
224
225
226
227
{
  int status;

  status = nc_inq_dimname(ncid, dimid, name);

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

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

234
235

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
236
237
238
239
240
241
{
  int status;

  status = nc_inq_dimlen(ncid, dimid, lengthp);

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

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

248
249

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
Uwe Schulzweida's avatar
Uwe Schulzweida committed
250
251
252
253
254
255
256
	    const int dimids[], int *varidp)
{
  int status;

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

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

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

264

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

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


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

  status = nc_inq_nvars(ncid, nvarsp);

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

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

292
293
294

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
295
296
297
298
299
300
{
  int status;

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

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

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

308
309

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
310
311
312
313
314
315
{
  int status;

  status = nc_inq_varname(ncid, varid, name);

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

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

322
323

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
324
325
326
327
328
329
{
  int status;

  status = nc_inq_vartype(ncid, varid, xtypep);

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

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

336
337

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
338
339
340
341
342
343
{
  int status;

  status = nc_inq_varndims(ncid, varid, ndimsp);

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

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

350
351

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
352
353
354
355
356
357
{
  int status;

  status = nc_inq_vardimid(ncid, varid, dimids);

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

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

364
365

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
366
367
368
369
370
371
{
  int status;

  status = nc_inq_varnatts(ncid, varid, nattsp);

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

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

378
379

void cdf_put_var_text(int ncid, int varid, const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
380
381
382
383
384
385
386
387
388
{
  int status;

  status = nc_put_var_text(ncid, varid, tp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_text : %d %d %s \n", ncid, varid, tp);

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


393
void cdf_put_var_short(int ncid, int varid, const short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
394
395
396
397
398
399
400
401
402
{
  int status;

  status = nc_put_var_short(ncid, varid, sp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_short : %d %d %hd \n", ncid, varid, *sp);

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

406
407

void cdf_put_var_int(int ncid, int varid, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
408
409
410
411
412
413
414
415
416
{
  int status;

  status = nc_put_var_int(ncid, varid, ip);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_int : %d %d %d \n", ncid, varid, *ip);

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

420
421

void cdf_put_var_long(int ncid, int varid, const long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
422
423
424
425
426
427
428
429
430
{
  int status;

  status = nc_put_var_long(ncid, varid, lp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_long : %d %d %ld \n", ncid, varid, *lp);

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

434
435

void cdf_put_var_float(int ncid, int varid, const float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
436
437
438
439
440
441
442
443
444
{
  int status;

  status = nc_put_var_float(ncid, varid, fp);

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_var_float : %d %d %f \n", ncid, varid, *fp);

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

448

449
450
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
451
452
453
454
455
456
{
  int status;

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

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

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

463

464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
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);

  if ( status != NC_NOERR )
    Error("%s", nc_strerror(status));
}


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
481
482
483
484
485
486
{
  int status;

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

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

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

493

494
495
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
496
497
498
499
500
501
{
  int status;

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

  if ( CDF_Debug || status != NC_NOERR )
502
503
504
505
506
507
508
    Message("ncid = %d varid = %d", ncid, varid);

  if ( status != NC_NOERR )
    Error("%s", nc_strerror(status));
}


509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
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);

  if ( status != NC_NOERR )
    Error("%s", nc_strerror(status));
}


524
525
526
527
528
529
530
531
532
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
533
534

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

538
539

void cdf_put_var_double (int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
540
541
542
543
544
545
{
  int status;

  status = nc_put_var_double(ncid, varid, dp);

  if ( CDF_Debug || status != NC_NOERR )
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
    Message("ncid = %d varid = %d val0 = %f", ncid, varid, *dp);

  if ( status != NC_NOERR )
    Error("%s", nc_strerror(status));
}


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
561
562

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

566
567

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

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

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

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

580
581

void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
582
583
584
585
586
587
{
  int status;

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

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

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

594
595

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
596
597
598
599
600
601
{
  int status;

  status = nc_get_var_text(ncid, varid, tp);

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

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

608
609

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
610
611
612
613
614
615
{
  int status;

  status = nc_get_var_short(ncid, varid, sp);

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

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

622
623

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
624
625
626
627
628
629
{
  int status;

  status = nc_get_var_int(ncid, varid, ip);

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

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

636
637

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
638
639
640
641
642
643
{
  int status;

  status = nc_get_var_long(ncid, varid, lp);

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

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

650
651

void cdf_get_var_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
652
653
654
655
656
657
{
  int status;

  status = nc_get_var_float(ncid, varid, fp);

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

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

664
665

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
666
667
668
669
670
671
{
  int status;

  status = nc_get_var_double(ncid, varid, dp);

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

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

678
679
680

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
681
682
683
684
685
686
687
688
689
690
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_copy_att : %d %d %s %d %d\n", ncid_in, varid_out,
	     name, ncid_out, varid_out);

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

694
695
696

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
697
698
699
700
701
702
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
703
    Message("ncid = %d varid = %d att = %s text = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
704
705
706
	    ncid, varid, name, tp);

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

710
711
712

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
713
714
715
716
717
718
{
  int status;

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

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

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

726
727
728

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
729
730
731
732
733
734
735
736
737
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
    fprintf (stderr, "cdf_put_att_double : %d %d %f \n", ncid, varid, *dp);

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

741
742

void cdf_get_att_text(int ncid, int varid, char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
743
744
745
746
747
748
{
  int status;

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

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

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

755
756

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

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

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

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

770

Uwe Schulzweida's avatar
Uwe Schulzweida committed
771
772
773
774
775
776
777
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 )
778
    Message("ncid = %d varid = %d att = %s val = %.9g",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
779
780
781
	    ncid, varid, name, *dp);

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

785

Uwe Schulzweida's avatar
Uwe Schulzweida committed
786
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
787
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
788
789
790
791
792
793
{
  int status;

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

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

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

800
801

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
802
803
804
805
806
807
{
  int status;

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

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

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

814
815

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
816
817
818
819
820
821
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
822
    Message("ncid = %d varid = %d name = %s len = %d",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
823
824
825
	    ncid, varid, name, *lenp);

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

829
830

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
831
832
833
834
835
836
{
  int status;

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

  if (CDF_Debug || status != NC_NOERR)
837
    Message("ncid = %d varid = %d attnum = %d name = %s",
Uwe Schulzweida's avatar
Uwe Schulzweida committed
838
839
840
	    ncid, varid, attnum, name);

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

844
845

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
846
847
848
849
850
851
{
  int status;

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

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

  if ( status != NC_NOERR )
855
    Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
856
857
858
}

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