denum.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*! \file
  2. Functions for Enum Types
  3. Copyright 2011 University Corporation for Atmospheric
  4. Research/Unidata. See \ref copyright file for more info. */
  5. #include "ncdispatch.h"
  6. /** \name Enum Types
  7. Functions to create and learn about enum types. */
  8. /*! \{ */ /* All these functions are part of this named group... */
  9. /** \ingroup user_types
  10. Create an enum type. Provide an ncid, a name, and a base integer type.
  11. After calling this function, fill out the type with repeated calls to
  12. nc_insert_enum(). Call nc_insert_enum() once for each value you wish
  13. to make part of the enumeration.
  14. \param ncid \ref ncid
  15. \param base_typeid The base integer type for this enum. Must be one
  16. of: ::NC_BYTE, ::NC_UBYTE, ::NC_SHORT, ::NC_USHORT, ::NC_INT,
  17. ::NC_UINT, ::NC_INT64, ::NC_UINT64.
  18. \param name \ref object_name of new type.
  19. \param typeidp A pointer to an nc_type. The typeid of the new type
  20. will be placed there.
  21. \returns ::NC_NOERR No error.
  22. \returns ::NC_EBADID Bad \ref ncid.
  23. \returns ::NC_EBADTYPE Bad type id.
  24. \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
  25. \returns ::NC_EHDFERR An error was reported by the HDF5 layer.
  26. \returns ::NC_ENAMEINUSE That name is in use.
  27. \returns ::NC_EMAXNAME Name exceeds max length NC_MAX_NAME.
  28. \returns ::NC_EBADNAME Name contains illegal characters.
  29. \returns ::NC_EPERM Attempt to write to a read-only file.
  30. \returns ::NC_ENOTINDEFINE Not in define mode.
  31. */
  32. int
  33. nc_def_enum(int ncid, nc_type base_typeid, const char *name, nc_type *typeidp)
  34. {
  35. NC* ncp;
  36. int stat = NC_check_id(ncid,&ncp);
  37. if(stat != NC_NOERR) return stat;
  38. return ncp->dispatch->def_enum(ncid,base_typeid,name,typeidp);
  39. }
  40. /** \ingroup user_types
  41. Insert a named member into a enum type.
  42. \param ncid \ref ncid
  43. \param xtype
  44. \param name The identifier (\ref object_name) of the new member.
  45. \param value The value that is to be associated with this member.
  46. \returns ::NC_NOERR No error.
  47. \returns ::NC_EBADID Bad \ref ncid.
  48. \returns ::NC_EBADTYPE Bad type id.
  49. \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
  50. \returns ::NC_EHDFERR An error was reported by the HDF5 layer.
  51. \returns ::NC_ENAMEINUSE That name is in use.
  52. \returns ::NC_EMAXNAME Name exceeds max length NC_MAX_NAME.
  53. \returns ::NC_EBADNAME Name contains illegal characters.
  54. \returns ::NC_EPERM Attempt to write to a read-only file.
  55. \returns ::NC_ENOTINDEFINE Not in define mode.
  56. */
  57. int
  58. nc_insert_enum(int ncid, nc_type xtype, const char *name,
  59. const void *value)
  60. {
  61. NC *ncp;
  62. int stat = NC_check_id(ncid, &ncp);
  63. if(stat != NC_NOERR) return stat;
  64. return ncp->dispatch->insert_enum(ncid, xtype, name,
  65. value);
  66. }
  67. /** \ingroup user_types
  68. Learn about a user-define enumeration type.
  69. \param ncid \ref ncid
  70. \param xtype Typeid to inquire about.
  71. \param name \ref object_name of type will be copied here. \ref
  72. ignored_if_null.
  73. \param base_nc_typep Typeid if the base type of the enum.\ref
  74. ignored_if_null.
  75. \param base_sizep Pointer that will get the size in bytes of the base
  76. type. \ref ignored_if_null.
  77. \param num_membersp Pointer that will get the number of members
  78. defined for this enum type. \ref ignored_if_null.
  79. \returns ::NC_NOERR No error.
  80. \returns ::NC_EBADID Bad \ref ncid.
  81. \returns ::NC_EBADTYPE Bad type id.
  82. \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
  83. \returns ::NC_EHDFERR An error was reported by the HDF5 layer.
  84. */
  85. int
  86. nc_inq_enum(int ncid, nc_type xtype, char *name, nc_type *base_nc_typep,
  87. size_t *base_sizep, size_t *num_membersp)
  88. {
  89. int class = 0;
  90. int stat = nc_inq_user_type(ncid, xtype, name, base_sizep,
  91. base_nc_typep, num_membersp, &class);
  92. if(stat != NC_NOERR) return stat;
  93. if(class != NC_ENUM) stat = NC_EBADTYPE;
  94. return stat;
  95. }
  96. /** \ingroup user_types
  97. Learn about a about a member of an enum type.
  98. \param ncid \ref ncid
  99. \param xtype Typeid of the enum type.
  100. \param idx Index to the member to inquire about.
  101. \param name The identifier (\ref object_name) of this member will be
  102. copied here. \ref ignored_if_null.
  103. \param value The value of this member will be copied here. \ref
  104. ignored_if_null.
  105. \returns ::NC_NOERR No error.
  106. \returns ::NC_EBADID Bad \ref ncid.
  107. \returns ::NC_EBADTYPE Bad type id.
  108. \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
  109. \returns ::NC_EHDFERR An error was reported by the HDF5 layer.
  110. */
  111. int
  112. nc_inq_enum_member(int ncid, nc_type xtype, int idx, char *name,
  113. void *value)
  114. {
  115. NC *ncp;
  116. int stat = NC_check_id(ncid, &ncp);
  117. if(stat != NC_NOERR) return stat;
  118. return ncp->dispatch->inq_enum_member(ncid, xtype, idx, name, value);
  119. }
  120. /** \ingroup user_types
  121. Get the name which is associated with an enum member value.
  122. \param ncid \ref ncid
  123. \param xtype Typeid of the enum type.
  124. \param value Value of interest.
  125. \param identifier The identifier (\ref object_name) of this value will
  126. be copied here. \ref ignored_if_null.
  127. \returns ::NC_NOERR No error.
  128. \returns ::NC_EBADID Bad \ref ncid.
  129. \returns ::NC_EBADTYPE Bad type id.
  130. \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
  131. \returns ::NC_EHDFERR An error was reported by the HDF5 layer.
  132. */
  133. int
  134. nc_inq_enum_ident(int ncid, nc_type xtype, long long value,
  135. char *identifier)
  136. {
  137. NC* ncp;
  138. int stat = NC_check_id(ncid,&ncp);
  139. if(stat != NC_NOERR) return stat;
  140. return ncp->dispatch->inq_enum_ident(ncid,xtype,value,identifier);
  141. }
  142. /*! \} */ /* End of named group ...*/