nc3dispatch.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*********************************************************************
  2. Copyright 2010, UCAR/Unidata See netcdf/COPYRIGHT file for
  3. copying and redistribution conditions.
  4. $Id: nc3dispatch.c,v 2.8 2010/05/26 11:11:26 ed Exp $
  5. *********************************************************************/
  6. #include "config.h"
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "netcdf.h"
  10. #include "nc.h"
  11. #include "nc3dispatch.h"
  12. #ifndef NC_CONTIGUOUS
  13. #define NC_CONTIGUOUS 1
  14. #endif
  15. #ifndef NC_ENOTNC4
  16. #define NC_ENOTNC4 (-111)
  17. #endif
  18. #ifndef NC_ENOGRP
  19. #define NC_ENOGRP (-125)
  20. #endif
  21. #ifndef NC_STRING
  22. #define NC_STRING (12)
  23. #endif
  24. static int NC3_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
  25. int *ndimsp, int *dimidsp, int *nattsp,
  26. int *shufflep, int *deflatep, int *deflate_levelp,
  27. int *fletcher32p, int *contiguousp, size_t *chunksizesp,
  28. int *no_fill, void *fill_valuep, int *endiannessp,
  29. int *options_maskp, int *pixels_per_blockp);
  30. #ifdef USE_NETCDF4
  31. static int NC3_show_metadata(int);
  32. static int NC3_inq_unlimdims(int,int*,int*);
  33. static int NC3_var_par_access(int,int,int);
  34. static int NC3_inq_ncid(int,const char*,int*);
  35. static int NC3_inq_grps(int,int*,int*);
  36. static int NC3_inq_grpname(int,char*);
  37. static int NC3_inq_grpname_full(int,size_t*,char*);
  38. static int NC3_inq_grp_parent(int,int*);
  39. static int NC3_inq_grp_full_ncid(int,const char*,int*);
  40. static int NC3_inq_varids(int,int* nvars,int*);
  41. static int NC3_inq_dimids(int,int* ndims,int*,int);
  42. static int NC3_inq_typeids(int,int* ntypes,int*);
  43. static int NC3_inq_type_equal(int,nc_type,int,nc_type,int*);
  44. static int NC3_def_grp(int,const char*,int*);
  45. static int NC3_inq_user_type(int,nc_type,char*,size_t*,nc_type*,size_t*,int*);
  46. static int NC3_inq_typeid(int,const char*,nc_type*);
  47. static int NC3_def_compound(int,size_t,const char*,nc_type*);
  48. static int NC3_insert_compound(int,nc_type,const char*,size_t,nc_type);
  49. static int NC3_insert_array_compound(int,nc_type,const char*,size_t,nc_type,int,const int*);
  50. static int NC3_inq_compound_field(int,nc_type,int,char*,size_t*,nc_type*,int*,int*);
  51. static int NC3_inq_compound_fieldindex(int,nc_type,const char*,int*);
  52. static int NC3_def_vlen(int,const char*,nc_type base_typeid,nc_type*);
  53. static int NC3_put_vlen_element(int,int,void*,size_t,const void*);
  54. static int NC3_get_vlen_element(int,int,const void*,size_t*,void*);
  55. static int NC3_def_enum(int,nc_type,const char*,nc_type*);
  56. static int NC3_insert_enum(int,nc_type,const char*,const void*);
  57. static int NC3_inq_enum_member(int,nc_type,int,char*,void*);
  58. static int NC3_inq_enum_ident(int,nc_type,long long,char*);
  59. static int NC3_def_opaque(int,size_t,const char*,nc_type*);
  60. static int NC3_def_var_deflate(int,int,int,int,int);
  61. static int NC3_def_var_fletcher32(int,int,int);
  62. static int NC3_def_var_chunking(int,int,int,const size_t*);
  63. static int NC3_def_var_fill(int,int,int,const void*);
  64. static int NC3_def_var_endian(int,int,int);
  65. static int NC3_set_var_chunk_cache(int,int,size_t,size_t,float);
  66. static int NC3_get_var_chunk_cache(int,int,size_t*,size_t*,float*);
  67. #endif /*USE_NETCDF4*/
  68. NC_Dispatch NC3_dispatcher = {
  69. NC_DISPATCH_NC3,
  70. NC3_new_nc,
  71. NC3_create,
  72. NC3_open,
  73. NC3_redef,
  74. NC3__enddef,
  75. NC3_sync,
  76. NC3_abort,
  77. NC3_close,
  78. NC3_set_fill,
  79. NC3_inq_base_pe,
  80. NC3_set_base_pe,
  81. NC3_inq_format,
  82. NC3_inq,
  83. NC3_inq_type,
  84. NC3_def_dim,
  85. NC3_inq_dimid,
  86. NC3_inq_dim,
  87. NC3_inq_unlimdim,
  88. NC3_rename_dim,
  89. NC3_inq_att,
  90. NC3_inq_attid,
  91. NC3_inq_attname,
  92. NC3_rename_att,
  93. NC3_del_att,
  94. NC3_get_att,
  95. NC3_put_att,
  96. NC3_def_var,
  97. NC3_inq_varid,
  98. NC3_rename_var,
  99. NC3_get_vara,
  100. NC3_put_vara,
  101. NCDEFAULT_get_vars,
  102. NCDEFAULT_put_vars,
  103. NCDEFAULT_get_varm,
  104. NCDEFAULT_put_varm,
  105. NC3_inq_var_all,
  106. #ifdef USE_NETCDF4
  107. NC3_show_metadata,
  108. NC3_inq_unlimdims,
  109. NC3_var_par_access,
  110. NC3_inq_ncid,
  111. NC3_inq_grps,
  112. NC3_inq_grpname,
  113. NC3_inq_grpname_full,
  114. NC3_inq_grp_parent,
  115. NC3_inq_grp_full_ncid,
  116. NC3_inq_varids,
  117. NC3_inq_dimids,
  118. NC3_inq_typeids,
  119. NC3_inq_type_equal,
  120. NC3_def_grp,
  121. NC3_inq_user_type,
  122. NC3_inq_typeid,
  123. NC3_def_compound,
  124. NC3_insert_compound,
  125. NC3_insert_array_compound,
  126. NC3_inq_compound_field,
  127. NC3_inq_compound_fieldindex,
  128. NC3_def_vlen,
  129. NC3_put_vlen_element,
  130. NC3_get_vlen_element,
  131. NC3_def_enum,
  132. NC3_insert_enum,
  133. NC3_inq_enum_member,
  134. NC3_inq_enum_ident,
  135. NC3_def_opaque,
  136. NC3_def_var_deflate,
  137. NC3_def_var_fletcher32,
  138. NC3_def_var_chunking,
  139. NC3_def_var_fill,
  140. NC3_def_var_endian,
  141. NC3_set_var_chunk_cache,
  142. NC3_get_var_chunk_cache,
  143. #endif /*_NC4DISPATCH_H*/
  144. };
  145. NC_Dispatch* NC3_dispatch_table = NULL; /* moved here from ddispatch.c */
  146. int
  147. NC3_initialize(void)
  148. {
  149. NC3_dispatch_table = &NC3_dispatcher;
  150. return NC_NOERR;
  151. }
  152. static int
  153. NC3_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
  154. int *ndimsp, int *dimidsp, int *nattsp,
  155. int *shufflep, int *deflatep, int *deflate_levelp,
  156. int *fletcher32p, int *contiguousp, size_t *chunksizesp,
  157. int *no_fill, void *fill_valuep, int *endiannessp,
  158. int *options_maskp, int *pixels_per_blockp)
  159. {
  160. int stat = NC3_inq_var(ncid,varid,name,xtypep,ndimsp,dimidsp,nattsp);
  161. if(stat) return stat;
  162. if(shufflep) *shufflep = 0;
  163. if(deflatep) *deflatep = 0;
  164. if(fletcher32p) *fletcher32p = 0;
  165. if(contiguousp) *contiguousp = NC_CONTIGUOUS;
  166. if(no_fill) *no_fill = 1;
  167. if(endiannessp) return NC_ENOTNC4;
  168. if(options_maskp) return NC_ENOTNC4;
  169. return NC_NOERR;
  170. }
  171. #ifdef USE_NETCDF4
  172. static int
  173. NC3_inq_unlimdims(int ncid, int *ndimsp, int *unlimdimidsp)
  174. {
  175. int retval;
  176. int unlimid;
  177. if ((retval = nc_inq_unlimdim(ncid, &unlimid)))
  178. return retval;
  179. if (unlimid != -1) {
  180. if(ndimsp) *ndimsp = 1;
  181. if (unlimdimidsp)
  182. unlimdimidsp[0] = unlimid;
  183. } else
  184. if(ndimsp) *ndimsp = 0;
  185. return NC_NOERR;
  186. }
  187. static int
  188. NC3_def_grp(int parent_ncid, const char *name, int *new_ncid)
  189. {
  190. return NC_ENOTNC4;
  191. }
  192. static int
  193. NC3_inq_ncid(int ncid, const char *name, int *grp_ncid)
  194. {
  195. if(grp_ncid) *grp_ncid = ncid;
  196. return NC_NOERR;
  197. }
  198. static int
  199. NC3_inq_grps(int ncid, int *numgrps, int *ncids)
  200. {
  201. if (numgrps)
  202. *numgrps = 0;
  203. return NC_NOERR;
  204. }
  205. static int
  206. NC3_inq_grpname(int ncid, char *name)
  207. {
  208. if (name)
  209. strcpy(name, "/");
  210. return NC_NOERR;
  211. }
  212. static int
  213. NC3_inq_grpname_full(int ncid, size_t *lenp, char *full_name)
  214. {
  215. if (full_name)
  216. strcpy(full_name, "/");
  217. if(lenp) *lenp = 1;
  218. return NC_NOERR;
  219. }
  220. static int
  221. NC3_inq_grp_parent(int ncid, int *parent_ncid)
  222. {
  223. return NC_ENOGRP;
  224. }
  225. static int
  226. NC3_inq_grp_full_ncid(int ncid, const char *full_name, int *grp_ncid)
  227. {
  228. return NC_ENOGRP;
  229. }
  230. static int
  231. NC3_inq_varids(int ncid, int *nvarsp, int *varids)
  232. {
  233. int retval,v,nvars;
  234. /* If this is a netcdf-3 file, there is only one group, the root
  235. group, and its vars have ids 0 thru nvars - 1. */
  236. if ((retval = nc_inq(ncid, NULL, &nvars, NULL, NULL)))
  237. return retval;
  238. if(nvarsp) *nvarsp = nvars;
  239. if (varids)
  240. for (v = 0; v < nvars; v++)
  241. varids[v] = v;
  242. return NC_NOERR;
  243. }
  244. static int
  245. NC3_inq_dimids(int ncid, int *ndimsp, int *dimids, int include_parents)
  246. {
  247. int retval,d,ndims;
  248. /* If this is a netcdf-3 file, then the dimids are going to be 0
  249. thru ndims-1, so just provide them. */
  250. if ((retval = nc_inq(ncid, &ndims, NULL, NULL, NULL)))
  251. return retval;
  252. if(ndimsp) *ndimsp = ndims;
  253. if (dimids)
  254. for (d = 0; d < ndims; d++)
  255. dimids[d] = d;
  256. return NC_NOERR;
  257. }
  258. static int
  259. NC3_show_metadata(int ncid)
  260. {
  261. return NC_NOERR;
  262. }
  263. static int
  264. NC3_inq_type_equal(int ncid1, nc_type typeid1, int ncid2, nc_type typeid2, int* equalp)
  265. {
  266. /* Check input. */
  267. if(equalp == NULL) return NC_NOERR;
  268. if (typeid1 <= NC_NAT || typeid2 <= NC_NAT)
  269. return NC_EINVAL;
  270. *equalp = 0; /* assume */
  271. /* If one is atomic, and the other user-defined, the types are not equal */
  272. if ((typeid1 <= NC_STRING && typeid2 > NC_STRING) ||
  273. (typeid2 <= NC_STRING && typeid1 > NC_STRING)) {
  274. if (equalp) *equalp = 0;
  275. return NC_NOERR;
  276. }
  277. /* If both are atomic types, the answer is easy. */
  278. if (typeid1 <= ATOMICTYPEMAX) {
  279. if (equalp) {
  280. if (typeid1 == typeid2)
  281. *equalp = 1;
  282. else
  283. *equalp = 0;
  284. }
  285. return NC_NOERR;
  286. }
  287. return NC_NOERR;
  288. }
  289. static int
  290. NC3_inq_typeid(int ncid, const char *name, nc_type *typeidp)
  291. {
  292. int i;
  293. for (i = 0; i <= ATOMICTYPEMAX; i++)
  294. if (!strcmp(name, NC_atomictypename(i))) {
  295. if (typeidp) *typeidp = i;
  296. return NC_NOERR;
  297. }
  298. return NC_ENOTNC4;
  299. }
  300. static int
  301. NC3_inq_typeids(int ncid, int *ntypes, int *typeids)
  302. {
  303. if(ntypes) *ntypes = 0;
  304. return NC_NOERR;
  305. }
  306. static int
  307. NC3_inq_user_type(int ncid, nc_type typeid, char *name, size_t *size,
  308. nc_type *base_nc_typep, size_t *nfieldsp, int *classp)
  309. {
  310. return NC_ENOTNC4;
  311. }
  312. static int
  313. NC3_def_compound(int ncid, size_t size, const char *name, nc_type *typeidp)
  314. {
  315. return NC_ENOTNC4;
  316. }
  317. static int
  318. NC3_insert_compound(int ncid, nc_type typeid, const char *name, size_t offset,
  319. nc_type field_typeid)
  320. {
  321. return NC_ENOTNC4;
  322. }
  323. static int
  324. NC3_insert_array_compound(int ncid, nc_type typeid, const char *name,
  325. size_t offset, nc_type field_typeid,
  326. int ndims, const int *dim_sizes)
  327. {
  328. return NC_ENOTNC4;
  329. }
  330. static int
  331. NC3_inq_compound_field(int ncid, nc_type typeid, int fieldid, char *name,
  332. size_t *offsetp, nc_type *field_typeidp, int *ndimsp,
  333. int *dim_sizesp)
  334. {
  335. return NC_ENOTNC4;
  336. }
  337. static int
  338. NC3_inq_compound_fieldindex(int ncid, nc_type typeid, const char *name, int *fieldidp)
  339. {
  340. return NC_ENOTNC4;
  341. }
  342. static int
  343. NC3_def_opaque(int ncid, size_t datum_size, const char *name, nc_type* xtypep)
  344. {
  345. return NC_ENOTNC4;
  346. }
  347. static int
  348. NC3_def_vlen(int ncid, const char *name, nc_type base_typeid, nc_type* xtypep)
  349. {
  350. return NC_ENOTNC4;
  351. }
  352. static int
  353. NC3_def_enum(int ncid, nc_type base_typeid, const char *name,
  354. nc_type *typeidp)
  355. {
  356. return NC_ENOTNC4;
  357. }
  358. static int
  359. NC3_inq_enum_ident(int ncid, nc_type xtype, long long value, char *identifier)
  360. {
  361. return NC_ENOTNC4;
  362. }
  363. static int
  364. NC3_inq_enum_member(int ncid, nc_type typeid, int idx, char *identifier,
  365. void *value)
  366. {
  367. return NC_ENOTNC4;
  368. }
  369. static int
  370. NC3_insert_enum(int ncid, nc_type typeid, const char *identifier,
  371. const void *value)
  372. {
  373. return NC_ENOTNC4;
  374. }
  375. static int
  376. NC3_put_vlen_element(int ncid, int typeid, void *vlen_element,
  377. size_t len, const void *data)
  378. {
  379. return NC_ENOTNC4;
  380. }
  381. static int
  382. NC3_get_vlen_element(int ncid, int typeid, const void *vlen_element,
  383. size_t *len, void *data)
  384. {
  385. return NC_ENOTNC4;
  386. }
  387. static int
  388. NC3_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems, float preemption)
  389. {
  390. return NC_ENOTNC4;
  391. }
  392. static int
  393. NC3_get_var_chunk_cache(int ncid, int varid, size_t *sizep, size_t *nelemsp, float *preemptionp)
  394. {
  395. return NC_ENOTNC4;
  396. }
  397. static int
  398. NC3_def_var_deflate(int ncid, int varid, int shuffle, int deflate,
  399. int deflate_level)
  400. {
  401. return NC_ENOTNC4;
  402. }
  403. static int
  404. NC3_def_var_fletcher32(int ncid, int varid, int fletcher32)
  405. {
  406. return NC_ENOTNC4;
  407. }
  408. static int
  409. NC3_def_var_chunking(int ncid, int varid, int contiguous, const size_t *chunksizesp)
  410. {
  411. return NC_ENOTNC4;
  412. }
  413. static int
  414. NC3_def_var_fill(int ncid, int varid, int no_fill, const void *fill_value)
  415. {
  416. return NC_ENOTNC4;
  417. }
  418. static int
  419. NC3_def_var_endian(int ncid, int varid, int endianness)
  420. {
  421. return NC_ENOTNC4;
  422. }
  423. static int
  424. NC3_var_par_access(int ncid, int varid, int par_access)
  425. {
  426. return NC_ENOTNC4;
  427. }
  428. #endif /*USE_NETCDF4*/