1 /*! \file
2   Functions for Opaque Types
3 
4   Copyright 2018 University Corporation for Atmospheric
5   Research/Unidata. See \ref copyright file for more info. */
6 
7 #include "ncdispatch.h"
8 
9 /** \name Opaque Types
10     Functions to create and learn about opaque types. */
11 /*! \{ */ /* All these functions are part of this named group... */
12 
13 /** \ingroup user_types
14 Create an opaque type. Provide a size and a name.
15 
16 \param ncid \ref ncid
17 \param size The size of each opaque object in bytes.
18 \param name \ref object_name of the new type.
19 \param xtypep Pointer where the new typeid for this type is returned.
20 
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
nc_def_opaque(int ncid,size_t size,const char * name,nc_type * xtypep)33 nc_def_opaque(int ncid, size_t size, const char *name, nc_type *xtypep)
34 {
35     NC* ncp;
36     int stat = NC_check_id(ncid,&ncp);
37     if(stat != NC_NOERR) return stat;
38     return ncp->dispatch->def_opaque(ncid,size,name,xtypep);
39 }
40 
41 /** \ingroup user_types
42 Learn about an opaque type.
43 
44 \param ncid \ref ncid
45 
46 \param xtype Typeid to inquire about.
47 
48 \param name The \ref object_name of this type will be
49 copied here. \ref ignored_if_null.
50 
51 \param sizep The size of the type will be copied here. \ref
52 ignored_if_null.
53 
54 \returns ::NC_NOERR No error.
55 \returns ::NC_EBADID Bad \ref ncid.
56 \returns ::NC_EBADTYPE Bad type id.
57 \returns ::NC_ENOTNC4 Not an netCDF-4 file, or classic model enabled.
58 \returns ::NC_EHDFERR An error was reported by the HDF5 layer.
59  */
60 int
nc_inq_opaque(int ncid,nc_type xtype,char * name,size_t * sizep)61 nc_inq_opaque(int ncid, nc_type xtype, char *name, size_t *sizep)
62 {
63     int class = 0;
64     int stat = nc_inq_user_type(ncid,xtype,name,sizep,NULL,NULL,&class);
65     if(stat != NC_NOERR) return stat;
66     if(class != NC_OPAQUE) stat = NC_EBADTYPE;
67     return stat;
68 }
69 
70 /*! \} */  /* End of named group ...*/
71