/*---------------------------------------------------------------------- * Routine silo_GetVarSize * * Function * * Return the size of the given variable; the number of elements * and number of bytes per element are returned via arguments. * The total byte-length is the function return value. * * This has been provided as a convenience function. * *---------------------------------------------------------------------*/ INTERNAL int silo_GetVarSize (int dbid, int varid, int *nels, int *nbytes_el) { VarEnt *ent; *nels = *nbytes_el = 0; if ((ent = silo_GetVarEnt(dbid, silonetcdf_ncdirget(dbid), varid)) == NULL) return (OOPS); *nels = ent->nels; *nbytes_el = ent->lenel; return (*nels * *nbytes_el); }
/*---------------------------------------------------------------------- * Routine SO_GetComponent * * Purpose * * Alloc space for and read an entity of arbitrary type from * a SILO file. * * Programmer * * Jeffery W. Long, NSSD-B * * Notes * * Modifications * Al Leibee, Tue Sep 7 11:32:16 PDT 1993 * Replace SCORE mem allocation by system mem allocation * so that memory returned to application is system * allocated and can be freed by system memman. * *--------------------------------------------------------------------*/ INTERNAL void * SO_GetComponent(int sid, int entid, int enttype, int entpar) { int datatype, ndims, natts, nels; int i, original_dir; int dims[20], start[20], count[20], index[5]; char *var; double *local_d; float *local_f; /* * Save current dir; restore when done. */ original_dir = silonetcdf_ncdirget(sid); /* * Set directory to parent of requested entity. */ if (OOPS == silonetcdf_ncdirset(sid, entpar)) return (NULL); switch (enttype) { case SILO_TYPE_DIM: var = ALLOC_N(char, sizeof(int)); if (OOPS == (silonetcdf_ncdiminq(sid, entid, NULL, (int *)var))) { FREE(var); return (NULL); } break; case SILO_TYPE_VAR: if (OOPS == (silonetcdf_ncvarinq(sid, entid, NULL, &datatype, &ndims, dims, &natts))) return (NULL); start[0] = 0; index[0] = 0; count[0] = 1; nels = 0; if (ndims > 0) { for (nels = 1, i = 0; i < ndims; i++) { start[i] = 0; count[i] = silo_GetDimSize(sid, dims[i]); nels *= count[i]; } } var = ALLOC_N(char, nels * silo_GetMachDataSize(datatype)); if (nels == 1) { if (OOPS == (silonetcdf_ncvarget1(sid, entid, index, var))) { FREE(var); return (NULL); } } else { if (OOPS == (silonetcdf_ncvarget(sid, entid, start, count, var))) { FREE(var); return (NULL); } } /* * Map double precision values to float if force-single flag is TRUE. */ if (datatype == DB_DOUBLE && _so_force_single) { local_d = (double *)var; local_f = ALLOC_N(float, nels); for (i = 0; i < nels; i++) local_f[i] = (float)local_d[i]; FREE(var); var = (char *)local_f; } break; default: var = ALLOC_N(char, sizeof(int)); memcpy(var, &entid, sizeof(int)); break; }