source: XIOS/dev/branch_openmp/extern/src_netcdf4/ncdispatch.h @ 1501

Last change on this file since 1501 was 409, checked in by ymipsl, 11 years ago

Add improved nectdf internal library src

YM

  • Property svn:eol-style set to native
File size: 12.7 KB
Line 
1/*********************************************************************
2 *   Copyright 2010, UCAR/Unidata
3 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
4 *********************************************************************/
5
6/* $Id: ncdispatch.h,v 1.18 2010/06/01 20:11:59 dmh Exp $ */
7/* $Header: /upc/share/CVS/netcdf-3/libdispatch/ncdispatch.h,v 1.18 2010/06/01 20:11:59 dmh Exp $ */
8
9#ifndef _DISPATCH_H
10#define _DISPATCH_H
11
12#include "config.h"
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <assert.h>
17#ifdef USE_PARALLEL
18#include "netcdf_par.h"
19#endif
20#include "netcdf.h"
21#include "nc.h"
22#include "nc_uri.h"
23
24#define longtype ((sizeof(long) == sizeof(int) ? NC_INT : NC_INT64))
25
26extern int nc_get_vara_ubyte(int ncid, int varid,
27                  const size_t* start, const size_t* count,
28                  unsigned char* value);
29extern int nc_get_vara_ushort(int ncid, int varid,
30                  const size_t* start, const size_t* count,
31                  unsigned short* value);
32extern int nc_get_vara_uint(int ncid, int varid,
33                  const size_t* start, const size_t* count,
34                  unsigned int* value);
35extern int nc_get_vara_ulonglong(int ncid, int varid,
36                  const size_t* start, const size_t* count,
37                  unsigned long long* value);
38
39extern int nc_put_vara_ushort(int ncid, int varid,
40                  const size_t* start, const size_t* count,
41                  const unsigned short* value);
42extern int nc_put_vara_uint(int ncid, int varid,
43                  const size_t* start, const size_t* count,
44                  const unsigned int* value);
45extern int nc_put_vara_ulonglong(int ncid, int varid,
46                  const size_t* start, const size_t* count,
47                  const unsigned long long* value);
48
49#define X_INT_MAX       2147483647
50
51/* Given a filename, check its magic number */
52#define MAGIC_NUMBER_LEN 4
53#define MAGIC_HDF5_FILE 1
54#define MAGIC_HDF4_FILE 2
55#define MAGIC_CDF1_FILE 1 /* std classic format */
56#define MAGIC_CDF2_FILE 2 /* classic 64 bit */
57
58/* Define the mappings from fcn name types
59   to corresponding NC types. */
60#define T_text   NC_CHAR
61#define T_schar  NC_BYTE
62#define T_char   NC_CHAR
63#define T_short  NC_SHORT
64#define T_int    NC_INT
65#define T_float  NC_FLOAT
66#define T_double NC_DOUBLE
67#define T_ubyte  NC_UBYTE
68#define T_ushort NC_USHORT
69#define T_uint   NC_UINT
70#define T_longlong  NC_INT64
71#define T_ulonglong  NC_UINT64
72#ifdef USE_NETCDF4
73#define T_string NC_STRING
74#endif
75
76/* Synthetic type to handle special memtypes */
77#define T_uchar  NC_UBYTE
78#define T_long   longtype
79#define T_ulong   ulongtype
80
81/**************************************************/
82/* Define the known classes of dispatchers */
83/* Flags may be or'd => powers of 2*/
84#define NC_DISPATCH_NC3    1
85#define NC_DISPATCH_NC4    2
86#define NC_DISPATCH_NCD    4
87#define NC_DISPATCH_NCR    8
88
89/* Define a type for use when doing e.g. nc_get_vara_long, etc. */
90/* Should matche values in libsrc4/netcdf.h */
91#ifndef NC_UINT64
92#define NC_UBYTE        7       /* unsigned 1 byte int */
93#define NC_USHORT       8       /* unsigned 2-byte int */
94#define NC_UINT         9       /* unsigned 4-byte int */
95#define NC_INT64        10      /* signed 8-byte int */
96#define NC_UINT64       11      /* unsigned 8-byte int */
97#define NC_STRING       12      /* char* */
98#endif
99
100/* Define the range of Atomic types */
101#ifdef USE_NETCDF4
102#define ATOMICTYPEMAX NC_STRING
103#else
104#define ATOMICTYPEMAX NC_DOUBLE
105#endif
106
107/* Define an alias for int to indicate an error return */
108typedef int NCerror;
109
110/* Define a struct to hold the MPI info so it can be passed down the
111 * call stack. This is used internally by the netCDF library. It
112 * should not be used by netcdf users. */
113#ifdef USE_PARALLEL
114typedef struct NC_MPI_INFO {
115    MPI_Comm comm;
116    MPI_Info info;
117} NC_MPI_INFO;
118#endif
119
120/* Define known dispatch tables and initializers */
121
122/*Forward*/
123typedef struct NC_Dispatch NC_Dispatch;
124
125extern NC_Dispatch* NCSUBSTRATE_dispatch_table;
126extern int NCDISPATCH_initialize(void);
127
128extern NC_Dispatch* NC3_dispatch_table;
129extern int NC3_initialize(void);
130
131#ifdef USE_DAP
132extern NC_Dispatch* NCD3_dispatch_table;
133extern int NCD3_initialize(void);
134#endif
135
136#ifdef USE_NETCDF4
137
138extern NC_Dispatch* NC4_dispatch_table;
139extern int NC4_initialize(void);
140
141#ifdef USE_DAP
142extern NC_Dispatch* NCD4_dispatch_table;
143extern int NCD4_initialize(void);
144#endif
145
146#ifdef USE_CDMREMOTE
147extern NC_Dispatch* NCCR_dispatch_table;
148extern int NCCR_initialize(void);
149#endif
150
151#ifdef BUILD_RPC
152extern NC_Dispatch* NCRPC_dispatch_table;
153extern int NCRPC_initialize(void);
154#endif
155
156#endif /*USE_NETCDF4*/
157
158/* Vectors of ones and zeros */
159extern size_t nc_sizevector0[NC_MAX_DIMS];
160extern size_t nc_sizevector1[NC_MAX_DIMS];
161extern ptrdiff_t nc_ptrdiffvector1[NC_MAX_DIMS];
162
163/**************************************************/
164/* Forward */
165#ifndef USE_NETCDF4
166/* Taken from libsrc4/netcdf.h */
167struct nc_vlen_t;
168#define NC_NETCDF4 0x1000
169#define NC_CLASSIC_MODEL 0x0100
170#define NC_ENOPAR (-114)
171#endif /*USE_NETCDF4*/
172
173struct NC;
174
175/* WARNING: this must match libsrc4/netcdf.h */
176#ifndef USE_PARALLEL
177#ifndef MPI_Comm
178#define MPI_Comm int
179#define MPI_Info int
180#define MPI_COMM_WORLD 0
181#ifndef MPI_INFO_NULL
182#define MPI_INFO_NULL 0
183#endif
184#endif
185#endif
186
187int NC_create(const char *path, int cmode,
188              size_t initialsz, int basepe, size_t *chunksizehintp, 
189              int useparallel,void* mpi_info,
190              int *ncidp);
191int NC_open(const char *path, int cmode,
192            int basepe, size_t *chunksizehintp,
193            int useparallel, void* mpi_info,
194            int *ncidp);
195
196/* Expose the default vars and varm dispatch entries */
197extern int NCDEFAULT_get_vars(int, int, const size_t*,
198               const size_t*, const ptrdiff_t*, void*, nc_type);
199extern int NCDEFAULT_put_vars(int, int, const size_t*,
200               const size_t*, const ptrdiff_t*, const void*, nc_type);
201extern int NCDEFAULT_get_varm(int, int, const size_t*,
202               const size_t*, const ptrdiff_t*, const ptrdiff_t*,
203               void*, nc_type);
204extern int NCDEFAULT_put_varm(int, int, const size_t*,
205               const size_t*, const ptrdiff_t*, const ptrdiff_t*,
206               const void*, nc_type);
207
208/**************************************************/
209/* Forward */
210struct NCHDR;
211
212struct NC_Dispatch {
213
214int model; /* one of the NC_DISPATCH #'s above */
215
216int (*new_nc)(struct NC**); /* Create an nc instance;free is not needed,
217                                because it can be done by close and abort*/
218
219/* Warning: these two will create appropriate NC instances
220   using new_nc dispatch function
221*/
222int (*create)(const char *path, int cmode,
223          size_t initialsz, int basepe, size_t *chunksizehintp, 
224          int use_parallel, void* parameters,
225          struct NC_Dispatch* table, NC** ncp);
226int (*open)(const char *path, int mode,
227            int basepe, size_t *chunksizehintp,
228            int use_parallel, void* parameters,
229            struct NC_Dispatch* table, NC** ncp);
230
231int (*redef)(int);
232int (*_enddef)(int,size_t,size_t,size_t,size_t);
233int (*sync)(int);
234int (*abort)(int);
235int (*close)(int);
236int (*set_fill)(int,int,int*);
237int (*inq_base_pe)(int,int*);
238int (*set_base_pe)(int,int);
239int (*inq_format)(int,int*);
240
241int (*inq)(int,int*,int*,int*,int*);
242int (*inq_type)(int, nc_type, char*, size_t*);
243
244int (*def_dim)(int, const char*, size_t, int*);
245int (*inq_dimid)(int, const char*, int*);
246int (*inq_dim)(int, int, char*, size_t*);
247int (*inq_unlimdim)(int ncid,  int *unlimdimidp);
248int (*rename_dim)(int, int, const char*);
249
250int (*inq_att)(int, int, const char*, nc_type*, size_t*);
251int (*inq_attid)(int, int, const char*, int*);
252int (*inq_attname)(int, int, int, char*);
253int (*rename_att)(int, int, const char*, const char*);
254int (*del_att)(int, int, const char*);
255int (*get_att)(int, int, const char*, void*, nc_type);
256int (*put_att)(int, int, const char*, nc_type, size_t, const void*, nc_type);
257
258int (*def_var)(int, const char*, nc_type, int, const int*, int*);
259int (*inq_varid)(int, const char*, int*);
260int (*rename_var)(int, int, const char*);
261
262int (*get_vara)(int, int, const size_t*, const size_t*, void*, nc_type);
263int (*put_vara)(int, int, const size_t*, const size_t*, const void*, nc_type);
264
265/* Added to solve Ferret performance problem with Opendap */
266int (*get_vars)(int, int, const size_t*, const size_t*, const ptrdiff_t*, void*, nc_type);
267int (*put_vars)(int, int, const size_t*, const size_t*, const ptrdiff_t*, const void*, nc_type);
268
269int (*get_varm)(int, int, const size_t*, const size_t*, const ptrdiff_t*, const ptrdiff_t*, void*, nc_type);
270int (*put_varm)(int, int, const size_t*, const size_t*, const ptrdiff_t*, const ptrdiff_t*, const void*, nc_type);
271
272
273int (*inq_var_all)(int ncid, int varid, char *name, nc_type *xtypep, 
274               int *ndimsp, int *dimidsp, int *nattsp, 
275               int *shufflep, int *deflatep, int *deflate_levelp,
276               int *fletcher32p, int *contiguousp, size_t *chunksizesp, 
277               int *no_fill, void *fill_valuep, int *endiannessp, 
278               int *options_maskp, int *pixels_per_blockp);
279
280/* Note the following may still be invoked by netcdf client code
281   even when the file is a classic file
282*/
283#ifdef USE_NETCDF4
284int (*show_metadata)(int);
285int (*inq_unlimdims)(int, int*, int*);
286int (*var_par_access)(int, int, int);
287int (*inq_ncid)(int, const char*, int*);
288int (*inq_grps)(int, int*, int*);
289int (*inq_grpname)(int, char*);
290int (*inq_grpname_full)(int, size_t*, char*);
291int (*inq_grp_parent)(int, int*);
292int (*inq_grp_full_ncid)(int, const char*, int*);
293int (*inq_varids)(int, int* nvars, int*);
294int (*inq_dimids)(int, int* ndims, int*, int);
295int (*inq_typeids)(int, int* ntypes, int*);
296int (*inq_type_equal)(int, nc_type, int, nc_type, int*);
297int (*def_grp)(int, const char*, int*);
298int (*inq_user_type)(int, nc_type, char*, size_t*, nc_type*, size_t*, int*);
299int (*inq_typeid)(int, const char*, nc_type*);
300
301int (*def_compound)(int, size_t, const char*, nc_type*);
302int (*insert_compound)(int, nc_type, const char*, size_t, nc_type);
303int (*insert_array_compound)(int, nc_type, const char*, size_t, nc_type, int, const int*);
304int (*inq_compound_field)(int, nc_type, int, char*, size_t*, nc_type*, int*, int*);
305int (*inq_compound_fieldindex)(int, nc_type, const char*, int*);
306int (*def_vlen)(int, const char*, nc_type base_typeid, nc_type*);
307int (*put_vlen_element)(int, int, void*, size_t, const void*);
308int (*get_vlen_element)(int, int, const void*, size_t*, void*);
309int (*def_enum)(int, nc_type, const char*, nc_type*);
310int (*insert_enum)(int, nc_type, const char*, const void*);
311int (*inq_enum_member)(int, nc_type, int, char*, void*);
312int (*inq_enum_ident)(int, nc_type, long long, char*);
313int (*def_opaque)(int, size_t, const char*, nc_type*);
314int (*def_var_deflate)(int, int, int, int, int);
315int (*def_var_fletcher32)(int, int, int);
316int (*def_var_chunking)(int, int, int, const size_t*);
317int (*def_var_fill)(int, int, int, const void*);
318int (*def_var_endian)(int, int, int);
319int (*set_var_chunk_cache)(int, int, size_t, size_t, float);
320int (*get_var_chunk_cache)(int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp);
321#endif /*USE_NETCDF4*/
322
323};
324
325/* Following functions must be handled as non-dispatch */
326#ifdef NONDISPATCH
327void(*nc_advise)(const char*cdf_routine_name,interr,const char*fmt,...);
328void(*nc_set_log_level)(int);
329const char* (*nc_inq_libvers)(void);
330const char* (*nc_strerror)(int);
331int(*nc_delete)(const char*path);
332int(*nc_delete_mp)(const char*path,intbasepe);
333#endif /*NONDISPATCH*/
334
335/* Define the common fields for NC and NC_FILE_INFO_T etc */
336typedef struct NCcommon {
337        int ext_ncid; /* uid << 16 */
338        int int_ncid; /* unspecified other id */
339        struct NC_Dispatch* dispatch;   
340        void* dispatchdata; /* per-protocol instance data */
341        char* path; /* as specified at open or create */
342        int   substrate; /* ncid for another protocol on which to build */
343} NCcommon;
344
345extern int NC_atomictypelen(nc_type xtype);
346extern char* NC_atomictypename(nc_type xtype);
347
348/* Provide an initializer */
349extern int NC_initialize(void);
350
351/* Provide a dispatch table overlay facility */
352extern int NC_dispatch_overlay(const NC_Dispatch* overlay,
353                                        const NC_Dispatch* base,
354                                        NC_Dispatch* merge);
355
356/* Get/set the override dispatch table */
357extern NC_Dispatch* NC_get_dispatch_override(void);
358extern void NC_set_dispatch_override(NC_Dispatch*);
359
360/* Does the path look like a url? */
361extern int NC_testurl(const char* path);
362/* Return model (0 or 3 or 4) as specified by the url */
363extern int NC_urlmodel(const char* path);
364
365/* allow access url parse and params without exposing nc_url.h */
366extern int NCDAP_urlparse(const char* s, void** dapurl);
367extern void NCDAP_urlfree(void* dapurl);
368extern const char* NCDAP_urllookup(void* dapurl, const char* param);
369
370/* Test for specific set of servers */
371extern const char* NC_findtestserver(const char*);
372/* Ping a specific server */
373extern int NCDAP_ping(const char*);
374
375/* Misc */
376
377extern int NC_getshape(int ncid, int varid, int ndims, size_t* shape);
378extern int NC_is_recvar(int ncid, int varid, size_t* nrecs);
379
380#define nullstring(s) (s==NULL?"(null)":s)
381
382extern size_t* NC_coord_zero;
383extern size_t* NC_coord_one;
384
385#endif /* _DISPATCH_H */
386
Note: See TracBrowser for help on using the repository browser.