dgroup.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*! \file
  2. Functions for netCDF-4 features.
  3. Copyright 2010 University Corporation for Atmospheric
  4. Research/Unidata. See \ref COPYRIGHT file for more info. */
  5. #include "ncdispatch.h"
  6. /** \defgroup user_types User-Defined Types
  7. User defined types allow for more complex data structures.
  8. NetCDF-4 has added support for four different user defined data
  9. types. User defined type may only be used in files created with the
  10. ::NC_NETCDF4 and without ::NC_CLASSIC_MODEL.
  11. - compound type: like a C struct, a compound type is a collection of
  12. types, including other user defined types, in one package.
  13. - variable length array type: used to store ragged arrays.
  14. - opaque type: This type has only a size per element, and no other
  15. type information.
  16. - enum type: Like an enumeration in C, this type lets you assign text
  17. values to integer values, and store the integer values.
  18. Users may construct user defined type with the various nc_def_*
  19. functions described in this section. They may learn about user defined
  20. types by using the nc_inq_ functions defined in this section.
  21. Once types are constructed, define variables of the new type with
  22. nc_def_var (see nc_def_var). Write to them with nc_put_var1,
  23. nc_put_var, nc_put_vara, or nc_put_vars. Read data of user-defined
  24. type with nc_get_var1, nc_get_var, nc_get_vara, or nc_get_vars (see
  25. \ref variables).
  26. Create attributes of the new type with nc_put_att (see nc_put_att_
  27. type). Read attributes of the new type with nc_get_att (see
  28. \ref attributes).
  29. */
  30. /** \{ */
  31. /** \} */
  32. /** \defgroup groups Groups
  33. NetCDF-4 added support for hierarchical groups within netCDF datasets.
  34. Groups are identified with a ncid, which identifies both the open
  35. file, and the group within that file. When a file is opened with
  36. nc_open or nc_create, the ncid for the root group of that file is
  37. provided. Using that as a starting point, users can add new groups, or
  38. list and navigate existing groups.
  39. All netCDF calls take a ncid which determines where the call will take
  40. its action. For example, the nc_def_var function takes a ncid as its
  41. first parameter. It will create a variable in whichever group its ncid
  42. refers to. Use the root ncid provided by nc_create or nc_open to
  43. create a variable in the root group. Or use nc_def_grp to create a
  44. group and use its ncid to define a variable in the new group.
  45. Variable are only visible in the group in which they are defined. The
  46. same applies to attributes. “Global” attributes are associated with
  47. the group whose ncid is used.
  48. Dimensions are visible in their groups, and all child groups.
  49. Group operations are only permitted on netCDF-4 files - that is, files
  50. created with the HDF5 flag in nc_create(). Groups are not compatible
  51. with the netCDF classic data model, so files created with the
  52. ::NC_CLASSIC_MODEL file cannot contain groups (except the root group).
  53. */
  54. /** \{ */
  55. int
  56. nc_inq_ncid(int ncid, const char *name, int *grp_ncid)
  57. {
  58. NC* ncp;
  59. int stat = NC_check_id(ncid,&ncp);
  60. if(stat != NC_NOERR) return stat;
  61. return ncp->dispatch->inq_ncid(ncid,name,grp_ncid);
  62. }
  63. int
  64. nc_inq_grps(int ncid, int *numgrps, int *ncids)
  65. {
  66. NC* ncp;
  67. int stat = NC_check_id(ncid,&ncp);
  68. if(stat != NC_NOERR) return stat;
  69. return ncp->dispatch->inq_grps(ncid,numgrps,ncids);
  70. }
  71. int
  72. nc_inq_grpname(int ncid, char *name)
  73. {
  74. NC* ncp;
  75. int stat = NC_check_id(ncid,&ncp);
  76. if(stat != NC_NOERR) return stat;
  77. return ncp->dispatch->inq_grpname(ncid,name);
  78. }
  79. int
  80. nc_inq_grpname_full(int ncid, size_t *lenp, char *full_name)
  81. {
  82. NC* ncp;
  83. int stat = NC_check_id(ncid,&ncp);
  84. if(stat != NC_NOERR) return stat;
  85. return ncp->dispatch->inq_grpname_full(ncid,lenp,full_name);
  86. }
  87. int
  88. nc_inq_grpname_len(int ncid, size_t *lenp)
  89. {
  90. int stat = nc_inq_grpname_full(ncid,lenp,NULL);
  91. return stat;
  92. }
  93. int
  94. nc_inq_grp_parent(int ncid, int *parent_ncid)
  95. {
  96. NC* ncp;
  97. int stat = NC_check_id(ncid,&ncp);
  98. if(stat != NC_NOERR) return stat;
  99. return ncp->dispatch->inq_grp_parent(ncid,parent_ncid);
  100. }
  101. /* This has same semantics as nc_inq_ncid */
  102. int
  103. nc_inq_grp_ncid(int ncid, const char *grp_name, int *grp_ncid)
  104. {
  105. return nc_inq_ncid(ncid,grp_name,grp_ncid);
  106. }
  107. int
  108. nc_inq_grp_full_ncid(int ncid, const char *full_name, int *grp_ncid)
  109. {
  110. NC* ncp;
  111. int stat = NC_check_id(ncid,&ncp);
  112. if(stat != NC_NOERR) return stat;
  113. return ncp->dispatch->inq_grp_full_ncid(ncid,full_name,grp_ncid);
  114. }
  115. int
  116. nc_inq_varids(int ncid, int *nvars, int *varids)
  117. {
  118. NC* ncp;
  119. int stat = NC_check_id(ncid,&ncp);
  120. if(stat != NC_NOERR) return stat;
  121. return ncp->dispatch->inq_varids(ncid,nvars,varids);
  122. }
  123. int
  124. nc_inq_dimids(int ncid, int *ndims, int *dimids, int include_parents)
  125. {
  126. NC* ncp;
  127. int stat = NC_check_id(ncid,&ncp);
  128. if(stat != NC_NOERR) return stat;
  129. return ncp->dispatch->inq_dimids(ncid,ndims,dimids,include_parents);
  130. }
  131. int
  132. nc_inq_typeids(int ncid, int *ntypes, int *typeids)
  133. {
  134. NC* ncp;
  135. int stat = NC_check_id(ncid,&ncp);
  136. if(stat != NC_NOERR) return stat;
  137. return ncp->dispatch->inq_typeids(ncid,ntypes,typeids);
  138. }
  139. int
  140. nc_def_grp(int parent_ncid, const char *name, int *new_ncid)
  141. {
  142. NC* ncp;
  143. int stat = NC_check_id(parent_ncid,&ncp);
  144. if(stat != NC_NOERR) return stat;
  145. return ncp->dispatch->def_grp(parent_ncid,name,new_ncid);
  146. }
  147. int
  148. nc_show_metadata(int ncid)
  149. {
  150. NC* ncp;
  151. int stat = NC_check_id(ncid,&ncp);
  152. if(stat != NC_NOERR) return stat;
  153. return ncp->dispatch->show_metadata(ncid);
  154. }
  155. /** \} */