cdf_int.c 20 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

extern int CDF_Debug;

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

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

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

  if ( stat(basename, &filestat) != 0 )
45
    SysError(basename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
46
47

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

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

56
57
  if ( cdiNcChunksizehint != CDI_UNDEFID )
    chunksizehint = (size_t)cdiNcChunksizehint;
58

59
  cdi_nc__create_funcp my_nc__create =
60
    (cdi_nc__create_funcp)namespaceSwitchGet(NSSWITCH_NC__CREATE).func;
61
  int status = my_nc__create(path, cmode, initialsz, &chunksizehint, ncidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
62
63

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

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

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

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

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


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

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

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

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

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

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

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

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

116
  return status;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
117
118
119
120
121
}


void cdf_close(int ncid)
{
122
  int status = nc_close(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
123

124
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
125
126
127
128
129
}


void cdf_redef(int ncid)
{
130
  int status = nc_redef(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
131

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


void cdf_enddef(int ncid)
{
138
  int status = nc_enddef(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
139

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
144
145
146
147
148
149
150
void cdf__enddef(const int ncid, const size_t hdr_pad)
{
  const size_t v_align   = 4UL; /* [B] Alignment of beginning of data section for fixed variables */
  const size_t v_minfree = 0UL; /* [B] Pad at end of data section for fixed size variables */
  const size_t r_align   = 4UL; /* [B] Alignment of beginning of data section for record variables */

  /* nc_enddef(ncid) is equivalent to nc__enddef(ncid, 0, 4, 0, 4) */
151
  int status = nc__enddef(ncid, hdr_pad, v_align, v_minfree, r_align);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
152
153
154
155
156

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
157
158
void cdf_sync(int ncid)
{
159
  int status = nc_sync(ncid);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
160

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


Uwe Schulzweida's avatar
Uwe Schulzweida committed
165
166
void cdf_inq(int ncid, int *ndimsp, int *nvarsp, int *ngattsp, int *unlimdimidp)
{
167
  int status = nc_inq(ncid, ndimsp, nvarsp, ngattsp, unlimdimidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
168
169

  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
	    ncid, *ndimsp, *nvarsp, *ngattsp, *unlimdimidp);

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


void cdf_def_dim(int ncid, const char *name, size_t len, int *dimidp)
{
179
  int status = nc_def_dim(ncid, name, len, dimidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
180
181

  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
  int status = nc_inq_dimid(ncid, name, dimidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
191

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

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

198
199

void cdf_inq_dim(int ncid, int dimid, char *name, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
200
{
201
  int status = nc_inq_dim(ncid, dimid, name, lengthp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
202
203

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

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

209
210

void cdf_inq_dimname(int ncid, int dimid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
211
{
212
  int status = nc_inq_dimname(ncid, dimid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
213
214

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

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

220
221

void cdf_inq_dimlen(int ncid, int dimid, size_t * lengthp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
222
{
223
  int status = nc_inq_dimlen(ncid, dimid, lengthp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
224
225

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

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

231
232

void cdf_def_var(int ncid, const char *name, nc_type xtype, int ndims,
233
                 const int dimids[], int *varidp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
234
{
235
  cdi_cdf_def_var_funcp my_cdf_def_var
236
    = (cdi_cdf_def_var_funcp)namespaceSwitchGet(NSSWITCH_CDF_DEF_VAR).func;
237
238
  my_cdf_def_var(ncid, name, xtype, ndims, dimids, varidp);
}
Uwe Schulzweida's avatar
Uwe Schulzweida committed
239

240
241
242
243
244
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
245
246

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

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

253

254

Uwe Schulzweida's avatar
Uwe Schulzweida committed
255
256
void cdf_inq_varid(int ncid, const char *name, int *varidp)
{
257
  int status = nc_inq_varid(ncid, name, varidp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
258
259

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

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


void cdf_inq_nvars(int ncid, int *nvarsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
267
{
268
  int status = nc_inq_nvars(ncid, nvarsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
269
270

  if ( CDF_Debug || status != NC_NOERR )
271
    Message("ncid = %d  nvars = %d", ncid, *nvarsp);
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
278

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
279
{
280
  int status = nc_inq_var(ncid, varid, name, xtypep, ndimsp, dimids, nattsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
281
282

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

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

289
290

void cdf_inq_varname(int ncid, int varid, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
291
{
292
  int status = nc_inq_varname(ncid, varid, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
293
294

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

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

300
301

void cdf_inq_vartype(int ncid, int varid, nc_type *xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
302
{
303
  int status = nc_inq_vartype(ncid, varid, xtypep);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
304
305

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

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

311
312

void cdf_inq_varndims(int ncid, int varid, int *ndimsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
313
{
314
  int status = nc_inq_varndims(ncid, varid, ndimsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
315
316

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

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

322
323

void cdf_inq_vardimid(int ncid, int varid, int dimids[])
Uwe Schulzweida's avatar
Uwe Schulzweida committed
324
{
325
  int status = nc_inq_vardimid(ncid, varid, dimids);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
326
327

  if ( CDF_Debug || status != NC_NOERR )
328
    Message("ncid = %d varid = %d", ncid, varid);
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

void cdf_inq_varnatts(int ncid, int varid, int *nattsp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
335
{
336
  int status = nc_inq_varnatts(ncid, varid, nattsp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
337

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

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

344
345

void cdf_put_var_text(int ncid, int varid, const char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
346
{
347
  int status = nc_put_var_text(ncid, varid, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
348

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

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


356
void cdf_put_var_short(int ncid, int varid, const short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
357
{
358
  int status = nc_put_var_short(ncid, varid, sp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
359

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

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

366
367

void cdf_put_var_int(int ncid, int varid, const int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
368
{
369
  int status = nc_put_var_int(ncid, varid, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
370

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

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

377
378

void cdf_put_var_long(int ncid, int varid, const long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
379
{
380
  int status = nc_put_var_long(ncid, varid, lp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
381

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

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

388
389

void cdf_put_var_float(int ncid, int varid, const float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
390
{
391
  int status = nc_put_var_float(ncid, varid, fp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
392

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

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

399

400
401
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
402
{
403
  int status = nc_put_vara_double(ncid, varid, start, count, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
404
405

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

  if ( status != NC_NOERR )
409
410
411
412
413
414
415
    {
      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
416
417
}

418

419
420
421
void  cdf_put_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], const float *fp)
{
422
  int status = nc_put_vara_float(ncid, varid, start, count, fp);
423
424
425
426

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

427
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
428
429
430
431
432
}


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
433
{
434
  int status = nc_get_vara_int(ncid, varid, start, count, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
435
436

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

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

442

443
444
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
445
{
446
  int status = nc_get_vara_double(ncid, varid, start, count, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
447
448

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

451
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
452
453
454
}


455
456
457
void  cdf_get_vara_float(int ncid, int varid, const size_t start[],
                         const size_t count[], float *fp)
{
458
  int status = nc_get_vara_float(ncid, varid, start, count, fp);
459
460
461
462

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

463
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
464
465
466
}


467
468
469
void  cdf_get_vara_text(int ncid, int varid, const size_t start[],
			const size_t count[], char *tp)
{
470
  int status = nc_get_vara_text(ncid, varid, start, count, tp);
471
472
473

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d", ncid, varid);
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_get_vara_uchar(int ncid, int varid, const size_t start[], const size_t count[], unsigned char *tp)
{
481
  int status = nc_get_vara_uchar(ncid, varid, start, count, tp);
482
483
484
485
486
487
488
489

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

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


490
void cdf_put_var_double(int ncid, int varid, const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
491
{
492
  int status = nc_put_var_double(ncid, varid, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
493
494

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

497
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
498
499
500
501
502
}


void cdf_get_var1_text(int ncid, int varid, const size_t index[], char *tp)
{
503
  int status = nc_get_var1_text(ncid, varid, index, tp);
504
505
506

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

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

511
512

void cdf_get_var1_double(int ncid, int varid, const size_t index[], double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
513
{
514
  int status = nc_get_var1_double(ncid, varid, index, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
515
516

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

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

522
523

void cdf_put_var1_double(int ncid, int varid, const size_t index[], const double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
524
{
525
  int status = nc_put_var1_double(ncid, varid, index, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
526
527

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

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

533
534

void cdf_get_var_text(int ncid, int varid, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
535
{
536
  int status = nc_get_var_text(ncid, varid, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
537
538

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

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

544
545

void cdf_get_var_short(int ncid, int varid, short *sp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
546
{
547
  int status = nc_get_var_short(ncid, varid, sp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
548
549

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

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

555
556

void cdf_get_var_int(int ncid, int varid, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
557
{
558
  int status = nc_get_var_int(ncid, varid, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
559
560

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

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

566
567

void cdf_get_var_long(int ncid, int varid, long *lp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
568
{
569
  int status = nc_get_var_long(ncid, varid, lp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
570
571

  if ( CDF_Debug || status != NC_NOERR )
572
    Message("ncid = %d varid = %d", ncid, varid);
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_float(int ncid, int varid, float *fp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
579
{
580
  int status = nc_get_var_float(ncid, varid, fp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
581
582

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

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

588
589

void cdf_get_var_double(int ncid, int varid, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
590
{
591
  int status = nc_get_var_double(ncid, varid, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
592

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

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

599
600
601

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
602
{
603
  int status = nc_copy_att(ncid_in, varid_in, name, ncid_out, varid_out);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
604

605
606
  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
607

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

611
612
613

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
614
{
615
  int status = nc_put_att_text(ncid, varid, name, len, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
616

617
  if ( CDF_Debug || status != NC_NOERR )
618
    Message("ncid = %d varid = %d att = %s text = %.*s", ncid, varid, name, (int)len, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
619

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

623
624
625

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
626
{
627
  int status = nc_put_att_int(ncid, varid, name, xtype, len, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
628

629
630
  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
631

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

635

636
637
638
void cdf_put_att_float(int ncid, int varid, const char *name, nc_type xtype,
                       size_t len, const float *dp)
{
639
  int status = nc_put_att_float(ncid, varid, name, xtype, len, dp);
640
641
642
643
644
645
646
647

  if ( CDF_Debug || status != NC_NOERR )
    Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);

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


648
649
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
650
{
651
  int status = nc_put_att_double(ncid, varid, name, xtype, len, dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
652

653
  if ( CDF_Debug || status != NC_NOERR )
654
    Message("ncid = %d varid = %d att = %s val = %g", ncid, varid, name, *dp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
655

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

659

660
void cdf_get_att_text(int ncid, int varid, const char *name, char *tp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
661
{
662
  int status = nc_get_att_text(ncid, varid, name, tp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
663

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

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

670
671
672
void cdf_get_att_string(int ncid, int varid, const char *name, char **tp)
{
#if  defined  (HAVE_NETCDF4)
673
  int status = nc_get_att_string(ncid, varid, name, tp);
674
675
676
677
678
679
680
681

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

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

682

683
void cdf_get_att_int(int ncid, int varid, const char *name, int *ip)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
684
{
685
  int status = nc_get_att_int(ncid, varid, name, ip);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
686

687
688
  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
689

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

693

694
void cdf_get_att_double(int ncid, int varid, const char *name, double *dp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
695
696
697
698
699
700
{
  int status;

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

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

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

706

Uwe Schulzweida's avatar
Uwe Schulzweida committed
707
void cdf_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
708
		 size_t *lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
709
{
710
  int status = nc_inq_att(ncid, varid, name, xtypep, lenp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
711
712

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

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

718
719

void cdf_inq_atttype(int ncid, int varid, const char *name, nc_type * xtypep)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
720
{
721
  int status = nc_inq_atttype(ncid, varid, name, xtypep);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
722
723

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

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

729
730

void cdf_inq_attlen(int ncid, int varid, const char *name, size_t * lenp)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
731
{
732
  int status = nc_inq_attlen(ncid, varid, name, lenp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
733

734
  if ( CDF_Debug || status != NC_NOERR )
735
    Message("ncid = %d varid = %d att = %s len = %d", ncid, varid, name, *lenp);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
736

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

740
741

void cdf_inq_attname(int ncid, int varid, int attnum, char *name)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
742
{
743
  int status = nc_inq_attname(ncid, varid, attnum, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
744

745
  if ( CDF_Debug || status != NC_NOERR )
746
    Message("ncid = %d varid = %d attnum = %d att = %s", ncid, varid, attnum, name);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
747

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

751
752

void cdf_inq_attid(int ncid, int varid, const char *name, int *attnump)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
753
{
754
  int status = nc_inq_attid(ncid, varid, name, attnump);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
755
756

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

759
  if ( status != NC_NOERR ) Error("%s", nc_strerror(status));
Uwe Schulzweida's avatar
Uwe Schulzweida committed
760
761
762
}

#endif
763
764
765
766
767
768
769
770
771
/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */