Ejemplo n.º 1
0
Archivo: fclib.c Proyecto: xhub/fclib
/** read problem info */
static struct fclib_info* read_problem_info (hid_t id)
{
  struct fclib_info *info;
  H5T_class_t class_id;
  hsize_t dim;
  size_t size;

  MM (info = malloc (sizeof (struct fclib_info)));

  if (H5LTfind_dataset (id, "title"))
  {
    IO (H5LTget_dataset_info  (id, "title", &dim, &class_id, &size));
    MM (info->title = malloc (sizeof (char [size])));
    IO (H5LTread_dataset_string (id, "title", info->title));
  }
  else info->title = NULL;

  if (H5LTfind_dataset (id, "description"))
  {
    IO (H5LTget_dataset_info  (id, "description", &dim, &class_id, &size));
    MM (info->description = malloc (sizeof (char [size])));
    IO (H5LTread_dataset_string (id, "description", info->description));
  }
  else info->description = NULL;

  if (H5LTfind_dataset (id, "math_info"))
  {
    IO (H5LTget_dataset_info  (id, "math_info", &dim, &class_id, &size));
    MM (info->math_info = malloc (sizeof (char [size])));
    IO (H5LTread_dataset_string (id, "math_info", info->math_info));
  }
  else info->math_info = NULL;

  return info;
}
int read_input_config(char *input_file, struct input_config *cfg) {
    herr_t   err = 0;
    size_t   type_size;
    hid_t    input_file_id;
    void    *p = NULL;

    cfg->rng_family            = NULL;
    cfg->levy_seed_family      = NULL;
    cfg->levy_seed_parameters  = NULL;
    cfg->levy_basis_dimension  = NULL;
    cfg->levy_basis_resolution = NULL;
    
    input_file_id = H5Fopen(input_file, H5F_ACC_RDONLY, H5P_DEFAULT);
        
    err = H5LTget_dataset_info(input_file_id, "/rng_family", NULL, NULL, &type_size);
    cfg->rng_family = malloc(type_size * sizeof(char));
    err = H5LTread_dataset_string(input_file_id, "/rng_family", cfg->rng_family);
    
    err = H5LTread_dataset_int(input_file_id, "/rng_seed", &cfg->rng_seed);
    
    err = H5LTget_dataset_info(input_file_id, "/levy_seed_family", NULL, NULL, &type_size);
    cfg->levy_seed_family = malloc(type_size * sizeof(char));
    err = H5LTread_dataset_string(input_file_id, "/levy_seed_family", cfg->levy_seed_family);

    err = H5LTread_dataset_int(input_file_id, "/levy_seed_dimension", &cfg->levy_seed_dimension);
    
    if (strcmp(cfg->levy_seed_family, "normal") == 0) {
        p = (struct normal_seed_parameters *)malloc(sizeof(struct normal_seed_parameters));
        err = read_normal_seed_parameters(input_file_id, p);
        cfg->levy_seed_parameters = (void *)p;
    }
    else if (strcmp(cfg->levy_seed_family, "generalised hyperbolic") == 0) {
        printf("Error: GH not yet supported.\n");
        err = -1;
        goto cleanup;
    }
    else {
        printf("Error: Unsupported Levy seed.\n");
        err = -1;
        goto cleanup;
    }
    
    err = H5LTread_dataset_int(input_file_id, "/levy_basis_rank", &cfg->levy_basis_rank);
    cfg->levy_basis_dimension = malloc(cfg->levy_basis_rank * sizeof(int));
    cfg->levy_basis_resolution = malloc(cfg->levy_basis_rank * sizeof(double));
    err = H5LTread_dataset_int(input_file_id, "/levy_basis_dimension", cfg->levy_basis_dimension);
    err = H5LTread_dataset_double(input_file_id, "/levy_basis_resolution", cfg->levy_basis_resolution);
    
  cleanup:
    if (input_file_id >= 0) H5Fclose(input_file_id);
    return (int)err;
}
Ejemplo n.º 3
0
int_f
nh5ltread_dataset_string_c (hid_t_f *loc_id,
                            int_f *namelen,
                            _fcd name,
                            char *buf)
{
 int     ret_value = -1;
 herr_t  ret;
 hid_t   c_loc_id;
 char    *c_name;
 int     c_namelen;

/*
 * Convert FORTRAN name to C name
 */
 c_namelen = *namelen;
 c_name = (char *)HD5f2cstring(name, c_namelen);
 if (c_name == NULL) return ret_value;

/*
 * Call H5LTread_dataset_string function.
 */
 c_loc_id = (hid_t)*loc_id;

 ret = H5LTread_dataset_string(c_loc_id,c_name,buf);

 if (ret < 0) return ret_value;
 ret_value = 0;
 return ret_value;
}
Ejemplo n.º 4
0
/*--------------------------------------------------------------*/
static void validateDependsOn(pNXVcontext self, hid_t groupID,
	hid_t fieldID)
{
	char fname[512], dpData[1024];
	hid_t h5type, dpfieldID;
	H5T_class_t h5class;

	memset(fname,0,sizeof(fname));
	memset(dpData,0,sizeof(dpData));
	H5Iget_name(fieldID,fname,sizeof(fname));
	NXVsetLog(self,"dataPath",fname);
	NXVsetLog(self,"sev","debug");
	NXVprintLog(self,"message","Validating depends_on chain starting at %s",
						fname);
	NXVlog(self);

	/*
		test that the depends_on field is of the right type
	*/
	h5type = H5Dget_type(fieldID);
	h5class = H5Tget_class(h5type);
	H5Tclose(h5type);
	if(h5class != H5T_STRING){
			NXVsetLog(self,"sev","error");
			NXVsetLog(self,"message",
			"depends_on field is of wrong type, expect string");
			NXVlog(self);
			self->errCount++;
			return;
	}

	/*
		read the field
	*/
	H5LTread_dataset_string(groupID,"depends_on",dpData);

	/*
		find the field and start iterating through the chain
	*/

	dpfieldID = findDependentField(self,fieldID,dpData);
	if(dpfieldID < 0){
		NXVsetLog(self,"sev","error");
		NXVprintLog(self,"message",
		"Cannot even find the starting point of the depends_on chain, %s",
		dpData);
		NXVlog(self);
		self->errCount++;
		return;
	} else {
		validateDependsOnField(self,groupID,dpfieldID);
		H5Dclose(dpfieldID);
	}

}
Ejemplo n.º 5
0
Archivo: hdf5.cpp Proyecto: jofeu/caffe
string hdf5_load_string(hid_t loc_id, const string& dataset_name) {
  // Get size of dataset
  size_t size;
  H5T_class_t class_;
  herr_t status = \
    H5LTget_dataset_info(loc_id, dataset_name.c_str(), NULL, &class_, &size);
  CHECK_GE(status, 0) << "Failed to get dataset info for " << dataset_name;
  char *buf = new char[size];
  status = H5LTread_dataset_string(loc_id, dataset_name.c_str(), buf);
  CHECK_GE(status, 0)
    << "Failed to load int dataset with name " << dataset_name;
  string val(buf);
  delete[] buf;
  return val;
}
Ejemplo n.º 6
0
int_f
h5ltread_dataset_string_c (hid_t_f *loc_id,
                            size_t_f *namelen,
                            _fcd name,
                            char *buf)
{
    int     ret_value = -1;
    herr_t  ret;
    hid_t   c_loc_id;
    char    *c_name = NULL;

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

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

    ret = H5LTread_dataset_string(c_loc_id,c_name,buf);

    if (ret < 0)
        goto done;

    ret_value = 0;

done:
    if(c_name!=NULL)
        HDfree(c_name);

    return ret_value;
}
Ejemplo n.º 7
0
void stfio::importHDF5File(const std::string& fName, Recording& ReturnData, ProgressInfo& progDlg) {
    /* Create a new file using default properties. */
    hid_t file_id = H5Fopen(fName.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
    
    /* H5TBread_table
       const int NRECORDS = 1;*/
    const int NFIELDS    = 3;

    /* Calculate the size and the offsets of our struct members in memory */
    size_t rt_offset[NFIELDS] = {  HOFFSET( rt, channels ),
                                   HOFFSET( rt, date ),
                                   HOFFSET( rt, time )};
    rt rt_buf[1];
    size_t rt_sizes[NFIELDS] = { sizeof( rt_buf[0].channels),
                                 sizeof( rt_buf[0].date),
                                 sizeof( rt_buf[0].time)};
    herr_t status=H5TBread_table( file_id, "description", sizeof(rt), rt_offset, rt_sizes, rt_buf );
    if (status < 0) {
        std::string errorMsg("Exception while reading description in stfio::importHDF5File");
        throw std::runtime_error(errorMsg);
    }
    int numberChannels =rt_buf[0].channels;
    if ( ReturnData.SetDate(rt_buf[0].date)
      || ReturnData.SetTime(rt_buf[0].time) ) {
        std::cout << "Warning HDF5: could not decode date/time " << rt_buf[0].date << " " << rt_buf[0].time << std::endl;
    }



    /* Create the data space for the dataset. */
    hsize_t dims;
    H5T_class_t class_id;
    size_t type_size;

    std::string description, comment;
    hid_t group_id = H5Gopen2(file_id, "/comment", H5P_DEFAULT);
    status = H5Lexists(group_id, "/comment/description", 0);
    if (status==1) {
        status = H5LTget_dataset_info( file_id, "/comment/description", &dims, &class_id, &type_size );
        if (status >= 0) {
            description.resize( type_size );
            status = H5LTread_dataset_string (file_id, "/comment/description", &description[0]);
            if (status < 0) {
                std::string errorMsg("Exception while reading description in stfio::importHDF5File");
                throw std::runtime_error(errorMsg);
            }
        }
    }
    ReturnData.SetFileDescription(description);
    
    status = H5Lexists(group_id, "/comment/comment", 0);
    if (status==1) {
        status = H5LTget_dataset_info( file_id, "/comment/comment", &dims, &class_id, &type_size );
        if (status >= 0) {
            comment.resize( type_size );
            status = H5LTread_dataset_string (file_id, "/comment/comment", &comment[0]);
            if (status < 0) {
                std::string errorMsg("Exception while reading comment in stfio::importHDF5File");
                throw std::runtime_error(errorMsg);
            }
        }
    }
    ReturnData.SetComment(comment);

    double dt = 1.0;
    std::string yunits = "";
    for (int n_c=0;n_c<numberChannels;++n_c) {
        /* Calculate the size and the offsets of our struct members in memory */
        size_t ct_offset[NFIELDS] = { HOFFSET( ct, n_sections ) };
        ct ct_buf[1];
        size_t ct_sizes[NFIELDS] = { sizeof( ct_buf[0].n_sections) };

        /* Read channel name */
        hsize_t cdims;
        H5T_class_t cclass_id;
        size_t ctype_size;
        std::ostringstream desc_path;
        desc_path << "/channels/ch" << (n_c);
        status = H5LTget_dataset_info( file_id, desc_path.str().c_str(), &cdims, &cclass_id, &ctype_size );
        if (status < 0) {
            std::string errorMsg("Exception while reading channel in stfio::importHDF5File");
            throw std::runtime_error(errorMsg);
        }
        hid_t string_typec= H5Tcopy( H5T_C_S1 );
        H5Tset_size( string_typec,  ctype_size );
        std::vector<char> szchannel_name(ctype_size);
        // szchannel_name.reset( new char[ctype_size] );
        status = H5LTread_dataset(file_id, desc_path.str().c_str(), string_typec, &szchannel_name[0] );
        if (status < 0) {
            std::string errorMsg("Exception while reading channel name in stfio::importHDF5File");
            throw std::runtime_error(errorMsg);
        }
        std::ostringstream channel_name;
        for (std::size_t c=0; c<ctype_size; ++c) {
            channel_name << szchannel_name[c];
        }

        std::ostringstream channel_path;
        channel_path << "/" << channel_name.str();

        hid_t channel_group = H5Gopen2(file_id, channel_path.str().c_str(), H5P_DEFAULT );
        status=H5TBread_table( channel_group, "description", sizeof(ct), ct_offset, ct_sizes, ct_buf );
        if (status < 0) {
            std::string errorMsg("Exception while reading channel description in stfio::importHDF5File");
            throw std::runtime_error(errorMsg);
        }
        Channel TempChannel(ct_buf[0].n_sections);
        TempChannel.SetChannelName( channel_name.str() );
        int max_log10 = 0;
        if (ct_buf[0].n_sections > 1) {
            max_log10 = int(log10((double)ct_buf[0].n_sections-1.0));
        }

        for (int n_s=0; n_s < ct_buf[0].n_sections; ++n_s) {
            int progbar =
                // Channel contribution:
                (int)(((double)n_c/(double)numberChannels)*100.0+
                      // Section contribution:
                      (double)(n_s)/(double)ct_buf[0].n_sections*(100.0/numberChannels));
            std::ostringstream progStr;
            progStr << "Reading channel #" << n_c + 1 << " of " << numberChannels
                    << ", Section #" << n_s+1 << " of " << ct_buf[0].n_sections;
            progDlg.Update(progbar, progStr.str());
            
            // construct a number with leading zeros:
            int n10 = 0;
            if (n_s > 0) {
                n10 = int(log10((double)n_s));
            }
            std::ostringstream strZero; strZero << "";
            for (int n_z=n10; n_z < max_log10; ++n_z) {
                strZero << "0";
            }

            // construct a section name:
            std::ostringstream section_name;
            section_name << "sec" << n_s;

            // create a child group in the channel:
            std::ostringstream section_path;
            section_path << channel_path.str() << "/" << "section_" << strZero.str() << n_s;
            hid_t section_group = H5Gopen2(file_id, section_path.str().c_str(), H5P_DEFAULT );

            std::ostringstream data_path; data_path << section_path.str() << "/data";
            hsize_t sdims;
            H5T_class_t sclass_id;
            size_t stype_size;
            status = H5LTget_dataset_info( file_id, data_path.str().c_str(), &sdims, &sclass_id, &stype_size );
            if (status < 0) {
                std::string errorMsg("Exception while reading data information in stfio::importHDF5File");
                throw std::runtime_error(errorMsg);
            }
            Vector_float TempSection(sdims);
            status = H5LTread_dataset(file_id, data_path.str().c_str(), H5T_IEEE_F32LE, &TempSection[0]);
            if (status < 0) {
                std::string errorMsg("Exception while reading data in stfio::importHDF5File");
                throw std::runtime_error(errorMsg);
            }

            Section TempSectionT(TempSection.size(), section_name.str());
            for (std::size_t cp = 0; cp < TempSectionT.size(); ++cp) {
                TempSectionT[cp] = double(TempSection[cp]);
            }
            // std::copy(TempSection.begin(),TempSection.end(),&TempSectionT[0]);
            try {
                TempChannel.InsertSection(TempSectionT,n_s);
            }
            catch (...) {
                throw;
            }


            /* H5TBread_table
               const int NSRECORDS = 1; */
            const int NSFIELDS    = 3;

            /* Calculate the size and the offsets of our struct members in memory */
            size_t st_offset[NSFIELDS] = {  HOFFSET( st, dt ),
                                            HOFFSET( st, xunits ),
                                            HOFFSET( st, yunits )};
            st st_buf[1];
            size_t st_sizes[NSFIELDS] = { sizeof( st_buf[0].dt),
                                          sizeof( st_buf[0].xunits),
                                          sizeof( st_buf[0].yunits)};
            status=H5TBread_table( section_group, "description", sizeof(st), st_offset, st_sizes, st_buf );
            if (status < 0) {
                std::string errorMsg("Exception while reading data description in stfio::importHDF5File");
                throw std::runtime_error(errorMsg);
            }
            dt = st_buf[0].dt;
            yunits = st_buf[0].yunits;
            H5Gclose( section_group );
        }
        try {
            if ((int)ReturnData.size()<numberChannels) {
                ReturnData.resize(numberChannels);
            }
            ReturnData.InsertChannel(TempChannel,n_c);
            ReturnData[n_c].SetYUnits( yunits );
        }
        catch (...) {
            ReturnData.resize(0);
            throw;
        }
        H5Gclose( channel_group );
    }
    ReturnData.SetXScale(dt);
    /* Terminate access to the file. */
    status = H5Fclose(file_id);
    if (status < 0) {
        std::string errorMsg("Exception while closing file in stfio::importHDF5File");
        throw std::runtime_error(errorMsg);
    }

    /* Release all hdf5 resources */
    status = H5close();
    if (status < 0) {
        std::string errorMsg("Exception while closing file in stfio::exportHDF5File");
        throw std::runtime_error(errorMsg);
    }
    
}
Ejemplo n.º 8
0
static int test_dsets( void )
{
    int     rank     = 2;
    hsize_t dims[2]  = {2,3};
    hid_t   file_id;
    hid_t   dataset_id;
    char    data_char_in[DIM]    = {1,2,3,4,5,6};
    char    data_char_out[DIM];
    short   data_short_in[DIM]   = {1,2,3,4,5,6};
    short   data_short_out[DIM];
    int     data_int_in[DIM]     = {1,2,3,4,5,6};
    int     data_int_out[DIM];
    long    data_long_in[DIM]    = {1,2,3,4,5,6};
    long    data_long_out[DIM];
    float   data_float_in[DIM]   = {1,2,3,4,5,6};
    float   data_float_out[DIM];
    double  data_double_in[DIM]  = {1,2,3,4,5,6};
    double  data_double_out[DIM];
    const char    *data_string_in = "This is a string";
    char    data_string_out[20];
    int     i;


    /* Create a new file using default properties. */
    file_id = H5Fcreate( FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );

    /*-------------------------------------------------------------------------
    * H5LTmake_dataset test
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset");

    /* Make dataset */
    if ( H5LTmake_dataset( file_id, DSET0_NAME, rank, dims, H5T_NATIVE_INT, data_int_in ) < 0 )
        goto out;

    /* Read dataset using the basic HDF5 API */

    if ( ( dataset_id = H5Dopen2(file_id, DSET0_NAME, H5P_DEFAULT) ) < 0 )
        goto out;

    if ( H5Dread ( dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_int_out ) < 0 )
        goto out;

    if ( H5Dclose( dataset_id ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * read using the LT function H5LTread_dataset
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTread_dataset");

    if ( H5LTread_dataset( file_id, DSET0_NAME, H5T_NATIVE_INT, data_int_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * test the H5LTmake_dataset_ functions
    *-------------------------------------------------------------------------
    */


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_char
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_char");

    /* Make dataset char */
    if ( H5LTmake_dataset_char( file_id, DSET1_NAME, rank, dims, data_char_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET1_NAME, H5T_NATIVE_CHAR, data_char_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_char_in[i] != data_char_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_char( file_id, DSET1_NAME, data_char_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_char_in[i] != data_char_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_short
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_short");

    /* Make dataset short */
    if ( H5LTmake_dataset_short( file_id, DSET2_NAME, rank, dims, data_short_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET2_NAME, H5T_NATIVE_SHORT, data_short_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_short_in[i] != data_short_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_short( file_id, DSET2_NAME, data_short_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_short_in[i] != data_short_out[i] ) {
            goto out;
        }
    }

    PASSED();

    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_int
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_int");

    /* Make dataset int */
    if ( H5LTmake_dataset_int( file_id, DSET3_NAME, rank, dims, data_int_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET3_NAME, H5T_NATIVE_INT, data_int_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_int( file_id, DSET3_NAME, data_int_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_int_in[i] != data_int_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_long
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_long");

    /* Make dataset long */
    if ( H5LTmake_dataset_long( file_id, DSET4_NAME, rank, dims, data_long_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET4_NAME, H5T_NATIVE_LONG, data_long_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_long_in[i] != data_long_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_long( file_id, DSET4_NAME, data_long_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_long_in[i] != data_long_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_float
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_float");

    /* Make dataset float */
    if ( H5LTmake_dataset_float( file_id, DSET5_NAME, rank, dims, data_float_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET5_NAME, H5T_NATIVE_FLOAT, data_float_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_float_in[i] != data_float_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_float( file_id, DSET5_NAME, data_float_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_float_in[i] != data_float_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_double
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_double");

    /* Make dataset double */
    if ( H5LTmake_dataset_double( file_id, DSET6_NAME, rank, dims, data_double_in ) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset( file_id, DSET6_NAME, H5T_NATIVE_DOUBLE, data_double_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_double_in[i] != data_double_out[i] ) {
            goto out;
        }
    }

    /* Read dataset */
    if ( H5LTread_dataset_double( file_id, DSET6_NAME, data_double_out ) < 0 )
        goto out;

    for (i = 0; i < DIM; i++)
    {
        if ( data_double_in[i] != data_double_out[i] ) {
            goto out;
        }
    }

    PASSED();


    /*-------------------------------------------------------------------------
    * H5LTmake_dataset_string
    *-------------------------------------------------------------------------
    */

    TESTING("H5LTmake_dataset_string");

    /* Make dataset string */
    if ( H5LTmake_dataset_string(file_id,DSET7_NAME,data_string_in) < 0 )
        goto out;

    /* Read dataset */
    if ( H5LTread_dataset_string(file_id,DSET7_NAME,data_string_out) < 0 )
        goto out;

    if ( strcmp(data_string_in,data_string_out) != 0 )
        goto out;



    /*-------------------------------------------------------------------------
    * end tests
    *-------------------------------------------------------------------------
    */

    /* Close the file. */
    H5Fclose( file_id );

    PASSED();


    return 0;

out:
    /* Close the file. */
    H5_FAILED();
    return -1;
}
Ejemplo n.º 9
0
Archivo: fclib.c Proyecto: xhub/fclib
/** read matrix */
struct fclib_matrix* read_matrix (hid_t id)
{
  struct fclib_matrix *mat;

  MM (mat = malloc (sizeof (struct fclib_matrix)));
 
  IO (H5LTread_dataset_int (id, "nzmax", &mat->nzmax));
  IO (H5LTread_dataset_int (id, "m", &mat->m));
  IO (H5LTread_dataset_int (id, "n", &mat->n));
  IO (H5LTread_dataset_int (id, "nz", &mat->nz));

  if (mat->nz >= 0) /* triplet */
  {
    MM (mat->p = malloc (sizeof (int [mat->nz])));
    MM (mat->i = malloc (sizeof (int [mat->nz])));
    IO (H5LTread_dataset_int (id, "p", mat->p));
    IO (H5LTread_dataset_int (id, "i", mat->i));
  }
  else if (mat->nz == -1) /* csc */
  {
    MM (mat->p = malloc (sizeof (int [mat->n+1])));
    MM (mat->i = malloc (sizeof (int [mat->nzmax])));
    IO (H5LTread_dataset_int (id, "p", mat->p));
    IO (H5LTread_dataset_int (id, "i", mat->i));
  }
  else if (mat->nz == -2) /* csr */
  {
    MM (mat->p = malloc (sizeof (int [mat->m+1])));
    MM (mat->i = malloc (sizeof (int [mat->nzmax])));
    IO (H5LTread_dataset_int (id, "p", mat->p));
    IO (H5LTread_dataset_int (id, "i", mat->i));
  }
  else ASSERT (0, "ERROR: unkown sparse matrix type => fclib_matrix->nz = %d\n", mat->nz);

  MM (mat->x = malloc (sizeof (double [mat->nzmax])));
  IO (H5LTread_dataset_double (id, "x", mat->x));

  if (H5LTfind_dataset (id, "conditioning"))
  {
    H5T_class_t class_id;
    hsize_t dim;
    size_t size;

    MM (mat->info = malloc (sizeof (struct fclib_matrix_info)));
    if (H5LTfind_dataset (id, "comment"))
    {
      IO (H5LTget_dataset_info  (id, "comment", &dim, &class_id, &size));
      MM (mat->info->comment = malloc (sizeof (char [size])));
      IO (H5LTread_dataset_string (id, "comment", mat->info->comment));
    }
    else mat->info->comment = NULL;
    IO (H5LTread_dataset_double (id, "conditioning", &mat->info->conditioning));
    IO (H5LTread_dataset_double (id, "determinant", &mat->info->determinant));
    IO (H5LTread_dataset_int (id, "rank", &mat->info->rank));
  }
  else
  {
    mat->info = NULL;
  }

  return mat;
}