Exemple #1
0
int pioReadAttributeDouble (PIOObject pioObject,
							const char* attr_name, double* attr_value)
{
	if (pioHasAttribute(pioObject, attr_name))
	{
		H5LTget_attribute_double(pioObject.identifier, ".",
								 attr_name, attr_value);	
		return 1;
	} 
	else {
		return -1;
	}
}
Exemple #2
0
int_f
nh5ltget_attribute_double_c(hid_t_f *loc_id,
                            int_f *namelen,
                            _fcd dsetname,
                            int_f *attrnamelen,
                            _fcd attrname,
                            void *buf)
{
    int     ret_value = -1;
    herr_t  ret;
    hid_t   c_loc_id;
    char    *c_name = NULL;
    char    *c_attrname = NULL;
    int     c_namelen;
    int     c_attrnamelen;

    /*
    * convert FORTRAN name to C name
    */
    c_namelen = (int)*namelen;
    c_name = (char *)HD5f2cstring(dsetname, c_namelen);
    if (c_name == NULL) 
        goto done;

    c_attrnamelen = (int)*attrnamelen;
    c_attrname = (char *)HD5f2cstring(attrname, c_attrnamelen);
    if (c_attrname == NULL) 
        goto done;

    /*
    * call H5LTget_attribute_int function.
    */
    c_loc_id = (hid_t)*loc_id;

    ret = H5LTget_attribute_double(c_loc_id,c_name,c_attrname,buf);

    if (ret < 0) 
        goto done;

    ret_value = 0;


done:
    if(c_name!=NULL)
        free(c_name);
    if(c_attrname!=NULL)
        free(c_attrname);

    return ret_value;
}
Exemple #3
0
static herr_t make_attributes( hid_t loc_id, const char* obj_name )
{

    int         rank_out;
    hsize_t     *dims_out = 0;
    H5T_class_t type_class;
    size_t      type_size;
    int         i;

    char    attr_str_in[]     = {"My attribute"};
    char    attr_str_out[20];
    char    attr_char_in[5]   = {1,2,3,4,5};
    char    attr_char_out[5];
    short   attr_short_in[5]  = {1,2,3,4,5};
    short   attr_short_out[5];
    int     attr_int_in[5]    = {1,2,3,4,5};
    int     attr_int_out[5];
    long    attr_long_in[5]   = {1,2,3,4,5};
    long    attr_long_out[5];
    float   attr_float_in[5]  = {1,2,3,4,5};
    float   attr_float_out[5];
    double  attr_double_in[5] = {1,2,3,4,5};
    double  attr_double_out[5];
    unsigned char    attr_uchar_in[5]   = {1,2,3,4,5};
    unsigned char    attr_uchar_out[5];
    unsigned short   attr_ushort_in[5]  = {1,2,3,4,5};
    unsigned short   attr_ushort_out[5];
    unsigned int     attr_uint_in[5]    = {1,2,3,4,5};
    unsigned int     attr_uint_out[5];
    unsigned long    attr_ulong_in[5]   = {1,2,3,4,5};
    unsigned long    attr_ulong_out[5];

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_string test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_string");

    /* Set the attribute */
    if ( H5LTset_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_in ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_string test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_string");


    /* Get the attribute */
    if ( H5LTget_attribute_string( loc_id, obj_name, ATTR1_NAME, attr_str_out ) < 0 )
        return -1;

    if ( strcmp( attr_str_in, attr_str_out ) != 0 )
    {
        return -1;
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_char test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_char");

    /* Set the attribute */
    if ( H5LTset_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_char test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_char");

    /* Get the attribute */
    if ( H5LTget_attribute_char( loc_id, obj_name, ATTR2_NAME, attr_char_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_char_in[i] != attr_char_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR2_NAME, H5T_NATIVE_CHAR, attr_char_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_char_in[i] != attr_char_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_short test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_short");

    /* Set the attribute */
    if ( H5LTset_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_short test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_short");

    /* Get the attribute */
    if ( H5LTget_attribute_short( loc_id, obj_name, ATTR3_NAME, attr_short_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_short_in[i] != attr_short_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR3_NAME, H5T_NATIVE_SHORT, attr_short_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_short_in[i] != attr_short_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_int");

    /* Set the attribute */
    if ( H5LTset_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_int");

    /* Get the attribute */
    if ( H5LTget_attribute_int( loc_id, obj_name, ATTR4_NAME, attr_int_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_int_in[i] != attr_int_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR4_NAME, H5T_NATIVE_INT, attr_int_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_int_in[i] != attr_int_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_long");

    /* Set the attribute */
    if ( H5LTset_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_long");

    /* Get the attribute */
    if ( H5LTget_attribute_long( loc_id, obj_name, ATTR5_NAME, attr_long_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_long_in[i] != attr_long_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR5_NAME, H5T_NATIVE_LONG, attr_long_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_long_in[i] != attr_long_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_uchar test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_uchar");

    /* Set the attribute */
    if ( H5LTset_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_uchar test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_uchar");

    /* Get the attribute */
    if ( H5LTget_attribute_uchar( loc_id, obj_name, ATTR6_NAME, attr_uchar_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR6_NAME, H5T_NATIVE_UCHAR, attr_uchar_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uchar_in[i] != attr_uchar_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_ushort test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_ushort");

    /* Set the attribute */
    if ( H5LTset_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_ushort test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_ushort");

    /* Get the attribute */
    if ( H5LTget_attribute_ushort( loc_id, obj_name, ATTR7_NAME, attr_ushort_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR7_NAME, H5T_NATIVE_USHORT, attr_ushort_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ushort_in[i] != attr_ushort_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_uint");

    /* Set the attribute */
    if ( H5LTset_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_int test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_uint");

    /* Get the attribute */
    if ( H5LTget_attribute_uint( loc_id, obj_name, ATTR8_NAME, attr_uint_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uint_in[i] != attr_uint_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR8_NAME, H5T_NATIVE_UINT, attr_uint_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_uint_in[i] != attr_uint_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_ulong test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_ulong");

    /* Set the attribute */
    if ( H5LTset_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_long test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_ulong");

    /* Get the attribute */
    if ( H5LTget_attribute_ulong( loc_id, obj_name, ATTR9_NAME, attr_ulong_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR9_NAME, H5T_NATIVE_ULONG, attr_ulong_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_ulong_in[i] != attr_ulong_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTset_attribute_float test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_float");

    /* Set the attribute */
    if ( H5LTset_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_float test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_float");


    /* Get the attribute */
    if ( H5LTget_attribute_float( loc_id, obj_name, ATTR10_NAME, attr_float_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_float_in[i] != attr_float_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR10_NAME, H5T_NATIVE_FLOAT, attr_float_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_float_in[i] != attr_float_out[i] ) {
            return -1;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTset_attribute_double test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTset_attribute_double");

    /* Set the attribute */
    if ( H5LTset_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_in, (size_t)5 ) < 0 )
        return -1;

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_double test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_double");

    /* Get the attribute */
    if ( H5LTget_attribute_double( loc_id, obj_name, ATTR11_NAME, attr_double_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_double_in[i] != attr_double_out[i] ) {
            return -1;
        }
    }

    /* Get the attribute */
    if ( H5LTget_attribute( loc_id, obj_name, ATTR11_NAME, H5T_NATIVE_DOUBLE, attr_double_out ) < 0 )
        return -1;

    for (i = 0; i < 5; i++)
    {
        if ( attr_double_in[i] != attr_double_out[i] ) {
            return -1;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTget_attribute_ndims test
    *-------------------------------------------------------------------------
    */


    TESTING("H5LTget_attribute_ndims");

    if ( H5LTget_attribute_ndims( loc_id, obj_name, ATTR2_NAME, &rank_out ) < 0 )
        return -1;

    if ( rank_out != 1 ) {
        return -1;
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTget_attribute_info test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTget_attribute_info");

    dims_out = (hsize_t*) malloc( sizeof(hsize_t) * rank_out );

    if ( H5LTget_attribute_info( loc_id, obj_name, ATTR2_NAME, dims_out, &type_class,
        &type_size) < 0 )
        return -1;

    for (i = 0; i < rank_out; i++)
    {
        if ( dims_out[i] != 5 ) {
            return -1;
        }
    }

    if ( type_class != H5T_INTEGER ) {
        return -1;
    }

    if ( dims_out )
        free( dims_out );

    PASSED();

    return 0;
}
Exemple #4
0
int main(int argc, char *argv[]) {
  progname = argv[0];
  int show_usage = 0;
  int outrate = 1, timesteps = 17;
  char *infile = NULL, *prefix = NULL;
  int optc;
  while ((optc = getopt_long(argc, argv, GETOPTS, long_opts, NULL)) != -1) {
    switch (optc) {
      case 'i':
        if (infile != NULL) {
          free(infile);
        }
        infile = strdup(optarg);
        break;
      case 'p':
        if (prefix != NULL) {
          free(prefix);
        }
        prefix = strdup(optarg);
        break;
      case 'r':
        outrate = atoi(optarg);
        break;
      case 't':
        timesteps = atoi(optarg);
        if (timesteps < 1) {
          fprintf(stderr, "Invalid value for timesteps: %s, must be a number greater than 1.\n", optarg);
          show_usage = 1;
        }
        break;
      default:
          show_usage = 1;
    }
  }
  if (show_usage == 1 || optind < argc || infile == NULL || prefix == NULL) {
    print_usage();
    return EXIT_FAILURE;
  }
  // READ FILE
  hsize_t dims[2];
  hid_t file_id;
  if ((file_id = H5Fopen(infile, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
    print_usage();
    return EXIT_FAILURE;
  }
  if (H5LTget_dataset_info(file_id, CCILK_DATASET, dims, NULL, NULL) < 0) {
    print_usage();
    return EXIT_FAILURE;
  }
  size_t rows = dims[0];
  size_t cols = dims[1];
  double *data = malloc(rows * cols * sizeof(double));
  double *next = malloc(rows * cols * sizeof(double));
  double width, depth, nu, sigma; 
  if (H5LTread_dataset_double(file_id, CCILK_DATASET, data) < 0
   || H5LTget_attribute_double(file_id, "/domain/", "width", &width) < 0 
   || H5LTget_attribute_double(file_id, "/domain/", "depth", &depth) < 0 
   || H5LTget_attribute_double(file_id, "/properties/", "nu", &nu) < 0 
   || H5LTget_attribute_double(file_id, "/properties/", "sigma", &sigma) < 0) {
    fprintf(stderr, "Encountered an issue reading the dataset\n");
    return EXIT_FAILURE;
  };

  printf("Width: %f dept %f\n", width, depth);

  simulate(data, next, rows, cols, width, depth, nu, sigma, outrate, timesteps, prefix);
  free(data);
  H5Fclose(file_id);
  return EXIT_SUCCESS;
}
/*----------------------------------------------------------------------
 NAME:                     read_epoch_time

 PURPOSE:  Reads the requested epoch time attribute from the ancillary
           data file

 RETURNS:  Integer status code of SUCCESS or ERROR

-------------------------------------------------------------------------*/
static int read_epoch_time
(
    hid_t hdf_file_id,       /* I:  Open ancillary data file handle */
    const char *epoch_name,  /* I:  Epoch time name  */
    double epoch_time[3]     /* O:  Array containing epoch time components */
)
{
    herr_t hdf_error_status = -1;    /* HDF5 error status code    */

    hsize_t epoch_dims = 0;          /* Epoch array dimension */

    H5T_class_t type_class;          /* Type class identifier */

    size_t type_size = 0;            /* Size of datatype in bytes */

    int rank = 0;                    /* Number of dimensions for the
                                        epoch time attribute   */


    /* Verify the epoch time array attribute has an array dimension of 1 */
    hdf_error_status = H5LTget_attribute_ndims(hdf_file_id, "/",
        epoch_name, &rank);
    if (hdf_error_status < 0)
    {
        IAS_LOG_ERROR("Retrieving epoch time attribute dimensions");
        return ERROR;
    }
    if (rank != 1)      /* Should only be 1D array */
    {
        IAS_LOG_ERROR("Invalid rank %d detected for epoch time array, "
            "should be 1", rank);
        return ERROR;
    }

    /* The epoch time attribute should be a 1D, 3-element array of datatype
       double */
    hdf_error_status = H5LTget_attribute_info(hdf_file_id, "/",
        epoch_name, &epoch_dims, &type_class, &type_size);
    if ((hdf_error_status < 0) || (epoch_dims != 3)
            || (type_class != H5T_FLOAT)
            || (type_size != sizeof(double)))
    {
        IAS_LOG_ERROR("Invalid epoch time array dimensions/datatype class/"
            "datatype size information");
        return ERROR;
    }

    /* Now get the epoch time components */
    hdf_error_status = H5LTget_attribute_double(hdf_file_id, "/",
        epoch_name, epoch_time);
    if (hdf_error_status < 0)
    {
        IAS_LOG_ERROR("Retrieving epoch time attribute values");
        return ERROR;
    }

   

    /* Done */
    return SUCCESS;
}
Exemple #6
0
int SpIO_FreadModel(const SpFile *sfp, const SpFile *popsfp, SpModel *model, int *read_pops)
{
	int status = 0;

	Deb_ASSERT(model->parms.mol == NULL);
	Deb_ASSERT(model->grid == NULL);
#if 1
        /* pre-check format version */
        if(!status){
                const char *default_format = "SPARX format v3";
                char *format = NULL;
                
                status = SpIO_H5GetAttribute_string(sfp->h5f_id, "/", "format", &format);
                if(strncmp(format, default_format, strlen("SPARX format v3"))){
                        printf("The format is not '%s' (%s)\n", default_format, format);
                        status = 1;
                }
                free(format);
        }
#endif 

        /* Read coordinate name */
        if(!status){
                char *coordinate = NULL;
                status = SpIO_H5GetAttribute_string(sfp->h5f_id, "/", "geom", &coordinate);
                /* Load molecule if present */
                if(strlen(coordinate) > 0) {
                        DatINode *geom = Dat_IList_NameLookup(GEOM_TYPES, coordinate);
                        model->parms.geom = geom->idx;
                }
                free(coordinate);
        }

        herr_t hstatus;

        /* Read T_cmb */
        if(!status) {
                hstatus = H5LTget_attribute_double(sfp->h5f_id, "/", "T_cmb", &model->parms.T_cmb);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read T_in */
        if(!status) {
                hstatus = H5LTget_attribute_double(sfp->h5f_id, "/", "T_in", &model->parms.T_in);
                if(hstatus < 0)
                        status = 1;
        }
	/* Read molecule name */
	if(!status){
                char *mol_name = NULL;
		status = SpIO_H5GetAttribute_string(sfp->h5f_id, "/", "molec", &mol_name);

                /* Load molecule if present */
                if(strlen(mol_name) > 0) {
                        if(!(model->parms.mol = SpIO_FreadMolec(mol_name)))
                                status = 1;
                }
                free(mol_name);
        }

        /* Read pops-switch */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "pops", &model->parms.pops);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read dust-switch */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "dust", &model->parms.dust);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read polariz-switch */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "polariz", &model->parms.polariz);
                if(hstatus < 0)
                        status = 1;
        }
        /* Read z (zeeman splitting) factor */
        if(!status) {
                hstatus = H5LTget_attribute_int(sfp->h5f_id, "/", "z", &model->parms.z);
                if(hstatus < 0)
                        status = 1;
        }

#if 0 
	/* Set velocity field: the "velfield" attribute is expected
	 * to contain a Python function named "Vgas((x1,x2,x3),(min1,min2,min3),(max1,max2,max3)" where
	 * (x1,x2,x3) are the three coordinates of the ray position, (min1,min2,min3) are the lower
	 * bounds of the bounding box, and (max1,max2,max3) are the upper baounds of the bounding
	 * box. An example Vgas function would be:
	 * def Vgas((x1, x2, x3), (min1, min2, min3), (max1, max2, max3)):"
	 *	return [0,0,0]"
	 */
	if(!status) {
                char *velfield = NULL;
		//if(!strncmp(velfield, "grid", strlen(velfield))) {
		if(!strncmp(velfield, "grid", strlen("grid"))) {
			model->parms.velfield = NULL;
		}
		else {
			status = PyRun_SimpleString(velfield);
			PyObject *__main__ = NULL, *ret = NULL;
			__main__ = PyImport_AddModule("__main__");
			model->parms.velfield = PyObject_GetAttrString(__main__, "Vgas");
			Py_INCREF(model->parms.velfield);
			/* Try calling the function and make sure it returns a sequence of length 3 */
                        char format[] = "(d,d,d),(d,d,d),(d,d,d)";
			ret = PyObject_CallFunction(model->parms.velfield, format, 0, 0, 0, 0, 0, 0, 0, 0, 0);
			if(!PySequence_Check(ret)) {
				PyWrErr_SetString(PyExc_Exception, "Vgas() does not return a vector!");
				status = 1;
			}
		}
		
		free(velfield);
	}
#endif


	/* Load grid */	
	if(!status)
		status = 
		SpIO_H5ReadGrid( 
                        sfp->h5f_id, 
                        (*read_pops) ? popsfp->h5f_id : NULL, 
                        &model->grid, 
                        &model->parms, 
                        read_pops
                );
	/* Cleanup */		

	if(status)
		PyWrErr_SetString(PyExc_Exception, "Error reading model from file `%s'", sfp->name);

	return status;
}