ncdispatch.h 13 KB

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