1 /* Copyright 2018-2018 University Corporation for Atmospheric 2 Research/Unidata. */ 3 /** 4 * @file 5 * @internal Includes prototypes for core dispatch functionality. 6 * 7 * @author Dennis Heimbigner 8 */ 9 10 #ifndef NC_DISPATCH_H 11 #define NC_DISPATCH_H 12 13 #if HAVE_CONFIG_H 14 #include "config.h" 15 #endif 16 #include <stdlib.h> 17 #include <stdio.h> 18 #include <string.h> 19 #include <assert.h> 20 #if defined(HDF5_PARALLEL) || defined(USE_PNETCDF) 21 #include <mpi.h> 22 #endif 23 #include "netcdf.h" 24 #include "ncmodel.h" 25 #include "nc.h" 26 #include "ncuri.h" 27 #ifdef USE_PARALLEL 28 #include "netcdf_par.h" 29 #endif 30 #include "netcdf_dispatch.h" 31 32 #define longtype ((sizeof(long) == sizeof(int) ? NC_INT : NC_INT64)) 33 34 #define X_INT_MAX 2147483647 35 36 /* Given a filename, check its magic number */ 37 /* Change magic number size from 4 to 8 to be more precise for HDF5 */ 38 #define MAGIC_NUMBER_LEN ((size_t)8) 39 #define MAGIC_HDF5_FILE 1 40 #define MAGIC_HDF4_FILE 2 41 #define MAGIC_CDF1_FILE 1 /* std classic format */ 42 #define MAGIC_CDF2_FILE 2 /* classic 64 bit */ 43 44 /* Define the mappings from fcn name types 45 to corresponding NC types. */ 46 #define T_text NC_CHAR 47 #define T_schar NC_BYTE 48 #define T_char NC_CHAR 49 #define T_short NC_SHORT 50 #define T_int NC_INT 51 #define T_float NC_FLOAT 52 #define T_double NC_DOUBLE 53 #define T_ubyte NC_UBYTE 54 #define T_ushort NC_USHORT 55 #define T_uint NC_UINT 56 #define T_longlong NC_INT64 57 #define T_ulonglong NC_UINT64 58 #ifdef USE_NETCDF4 59 #define T_string NC_STRING 60 #endif 61 62 /* Synthetic type to handle special memtypes */ 63 #define T_uchar NC_UBYTE 64 #define T_long longtype 65 #define T_ulong ulongtype 66 67 /**************************************************/ 68 69 /* Define a type for use when doing e.g. nc_get_vara_long, etc. */ 70 /* Should matche values in libsrc4/netcdf.h */ 71 #ifndef NC_UINT64 72 #define NC_UBYTE 7 /* unsigned 1 byte int */ 73 #define NC_USHORT 8 /* unsigned 2-byte int */ 74 #define NC_UINT 9 /* unsigned 4-byte int */ 75 #define NC_INT64 10 /* signed 8-byte int */ 76 #define NC_UINT64 11 /* unsigned 8-byte int */ 77 #define NC_STRING 12 /* char* */ 78 #endif 79 80 /* Define the range of Atomic types */ 81 #define ATOMICTYPEMAX4 NC_STRING 82 #define ATOMICTYPEMAX3 NC_DOUBLE 83 #define ATOMICTYPEMAX5 NC_UINT64 84 85 /* Define an alias for int to indicate an error return */ 86 typedef int NCerror; 87 88 #if !defined HDF5_PARALLEL && !defined USE_PNETCDF 89 typedef int MPI_Comm; 90 typedef int MPI_Info; 91 #define MPI_COMM_WORLD 0 92 #define MPI_INFO_NULL 0 93 #endif 94 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 typedef struct NC_MPI_INFO { 99 MPI_Comm comm; 100 MPI_Info info; 101 } NC_MPI_INFO; 102 103 /* Define known dispatch tables and initializers */ 104 105 extern int NCDISPATCH_initialize(void); 106 extern int NCDISPATCH_finalize(void); 107 108 extern const NC_Dispatch* NC3_dispatch_table; 109 extern int NC3_initialize(void); 110 extern int NC3_finalize(void); 111 112 #ifdef ENABLE_DAP 113 extern const NC_Dispatch* NCD2_dispatch_table; 114 extern int NCD2_initialize(void); 115 extern int NCD2_finalize(void); 116 #endif 117 #ifdef ENABLE_DAP4 118 extern const NC_Dispatch* NCD4_dispatch_table; 119 extern int NCD4_initialize(void); 120 extern int NCD4_finalize(void); 121 #endif 122 123 #ifdef USE_PNETCDF 124 extern const NC_Dispatch* NCP_dispatch_table; 125 extern int NCP_initialize(void); 126 extern int NCP_finalize(void); 127 #endif 128 129 #ifdef USE_NETCDF4 130 extern int NC4_initialize(void); 131 extern int NC4_finalize(void); 132 #endif 133 134 #ifdef USE_HDF5 135 extern const NC_Dispatch* HDF5_dispatch_table; 136 extern int NC_HDF5_initialize(void); 137 extern int NC_HDF5_finalize(void); 138 #endif 139 140 #ifdef USE_HDF4 141 extern const NC_Dispatch* HDF4_dispatch_table; 142 extern int HDF4_initialize(void); 143 extern int HDF4_finalize(void); 144 #endif 145 146 /* User-defined formats.*/ 147 extern NC_Dispatch* UDF0_dispatch_table; 148 extern char UDF0_magic_number[NC_MAX_MAGIC_NUMBER_LEN + 1]; 149 extern NC_Dispatch* UDF1_dispatch_table; 150 extern char UDF1_magic_number[NC_MAX_MAGIC_NUMBER_LEN + 1]; 151 152 /* Prototypes. */ 153 int NC_check_nulls(int ncid, int varid, const size_t *start, size_t **count, 154 ptrdiff_t **stride); 155 156 /**************************************************/ 157 /* Forward */ 158 #ifndef USE_NETCDF4 159 /* Taken from libsrc4/netcdf.h */ 160 struct nc_vlen_t; 161 #define NC_NETCDF4 0x1000 162 #define NC_CLASSIC_MODEL 0x0100 163 #define NC_ENOPAR (-114) 164 #endif /*!USE_NETCDF4*/ 165 166 struct NC; 167 168 int NC_create(const char *path, int cmode, 169 size_t initialsz, int basepe, size_t *chunksizehintp, 170 int useparallel, void *parameters, int *ncidp); 171 int NC_open(const char *path, int cmode, 172 int basepe, size_t *chunksizehintp, 173 int useparallel, void *parameters, int *ncidp); 174 175 /* Expose the default vars and varm dispatch entries */ 176 EXTERNL int NCDEFAULT_get_vars(int, int, const size_t*, 177 const size_t*, const ptrdiff_t*, void*, nc_type); 178 EXTERNL int NCDEFAULT_put_vars(int, int, const size_t*, 179 const size_t*, const ptrdiff_t*, const void*, nc_type); 180 EXTERNL int NCDEFAULT_get_varm(int, int, const size_t*, 181 const size_t*, const ptrdiff_t*, const ptrdiff_t*, 182 void*, nc_type); 183 EXTERNL int NCDEFAULT_put_varm(int, int, const size_t*, 184 const size_t*, const ptrdiff_t*, const ptrdiff_t*, 185 const void*, nc_type); 186 187 /**************************************************/ 188 /* Forward */ 189 struct NCHDR; 190 191 192 /* Following functions must be handled as non-dispatch */ 193 #ifdef NONDISPATCH 194 void (*nc_advise)(const char*cdf_routine_name,interr,const char*fmt,...); 195 void (*nc_set_log_level)(int); 196 const char* (*nc_inq_libvers)(void); 197 const char* (*nc_strerror)(int); 198 int (*nc_delete)(const char*path); 199 int (*nc_delete_mp)(const char*path,intbasepe); 200 int (*nc_initialize)(); 201 int (*nc_finalize)(); 202 #endif /*NONDISPATCH*/ 203 204 /* Define the common fields for NC and NC_FILE_INFO_T etc */ 205 typedef struct NCcommon { 206 int ext_ncid; /* uid << 16 */ 207 int int_ncid; /* unspecified other id */ 208 const struct NC_Dispatch* dispatch; 209 void* dispatchdata; /* per-protocol instance data */ 210 char* path; /* as specified at open or create */ 211 } NCcommon; 212 213 EXTERNL size_t NC_atomictypelen(nc_type xtype); 214 EXTERNL char* NC_atomictypename(nc_type xtype); 215 216 /* Misc */ 217 218 extern int NC_getshape(int ncid, int varid, int ndims, size_t* shape); 219 extern int NC_is_recvar(int ncid, int varid, size_t* nrecs); 220 extern int NC_inq_recvar(int ncid, int varid, int* nrecdims, int* is_recdim); 221 222 #define nullstring(s) (s==NULL?"(null)":s) 223 224 #undef TRACECALLS 225 #ifdef TRACECALLS 226 #include <stdio.h> 227 #define TRACE(fname) fprintf(stderr,"call: %s\n",#fname) 228 #else 229 #define TRACE(fname) 230 #endif 231 232 /* Vectors of ones and zeros */ 233 extern size_t NC_coord_zero[NC_MAX_VAR_DIMS]; 234 extern size_t NC_coord_one[NC_MAX_VAR_DIMS]; 235 extern ptrdiff_t NC_stride_one[NC_MAX_VAR_DIMS]; 236 237 extern int NC_initialized; 238 239 /** 240 Certain functions are in the dispatch table, 241 but not in the netcdf.h API. These need to 242 be exposed for use in delegation such as 243 in libdap2. 244 */ 245 EXTERNL int 246 NCDISPATCH_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep, 247 int *ndimsp, int *dimidsp, int *nattsp, 248 int *shufflep, int *deflatep, int *deflate_levelp, 249 int *fletcher32p, int *contiguousp, size_t *chunksizesp, 250 int *no_fill, void *fill_valuep, int *endiannessp, 251 unsigned int* idp, size_t* nparamsp, unsigned int* paramsp 252 ); 253 EXTERNL int 254 NCDISPATCH_get_att(int ncid, int varid, const char* name, void* value, nc_type t); 255 256 #endif /* NC_DISPATCH_H */ 257