Exemplo n.º 1
0
/*----------------------------------------------------------------------
 *  Routine                                               silo_GetDimSize
 *
 *  Function
 *
 *      Return the size of the given dimension ID.  This is a
 *      convenience function, so ncdiminq needn't be called.
 *
 *  Modifications:
 *
 *    Hank Childs, Thu Oct 12 10:26:10 PDT 2000
 *    Changed ncdiminq to silonetcdf_ncdiminq to take care of unresolved
 *    symbol.
 *
 *---------------------------------------------------------------------*/
INTERNAL int
silo_GetDimSize (int dbid, int dimid)
{
   int            size;

   silonetcdf_ncdiminq(dbid, dimid, NULL, &size);

   return (size);
}
Exemplo n.º 2
0
/*----------------------------------------------------------------------
 *  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;
    }