[1022] | 1 | /*! \file |
---|
| 2 | Functions for writing data to variables. |
---|
| 3 | |
---|
| 4 | Copyright 2010 University Corporation for Atmospheric |
---|
| 5 | Research/Unidata. See COPYRIGHT file for more info. |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "ncdispatch.h" |
---|
| 9 | |
---|
| 10 | /** \internal |
---|
| 11 | \ingroup variables |
---|
| 12 | */ |
---|
| 13 | static int |
---|
| 14 | NC_put_vara(int ncid, int varid, const size_t *start, |
---|
| 15 | const size_t *edges, const void *value, nc_type memtype) |
---|
| 16 | { |
---|
| 17 | NC* ncp; |
---|
| 18 | int stat = NC_check_id(ncid, &ncp); |
---|
| 19 | if(stat != NC_NOERR) return stat; |
---|
| 20 | if(edges == NULL) { |
---|
| 21 | size_t shape[NC_MAX_VAR_DIMS]; |
---|
| 22 | int ndims; |
---|
| 23 | stat = nc_inq_varndims(ncid, varid, &ndims); |
---|
| 24 | if(stat != NC_NOERR) return stat; |
---|
| 25 | stat = NC_getshape(ncid, varid, ndims, shape); |
---|
| 26 | if(stat != NC_NOERR) return stat; |
---|
| 27 | return ncp->dispatch->put_vara(ncid, varid, start, shape, value, memtype); |
---|
| 28 | } else |
---|
| 29 | return ncp->dispatch->put_vara(ncid, varid, start, edges, value, memtype); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | /** \internal |
---|
| 33 | \ingroup variables |
---|
| 34 | */ |
---|
| 35 | static int |
---|
| 36 | NC_put_var(int ncid, int varid, const void *value, nc_type memtype) |
---|
| 37 | { |
---|
| 38 | int ndims; |
---|
| 39 | size_t shape[NC_MAX_VAR_DIMS]; |
---|
| 40 | int stat = nc_inq_varndims(ncid,varid, &ndims); |
---|
| 41 | if(stat) return stat; |
---|
| 42 | stat = NC_getshape(ncid,varid, ndims, shape); |
---|
| 43 | if(stat) return stat; |
---|
| 44 | return NC_put_vara(ncid, varid, NC_coord_zero, shape, value, memtype); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | /** \internal |
---|
| 48 | \ingroup variables |
---|
| 49 | */ |
---|
| 50 | static int |
---|
| 51 | NC_put_var1(int ncid, int varid, const size_t *coord, const void* value, |
---|
| 52 | nc_type memtype) |
---|
| 53 | { |
---|
| 54 | return NC_put_vara(ncid, varid, coord, NC_coord_one, value, memtype); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** \internal |
---|
| 58 | \ingroup variables |
---|
| 59 | */ |
---|
| 60 | int |
---|
| 61 | NCDEFAULT_put_vars(int ncid, int varid, const size_t * start, |
---|
| 62 | const size_t * edges, const ptrdiff_t * stride, |
---|
| 63 | const void *value, nc_type memtype) |
---|
| 64 | { |
---|
| 65 | NC* ncp; |
---|
| 66 | int stat = NC_check_id(ncid, &ncp); |
---|
| 67 | |
---|
| 68 | if(stat != NC_NOERR) return stat; |
---|
| 69 | return ncp->dispatch->put_varm(ncid,varid,start,edges,stride,NULL,value,memtype); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /** \internal |
---|
| 73 | \ingroup variables |
---|
| 74 | */ |
---|
| 75 | int |
---|
| 76 | NCDEFAULT_put_varm( |
---|
| 77 | int ncid, |
---|
| 78 | int varid, |
---|
| 79 | const size_t * start, |
---|
| 80 | const size_t * edges, |
---|
| 81 | const ptrdiff_t * stride, |
---|
| 82 | const ptrdiff_t * imapp, |
---|
| 83 | const void *value0, |
---|
| 84 | nc_type memtype) |
---|
| 85 | { |
---|
| 86 | int status = NC_NOERR; |
---|
| 87 | nc_type vartype = NC_NAT; |
---|
| 88 | int varndims = 0; |
---|
| 89 | int maxidim = 0; |
---|
| 90 | NC* ncp; |
---|
| 91 | size_t memtypelen; |
---|
| 92 | ptrdiff_t cvtmap[NC_MAX_VAR_DIMS]; |
---|
| 93 | const char* value = (char*)value0; |
---|
| 94 | |
---|
| 95 | status = NC_check_id (ncid, &ncp); |
---|
| 96 | if(status != NC_NOERR) return status; |
---|
| 97 | |
---|
| 98 | /* |
---|
| 99 | if(NC_indef(ncp)) return NC_EINDEFINE; |
---|
| 100 | if(NC_readonly (ncp)) return NC_EPERM; |
---|
| 101 | */ |
---|
| 102 | |
---|
| 103 | /* mid body */ |
---|
| 104 | status = nc_inq_vartype(ncid, varid, &vartype); |
---|
| 105 | if(status != NC_NOERR) return status; |
---|
| 106 | /* Check that this is an atomic type */ |
---|
| 107 | if(vartype >= NC_MAX_ATOMIC_TYPE) |
---|
| 108 | return NC_EMAPTYPE; |
---|
| 109 | |
---|
| 110 | status = nc_inq_varndims(ncid, varid, &varndims); |
---|
| 111 | if(status != NC_NOERR) return status; |
---|
| 112 | |
---|
| 113 | if(memtype == NC_NAT) { |
---|
| 114 | if(imapp != NULL && varndims != 0) { |
---|
| 115 | /* |
---|
| 116 | * convert map units from bytes to units of sizeof(type) |
---|
| 117 | */ |
---|
| 118 | size_t ii; |
---|
| 119 | const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype); |
---|
| 120 | for(ii = 0; ii < varndims; ii++) { |
---|
| 121 | if(imapp[ii] % szof != 0) { |
---|
| 122 | /*free(cvtmap);*/ |
---|
| 123 | return NC_EINVAL; |
---|
| 124 | } |
---|
| 125 | cvtmap[ii] = imapp[ii] / szof; |
---|
| 126 | } |
---|
| 127 | imapp = cvtmap; |
---|
| 128 | } |
---|
| 129 | memtype = vartype; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | if(memtype == NC_CHAR && vartype != NC_CHAR) |
---|
| 133 | return NC_ECHAR; |
---|
| 134 | else if(memtype != NC_CHAR && vartype == NC_CHAR) |
---|
| 135 | return NC_ECHAR; |
---|
| 136 | |
---|
| 137 | memtypelen = nctypelen(memtype); |
---|
| 138 | |
---|
| 139 | maxidim = (int) varndims - 1; |
---|
| 140 | |
---|
| 141 | if (maxidim < 0) |
---|
| 142 | { |
---|
| 143 | /* |
---|
| 144 | * The variable is a scalar; consequently, |
---|
| 145 | * there s only one thing to get and only one place to put it. |
---|
| 146 | * (Why was I called?) |
---|
| 147 | */ |
---|
| 148 | size_t edge1[1] = {1}; |
---|
| 149 | return NC_put_vara(ncid, varid, start, edge1, value, memtype); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /* |
---|
| 153 | * else |
---|
| 154 | * The variable is an array. |
---|
| 155 | */ |
---|
| 156 | { |
---|
| 157 | int idim; |
---|
| 158 | size_t *mystart = NULL; |
---|
| 159 | size_t *myedges; |
---|
| 160 | size_t *iocount; /* count vector */ |
---|
| 161 | size_t *stop; /* stop indexes */ |
---|
| 162 | size_t *length; /* edge lengths in bytes */ |
---|
| 163 | ptrdiff_t *mystride; |
---|
| 164 | ptrdiff_t *mymap; |
---|
| 165 | size_t varshape[NC_MAX_VAR_DIMS]; |
---|
| 166 | int isrecvar; |
---|
| 167 | size_t numrecs; |
---|
| 168 | int stride1; /* is stride all ones? */ |
---|
| 169 | |
---|
| 170 | /* |
---|
| 171 | * Verify stride argument. |
---|
| 172 | */ |
---|
| 173 | stride1 = 1; /* assume ok; */ |
---|
| 174 | if(stride != NULL) { |
---|
| 175 | for (idim = 0; idim <= maxidim; ++idim) { |
---|
| 176 | if ((stride[idim] == 0) |
---|
| 177 | /* cast needed for braindead systems with signed size_t */ |
---|
| 178 | || ((unsigned long) stride[idim] >= X_INT_MAX)) |
---|
| 179 | { |
---|
| 180 | return NC_ESTRIDE; |
---|
| 181 | } |
---|
| 182 | if(stride[idim] != 1) stride1 = 0; |
---|
| 183 | } |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /* If stride1 is true, and there is no imap, then call get_vara |
---|
| 187 | directly |
---|
| 188 | */ |
---|
| 189 | if(stride1 && imapp == NULL) { |
---|
| 190 | return NC_put_vara(ncid, varid, start, edges, value, memtype); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | /* Compute some dimension related values */ |
---|
| 194 | isrecvar = NC_is_recvar(ncid,varid,&numrecs); |
---|
| 195 | NC_getshape(ncid,varid,varndims,varshape); |
---|
| 196 | |
---|
| 197 | /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ |
---|
| 198 | mystart = (size_t *)calloc(varndims * 7, sizeof(ptrdiff_t)); |
---|
| 199 | if(mystart == NULL) return NC_ENOMEM; |
---|
| 200 | myedges = mystart + varndims; |
---|
| 201 | iocount = myedges + varndims; |
---|
| 202 | stop = iocount + varndims; |
---|
| 203 | length = stop + varndims; |
---|
| 204 | mystride = (ptrdiff_t *)(length + varndims); |
---|
| 205 | mymap = mystride + varndims; |
---|
| 206 | |
---|
| 207 | /* |
---|
| 208 | * Initialize I/O parameters. |
---|
| 209 | */ |
---|
| 210 | for (idim = maxidim; idim >= 0; --idim) |
---|
| 211 | { |
---|
| 212 | mystart[idim] = start != NULL |
---|
| 213 | ? start[idim] |
---|
| 214 | : 0; |
---|
| 215 | |
---|
| 216 | if (edges != NULL && edges[idim] == 0) |
---|
| 217 | { |
---|
| 218 | status = NC_NOERR; /* read/write no data */ |
---|
| 219 | goto done; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | myedges[idim] = edges != NULL |
---|
| 223 | ? edges[idim] |
---|
| 224 | : idim == 0 && isrecvar |
---|
| 225 | ? numrecs - mystart[idim] |
---|
| 226 | : varshape[idim] - mystart[idim]; |
---|
| 227 | mystride[idim] = stride != NULL |
---|
| 228 | ? stride[idim] |
---|
| 229 | : 1; |
---|
| 230 | mymap[idim] = imapp != NULL |
---|
| 231 | ? imapp[idim] |
---|
| 232 | : idim == maxidim |
---|
| 233 | ? 1 |
---|
| 234 | : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; |
---|
| 235 | |
---|
| 236 | iocount[idim] = 1; |
---|
| 237 | length[idim] = mymap[idim] * myedges[idim]; |
---|
| 238 | stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | /* |
---|
| 242 | * Check start, edges |
---|
| 243 | */ |
---|
| 244 | for (idim = isrecvar; idim < maxidim; ++idim) |
---|
| 245 | { |
---|
| 246 | if (mystart[idim] > varshape[idim]) |
---|
| 247 | { |
---|
| 248 | status = NC_EINVALCOORDS; |
---|
| 249 | goto done; |
---|
| 250 | } |
---|
| 251 | if (mystart[idim] + myedges[idim] > varshape[idim]) |
---|
| 252 | { |
---|
| 253 | status = NC_EEDGE; |
---|
| 254 | goto done; |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | /* Lower body */ |
---|
| 259 | /* |
---|
| 260 | * As an optimization, adjust I/O parameters when the fastest |
---|
| 261 | * dimension has unity stride both externally and internally. |
---|
| 262 | * In this case, the user could have called a simpler routine |
---|
| 263 | * (i.e. ncvar$1() |
---|
| 264 | */ |
---|
| 265 | if (mystride[maxidim] == 1 |
---|
| 266 | && mymap[maxidim] == 1) |
---|
| 267 | { |
---|
| 268 | iocount[maxidim] = myedges[maxidim]; |
---|
| 269 | mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; |
---|
| 270 | mymap[maxidim] = (ptrdiff_t) length[maxidim]; |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | /* |
---|
| 274 | * Perform I/O. Exit when done. |
---|
| 275 | */ |
---|
| 276 | for (;;) |
---|
| 277 | { |
---|
| 278 | /* TODO: */ |
---|
| 279 | int lstatus = NC_put_vara(ncid, varid, mystart, iocount, |
---|
| 280 | value, memtype); |
---|
| 281 | if (lstatus != NC_NOERR) { |
---|
| 282 | if(status == NC_NOERR || lstatus != NC_ERANGE) |
---|
| 283 | status = lstatus; |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | /* |
---|
| 287 | * The following code permutes through the variable s |
---|
| 288 | * external start-index space and it s internal address |
---|
| 289 | * space. At the UPC, this algorithm is commonly |
---|
| 290 | * called "odometer code". |
---|
| 291 | */ |
---|
| 292 | idim = maxidim; |
---|
| 293 | carry: |
---|
| 294 | value += (mymap[idim] * memtypelen); |
---|
| 295 | mystart[idim] += mystride[idim]; |
---|
| 296 | if (mystart[idim] == stop[idim]) |
---|
| 297 | { |
---|
| 298 | mystart[idim] = start[idim]; |
---|
| 299 | value -= (length[idim] * memtypelen); |
---|
| 300 | if (--idim < 0) |
---|
| 301 | break; /* normal return */ |
---|
| 302 | goto carry; |
---|
| 303 | } |
---|
| 304 | } /* I/O loop */ |
---|
| 305 | done: |
---|
| 306 | free(mystart); |
---|
| 307 | } /* variable is array */ |
---|
| 308 | return status; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | /** \internal |
---|
| 312 | \ingroup variables |
---|
| 313 | */ |
---|
| 314 | static int |
---|
| 315 | NC_put_vars(int ncid, int varid, const size_t *start, |
---|
| 316 | const size_t *edges, const ptrdiff_t *stride, |
---|
| 317 | const void *value, nc_type memtype) |
---|
| 318 | { |
---|
| 319 | NC* ncp; |
---|
| 320 | int stat = NC_check_id(ncid, &ncp); |
---|
| 321 | |
---|
| 322 | if(stat != NC_NOERR) return stat; |
---|
| 323 | #ifdef USE_NETCDF4 |
---|
| 324 | if(memtype >= NC_FIRSTUSERTYPEID) memtype = NC_NAT; |
---|
| 325 | #endif |
---|
| 326 | return ncp->dispatch->put_vars(ncid,varid,start,edges,stride,value,memtype); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | /** \internal |
---|
| 330 | \ingroup variables |
---|
| 331 | */ |
---|
| 332 | static int |
---|
| 333 | NC_put_varm(int ncid, int varid, const size_t *start, |
---|
| 334 | const size_t *edges, const ptrdiff_t *stride, const ptrdiff_t* map, |
---|
| 335 | const void *value, nc_type memtype) |
---|
| 336 | { |
---|
| 337 | NC* ncp; |
---|
| 338 | int stat = NC_check_id(ncid, &ncp); |
---|
| 339 | |
---|
| 340 | if(stat != NC_NOERR) return stat; |
---|
| 341 | #ifdef USE_NETCDF4 |
---|
| 342 | if(memtype >= NC_FIRSTUSERTYPEID) memtype = NC_NAT; |
---|
| 343 | #endif |
---|
| 344 | return ncp->dispatch->put_varm(ncid,varid,start,edges,stride,map,value,memtype); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | /** \name Writing Data to Variables |
---|
| 348 | |
---|
| 349 | Functions to write data from variables. */ |
---|
| 350 | /*! \{ */ /* All these functions are part of this named group... */ |
---|
| 351 | |
---|
| 352 | /** \ingroup variables |
---|
| 353 | Write an array of values to a variable. |
---|
| 354 | |
---|
| 355 | The values to be written are associated with the netCDF variable by |
---|
| 356 | assuming that the last dimension of the netCDF variable varies fastest |
---|
| 357 | in the C interface. The netCDF dataset must be in data mode. The array |
---|
| 358 | to be written is specified by giving a corner and a vector of edge |
---|
| 359 | lengths to \ref specify_hyperslab. |
---|
| 360 | |
---|
| 361 | The functions for types ubyte, ushort, uint, longlong, ulonglong, and |
---|
| 362 | string are only available for netCDF-4/HDF5 files. |
---|
| 363 | |
---|
| 364 | The nc_put_var() function will write a variable of any type, including |
---|
| 365 | user defined type. For this function, the type of the data in memory |
---|
| 366 | must match the type of the variable - no data conversion is done. |
---|
| 367 | |
---|
| 368 | \param ncid NetCDF or group ID, from a previous call to nc_open(), |
---|
| 369 | nc_create(), nc_def_grp(), or associated inquiry functions such as |
---|
| 370 | nc_inq_ncid(). |
---|
| 371 | |
---|
| 372 | \param varid Variable ID |
---|
| 373 | |
---|
| 374 | \param startp Start vector with one element for each dimension to \ref |
---|
| 375 | specify_hyperslab. |
---|
| 376 | |
---|
| 377 | \param countp Count vector with one element for each dimension to \ref |
---|
| 378 | specify_hyperslab. |
---|
| 379 | |
---|
| 380 | \param op Pointer where the data will be copied. Memory must be |
---|
| 381 | allocated by the user before this function is called. |
---|
| 382 | |
---|
| 383 | \returns ::NC_NOERR No error. |
---|
| 384 | \returns ::NC_ENOTVAR Variable not found. |
---|
| 385 | \returns ::NC_EINVALCOORDS Index exceeds dimension bound. |
---|
| 386 | \returns ::NC_EEDGE Start+count exceeds dimension bound. |
---|
| 387 | \returns ::NC_ERANGE One or more of the values are out of range. |
---|
| 388 | \returns ::NC_EINDEFINE Operation not allowed in define mode. |
---|
| 389 | \returns ::NC_EBADID Bad ncid. |
---|
| 390 | */ |
---|
| 391 | /**@{*/ |
---|
| 392 | int |
---|
| 393 | nc_put_vara(int ncid, int varid, const size_t *startp, |
---|
| 394 | const size_t *countp, const void *op) |
---|
| 395 | { |
---|
| 396 | NC* ncp; |
---|
| 397 | int stat = NC_check_id(ncid, &ncp); |
---|
| 398 | nc_type xtype; |
---|
| 399 | if(stat != NC_NOERR) return stat; |
---|
| 400 | stat = nc_inq_vartype(ncid, varid, &xtype); |
---|
| 401 | if(stat != NC_NOERR) return stat; |
---|
| 402 | return NC_put_vara(ncid, varid, startp, countp, op, xtype); |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | int |
---|
| 406 | nc_put_vara_text(int ncid, int varid, const size_t *startp, |
---|
| 407 | const size_t *countp, const char *op) |
---|
| 408 | { |
---|
| 409 | return NC_put_vara(ncid, varid, startp, countp, |
---|
| 410 | (void*)op, NC_CHAR); |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | int |
---|
| 414 | nc_put_vara_schar(int ncid, int varid, const size_t *startp, |
---|
| 415 | const size_t *countp, const signed char *op) |
---|
| 416 | { |
---|
| 417 | NC* ncp; |
---|
| 418 | int stat = NC_check_id(ncid, &ncp); |
---|
| 419 | if(stat != NC_NOERR) return stat; |
---|
| 420 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 421 | NC_BYTE); |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | int |
---|
| 425 | nc_put_vara_uchar(int ncid, int varid, const size_t *startp, |
---|
| 426 | const size_t *countp, const unsigned char *op) |
---|
| 427 | { |
---|
| 428 | NC* ncp; |
---|
| 429 | int stat = NC_check_id(ncid, &ncp); |
---|
| 430 | if(stat != NC_NOERR) return stat; |
---|
| 431 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 432 | T_uchar); |
---|
| 433 | } |
---|
| 434 | |
---|
| 435 | int |
---|
| 436 | nc_put_vara_short(int ncid, int varid, const size_t *startp, |
---|
| 437 | const size_t *countp, const short *op) |
---|
| 438 | { |
---|
| 439 | NC* ncp; |
---|
| 440 | int stat = NC_check_id(ncid, &ncp); |
---|
| 441 | if(stat != NC_NOERR) return stat; |
---|
| 442 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 443 | NC_SHORT); |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | int |
---|
| 447 | nc_put_vara_int(int ncid, int varid, const size_t *startp, |
---|
| 448 | const size_t *countp, const int *op) |
---|
| 449 | { |
---|
| 450 | NC* ncp; |
---|
| 451 | int stat = NC_check_id(ncid, &ncp); |
---|
| 452 | if(stat != NC_NOERR) return stat; |
---|
| 453 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 454 | NC_INT); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | int |
---|
| 458 | nc_put_vara_long(int ncid, int varid, const size_t *startp, |
---|
| 459 | const size_t *countp, const long *op) |
---|
| 460 | { |
---|
| 461 | NC* ncp; |
---|
| 462 | int stat = NC_check_id(ncid, &ncp); |
---|
| 463 | if(stat != NC_NOERR) return stat; |
---|
| 464 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 465 | T_long); |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | int |
---|
| 469 | nc_put_vara_float(int ncid, int varid, const size_t *startp, |
---|
| 470 | const size_t *countp, const float *op) |
---|
| 471 | { |
---|
| 472 | NC* ncp; |
---|
| 473 | int stat = NC_check_id(ncid, &ncp); |
---|
| 474 | if(stat != NC_NOERR) return stat; |
---|
| 475 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 476 | T_float); |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | int |
---|
| 480 | nc_put_vara_double(int ncid, int varid, const size_t *startp, |
---|
| 481 | const size_t *countp, const double *op) |
---|
| 482 | { |
---|
| 483 | NC* ncp; |
---|
| 484 | int stat = NC_check_id(ncid, &ncp); |
---|
| 485 | if(stat != NC_NOERR) return stat; |
---|
| 486 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 487 | T_double); |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | int |
---|
| 491 | nc_put_vara_ubyte(int ncid, int varid, const size_t *startp, |
---|
| 492 | const size_t *countp, const unsigned char *op) |
---|
| 493 | { |
---|
| 494 | NC* ncp; |
---|
| 495 | int stat = NC_check_id(ncid, &ncp); |
---|
| 496 | if(stat != NC_NOERR) return stat; |
---|
| 497 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 498 | T_ubyte); |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | int |
---|
| 502 | nc_put_vara_ushort(int ncid, int varid, const size_t *startp, |
---|
| 503 | const size_t *countp, const unsigned short *op) |
---|
| 504 | { |
---|
| 505 | NC* ncp; |
---|
| 506 | int stat = NC_check_id(ncid, &ncp); |
---|
| 507 | if(stat != NC_NOERR) return stat; |
---|
| 508 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 509 | T_ushort); |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | int |
---|
| 513 | nc_put_vara_uint(int ncid, int varid, const size_t *startp, |
---|
| 514 | const size_t *countp, const unsigned int *op) |
---|
| 515 | { |
---|
| 516 | NC* ncp; |
---|
| 517 | int stat = NC_check_id(ncid, &ncp); |
---|
| 518 | if(stat != NC_NOERR) return stat; |
---|
| 519 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 520 | T_uint); |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | int |
---|
| 524 | nc_put_vara_longlong(int ncid, int varid, const size_t *startp, |
---|
| 525 | const size_t *countp, const long long *op) |
---|
| 526 | { |
---|
| 527 | NC* ncp; |
---|
| 528 | int stat = NC_check_id(ncid, &ncp); |
---|
| 529 | if(stat != NC_NOERR) return stat; |
---|
| 530 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 531 | T_longlong); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | int |
---|
| 535 | nc_put_vara_ulonglong(int ncid, int varid, const size_t *startp, |
---|
| 536 | const size_t *countp, const unsigned long long *op) |
---|
| 537 | { |
---|
| 538 | NC* ncp; |
---|
| 539 | int stat = NC_check_id(ncid, &ncp); |
---|
| 540 | if(stat != NC_NOERR) return stat; |
---|
| 541 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 542 | NC_UINT64); |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | #ifdef USE_NETCDF4 |
---|
| 546 | int |
---|
| 547 | nc_put_vara_string(int ncid, int varid, const size_t *startp, |
---|
| 548 | const size_t *countp, const char* *op) |
---|
| 549 | { |
---|
| 550 | NC* ncp; |
---|
| 551 | int stat = NC_check_id(ncid, &ncp); |
---|
| 552 | if(stat != NC_NOERR) return stat; |
---|
| 553 | return NC_put_vara(ncid, varid, startp, countp, (void *)op, |
---|
| 554 | NC_STRING); |
---|
| 555 | } |
---|
| 556 | |
---|
| 557 | #endif /*USE_NETCDF4*/ |
---|
| 558 | /**@}*/ |
---|
| 559 | |
---|
| 560 | /** \ingroup variables |
---|
| 561 | Write one datum. |
---|
| 562 | |
---|
| 563 | \param ncid NetCDF or group ID, from a previous call to nc_open(), |
---|
| 564 | nc_create(), nc_def_grp(), or associated inquiry functions such as |
---|
| 565 | nc_inq_ncid(). |
---|
| 566 | |
---|
| 567 | \param varid Variable ID |
---|
| 568 | |
---|
| 569 | \param indexp Index vector with one element for each dimension. |
---|
| 570 | |
---|
| 571 | \param op Pointer from where the data will be copied. |
---|
| 572 | |
---|
| 573 | \returns ::NC_NOERR No error. |
---|
| 574 | \returns ::NC_ENOTVAR Variable not found. |
---|
| 575 | \returns ::NC_EINVALCOORDS Index exceeds dimension bound. |
---|
| 576 | \returns ::NC_EEDGE Start+count exceeds dimension bound. |
---|
| 577 | \returns ::NC_ERANGE One or more of the values are out of range. |
---|
| 578 | \returns ::NC_EINDEFINE Operation not allowed in define mode. |
---|
| 579 | \returns ::NC_EBADID Bad ncid. |
---|
| 580 | */ |
---|
| 581 | /**@{*/ |
---|
| 582 | int |
---|
| 583 | nc_put_var1(int ncid, int varid, const size_t *indexp, const void *op) |
---|
| 584 | { |
---|
| 585 | return NC_put_var1(ncid, varid, indexp, op, NC_NAT); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | int |
---|
| 589 | nc_put_var1_text(int ncid, int varid, const size_t *indexp, const char *op) |
---|
| 590 | { |
---|
| 591 | NC* ncp; |
---|
| 592 | int stat = NC_check_id(ncid, &ncp); |
---|
| 593 | if(stat != NC_NOERR) return stat; |
---|
| 594 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_CHAR); |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | int |
---|
| 598 | nc_put_var1_schar(int ncid, int varid, const size_t *indexp, const signed char *op) |
---|
| 599 | { |
---|
| 600 | NC* ncp; |
---|
| 601 | int stat = NC_check_id(ncid, &ncp); |
---|
| 602 | if(stat != NC_NOERR) return stat; |
---|
| 603 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_BYTE); |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | int |
---|
| 607 | nc_put_var1_uchar(int ncid, int varid, const size_t *indexp, const unsigned char *op) |
---|
| 608 | { |
---|
| 609 | NC* ncp; |
---|
| 610 | int stat = NC_check_id(ncid, &ncp); |
---|
| 611 | if(stat != NC_NOERR) return stat; |
---|
| 612 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UBYTE); |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | int |
---|
| 616 | nc_put_var1_short(int ncid, int varid, const size_t *indexp, const short *op) |
---|
| 617 | { |
---|
| 618 | NC* ncp; |
---|
| 619 | int stat = NC_check_id(ncid, &ncp); |
---|
| 620 | if(stat != NC_NOERR) return stat; |
---|
| 621 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_SHORT); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | int |
---|
| 625 | nc_put_var1_int(int ncid, int varid, const size_t *indexp, const int *op) |
---|
| 626 | { |
---|
| 627 | NC* ncp; |
---|
| 628 | int stat = NC_check_id(ncid, &ncp); |
---|
| 629 | if(stat != NC_NOERR) return stat; |
---|
| 630 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_INT); |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | int |
---|
| 634 | nc_put_var1_long(int ncid, int varid, const size_t *indexp, const long *op) |
---|
| 635 | { |
---|
| 636 | NC* ncp; |
---|
| 637 | int stat = NC_check_id(ncid, &ncp); |
---|
| 638 | if(stat != NC_NOERR) return stat; |
---|
| 639 | return NC_put_var1(ncid, varid, indexp, (void*)op, longtype); |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | int |
---|
| 643 | nc_put_var1_float(int ncid, int varid, const size_t *indexp, const float *op) |
---|
| 644 | { |
---|
| 645 | NC* ncp; |
---|
| 646 | int stat = NC_check_id(ncid, &ncp); |
---|
| 647 | if(stat != NC_NOERR) return stat; |
---|
| 648 | return NC_put_var1(ncid, varid, indexp, (void*)op, NC_FLOAT); |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | int |
---|
| 652 | nc_put_var1_double(int ncid, int varid, const size_t *indexp, const double *op) |
---|
| 653 | { |
---|
| 654 | NC* ncp; |
---|
| 655 | int stat = NC_check_id(ncid, &ncp); |
---|
| 656 | if(stat != NC_NOERR) return stat; |
---|
| 657 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_DOUBLE); |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | int |
---|
| 661 | nc_put_var1_ubyte(int ncid, int varid, const size_t *indexp, const unsigned char *op) |
---|
| 662 | { |
---|
| 663 | NC* ncp; |
---|
| 664 | int stat = NC_check_id(ncid, &ncp); |
---|
| 665 | if(stat != NC_NOERR) return stat; |
---|
| 666 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UBYTE); |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | int |
---|
| 670 | nc_put_var1_ushort(int ncid, int varid, const size_t *indexp, const unsigned short *op) |
---|
| 671 | { |
---|
| 672 | NC* ncp; |
---|
| 673 | int stat = NC_check_id(ncid, &ncp); |
---|
| 674 | if(stat != NC_NOERR) return stat; |
---|
| 675 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_USHORT); |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | int |
---|
| 679 | nc_put_var1_uint(int ncid, int varid, const size_t *indexp, const unsigned int *op) |
---|
| 680 | { |
---|
| 681 | NC* ncp; |
---|
| 682 | int stat = NC_check_id(ncid, &ncp); |
---|
| 683 | if(stat != NC_NOERR) return stat; |
---|
| 684 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UINT); |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | int |
---|
| 688 | nc_put_var1_longlong(int ncid, int varid, const size_t *indexp, const long long *op) |
---|
| 689 | { |
---|
| 690 | NC* ncp; |
---|
| 691 | int stat = NC_check_id(ncid, &ncp); |
---|
| 692 | if(stat != NC_NOERR) return stat; |
---|
| 693 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_INT64); |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | int |
---|
| 697 | nc_put_var1_ulonglong(int ncid, int varid, const size_t *indexp, const unsigned long long *op) |
---|
| 698 | { |
---|
| 699 | NC* ncp; |
---|
| 700 | int stat = NC_check_id(ncid, &ncp); |
---|
| 701 | if(stat != NC_NOERR) return stat; |
---|
| 702 | return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UINT64); |
---|
| 703 | } |
---|
| 704 | |
---|
| 705 | #ifdef USE_NETCDF4 |
---|
| 706 | int |
---|
| 707 | nc_put_var1_string(int ncid, int varid, const size_t *indexp, const char* *op) |
---|
| 708 | { |
---|
| 709 | NC* ncp; |
---|
| 710 | int stat = NC_check_id(ncid, &ncp); |
---|
| 711 | if(stat != NC_NOERR) return stat; |
---|
| 712 | return NC_put_var1(ncid, varid, indexp, (void*)op, NC_STRING); |
---|
| 713 | } |
---|
| 714 | #endif /*USE_NETCDF4*/ |
---|
| 715 | /**@}*/ |
---|
| 716 | |
---|
| 717 | /** \ingroup variables |
---|
| 718 | Write an entire variable with one call. |
---|
| 719 | |
---|
| 720 | The nc_put_var_ type family of functions write all the values of a |
---|
| 721 | variable into a netCDF variable of an open netCDF dataset. This is the |
---|
| 722 | simplest interface to use for writing a value in a scalar variable or |
---|
| 723 | whenever all the values of a multidimensional variable can all be |
---|
| 724 | written at once. The values to be written are associated with the |
---|
| 725 | netCDF variable by assuming that the last dimension of the netCDF |
---|
| 726 | variable varies fastest in the C interface. The values are converted |
---|
| 727 | to the external data type of the variable, if necessary. |
---|
| 728 | |
---|
| 729 | Take care when using this function with record variables (variables |
---|
| 730 | that use the ::NC_UNLIMITED dimension). If you try to write all the |
---|
| 731 | values of a record variable into a netCDF file that has no record data |
---|
| 732 | yet (hence has 0 records), nothing will be written. Similarly, if you |
---|
| 733 | try to write all the values of a record variable but there are more |
---|
| 734 | records in the file than you assume, more in-memory data will be |
---|
| 735 | accessed than you supply, which may result in a segmentation |
---|
| 736 | violation. To avoid such problems, it is better to use the nc_put_vara |
---|
| 737 | interfaces for variables that use the ::NC_UNLIMITED dimension. |
---|
| 738 | |
---|
| 739 | The functions for types ubyte, ushort, uint, longlong, ulonglong, and |
---|
| 740 | string are only available for netCDF-4/HDF5 files. |
---|
| 741 | |
---|
| 742 | The nc_put_var() function will write a variable of any type, including |
---|
| 743 | user defined type. For this function, the type of the data in memory |
---|
| 744 | must match the type of the variable - no data conversion is done. |
---|
| 745 | |
---|
| 746 | \param ncid NetCDF or group ID, from a previous call to nc_open(), |
---|
| 747 | nc_create(), nc_def_grp(), or associated inquiry functions such as |
---|
| 748 | nc_inq_ncid(). |
---|
| 749 | |
---|
| 750 | \param varid Variable ID |
---|
| 751 | |
---|
| 752 | \param op Pointer from where the data will be copied. |
---|
| 753 | |
---|
| 754 | \returns ::NC_NOERR No error. |
---|
| 755 | \returns ::NC_ENOTVAR Variable not found. |
---|
| 756 | \returns ::NC_EINVALCOORDS Index exceeds dimension bound. |
---|
| 757 | \returns ::NC_EEDGE Start+count exceeds dimension bound. |
---|
| 758 | \returns ::NC_ERANGE One or more of the values are out of range. |
---|
| 759 | \returns ::NC_EINDEFINE Operation not allowed in define mode. |
---|
| 760 | \returns ::NC_EBADID Bad ncid. |
---|
| 761 | */ |
---|
| 762 | /**@{*/ |
---|
| 763 | int |
---|
| 764 | nc_put_var(int ncid, int varid, const void *op) |
---|
| 765 | { |
---|
| 766 | return NC_put_var(ncid, varid, op, NC_NAT); |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | int |
---|
| 770 | nc_put_var_text(int ncid, int varid, const char *op) |
---|
| 771 | { |
---|
| 772 | NC* ncp; |
---|
| 773 | int stat = NC_check_id(ncid, &ncp); |
---|
| 774 | if(stat != NC_NOERR) return stat; |
---|
| 775 | return NC_put_var(ncid,varid,(void*)op,NC_CHAR); |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | int |
---|
| 779 | nc_put_var_schar(int ncid, int varid, const signed char *op) |
---|
| 780 | { |
---|
| 781 | NC* ncp; |
---|
| 782 | int stat = NC_check_id(ncid, &ncp); |
---|
| 783 | if(stat != NC_NOERR) return stat; |
---|
| 784 | return NC_put_var(ncid,varid,(void*)op,NC_BYTE); |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | int |
---|
| 788 | nc_put_var_uchar(int ncid, int varid, const unsigned char *op) |
---|
| 789 | { |
---|
| 790 | NC* ncp; |
---|
| 791 | int stat = NC_check_id(ncid, &ncp); |
---|
| 792 | if(stat != NC_NOERR) return stat; |
---|
| 793 | return NC_put_var(ncid,varid,(void*)op,T_uchar); |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | int |
---|
| 797 | nc_put_var_short(int ncid, int varid, const short *op) |
---|
| 798 | { |
---|
| 799 | NC* ncp; |
---|
| 800 | int stat = NC_check_id(ncid, &ncp); |
---|
| 801 | if(stat != NC_NOERR) return stat; |
---|
| 802 | return NC_put_var(ncid,varid,(void*)op,NC_SHORT); |
---|
| 803 | } |
---|
| 804 | |
---|
| 805 | int |
---|
| 806 | nc_put_var_int(int ncid, int varid, const int *op) |
---|
| 807 | { |
---|
| 808 | NC* ncp; |
---|
| 809 | int stat = NC_check_id(ncid, &ncp); |
---|
| 810 | if(stat != NC_NOERR) return stat; |
---|
| 811 | return NC_put_var(ncid,varid,(void*)op,NC_INT); |
---|
| 812 | } |
---|
| 813 | |
---|
| 814 | int |
---|
| 815 | nc_put_var_long(int ncid, int varid, const long *op) |
---|
| 816 | { |
---|
| 817 | NC* ncp; |
---|
| 818 | int stat = NC_check_id(ncid, &ncp); |
---|
| 819 | if(stat != NC_NOERR) return stat; |
---|
| 820 | return NC_put_var(ncid,varid,(void*)op,T_long); |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | int |
---|
| 824 | nc_put_var_float(int ncid, int varid, const float *op) |
---|
| 825 | { |
---|
| 826 | NC* ncp; |
---|
| 827 | int stat = NC_check_id(ncid, &ncp); |
---|
| 828 | if(stat != NC_NOERR) return stat; |
---|
| 829 | return NC_put_var(ncid,varid,(void*)op,T_float); |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | int |
---|
| 833 | nc_put_var_double(int ncid, int varid, const double *op) |
---|
| 834 | { |
---|
| 835 | NC* ncp; |
---|
| 836 | int stat = NC_check_id(ncid, &ncp); |
---|
| 837 | if(stat != NC_NOERR) return stat; |
---|
| 838 | return NC_put_var(ncid,varid,(void*)op,T_double); |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | int |
---|
| 842 | nc_put_var_ubyte(int ncid, int varid, const unsigned char *op) |
---|
| 843 | { |
---|
| 844 | NC* ncp; |
---|
| 845 | int stat = NC_check_id(ncid, &ncp); |
---|
| 846 | if(stat != NC_NOERR) return stat; |
---|
| 847 | return NC_put_var(ncid,varid,(void*)op,T_ubyte); |
---|
| 848 | } |
---|
| 849 | |
---|
| 850 | int |
---|
| 851 | nc_put_var_ushort(int ncid, int varid, const unsigned short *op) |
---|
| 852 | { |
---|
| 853 | NC* ncp; |
---|
| 854 | int stat = NC_check_id(ncid, &ncp); |
---|
| 855 | if(stat != NC_NOERR) return stat; |
---|
| 856 | return NC_put_var(ncid,varid,(void*)op,T_ushort); |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | int |
---|
| 860 | nc_put_var_uint(int ncid, int varid, const unsigned int *op) |
---|
| 861 | { |
---|
| 862 | NC* ncp; |
---|
| 863 | int stat = NC_check_id(ncid, &ncp); |
---|
| 864 | if(stat != NC_NOERR) return stat; |
---|
| 865 | return NC_put_var(ncid,varid,(void*)op,T_uint); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | int |
---|
| 869 | nc_put_var_longlong(int ncid, int varid, const long long *op) |
---|
| 870 | { |
---|
| 871 | NC* ncp; |
---|
| 872 | int stat = NC_check_id(ncid, &ncp); |
---|
| 873 | if(stat != NC_NOERR) return stat; |
---|
| 874 | return NC_put_var(ncid,varid,(void*)op,T_longlong); |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | int |
---|
| 878 | nc_put_var_ulonglong(int ncid, int varid, const unsigned long long *op) |
---|
| 879 | { |
---|
| 880 | NC* ncp; |
---|
| 881 | int stat = NC_check_id(ncid, &ncp); |
---|
| 882 | if(stat != NC_NOERR) return stat; |
---|
| 883 | return NC_put_var(ncid,varid,(void*)op,NC_UINT64); |
---|
| 884 | } |
---|
| 885 | |
---|
| 886 | #ifdef USE_NETCDF4 |
---|
| 887 | int |
---|
| 888 | nc_put_var_string(int ncid, int varid, const char* *op) |
---|
| 889 | { |
---|
| 890 | NC* ncp; |
---|
| 891 | int stat = NC_check_id(ncid, &ncp); |
---|
| 892 | if(stat != NC_NOERR) return stat; |
---|
| 893 | return NC_put_var(ncid,varid,(void*)op,NC_STRING); |
---|
| 894 | } |
---|
| 895 | #endif /*USE_NETCDF4*/ |
---|
| 896 | /**\} */ |
---|
| 897 | |
---|
| 898 | /** \ingroup variables |
---|
| 899 | Write a strided array of values to a variable. |
---|
| 900 | |
---|
| 901 | \param ncid NetCDF or group ID, from a previous call to nc_open(), |
---|
| 902 | nc_create(), nc_def_grp(), or associated inquiry functions such as |
---|
| 903 | nc_inq_ncid(). |
---|
| 904 | |
---|
| 905 | \param varid Variable ID |
---|
| 906 | |
---|
| 907 | \param startp Start vector with one element for each dimension to \ref |
---|
| 908 | specify_hyperslab. |
---|
| 909 | |
---|
| 910 | \param countp Count vector with one element for each dimension to \ref |
---|
| 911 | specify_hyperslab. |
---|
| 912 | |
---|
| 913 | \param stridep Stride vector with one element for each dimension to |
---|
| 914 | \ref specify_hyperslab. |
---|
| 915 | |
---|
| 916 | \param op Pointer where the data will be copied. Memory must be |
---|
| 917 | allocated by the user before this function is called. |
---|
| 918 | |
---|
| 919 | \returns ::NC_NOERR No error. |
---|
| 920 | \returns ::NC_ENOTVAR Variable not found. |
---|
| 921 | \returns ::NC_EINVALCOORDS Index exceeds dimension bound. |
---|
| 922 | \returns ::NC_EEDGE Start+count exceeds dimension bound. |
---|
| 923 | \returns ::NC_ERANGE One or more of the values are out of range. |
---|
| 924 | \returns ::NC_EINDEFINE Operation not allowed in define mode. |
---|
| 925 | \returns ::NC_EBADID Bad ncid. |
---|
| 926 | */ |
---|
| 927 | /**@{*/ |
---|
| 928 | int |
---|
| 929 | nc_put_vars (int ncid, int varid, const size_t *startp, |
---|
| 930 | const size_t *countp, const ptrdiff_t *stridep, |
---|
| 931 | const void *op) |
---|
| 932 | { |
---|
| 933 | NC *ncp; |
---|
| 934 | int stat = NC_NOERR; |
---|
| 935 | |
---|
| 936 | if ((stat = NC_check_id(ncid, &ncp))) |
---|
| 937 | return stat; |
---|
| 938 | return ncp->dispatch->put_vars(ncid, varid, startp, countp, |
---|
| 939 | stridep, op, NC_NAT); |
---|
| 940 | } |
---|
| 941 | |
---|
| 942 | int |
---|
| 943 | nc_put_vars_text(int ncid, int varid, const size_t *startp, |
---|
| 944 | const size_t *countp, const ptrdiff_t *stridep, |
---|
| 945 | const char *op) |
---|
| 946 | { |
---|
| 947 | NC *ncp; |
---|
| 948 | int stat = NC_check_id(ncid, &ncp); |
---|
| 949 | if(stat != NC_NOERR) return stat; |
---|
| 950 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 951 | stridep,(void*)op,NC_CHAR); |
---|
| 952 | } |
---|
| 953 | |
---|
| 954 | int |
---|
| 955 | nc_put_vars_schar(int ncid, int varid, const size_t *startp, |
---|
| 956 | const size_t *countp, const ptrdiff_t *stridep, |
---|
| 957 | const signed char *op) |
---|
| 958 | { |
---|
| 959 | NC *ncp; |
---|
| 960 | int stat = NC_check_id(ncid, &ncp); |
---|
| 961 | if(stat != NC_NOERR) return stat; |
---|
| 962 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 963 | stridep,(void*)op,NC_BYTE); |
---|
| 964 | } |
---|
| 965 | |
---|
| 966 | int |
---|
| 967 | nc_put_vars_uchar(int ncid, int varid, |
---|
| 968 | const size_t *startp, const size_t *countp, |
---|
| 969 | const ptrdiff_t *stridep, |
---|
| 970 | const unsigned char *op) |
---|
| 971 | { |
---|
| 972 | NC *ncp; |
---|
| 973 | int stat = NC_check_id(ncid, &ncp); |
---|
| 974 | if(stat != NC_NOERR) return stat; |
---|
| 975 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 976 | stridep, (void *)op, T_uchar); |
---|
| 977 | } |
---|
| 978 | |
---|
| 979 | int |
---|
| 980 | nc_put_vars_short(int ncid, int varid, |
---|
| 981 | const size_t *startp, const size_t *countp, |
---|
| 982 | const ptrdiff_t *stridep, |
---|
| 983 | const short *op) |
---|
| 984 | { |
---|
| 985 | NC *ncp; |
---|
| 986 | int stat = NC_check_id(ncid, &ncp); |
---|
| 987 | if(stat != NC_NOERR) return stat; |
---|
| 988 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 989 | stridep, (void *)op, NC_SHORT); |
---|
| 990 | } |
---|
| 991 | |
---|
| 992 | int |
---|
| 993 | nc_put_vars_int(int ncid, int varid, |
---|
| 994 | const size_t *startp, const size_t *countp, |
---|
| 995 | const ptrdiff_t *stridep, |
---|
| 996 | const int *op) |
---|
| 997 | { |
---|
| 998 | NC *ncp; |
---|
| 999 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1000 | if(stat != NC_NOERR) return stat; |
---|
| 1001 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1002 | stridep, (void *)op, NC_INT); |
---|
| 1003 | } |
---|
| 1004 | |
---|
| 1005 | int |
---|
| 1006 | nc_put_vars_long(int ncid, int varid, |
---|
| 1007 | const size_t *startp, const size_t *countp, |
---|
| 1008 | const ptrdiff_t *stridep, |
---|
| 1009 | const long *op) |
---|
| 1010 | { |
---|
| 1011 | NC *ncp; |
---|
| 1012 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1013 | if(stat != NC_NOERR) return stat; |
---|
| 1014 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1015 | stridep, (void *)op, T_long); |
---|
| 1016 | } |
---|
| 1017 | |
---|
| 1018 | int |
---|
| 1019 | nc_put_vars_float(int ncid, int varid, |
---|
| 1020 | const size_t *startp, const size_t *countp, |
---|
| 1021 | const ptrdiff_t *stridep, |
---|
| 1022 | const float *op) |
---|
| 1023 | { |
---|
| 1024 | NC *ncp; |
---|
| 1025 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1026 | if(stat != NC_NOERR) return stat; |
---|
| 1027 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1028 | stridep, (void *)op, T_float); |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | int |
---|
| 1032 | nc_put_vars_double(int ncid, int varid, |
---|
| 1033 | const size_t *startp, const size_t *countp, |
---|
| 1034 | const ptrdiff_t *stridep, |
---|
| 1035 | const double *op) |
---|
| 1036 | { |
---|
| 1037 | NC *ncp; |
---|
| 1038 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1039 | if(stat != NC_NOERR) return stat; |
---|
| 1040 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1041 | stridep, (void *)op, T_double); |
---|
| 1042 | } |
---|
| 1043 | |
---|
| 1044 | int |
---|
| 1045 | nc_put_vars_ubyte(int ncid, int varid, |
---|
| 1046 | const size_t *startp, const size_t *countp, |
---|
| 1047 | const ptrdiff_t *stridep, |
---|
| 1048 | const unsigned char *op) |
---|
| 1049 | { |
---|
| 1050 | NC *ncp; |
---|
| 1051 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1052 | if(stat != NC_NOERR) return stat; |
---|
| 1053 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1054 | stridep, (void *)op, T_ubyte); |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | int |
---|
| 1058 | nc_put_vars_ushort(int ncid, int varid, |
---|
| 1059 | const size_t *startp, const size_t *countp, |
---|
| 1060 | const ptrdiff_t *stridep, |
---|
| 1061 | const unsigned short *op) |
---|
| 1062 | { |
---|
| 1063 | NC *ncp; |
---|
| 1064 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1065 | if(stat != NC_NOERR) return stat; |
---|
| 1066 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1067 | stridep, (void *)op, T_ushort); |
---|
| 1068 | } |
---|
| 1069 | |
---|
| 1070 | int |
---|
| 1071 | nc_put_vars_uint(int ncid, int varid, |
---|
| 1072 | const size_t *startp, const size_t *countp, |
---|
| 1073 | const ptrdiff_t *stridep, |
---|
| 1074 | const unsigned int *op) |
---|
| 1075 | { |
---|
| 1076 | NC *ncp; |
---|
| 1077 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1078 | if(stat != NC_NOERR) return stat; |
---|
| 1079 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1080 | stridep, (void *)op, T_uint); |
---|
| 1081 | } |
---|
| 1082 | |
---|
| 1083 | int |
---|
| 1084 | nc_put_vars_longlong(int ncid, int varid, |
---|
| 1085 | const size_t *startp, const size_t *countp, |
---|
| 1086 | const ptrdiff_t *stridep, |
---|
| 1087 | const long long *op) |
---|
| 1088 | { |
---|
| 1089 | NC *ncp; |
---|
| 1090 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1091 | if(stat != NC_NOERR) return stat; |
---|
| 1092 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1093 | stridep, (void *)op, T_longlong); |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | int |
---|
| 1097 | nc_put_vars_ulonglong(int ncid, int varid, |
---|
| 1098 | const size_t *startp, const size_t *countp, |
---|
| 1099 | const ptrdiff_t *stridep, |
---|
| 1100 | const unsigned long long *op) |
---|
| 1101 | { |
---|
| 1102 | NC *ncp; |
---|
| 1103 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1104 | if(stat != NC_NOERR) return stat; |
---|
| 1105 | return NC_put_vars(ncid, varid, startp, countp, |
---|
| 1106 | stridep, (void *)op, NC_UINT64); |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | #ifdef USE_NETCDF4 |
---|
| 1110 | int |
---|
| 1111 | nc_put_vars_string(int ncid, int varid, |
---|
| 1112 | const size_t *startp, const size_t *countp, |
---|
| 1113 | const ptrdiff_t *stridep, |
---|
| 1114 | const char**op) |
---|
| 1115 | { |
---|
| 1116 | NC *ncp; |
---|
| 1117 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1118 | if(stat != NC_NOERR) return stat; |
---|
| 1119 | return NC_put_vars(ncid, varid, startp, countp, stridep, |
---|
| 1120 | (void *)op, NC_STRING); |
---|
| 1121 | } |
---|
| 1122 | #endif /*USE_NETCDF4*/ |
---|
| 1123 | /**\} */ |
---|
| 1124 | |
---|
| 1125 | /** \ingroup variables |
---|
| 1126 | Write a mapped array of values to a variable. |
---|
| 1127 | |
---|
| 1128 | \param ncid NetCDF or group ID, from a previous call to nc_open(), |
---|
| 1129 | nc_create(), nc_def_grp(), or associated inquiry functions such as |
---|
| 1130 | nc_inq_ncid(). |
---|
| 1131 | |
---|
| 1132 | \param varid Variable ID |
---|
| 1133 | |
---|
| 1134 | \param startp Start vector with one element for each dimension to \ref |
---|
| 1135 | specify_hyperslab. |
---|
| 1136 | |
---|
| 1137 | \param countp Count vector with one element for each dimension to \ref |
---|
| 1138 | specify_hyperslab. |
---|
| 1139 | |
---|
| 1140 | \param stridep Stride vector with one element for each dimension to |
---|
| 1141 | \ref specify_hyperslab. |
---|
| 1142 | |
---|
| 1143 | \param imapp Mapping vector with one element for each dimension to |
---|
| 1144 | \ref specify_hyperslab. |
---|
| 1145 | |
---|
| 1146 | \param op Pointer where the data will be copied. Memory must be |
---|
| 1147 | allocated by the user before this function is called. |
---|
| 1148 | |
---|
| 1149 | \returns ::NC_NOERR No error. |
---|
| 1150 | \returns ::NC_ENOTVAR Variable not found. |
---|
| 1151 | \returns ::NC_EINVALCOORDS Index exceeds dimension bound. |
---|
| 1152 | \returns ::NC_EEDGE Start+count exceeds dimension bound. |
---|
| 1153 | \returns ::NC_ERANGE One or more of the values are out of range. |
---|
| 1154 | \returns ::NC_EINDEFINE Operation not allowed in define mode. |
---|
| 1155 | \returns ::NC_EBADID Bad ncid. |
---|
| 1156 | */ |
---|
| 1157 | /**@{*/ |
---|
| 1158 | int |
---|
| 1159 | nc_put_varm (int ncid, int varid, const size_t *startp, |
---|
| 1160 | const size_t *countp, const ptrdiff_t *stridep, |
---|
| 1161 | const ptrdiff_t *imapp, const void *op) |
---|
| 1162 | { |
---|
| 1163 | NC *ncp; |
---|
| 1164 | int stat = NC_NOERR; |
---|
| 1165 | |
---|
| 1166 | if ((stat = NC_check_id(ncid, &ncp))) |
---|
| 1167 | return stat; |
---|
| 1168 | return ncp->dispatch->put_varm(ncid, varid, startp, countp, |
---|
| 1169 | stridep, imapp, op, NC_NAT); |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | int |
---|
| 1173 | nc_put_varm_text(int ncid, int varid, const size_t *startp, |
---|
| 1174 | const size_t *countp, const ptrdiff_t *stridep, |
---|
| 1175 | const ptrdiff_t *imapp, const char *op) |
---|
| 1176 | { |
---|
| 1177 | NC *ncp; |
---|
| 1178 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1179 | if(stat != NC_NOERR) return stat; |
---|
| 1180 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1181 | (void *)op, NC_CHAR); |
---|
| 1182 | } |
---|
| 1183 | |
---|
| 1184 | int |
---|
| 1185 | nc_put_varm_schar(int ncid, int varid, |
---|
| 1186 | const size_t *startp, const size_t *countp, |
---|
| 1187 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1188 | const signed char *op) |
---|
| 1189 | { |
---|
| 1190 | NC *ncp; |
---|
| 1191 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1192 | if(stat != NC_NOERR) return stat; |
---|
| 1193 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1194 | (void *)op, NC_BYTE); |
---|
| 1195 | } |
---|
| 1196 | |
---|
| 1197 | int |
---|
| 1198 | nc_put_varm_uchar(int ncid, int varid, |
---|
| 1199 | const size_t *startp, const size_t *countp, |
---|
| 1200 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1201 | const unsigned char *op) |
---|
| 1202 | { |
---|
| 1203 | NC *ncp; |
---|
| 1204 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1205 | if(stat != NC_NOERR) return stat; |
---|
| 1206 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1207 | (void *)op, T_uchar); |
---|
| 1208 | } |
---|
| 1209 | |
---|
| 1210 | int |
---|
| 1211 | nc_put_varm_short(int ncid, int varid, |
---|
| 1212 | const size_t *startp, const size_t *countp, |
---|
| 1213 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1214 | const short *op) |
---|
| 1215 | { |
---|
| 1216 | NC *ncp; |
---|
| 1217 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1218 | if(stat != NC_NOERR) return stat; |
---|
| 1219 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1220 | (void *)op, NC_SHORT); |
---|
| 1221 | } |
---|
| 1222 | |
---|
| 1223 | int |
---|
| 1224 | nc_put_varm_int(int ncid, int varid, |
---|
| 1225 | const size_t *startp, const size_t *countp, |
---|
| 1226 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1227 | const int *op) |
---|
| 1228 | { |
---|
| 1229 | NC *ncp; |
---|
| 1230 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1231 | if(stat != NC_NOERR) return stat; |
---|
| 1232 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1233 | (void *)op, NC_INT); |
---|
| 1234 | } |
---|
| 1235 | |
---|
| 1236 | int |
---|
| 1237 | nc_put_varm_long(int ncid, int varid, |
---|
| 1238 | const size_t *startp, const size_t *countp, |
---|
| 1239 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1240 | const long *op) |
---|
| 1241 | { |
---|
| 1242 | NC *ncp; |
---|
| 1243 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1244 | if(stat != NC_NOERR) return stat; |
---|
| 1245 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1246 | (void *)op, T_long); |
---|
| 1247 | } |
---|
| 1248 | |
---|
| 1249 | int |
---|
| 1250 | nc_put_varm_float(int ncid, int varid, |
---|
| 1251 | const size_t *startp, const size_t *countp, |
---|
| 1252 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1253 | const float *op) |
---|
| 1254 | { |
---|
| 1255 | NC *ncp; |
---|
| 1256 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1257 | if(stat != NC_NOERR) return stat; |
---|
| 1258 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1259 | (void *)op, T_float); |
---|
| 1260 | } |
---|
| 1261 | |
---|
| 1262 | int |
---|
| 1263 | nc_put_varm_double(int ncid, int varid, |
---|
| 1264 | const size_t *startp, const size_t *countp, |
---|
| 1265 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1266 | const double *op) |
---|
| 1267 | { |
---|
| 1268 | NC *ncp; |
---|
| 1269 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1270 | if(stat != NC_NOERR) return stat; |
---|
| 1271 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1272 | (void *)op, T_double); |
---|
| 1273 | } |
---|
| 1274 | |
---|
| 1275 | int |
---|
| 1276 | nc_put_varm_ubyte(int ncid, int varid, |
---|
| 1277 | const size_t *startp, const size_t *countp, |
---|
| 1278 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1279 | const unsigned char *op) |
---|
| 1280 | { |
---|
| 1281 | NC *ncp; |
---|
| 1282 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1283 | if(stat != NC_NOERR) return stat; |
---|
| 1284 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1285 | (void *)op, T_ubyte); |
---|
| 1286 | } |
---|
| 1287 | |
---|
| 1288 | int |
---|
| 1289 | nc_put_varm_ushort(int ncid, int varid, |
---|
| 1290 | const size_t *startp, const size_t *countp, |
---|
| 1291 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1292 | const unsigned short *op) |
---|
| 1293 | { |
---|
| 1294 | NC *ncp; |
---|
| 1295 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1296 | if(stat != NC_NOERR) return stat; |
---|
| 1297 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1298 | (void *)op, T_ushort); |
---|
| 1299 | } |
---|
| 1300 | |
---|
| 1301 | int |
---|
| 1302 | nc_put_varm_uint(int ncid, int varid, |
---|
| 1303 | const size_t *startp, const size_t *countp, |
---|
| 1304 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1305 | const unsigned int *op) |
---|
| 1306 | { |
---|
| 1307 | NC *ncp; |
---|
| 1308 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1309 | if(stat != NC_NOERR) return stat; |
---|
| 1310 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1311 | (void *)op, T_uint); |
---|
| 1312 | } |
---|
| 1313 | |
---|
| 1314 | int |
---|
| 1315 | nc_put_varm_longlong(int ncid, int varid, |
---|
| 1316 | const size_t *startp, const size_t *countp, |
---|
| 1317 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1318 | const long long *op) |
---|
| 1319 | { |
---|
| 1320 | NC *ncp; |
---|
| 1321 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1322 | if(stat != NC_NOERR) return stat; |
---|
| 1323 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1324 | (void *)op, T_longlong); |
---|
| 1325 | } |
---|
| 1326 | |
---|
| 1327 | int |
---|
| 1328 | nc_put_varm_ulonglong(int ncid, int varid, |
---|
| 1329 | const size_t *startp, const size_t *countp, |
---|
| 1330 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1331 | const unsigned long long *op) |
---|
| 1332 | { |
---|
| 1333 | NC *ncp; |
---|
| 1334 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1335 | if(stat != NC_NOERR) return stat; |
---|
| 1336 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1337 | (void *)op, NC_UINT64); |
---|
| 1338 | } |
---|
| 1339 | |
---|
| 1340 | #ifdef USE_NETCDF4 |
---|
| 1341 | int |
---|
| 1342 | nc_put_varm_string(int ncid, int varid, |
---|
| 1343 | const size_t *startp, const size_t *countp, |
---|
| 1344 | const ptrdiff_t *stridep, const ptrdiff_t *imapp, |
---|
| 1345 | const char**op) |
---|
| 1346 | { |
---|
| 1347 | NC *ncp; |
---|
| 1348 | int stat = NC_check_id(ncid, &ncp); |
---|
| 1349 | if(stat != NC_NOERR) return stat; |
---|
| 1350 | return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, |
---|
| 1351 | (void *)op, NC_STRING); |
---|
| 1352 | } |
---|
| 1353 | #endif /*USE_NETCDF4*/ |
---|
| 1354 | /**\} */ |
---|
| 1355 | |
---|
| 1356 | |
---|
| 1357 | /*! \} */ /*End of named group... */ |
---|
| 1358 | |
---|