Beispiel #1
0
bool
PDBFileObject::GetDouble(const char *name, double *val)
{
    bool retval = false;

    if(AutoOpen())
    {
        syment *ep;

        if((ep = PD_inquire_entry(pdb, (char *)name, 0, NULL)) != NULL)
        {
            debug4 << "PDBFileObject::GetDouble: var="<< name
                   << ", type=" << PD_entry_type(ep) << endl;

            if(strcmp(PD_entry_type(ep), "double") == 0)
            {
                retval = (PD_read(pdb, (char *)name, (void *)val) ==  TRUE);
            }
            else if(strcmp(PD_entry_type(ep), "float") == 0)
            {
                float tmp;
                retval = (PD_read(pdb, (char *)name, (void *)&tmp) ==  TRUE);
                if(retval)
                    *val = (double)tmp;
            }
        }
    }

    return retval;
}
Beispiel #2
0
static int read_test_10_data(PDBfile *strm)
   {int err;

/* read the scalar data from the file */
    err = PD_read(strm, "qs", &qs_r);

/* read the primitive arrays from the file */
    err = PD_read(strm, "qa",  qa_r);

    return(err);}
Beispiel #3
0
bool
PDBFileObject::GetInteger(const char *name, int *val)
{
    bool retval = false;

    if(AutoOpen())
    {
        syment *ep;

        if((ep = PD_inquire_entry(pdb, (char *)name, 0, NULL)) != NULL)
        {
            debug4 << "PDBFileObject::GetInteger: var="<< name
                   << ", type=" << PD_entry_type(ep) << endl;

            if(strcmp(PD_entry_type(ep), "integer") == 0 ||
               strcmp(PD_entry_type(ep), "int") == 0)
            {
                //
                // Get the integer as an array in case there is more than 1
                // integer. This way, we don't clobber memory when we read
                // the integer if it happens to be an array of integers.
                //
                int *vals = 0, nvals = 0;
                if(GetIntegerArray(name, &vals, &nvals) && nvals > 0)
                {
                    *val = vals[0];
                    delete [] vals;
                    retval = true;
                }
            }
            else if(strcmp(PD_entry_type(ep), "short") == 0)
            {
                short tmp;
                retval = (PD_read(pdb, (char *)name, (void *)&tmp) ==  TRUE);
                if(retval)
                    *val = (short)tmp;
            }
            else if(strcmp(PD_entry_type(ep), "long") == 0)
            {
                long tmp;
                retval = (PD_read(pdb, (char *)name, (void *)&tmp) ==  TRUE);
                if(retval)
                    *val = (int)tmp;
            }
        }
    }

    return retval;
}
Beispiel #4
0
int _PD_cksum_var_read(PDBfile *file, char *name, char *type,
		      syment *ep, void *vr)
   {int rv, ok;
    inti ni, len;
    intb bpi;
    unsigned char rdig[PD_CKSUM_LEN], cdig[PD_CKSUM_LEN];
    char *path;
            
    rv = TRUE;

/* if requested, check MD5 checksum for this var */
    if ((file->cksum.use & PD_MD5_RW) && (strstr(name, PD_MD5_DIR) == NULL)) 
       {len  = strlen(PD_MD5_DIR) + strlen(name) + strlen(PD_MD5_SUFFIX) + 2;
        path = CMAKE_N(char, len);

/* read checksum as /&md5/<varname> */
        snprintf(path, len, "%s%s", PD_MD5_DIR, name);
        
        if (PD_query_entry(file, path, NULL) == NULL)

/* if preferred form is not there check archaic form - /&md5/<varname>-md5 */
	   {snprintf(path, len, "%s%s%s", PD_MD5_DIR, name, PD_MD5_SUFFIX);
        
/* make sure &md5 var has been created */
	    if (PD_query_entry(file, path, NULL) == NULL)
	       PD_error("NO MD5 CHECKSUM AVAILABLE FOR THIS VARIABLE - _PD_CKSUM_VAR_READ",
			PD_READ);}
        else
           {ni  = _PD_comp_num(ep->dimensions);
            bpi = _PD_lookup_size(type, file->host_chart);
        
/* do checksum in local memory on vr just read */
            memset(cdig, 0, PD_CKSUM_LEN);
            PM_md5_checksum_array(vr, ni, bpi, cdig);
        
/* read previous checksum */
            PD_read(file, path, rdig);
        
            CFREE(path);
        
/* return -1 and set PD_error if MD5 mismatch */
	    ok = _PD_cksum_compare(cdig, rdig);
	    if (ok == FALSE)
	       {rv = -1;

/* NOTE: this must be treated as generic because of the PD_read above */
		PD_error("MD5 CHECKSUM OF VARIABLE FAILED - _PD_CKSUM_VAR_READ",
			 PD_GENERIC);};};};
Beispiel #5
0
void *
PDBFileObject::ReadValues(const char *name, TypeEnum *t, int *nTotalElements,
    int **dimensions, int *nDims, int extraElements)
{
    void *retval = 0;

    if(AutoOpen())
    {
        //
        // Get information about the variable if it is in the file.
        //
        if(SymbolExists(name, t, nTotalElements, dimensions, nDims))
        {
            int nels = *nTotalElements + extraElements;

            //
            // Allocate memory for the variable.
            //
            switch(*t)
            {
            case CHAR_TYPE:
            case CHARARRAY_TYPE:
                retval = (void *)new char[nels];
                break;
            case SHORT_TYPE:
            case SHORTARRAY_TYPE:
                retval = (void *)new short[nels];
                break;
            case INTEGER_TYPE:
            case INTEGERARRAY_TYPE:
                retval = (void *)new int[nels];
                break;
            case FLOAT_TYPE:
            case FLOATARRAY_TYPE:
                retval = (void *)new float[nels];
                break;
            case DOUBLE_TYPE:
            case DOUBLEARRAY_TYPE:
                retval = (void *)new double[nels];
                break;
            case LONG_TYPE:
            case LONGARRAY_TYPE:
                retval = (void *)new long[nels];
                break;
            default:
                EXCEPTION1(InvalidVariableException, "unsupported type");
            }

            //
            // Try reading the variable from the file.
            //
            if(PD_read(pdb, (char *)name, retval) == FALSE)
            {
                debug4 << "PDBFileObject::ReadValues: PD_read failed for " << name
                       << ". " << PDBLIB_ERRORSTRING << endl;

                pdb_free_void_mem(retval, *t);
                retval = 0;
                *t = NO_TYPE;
                *nTotalElements = 0;
                free_mem(*dimensions);
                *dimensions = 0;
                *nDims = 0;
            }
        }
        else
        {
            debug4 << "PDBFileObject::ReadValues: Variable \"" << name
                   << "\" could not be located. " << PDBLIB_ERRORSTRING << endl;
        }
    }

    return retval;
}
Beispiel #6
0
int main(int c, char **v)
   {int i;
    float nonew[24];   /* these are all half the size of the */
    float middlew[24]; /* space that will be defent for them */
    float allw[24];    /* which will be of dim [2][6][4] */
    float allwstep[48]; 
    float allrstep[48]; 
    float zerostep[48]; 
    float noner[24];   /* over the course of three cases we */
    float middler[24]; /* write and read back non-contiguously, */
    float allr[24];    /* partially contiguously, and contiguously */
    float zero[24];
    PDBfile *file;

    debug_mode = FALSE;
    for (i = 1; i < c; i++)
        {if (v[i][0] == '-')
            {switch (v[i][1])
                {case 'd' :
		      debug_mode  = TRUE;
		      SC_gs.mm_debug = TRUE;
		      break;
                 case 'h' :
		      print_help();
		      return(1);
                 case 'v' :
                      PD_set_fmt_version(SC_stoi(v[++i]));
		      break;};}
         else
            break;};

    file = PD_open(DATA_FILE, "w+");
    if (file == NULL)
       {printf("Error creating %s\n", DATA_FILE);
	exit(1);};

/* initialize the write vars to some semi-arbitrary values */
    for (i = 0; i < 24; i++)
        {nonew[i]   = (float) i;
         middlew[i] = (float) i;
         allw[i]    = (float) i;
         zero[i]    = 0.0;
         noner[i]   = 0.0;
         middler[i] = 0.0;
         allr[i]    = 0.0;}; 


/* step == 1 CASES */

/* first case: NONE of the dimension descriptor describe contiguity */
    if (!PD_defent(file, "none[2,6,4]", "float"))
       {printf("PD_defent failed\n");
        exit(2);};

/* write out one "physics" variable such that there
 * are no contiguous regions to optimize on
 */
    if (!PD_write(file, "none[0:1, 0:5, 0:1]", "float", nonew))
       {printf("PD_write failed\n");
        exit(3);};

/* zero out the rest of it */
    if (!PD_write(file, "none[0:1, 0:5, 2:3]", "float", zero))
       {printf("PD_write failed\n");
        exit(3);};

/* read that variable back again such that there
 * are no contiguous regions to optimize on
 */
    if (!PD_read(file, "none[0:1, 0:5, 0:1]", noner))
       {printf("PD_read failed\n");
        exit(4);};

/* check it to make sure it is correct */
    for (i = 0; i < 24; i++)
        {if (fabsf(nonew[i] - noner[i]) > FLOAT_TOLERANCE)
            {printf("Error in check %f != %f ", nonew[i], noner[i]);
             printf("at position none[%d]\n", i); 
             PD_close(file);
             exit(-1);};};


/* second case: MIDDLE dimension contains contiguity */
    if (!PD_defent(file, "middle[2,6,4]", "float"))
       {printf("PD_defent failed\n");
        exit(5);};

/* write out on "physics" variable such that some 
 * partial contiguous regions exist to optimize upon
 */
    if (!PD_write(file, "middle[0:1, 3:5, 0:3]", "float", middlew))
       {printf("PD_write failed\n");
        exit(6);};

    if (!PD_write(file, "middle[0:1, 0:2, 0:3]", "float", zero))
       {printf("PD_write failed\n");
        exit(6);};

/* read that variable back again */
    if (!PD_read(file, "middle[0:1, 3:5, 0:3]", middler))
       {printf("PD_read failed\n");
        exit(7);};

/* check it to make sure it is correct */
    for (i = 0; i < 24; i++)
        {if (fabs(middlew[i] - middler[i]) > FLOAT_TOLERANCE)
            {printf("Error in check %f != %f ", middlew[i], middler[i]);
             printf("at position middle[%d]\n", i);
             PD_close(file);
             exit(-1);};};


/* third case: ALL of the region to write/read is contiguous */
    if (!PD_defent(file, "all[2,6,4]", "float"))
       {printf("PD_defent failed\n");
        exit(8);};

/* write out on "physics" variable such that the  
 * entire region is contiguous to check full optimization 
 */
    if (!PD_write(file, "all[0:0, 0:5, 0:3]", "float", allw))
       {printf("PD_write failed\n");
        exit(9);};

    if (!PD_write(file, "all[1:1, 0:5, 0:3]", "float", zero))
       {printf("PD_write failed\n");
        exit(9);};

/* read that variable back again */
    if (!PD_read(file, "all[0:0, 0:5, 0:3]", allr))
       {printf("PD_read failed\n");
        exit(10);};

/* check it to make sure it is correct */
    for (i = 0; i < 24; i++)
        {if (fabs(allw[i] - allr[i]) > FLOAT_TOLERANCE)
            {printf("Error in check %f != %f ", allw[i], allr[i]);
             printf("at position all[%d]\n", i); 
             PD_close(file);
             exit(-1);};};


/* step != 1 CASES */

/* first case: NONE of the dimension descriptor describe contiguity */
    if (!PD_defent(file, "nonestep[2,6,4]", "float"))
       {printf("PD_defent failed\n");
        exit(2);};

/* write out one "physics" variable such that there
 * are no contiguous regions to optimize on
 */
    if (!PD_write(file, "nonestep[0:1, 0:5, 1:3:2]", "float", nonew))
       {printf("PD_write failed\n");
        exit(3);};

/* zero out the rest of it */
    if (!PD_write(file, "nonestep[0:1, 0:5, 0:2:2]", "float", zero))
       {printf("PD_write failed\n");
        exit(3);};

/* read that variable back again such that there
 * are no contiguous regions to optimize on
 */
    if (!PD_read(file, "nonestep[0:1, 0:5, 1:3:2]", noner))
       {printf("PD_read failed\n");
        exit(4);};

/* check it to make sure it is correct */
    for (i = 0; i < 24; i++)
        {if (fabs(nonew[i] - noner[i]) > FLOAT_TOLERANCE)
            {printf("Error in check %f != %f ", nonew[i], noner[i]);
             printf("at position nonestep[%d]\n", i);
             PD_close(file);
             exit(-1);};};


/* second case: MIDDLE dimension contains step; 3rd dim is contiguity */
    if (!PD_defent(file, "middlestep[2,6,4]", "float"))
       {printf("PD_defent failed\n");
        exit(5);};

/* write out on "physics" variable such that some
 * partial contiguous regions exist to optimize upon
 */
    if (!PD_write(file, "middlestep[0:1, 1:5:2, 0:3]", "float", middlew))
       {printf("PD_write failed\n");
        exit(6);};

    if (!PD_write(file, "middlestep[0:1, 0:4:2, 0:3]", "float", zero))
       {printf("PD_write failed\n");
        exit(6);};

/* read that variable back again */
    if (!PD_read(file, "middlestep[0:1, 1:5:2, 0:3]", middler))
       {printf("PD_read failed\n");
        exit(7);};

/* check it to make sure it is correct */
    for (i = 0; i < 24; i++)
        {if (fabs(middlew[i] - middler[i]) > FLOAT_TOLERANCE)
            {printf("Error in check %f != %f ", middlew[i], middler[i]);
             printf("at position middlestep[%d]\n", i);
             PD_close(file);
             exit(-1);};};


/* third case: OUTTER dim steps, hence only 2nd dim in is contiguous
 *             This is the only step != 1 case that causes optimization
 */
    for (i = 0; i < 48; i++)
        {allwstep[i] = (float) i;
         allrstep[i] = 0.0; 
         zerostep[i] = 0.0;};

    if (!PD_defent(file, "allstep[4,6,4]", "float"))
       {printf("PD_defent failed\n");
        exit(8);};

/* write out on "physics" variable such that the
 * entire region is contiguous to check full optimization
 */
    if (!PD_write(file, "allstep[0:2:2, 0:5, 0:3]", "float", allwstep))
       {printf("PD_write failed\n");
        exit(9);};

    if (!PD_write(file, "allstep[1:3:2, 0:5, 0:3]", "float", zerostep))
       {printf("PD_write failed\n");
        exit(9);};

/* read that variable back again */
    if (!PD_read(file, "allstep[0:2:2, 0:5, 0:3]", allrstep))
       {printf("PD_read failed\n");
        exit(10);};

/* check it to make sure it is correct */
    for (i = 0; i < 24; i++)
        {if (fabs(allwstep[i] - allrstep[i]) > FLOAT_TOLERANCE)
            {printf("Error in check %f != %f ", allwstep[i], allrstep[i]);
             printf("at position allstep[%d]\n", i);
             PD_close(file);
             exit(-1);};};

    PD_close(file);

    SC_remove(DATA_FILE);

    exit(0);}