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 | |
---|
26 | extern int nc_get_vara_ubyte(int ncid, int varid, |
---|
27 | const size_t* start, const size_t* count, |
---|
28 | unsigned char* value); |
---|
29 | extern int nc_get_vara_ushort(int ncid, int varid, |
---|
30 | const size_t* start, const size_t* count, |
---|
31 | unsigned short* value); |
---|
32 | extern int nc_get_vara_uint(int ncid, int varid, |
---|
33 | const size_t* start, const size_t* count, |
---|
34 | unsigned int* value); |
---|
35 | extern int nc_get_vara_ulonglong(int ncid, int varid, |
---|
36 | const size_t* start, const size_t* count, |
---|
37 | unsigned long long* value); |
---|
38 | |
---|
39 | extern int nc_put_vara_ushort(int ncid, int varid, |
---|
40 | const size_t* start, const size_t* count, |
---|
41 | const unsigned short* value); |
---|
42 | extern int nc_put_vara_uint(int ncid, int varid, |
---|
43 | const size_t* start, const size_t* count, |
---|
44 | const unsigned int* value); |
---|
45 | extern 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 */ |
---|
108 | typedef 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 |
---|
114 | typedef 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*/ |
---|
123 | typedef struct NC_Dispatch NC_Dispatch; |
---|
124 | |
---|
125 | extern NC_Dispatch* NCSUBSTRATE_dispatch_table; |
---|
126 | extern int NCDISPATCH_initialize(void); |
---|
127 | |
---|
128 | extern NC_Dispatch* NC3_dispatch_table; |
---|
129 | extern int NC3_initialize(void); |
---|
130 | |
---|
131 | #ifdef USE_DAP |
---|
132 | extern NC_Dispatch* NCD3_dispatch_table; |
---|
133 | extern int NCD3_initialize(void); |
---|
134 | #endif |
---|
135 | |
---|
136 | #ifdef USE_NETCDF4 |
---|
137 | |
---|
138 | extern NC_Dispatch* NC4_dispatch_table; |
---|
139 | extern int NC4_initialize(void); |
---|
140 | |
---|
141 | #ifdef USE_DAP |
---|
142 | extern NC_Dispatch* NCD4_dispatch_table; |
---|
143 | extern int NCD4_initialize(void); |
---|
144 | #endif |
---|
145 | |
---|
146 | #ifdef USE_CDMREMOTE |
---|
147 | extern NC_Dispatch* NCCR_dispatch_table; |
---|
148 | extern int NCCR_initialize(void); |
---|
149 | #endif |
---|
150 | |
---|
151 | #ifdef BUILD_RPC |
---|
152 | extern NC_Dispatch* NCRPC_dispatch_table; |
---|
153 | extern int NCRPC_initialize(void); |
---|
154 | #endif |
---|
155 | |
---|
156 | #endif /*USE_NETCDF4*/ |
---|
157 | |
---|
158 | /* Vectors of ones and zeros */ |
---|
159 | extern size_t nc_sizevector0[NC_MAX_DIMS]; |
---|
160 | extern size_t nc_sizevector1[NC_MAX_DIMS]; |
---|
161 | extern ptrdiff_t nc_ptrdiffvector1[NC_MAX_DIMS]; |
---|
162 | |
---|
163 | /**************************************************/ |
---|
164 | /* Forward */ |
---|
165 | #ifndef USE_NETCDF4 |
---|
166 | /* Taken from libsrc4/netcdf.h */ |
---|
167 | struct nc_vlen_t; |
---|
168 | #define NC_NETCDF4 0x1000 |
---|
169 | #define NC_CLASSIC_MODEL 0x0100 |
---|
170 | #define NC_ENOPAR (-114) |
---|
171 | #endif /*USE_NETCDF4*/ |
---|
172 | |
---|
173 | struct 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 | |
---|
187 | int 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); |
---|
191 | int 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 */ |
---|
197 | extern int NCDEFAULT_get_vars(int, int, const size_t*, |
---|
198 | const size_t*, const ptrdiff_t*, void*, nc_type); |
---|
199 | extern int NCDEFAULT_put_vars(int, int, const size_t*, |
---|
200 | const size_t*, const ptrdiff_t*, const void*, nc_type); |
---|
201 | extern int NCDEFAULT_get_varm(int, int, const size_t*, |
---|
202 | const size_t*, const ptrdiff_t*, const ptrdiff_t*, |
---|
203 | void*, nc_type); |
---|
204 | extern 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 */ |
---|
210 | struct NCHDR; |
---|
211 | |
---|
212 | struct NC_Dispatch { |
---|
213 | |
---|
214 | int model; /* one of the NC_DISPATCH #'s above */ |
---|
215 | |
---|
216 | int (*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 | */ |
---|
222 | int (*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); |
---|
226 | int (*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 | |
---|
231 | int (*redef)(int); |
---|
232 | int (*_enddef)(int,size_t,size_t,size_t,size_t); |
---|
233 | int (*sync)(int); |
---|
234 | int (*abort)(int); |
---|
235 | int (*close)(int); |
---|
236 | int (*set_fill)(int,int,int*); |
---|
237 | int (*inq_base_pe)(int,int*); |
---|
238 | int (*set_base_pe)(int,int); |
---|
239 | int (*inq_format)(int,int*); |
---|
240 | |
---|
241 | int (*inq)(int,int*,int*,int*,int*); |
---|
242 | int (*inq_type)(int, nc_type, char*, size_t*); |
---|
243 | |
---|
244 | int (*def_dim)(int, const char*, size_t, int*); |
---|
245 | int (*inq_dimid)(int, const char*, int*); |
---|
246 | int (*inq_dim)(int, int, char*, size_t*); |
---|
247 | int (*inq_unlimdim)(int ncid, int *unlimdimidp); |
---|
248 | int (*rename_dim)(int, int, const char*); |
---|
249 | |
---|
250 | int (*inq_att)(int, int, const char*, nc_type*, size_t*); |
---|
251 | int (*inq_attid)(int, int, const char*, int*); |
---|
252 | int (*inq_attname)(int, int, int, char*); |
---|
253 | int (*rename_att)(int, int, const char*, const char*); |
---|
254 | int (*del_att)(int, int, const char*); |
---|
255 | int (*get_att)(int, int, const char*, void*, nc_type); |
---|
256 | int (*put_att)(int, int, const char*, nc_type, size_t, const void*, nc_type); |
---|
257 | |
---|
258 | int (*def_var)(int, const char*, nc_type, int, const int*, int*); |
---|
259 | int (*inq_varid)(int, const char*, int*); |
---|
260 | int (*rename_var)(int, int, const char*); |
---|
261 | |
---|
262 | int (*get_vara)(int, int, const size_t*, const size_t*, void*, nc_type); |
---|
263 | int (*put_vara)(int, int, const size_t*, const size_t*, const void*, nc_type); |
---|
264 | |
---|
265 | /* Added to solve Ferret performance problem with Opendap */ |
---|
266 | int (*get_vars)(int, int, const size_t*, const size_t*, const ptrdiff_t*, void*, nc_type); |
---|
267 | int (*put_vars)(int, int, const size_t*, const size_t*, const ptrdiff_t*, const void*, nc_type); |
---|
268 | |
---|
269 | int (*get_varm)(int, int, const size_t*, const size_t*, const ptrdiff_t*, const ptrdiff_t*, void*, nc_type); |
---|
270 | int (*put_varm)(int, int, const size_t*, const size_t*, const ptrdiff_t*, const ptrdiff_t*, const void*, nc_type); |
---|
271 | |
---|
272 | |
---|
273 | int (*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 |
---|
284 | int (*show_metadata)(int); |
---|
285 | int (*inq_unlimdims)(int, int*, int*); |
---|
286 | int (*var_par_access)(int, int, int); |
---|
287 | int (*inq_ncid)(int, const char*, int*); |
---|
288 | int (*inq_grps)(int, int*, int*); |
---|
289 | int (*inq_grpname)(int, char*); |
---|
290 | int (*inq_grpname_full)(int, size_t*, char*); |
---|
291 | int (*inq_grp_parent)(int, int*); |
---|
292 | int (*inq_grp_full_ncid)(int, const char*, int*); |
---|
293 | int (*inq_varids)(int, int* nvars, int*); |
---|
294 | int (*inq_dimids)(int, int* ndims, int*, int); |
---|
295 | int (*inq_typeids)(int, int* ntypes, int*); |
---|
296 | int (*inq_type_equal)(int, nc_type, int, nc_type, int*); |
---|
297 | int (*def_grp)(int, const char*, int*); |
---|
298 | int (*inq_user_type)(int, nc_type, char*, size_t*, nc_type*, size_t*, int*); |
---|
299 | int (*inq_typeid)(int, const char*, nc_type*); |
---|
300 | |
---|
301 | int (*def_compound)(int, size_t, const char*, nc_type*); |
---|
302 | int (*insert_compound)(int, nc_type, const char*, size_t, nc_type); |
---|
303 | int (*insert_array_compound)(int, nc_type, const char*, size_t, nc_type, int, const int*); |
---|
304 | int (*inq_compound_field)(int, nc_type, int, char*, size_t*, nc_type*, int*, int*); |
---|
305 | int (*inq_compound_fieldindex)(int, nc_type, const char*, int*); |
---|
306 | int (*def_vlen)(int, const char*, nc_type base_typeid, nc_type*); |
---|
307 | int (*put_vlen_element)(int, int, void*, size_t, const void*); |
---|
308 | int (*get_vlen_element)(int, int, const void*, size_t*, void*); |
---|
309 | int (*def_enum)(int, nc_type, const char*, nc_type*); |
---|
310 | int (*insert_enum)(int, nc_type, const char*, const void*); |
---|
311 | int (*inq_enum_member)(int, nc_type, int, char*, void*); |
---|
312 | int (*inq_enum_ident)(int, nc_type, long long, char*); |
---|
313 | int (*def_opaque)(int, size_t, const char*, nc_type*); |
---|
314 | int (*def_var_deflate)(int, int, int, int, int); |
---|
315 | int (*def_var_fletcher32)(int, int, int); |
---|
316 | int (*def_var_chunking)(int, int, int, const size_t*); |
---|
317 | int (*def_var_fill)(int, int, int, const void*); |
---|
318 | int (*def_var_endian)(int, int, int); |
---|
319 | int (*set_var_chunk_cache)(int, int, size_t, size_t, float); |
---|
320 | int (*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 |
---|
327 | void(*nc_advise)(const char*cdf_routine_name,interr,const char*fmt,...); |
---|
328 | void(*nc_set_log_level)(int); |
---|
329 | const char* (*nc_inq_libvers)(void); |
---|
330 | const char* (*nc_strerror)(int); |
---|
331 | int(*nc_delete)(const char*path); |
---|
332 | int(*nc_delete_mp)(const char*path,intbasepe); |
---|
333 | #endif /*NONDISPATCH*/ |
---|
334 | |
---|
335 | /* Define the common fields for NC and NC_FILE_INFO_T etc */ |
---|
336 | typedef 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 | |
---|
345 | extern int NC_atomictypelen(nc_type xtype); |
---|
346 | extern char* NC_atomictypename(nc_type xtype); |
---|
347 | |
---|
348 | /* Provide an initializer */ |
---|
349 | extern int NC_initialize(void); |
---|
350 | |
---|
351 | /* Provide a dispatch table overlay facility */ |
---|
352 | extern 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 */ |
---|
357 | extern NC_Dispatch* NC_get_dispatch_override(void); |
---|
358 | extern void NC_set_dispatch_override(NC_Dispatch*); |
---|
359 | |
---|
360 | /* Does the path look like a url? */ |
---|
361 | extern int NC_testurl(const char* path); |
---|
362 | /* Return model (0 or 3 or 4) as specified by the url */ |
---|
363 | extern int NC_urlmodel(const char* path); |
---|
364 | |
---|
365 | /* allow access url parse and params without exposing nc_url.h */ |
---|
366 | extern int NCDAP_urlparse(const char* s, void** dapurl); |
---|
367 | extern void NCDAP_urlfree(void* dapurl); |
---|
368 | extern const char* NCDAP_urllookup(void* dapurl, const char* param); |
---|
369 | |
---|
370 | /* Test for specific set of servers */ |
---|
371 | extern const char* NC_findtestserver(const char*); |
---|
372 | /* Ping a specific server */ |
---|
373 | extern int NCDAP_ping(const char*); |
---|
374 | |
---|
375 | /* Misc */ |
---|
376 | |
---|
377 | extern int NC_getshape(int ncid, int varid, int ndims, size_t* shape); |
---|
378 | extern int NC_is_recvar(int ncid, int varid, size_t* nrecs); |
---|
379 | |
---|
380 | #define nullstring(s) (s==NULL?"(null)":s) |
---|
381 | |
---|
382 | extern size_t* NC_coord_zero; |
---|
383 | extern size_t* NC_coord_one; |
---|
384 | |
---|
385 | #endif /* _DISPATCH_H */ |
---|
386 | |
---|