예제 #1
0
파일: enum.c 프로젝트: MattNapsAlot/rHDF5
/*-------------------------------------------------------------------------
 * Function:	test_named
 *
 * Purpose:	Create an enumeration data type and store it in the file.
 *
 * Return:	Success:	0
 *
 *		Failure:	number of errors
 *
 * Programmer:	Robb Matzke
 *              Wednesday, December 23, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_named(hid_t file)
{
    hid_t	type=-1, cwg=-1;
    c_e1	val;
    signed char	val8;

    TESTING("named enumeration types");
    if ((cwg=H5Gcreate(file, "test_named", 0))<0) goto error;

    /* A native integer */
    if ((type = H5Tcreate(H5T_ENUM, sizeof(c_e1)))<0) goto error;
    if (H5Tenum_insert(type, "RED",   CPTR(val, E1_RED  ))<0) goto error;
    if (H5Tenum_insert(type, "GREEN", CPTR(val, E1_GREEN))<0) goto error;
    if (H5Tenum_insert(type, "BLUE",  CPTR(val, E1_BLUE ))<0) goto error;
    if (H5Tenum_insert(type, "WHITE", CPTR(val, E1_WHITE))<0) goto error;
    if (H5Tenum_insert(type, "BLACK", CPTR(val, E1_BLACK))<0) goto error;
    if (H5Tcommit(cwg, "e1_a", type)<0) goto error;
    if (H5Tclose(type)<0) goto error;

    /* A smaller type */
    if ((type = H5Tcreate(H5T_ENUM, 1))<0) goto error;
    if (H5Tenum_insert(type, "RED",   CPTR(val8, E1_RED  ))<0) goto error;
    if (H5Tenum_insert(type, "GREEN", CPTR(val8, E1_GREEN))<0) goto error;
    if (H5Tenum_insert(type, "BLUE",  CPTR(val8, E1_BLUE ))<0) goto error;
    if (H5Tenum_insert(type, "WHITE", CPTR(val8, E1_WHITE))<0) goto error;
    if (H5Tenum_insert(type, "BLACK", CPTR(val8, E1_BLACK))<0) goto error;
    if (H5Tcommit(cwg, "e1_b", type)<0) goto error;
    if (H5Tclose(type)<0) goto error;

    /* A non-native type */
    if (H5T_ORDER_BE==H5Tget_order(H5T_NATIVE_INT)) {
	if ((type = H5Tenum_create(H5T_STD_U8LE))<0) goto error;
    } else {
	if ((type = H5Tenum_create(H5T_STD_U8BE))<0) goto error;
    }
    if (H5Tenum_insert(type, "RED",   CPTR(val8, E1_RED  ))<0) goto error;
    if (H5Tenum_insert(type, "GREEN", CPTR(val8, E1_GREEN))<0) goto error;
    if (H5Tenum_insert(type, "BLUE",  CPTR(val8, E1_BLUE ))<0) goto error;
    if (H5Tenum_insert(type, "WHITE", CPTR(val8, E1_WHITE))<0) goto error;
    if (H5Tenum_insert(type, "BLACK", CPTR(val8, E1_BLACK))<0) goto error;
    if (H5Tcommit(cwg, "e1_c", type)<0) goto error;
    if (H5Tclose(type)<0) goto error;

    if (H5Gclose(cwg)<0) goto error;
    PASSED();
    return 0;

 error:
    H5E_BEGIN_TRY {
	H5Tclose(type);
	H5Gclose(cwg);
    } H5E_END_TRY;
    return 1;
}
예제 #2
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiSpike16_t and commit
//          Note: For performance reasons and because spike length is constant during
//           and experiment we use fixed-length array here instead of varible-length
// Inputs:
//  loc         - where to add the type
//  spikeLength - the spike length to use
// Outputs:
//   Returns the type id
hid_t CreateSpike16Type(hid_t loc, UINT16 spikeLength)
{
    herr_t ret;
    hid_t tid = -1;

    // e.g. for spike length of 48 type name will be "BmiSpike16_48_t"
    char szNum[4] = {'\0'};
    sprintf(szNum, "%u", spikeLength);
    std::string strLink = "BmiSpike16_";
    strLink += szNum;
    strLink += "_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }

    hsize_t     dims[1] = {spikeLength};
    hid_t tid_arr_wave = H5Tarray_create(H5T_NATIVE_INT16, 1, dims);

    tid = H5Tcreate(H5T_COMPOUND, offsetof(BmiSpike16_t, wave) + sizeof(INT16) * spikeLength);
    ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiSpike16_t, dwTimestamp), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "Unit", offsetof(BmiSpike16_t, unit), H5T_NATIVE_UINT8);
    ret = H5Tinsert(tid, "Wave", offsetof(BmiSpike16_t, wave), tid_arr_wave);
    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Tclose(tid_arr_wave);
    return tid;
}
예제 #3
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiTrackingAttr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateTrackingAttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiTrackingAttr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }
    hid_t tid_attr_label_str = H5Tcopy(H5T_C_S1);
    ret = H5Tset_size(tid_attr_label_str, 128);

    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiTrackingAttr_t));
    ret = H5Tinsert(tid, "Label", offsetof(BmiTrackingAttr_t, szLabel), tid_attr_label_str);
    ret = H5Tinsert(tid, "Type", offsetof(BmiTrackingAttr_t, type), H5T_NATIVE_UINT16);
    ret = H5Tinsert(tid, "TrackID", offsetof(BmiTrackingAttr_t, trackID), H5T_NATIVE_UINT16);
    ret = H5Tinsert(tid, "MaxPoints", offsetof(BmiTrackingAttr_t, maxPoints), H5T_NATIVE_UINT16);

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Tclose(tid_attr_label_str);
    return tid;
}
예제 #4
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiRootAttr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateRootAttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiRootAttr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }
    hid_t tid_attr_str = H5Tcopy(H5T_C_S1);
    ret = H5Tset_size(tid_attr_str, 64);
    hid_t tid_attr_comment_str = H5Tcopy(H5T_C_S1);
    ret = H5Tset_size(tid_attr_comment_str, 1024);

    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiRootAttr_t));
    ret = H5Tinsert(tid, "MajorVersion", offsetof(BmiRootAttr_t, nMajorVersion), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "MinorVersion", offsetof(BmiRootAttr_t, nMinorVersion), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "Flags", offsetof(BmiRootAttr_t, nFlags), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "GroupCount", offsetof(BmiRootAttr_t, nGroupCount), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "Date", offsetof(BmiRootAttr_t, szDate), tid_attr_str); // date of the file creation
    ret = H5Tinsert(tid, "Application", offsetof(BmiRootAttr_t, szApplication), tid_attr_str); // application that created the file
    ret = H5Tinsert(tid, "Comment", offsetof(BmiRootAttr_t, szComment), tid_attr_comment_str); // file comments

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Tclose(tid_attr_str);
    H5Tclose(tid_attr_comment_str);
    return tid;
}
예제 #5
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiChanExt2Attr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateChanExt2AttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiChanExt2Attr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }
    hid_t tid_attr_unit_str = H5Tcopy(H5T_C_S1);
    ret = H5Tset_size(tid_attr_unit_str, 16);

    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiChanExt2Attr_t));
    ret = H5Tinsert(tid, "DigitalMin", offsetof(BmiChanExt2Attr_t, digmin), H5T_NATIVE_INT32);
    ret = H5Tinsert(tid, "DigitalMax", offsetof(BmiChanExt2Attr_t, digmax), H5T_NATIVE_INT32);
    ret = H5Tinsert(tid, "AnalogMin", offsetof(BmiChanExt2Attr_t, anamin), H5T_NATIVE_INT32);
    ret = H5Tinsert(tid, "AnalogMax", offsetof(BmiChanExt2Attr_t, anamax), H5T_NATIVE_INT32);
    ret = H5Tinsert(tid, "AnalogUnit", offsetof(BmiChanExt2Attr_t, anaunit), tid_attr_unit_str);

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Tclose(tid_attr_unit_str);

    return tid;
}
예제 #6
0
int main(){
  hid_t fprop;
  hid_t fid;
  hid_t vol_id = H5VL_memvol_init();
  char name[1024];

  // create some datatypes

  hid_t tid = H5Tcreate (H5T_COMPOUND, sizeof(complex_type));
  H5Tinsert(tid, "re", HOFFSET(complex_type,re), H5T_NATIVE_DOUBLE);
  H5Tinsert(tid, "im", HOFFSET(complex_type,im), H5T_NATIVE_DOUBLE);
  hid_t s10 = H5Tcopy(H5T_C_S1);
  H5Tset_size(s10, 10);
  H5Tinsert(tid, "name", HOFFSET(complex_type,name), s10);
  H5Tinsert(tid, "val", HOFFSET(complex_type,val), H5T_NATIVE_INT);

  // packed version of the datatype
  hid_t disk_tid = H5Tcopy (tid);
  H5Tpack(disk_tid);

  fprop = H5Pcreate(H5P_FILE_ACCESS);
  H5Pset_vol(fprop, vol_id, &fprop);

  fid = H5Fcreate("test", H5F_ACC_TRUNC, H5P_DEFAULT, fprop);
  H5VLget_plugin_name(fid, name, 1024);
  printf ("%s using VOL %s\n", __FILE__ , name);

  assert(H5Tcommit(fid, "t_complex", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) >= 0);
  assert(H5Tcommit(fid, "t_complex_p", disk_tid,  H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) >= 0);

  hid_t tid_stored1 = H5Topen(fid, "t_complex", H5P_DEFAULT);
  hid_t tid_stored2 = H5Topen(fid, "t_complex_p", H5P_DEFAULT);
  // hid_t tid_stored3 = H5Topen(fid, "NotExisting", H5P_DEFAULT);
  // assert(tid_stored3 < 0);

  assert(H5Tequal(tid_stored1, tid));
  assert(H5Tequal(tid_stored2, disk_tid));

  H5Fclose(fid);

  H5Tclose(tid);
  H5Tclose(disk_tid);

  H5VL_memvol_finalize();

  return 0;
}
예제 #7
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiSynch_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateSynchType(hid_t loc)
{
    herr_t ret;

    hid_t tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiSynch_t));
    ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiSynch_t, dwTimestamp), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "Split", offsetof(BmiSynch_t, split), H5T_NATIVE_UINT16);
    ret = H5Tinsert(tid, "Frame", offsetof(BmiSynch_t, frame), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "ElapsedTime", offsetof(BmiSynch_t, etime), H5T_NATIVE_UINT32);

    ret = H5Tcommit(loc, "BmiSynch_t", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    return tid;
}
예제 #8
0
// Author & Date:   Ehsan Azar   Nov 23, 2012
// Purpose: Create type for BmiDig16_t and commit
// Inputs:
//  loc         - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateDig16Type(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiDig16_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }

    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiDig16_t));
    ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiDig16_t, dwTimestamp), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "Value", offsetof(BmiDig16_t, value), H5T_NATIVE_UINT16);
    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    return tid;
}
예제 #9
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiSamplingAttr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateSamplingAttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiSamplingAttr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }
    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiSamplingAttr_t));
    ret = H5Tinsert(tid, "Clock", offsetof(BmiSamplingAttr_t, fClock), H5T_NATIVE_FLOAT);
    ret = H5Tinsert(tid, "SampleRate", offsetof(BmiSamplingAttr_t, fSampleRate), H5T_NATIVE_FLOAT);
    ret = H5Tinsert(tid, "SampleBits", offsetof(BmiSamplingAttr_t, nSampleBits), H5T_NATIVE_UINT8);

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    return tid;
}
예제 #10
0
// Author & Date:   Ehsan Azar   Nov 19, 2012
// Purpose: Create type for BmiComment_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateCommentType(hid_t loc)
{
    herr_t ret;
    // Use fixed-size comments because 
    //  it is faster, more tools support it, and also allows compression
    hid_t tid_str_array = H5Tcopy(H5T_C_S1);
    ret = H5Tset_size(tid_str_array, BMI_COMMENT_LEN);

    hid_t tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiComment_t));
    ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiComment_t, dwTimestamp), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "Data", offsetof(BmiComment_t, data), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "Flags", offsetof(BmiComment_t, flags), H5T_NATIVE_UINT8);
    ret = H5Tinsert(tid, "Comment", offsetof(BmiComment_t, szComment), tid_str_array);

    ret = H5Tcommit(loc, "BmiComment_t", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Tclose(tid_str_array);

    return tid;
}
예제 #11
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiChanExtAttr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateChanExtAttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiChanExtAttr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }

    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiChanExtAttr_t));
    ret = H5Tinsert(tid, "NanoVoltsPerLSB", offsetof(BmiChanExtAttr_t, dFactor), H5T_NATIVE_DOUBLE);
    ret = H5Tinsert(tid, "PhysicalConnector", offsetof(BmiChanExtAttr_t, phys_connector), H5T_NATIVE_UINT8);
    ret = H5Tinsert(tid, "ConnectorPin", offsetof(BmiChanExtAttr_t, connector_pin), H5T_NATIVE_UINT8);

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    return tid;
}
예제 #12
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiChanExt1Attr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateChanExt1AttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiChanExt1Attr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }
    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiChanExt1Attr_t));
    ret = H5Tinsert(tid, "SortCount", offsetof(BmiChanExt1Attr_t, sortCount), H5T_NATIVE_UINT8);
    ret = H5Tinsert(tid, "EnergyThreshold", offsetof(BmiChanExt1Attr_t, energy_thresh), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "HighThreshold", offsetof(BmiChanExt1Attr_t, high_thresh), H5T_NATIVE_INT32);
    ret = H5Tinsert(tid, "LowThreshold", offsetof(BmiChanExt1Attr_t, low_thresh), H5T_NATIVE_INT32);

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    return tid;
}
예제 #13
0
// Author & Date:   Ehsan Azar   Nov 13, 2012
// Purpose: Create type for BmiFiltAttr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateFiltAttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiFiltAttr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }
    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiFiltAttr_t));
    ret = H5Tinsert(tid, "HighPassFreq", offsetof(BmiFiltAttr_t, hpfreq), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "HighPassOrder", offsetof(BmiFiltAttr_t, hporder), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "HighPassType", offsetof(BmiFiltAttr_t, hptype), H5T_NATIVE_UINT16);
    ret = H5Tinsert(tid, "LowPassFreq", offsetof(BmiFiltAttr_t, lpfreq), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "LowPassOrder", offsetof(BmiFiltAttr_t, lporder), H5T_NATIVE_UINT32);
    ret = H5Tinsert(tid, "LowPassType", offsetof(BmiFiltAttr_t, lptype), H5T_NATIVE_UINT16);

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    return tid;
}
예제 #14
0
// Author & Date:   Ehsan Azar   Nov 17, 2012
// Purpose: Create type for BmiSynchAttr_t and commit
// Inputs:
//  loc  - where to add the type
// Outputs:
//   Returns the type id
hid_t CreateSynchAttrType(hid_t loc)
{
    herr_t ret;
    hid_t tid = -1;
    std::string strLink = "BmiSynchAttr_t";
    // If already there return it
    if(H5Lexists(loc, strLink.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLink.c_str(), H5P_DEFAULT);
        return tid;
    }
    hid_t tid_attr_label_str = H5Tcopy(H5T_C_S1);
    ret = H5Tset_size(tid_attr_label_str, 64);

    tid = H5Tcreate(H5T_COMPOUND, sizeof(BmiSynchAttr_t));
    ret = H5Tinsert(tid, "ID", offsetof(BmiSynchAttr_t, id), H5T_NATIVE_UINT16);
    ret = H5Tinsert(tid, "Label", offsetof(BmiSynchAttr_t, szLabel), tid_attr_label_str);
    ret = H5Tinsert(tid, "FPS", offsetof(BmiSynchAttr_t, fFps), H5T_NATIVE_FLOAT);

    ret = H5Tcommit(loc, strLink.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Tclose(tid_attr_label_str);
    return tid;
}
예제 #15
0
int 
main(void) {
    hid_t		fid1;		/* HDF5 File IDs		*/
    hid_t		dataset;	/* Dataset ID			*/
    hid_t		group;      /* Group ID             */
    hid_t		sid1;       /* Dataspace ID			*/
    hid_t		tid1;       /* Datatype ID			*/
    hsize_t		dims1[] = {SPACE1_DIM1};
    hobj_ref_t      *wbuf;      /* buffer to write to disk */
    int       *tu32;      /* Temporary pointer to int data */
    int        i;          /* counting variables */
    const char *write_comment="Foo!"; /* Comments for group */
    herr_t		ret;		/* Generic return value		*/

/* Compound datatype */
typedef struct s1_t {
    unsigned int a;
    unsigned int b;
    float c;
} s1_t;

    /* Allocate write buffers */
    wbuf=(hobj_ref_t *)malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
    tu32=malloc(sizeof(int)*SPACE1_DIM1);

    /* Create file */
    fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    /* Create dataspace for datasets */
    sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);

    /* Create a group */
    group=H5Gcreate(fid1,"Group1",-1);

    /* Set group's comment */
    ret=H5Gset_comment(group,".",write_comment);

    /* Create a dataset (inside Group1) */
    dataset=H5Dcreate(group,"Dataset1",H5T_STD_U32LE,sid1,H5P_DEFAULT);

    for(i=0; i<SPACE1_DIM1; i++)
        tu32[i] = i*3;

    /* Write selection to disk */
    ret=H5Dwrite(dataset,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,tu32);

    /* Close Dataset */
    ret = H5Dclose(dataset);

    /* Create another dataset (inside Group1) */
    dataset=H5Dcreate(group,"Dataset2",H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT);

    /* Close Dataset */
    ret = H5Dclose(dataset);

    /* Create a datatype to refer to */
    tid1 = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));

    /* Insert fields */
    ret=H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT);

    ret=H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT);

    ret=H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT);

    /* Save datatype for later */
    ret=H5Tcommit (group, "Datatype1", tid1);

    /* Close datatype */
    ret = H5Tclose(tid1);

    /* Close group */
    ret = H5Gclose(group);

    /* Create a dataset to store references */
    dataset=H5Dcreate(fid1,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT);

    /* Create reference to dataset */
    ret = H5Rcreate(&wbuf[0],fid1,"/Group1/Dataset1",H5R_OBJECT,-1);

    /* Create reference to dataset */
    ret = H5Rcreate(&wbuf[1],fid1,"/Group1/Dataset2",H5R_OBJECT,-1);

    /* Create reference to group */
    ret = H5Rcreate(&wbuf[2],fid1,"/Group1",H5R_OBJECT,-1);

    /* Create reference to named datatype */
    ret = H5Rcreate(&wbuf[3],fid1,"/Group1/Datatype1",H5R_OBJECT,-1);

    /* Write selection to disk */
    ret=H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);

    /* Close disk dataspace */
    ret = H5Sclose(sid1);
    
    /* Close Dataset */
    ret = H5Dclose(dataset);

    /* Close file */
    ret = H5Fclose(fid1);
    free(wbuf);
    free(tu32);
    return 0;
}
예제 #16
0
int
main()
{
   printf("\n*** Checking HDF5 attribute functions some more.\n");
   printf("*** Creating tst_xplatform2_3.nc with HDF only...");
   {
      hid_t fapl_id, fcpl_id;
      size_t chunk_cache_size = MY_CHUNK_CACHE_SIZE;
      size_t chunk_cache_nelems = CHUNK_CACHE_NELEMS;
      float chunk_cache_preemption = CHUNK_CACHE_PREEMPTION;
      hid_t fileid, grpid, attid, spaceid;
      hid_t s1_typeid, vlen_typeid, s3_typeid;
      hid_t file_typeid1[NUM_OBJ], native_typeid1[NUM_OBJ];
      hid_t file_typeid2, native_typeid2;
      hsize_t num_obj;
      H5O_info_t obj_info;
      char obj_name[STR_LEN + 1];
      hsize_t dims[1] = {ATT_LEN}; /* netcdf attributes always 1-D. */
      struct s1
      {
	 float x;
	 double y;
      };
      struct s3
      {
	 hvl_t data[NUM_VL];
      };
      /* cvc stands for "Compound with Vlen of Compound." */
      struct s3 cvc_out[ATT_LEN];
      int i, j, k;

      /* Create some output data: a struct s3 array (length ATT_LEN)
       * which holds an array of vlen (length NUM_VL) of struct s1. */
      for (i = 0; i < ATT_LEN; i++)
	 for (j = 0; j < NUM_VL; j++)
	 {
	    cvc_out[i].data[j].len = i + 1; 
	    if (!(cvc_out[i].data[j].p = calloc(sizeof(struct s1), cvc_out[i].data[j].len))) ERR;
	    for (k = 0; k < cvc_out[i].data[j].len; k++)
	    {
	       ((struct s1 *)cvc_out[i].data[j].p)[k].x = 42.42;
	       ((struct s1 *)cvc_out[i].data[j].p)[k].y = 2.0;
	    }
	 }

      /* Create the HDF5 file, with cache control, creation order, and
       * all the timmings. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if (H5Pset_fclose_degree(fapl_id, H5F_CLOSE_STRONG)) ERR;
      if (H5Pset_cache(fapl_id, 0, chunk_cache_nelems, chunk_cache_size, 
		       chunk_cache_preemption) < 0) ERR;
      if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, 
			       H5F_LIBVER_LATEST) < 0) ERR;
      if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
      if (H5Pclose(fapl_id) < 0) ERR;
      if (H5Pclose(fcpl_id) < 0) ERR;

      /* Open the root group. */
      if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR;

      /* Create the compound type for struct s1. */
      if ((s1_typeid = H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0) ERR;
      if (H5Tinsert(s1_typeid, X_NAME, offsetof(struct s1, x), 
		    H5T_NATIVE_FLOAT) < 0) ERR;
      if (H5Tinsert(s1_typeid, Y_NAME, offsetof(struct s1, y), 
		    H5T_NATIVE_DOUBLE) < 0) ERR;
      if (H5Tcommit(grpid, S1_TYPE_NAME, s1_typeid) < 0) ERR;

      /* Create a vlen type. Its a vlen of struct s1. */
      if ((vlen_typeid = H5Tvlen_create(s1_typeid)) < 0) ERR;
      if (H5Tcommit(grpid, VLEN_TYPE_NAME, vlen_typeid) < 0) ERR;

      /* Create the struct s3 type, which contains the vlen. */
      if ((s3_typeid = H5Tcreate(H5T_COMPOUND, sizeof(struct s3))) < 0) ERR;
      if (H5Tinsert(s3_typeid, VL_NAME, offsetof(struct s3, data), 
		    vlen_typeid) < 0) ERR;
      if (H5Tcommit(grpid, S3_TYPE_NAME, s3_typeid) < 0) ERR;

      /* Create an attribute of this new type. */
      if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0) ERR;
      if ((attid = H5Acreate(grpid, S3_ATT_NAME, s3_typeid, spaceid, 
			     H5P_DEFAULT)) < 0) ERR;
      if (H5Awrite(attid, s3_typeid, cvc_out) < 0) ERR;

      /* Close the types. */
      if (H5Tclose(s1_typeid) < 0 ||
	  H5Tclose(vlen_typeid) < 0 ||
	  H5Tclose(s3_typeid) < 0) ERR;

      /* Close the att. */
      if (H5Aclose(attid) < 0) ERR;
      
      /* Close the space. */
      if (H5Sclose(spaceid) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen the file. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;

      /* How many objects in this group? (There should be 3, the
       * types. Atts don't count as objects to HDF5.) */
      if (H5Gget_num_objs(grpid, &num_obj) < 0) ERR;
      if (num_obj != NUM_OBJ) ERR;

      /* For each object in the group... */
      for (i = 0; i < num_obj; i++)
      {
	 /* Get the name, and make sure this is a type. */
	 if (H5Oget_info_by_idx(grpid, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC,
				i, &obj_info, H5P_DEFAULT) < 0) ERR;
	 if (H5Lget_name_by_idx(grpid, ".", H5_INDEX_NAME, H5_ITER_INC, i,
				obj_name, STR_LEN + 1, H5P_DEFAULT) < 0) ERR;
	 if (obj_info.type != H5O_TYPE_NAMED_DATATYPE) ERR;

	 /* Get the typeid and native typeid. */
	 if ((file_typeid1[i] = H5Topen2(grpid, obj_name, H5P_DEFAULT)) < 0) ERR;
	 if ((native_typeid1[i] = H5Tget_native_type(file_typeid1[i], 
						     H5T_DIR_DEFAULT)) < 0) ERR;
      }

      /* There is one att: open it by index. */
      if ((attid = H5Aopen_idx(grpid, 0)) < 0) ERR;

      /* Get file and native typeids of the att. */
      if ((file_typeid2 = H5Aget_type(attid)) < 0) ERR;
      if ((native_typeid2 = H5Tget_native_type(file_typeid2, H5T_DIR_DEFAULT)) < 0) ERR;

      /* Close the attribute. */
      if (H5Aclose(attid) < 0) ERR;

      /* Close the typeids. */
      for (i = 0; i < NUM_OBJ; i++)
      {
	 if (H5Tclose(file_typeid1[i]) < 0) ERR;
	 if (H5Tclose(native_typeid1[i]) < 0) ERR;
      }
      if (H5Tclose(file_typeid2) < 0) ERR;
      if (H5Tclose(native_typeid2) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Deallocate our vlens. */
      for (i = 0; i < ATT_LEN; i++)
	 for (j = 0; j < NUM_VL; j++)
	    free(cvc_out[i].data[j].p);
   }
   SUMMARIZE_ERR;
   printf("*** Checking vlen of compound file...");
   {
#define NUM_OBJ_1 1
#define ATT_NAME "Poseidon"
      hid_t fapl_id, fcpl_id;
      hid_t fileid, grpid, attid, spaceid;
      hid_t vlen_typeid;
      hid_t file_typeid1[NUM_OBJ_1], native_typeid1[NUM_OBJ_1];
      hid_t file_typeid2, native_typeid2;
      hsize_t num_obj;
      H5O_info_t obj_info;
      char obj_name[STR_LEN + 1];
      hsize_t dims[1] = {ATT_LEN}; /* netcdf attributes always 1-D. */

      /* vc stands for "Vlen of Compound." */
      hvl_t vc_out[ATT_LEN];
      int i, k;

      /* Create some output data: an array of vlen (length ATT_LEN) of
       * int. */
      for (i = 0; i < ATT_LEN; i++)
      {
	 vc_out[i].len = i + 1; 
	 if (!(vc_out[i].p = calloc(sizeof(int), vc_out[i].len))) ERR;
	 for (k = 0; k < vc_out[i].len; k++)
	    ((int *)vc_out[i].p)[k] = 42;
      }
      
      /* Create the HDF5 file with creation order. */
      if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) ERR;
      if ((fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) ERR;
      if (H5Pset_link_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if (H5Pset_attr_creation_order(fcpl_id, (H5P_CRT_ORDER_TRACKED | 
					       H5P_CRT_ORDER_INDEXED)) < 0) ERR;
      if ((fileid = H5Fcreate(FILE_NAME, H5F_ACC_TRUNC, fcpl_id, fapl_id)) < 0) ERR;
      if (H5Pclose(fapl_id) < 0) ERR;
      if (H5Pclose(fcpl_id) < 0) ERR;
      
      /* Open the root group. */
      if ((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) ERR;
      
      /* Create a vlen type. Its a vlen of int. */
      if ((vlen_typeid = H5Tvlen_create(H5T_NATIVE_INT)) < 0) ERR;
      if (H5Tcommit(grpid, VLEN_TYPE_NAME, vlen_typeid) < 0) ERR;
      
      /* Create an attribute of this new type. */
      if ((spaceid = H5Screate_simple(1, dims, NULL)) < 0) ERR;
      if ((attid = H5Acreate(grpid, ATT_NAME, vlen_typeid, spaceid, 
			     H5P_DEFAULT)) < 0) ERR;
      if (H5Awrite(attid, vlen_typeid, vc_out) < 0) ERR;
      
      /* Close the type. */
      if (H5Tclose(vlen_typeid) < 0) ERR;
	  
      /* Close the att. */
      if (H5Aclose(attid) < 0) ERR;
      
      /* Close the space. */
      if (H5Sclose(spaceid) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Reopen the file. */
      if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) ERR;
      if ((grpid = H5Gopen(fileid, "/")) < 0) ERR;

      /* How many objects in this group? (There should be 2, the
       * types. Atts don't count as objects to HDF5.) */
      if (H5Gget_num_objs(grpid, &num_obj) < 0) ERR;
      if (num_obj != NUM_OBJ_1) ERR;

      /* For each object in the group... */
      for (i = 0; i < num_obj; i++)
      {
	 /* Get the name, and make sure this is a type. */
	 if (H5Oget_info_by_idx(grpid, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC,
				i, &obj_info, H5P_DEFAULT) < 0) ERR;
	 if (H5Lget_name_by_idx(grpid, ".", H5_INDEX_NAME, H5_ITER_INC, i,
				obj_name, STR_LEN + 1, H5P_DEFAULT) < 0) ERR;
	 if (obj_info.type != H5O_TYPE_NAMED_DATATYPE) ERR;

	 /* Get the typeid and native typeid. */
	 if ((file_typeid1[i] = H5Topen2(grpid, obj_name, H5P_DEFAULT)) < 0) ERR;
	 if ((native_typeid1[i] = H5Tget_native_type(file_typeid1[i],
						     H5T_DIR_DEFAULT)) < 0) ERR;
      }

      /* There is one att: open it by index. */
      if ((attid = H5Aopen_idx(grpid, 0)) < 0) ERR;

      /* Get file and native typeids of the att. */
      if ((file_typeid2 = H5Aget_type(attid)) < 0) ERR;
      if ((native_typeid2 = H5Tget_native_type(file_typeid2, H5T_DIR_DEFAULT)) < 0) ERR;

      /* Close the attribute. */
      if (H5Aclose(attid) < 0) ERR;

      /* Close the typeids. */
      for (i = 0; i < NUM_OBJ_1; i++)
      {
	 if (H5Tclose(file_typeid1[i]) < 0) ERR;
	 if (H5Tclose(native_typeid1[i]) < 0) ERR;
      }
      if (H5Tclose(file_typeid2) < 0) ERR;
      if (H5Tclose(native_typeid2) < 0) ERR;

      /* Close the group and file. */
      if (H5Gclose(grpid) < 0 ||
	  H5Fclose(fileid) < 0) ERR;

      /* Deallocate our vlens. */
      for (i = 0; i < ATT_LEN; i++)
	 free(vc_out[i].p);
   }
   SUMMARIZE_ERR;
   FINAL_RESULTS;
}
예제 #17
0
파일: file.c 프로젝트: chrismullins/moab
mhdf_FileHandle
mhdf_createFile( const char* filename, 
                 int overwrite, 
                 const char** elem_type_list,
                 size_t elem_list_len,
                 hid_t id_type,
                 mhdf_Status* status )
{
  FileHandle* file_ptr;
  unsigned int flags;
  unsigned char idx;
  size_t i;
  hid_t enum_id, group_id;
  int rval;
  API_BEGIN;
  
  if (elem_list_len > 255)
  {
    mhdf_setFail( status, "Element type list too long." );
    return NULL;
  }
  mhdf_setOkay( status );
  
    /* Create struct to hold working data */
  file_ptr = mhdf_alloc_FileHandle( 0, id_type, status );
  if (!file_ptr) return NULL;

    /* Create the file */
  flags = overwrite ? H5F_ACC_TRUNC : H5F_ACC_EXCL;
  file_ptr->hdf_handle = H5Fcreate( filename, flags, H5P_DEFAULT, H5P_DEFAULT );
  if (file_ptr->hdf_handle < 0)
  {
    mhdf_setFail( status, "Failed to create file \"%s\"", filename );
    free( file_ptr );
    return NULL;
  }
  
  
    /* Create file structure */
  if (!make_hdf_group(     ROOT_GROUP, file_ptr->hdf_handle, 6, status )
   || !make_hdf_group(      TAG_GROUP, file_ptr->hdf_handle, 0, status )
   || !make_hdf_group(  ELEMENT_GROUP, file_ptr->hdf_handle, 8, status )
   || !make_hdf_group(     NODE_GROUP, file_ptr->hdf_handle, 3, status )
   || !make_hdf_group(      SET_GROUP, file_ptr->hdf_handle, 5, status )
   || !make_hdf_group( NODE_TAG_GROUP, file_ptr->hdf_handle, 0, status )
   || !make_hdf_group(  SET_TAG_GROUP, file_ptr->hdf_handle, 0, status ))
  {
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  
    /* Store the max ID as an attribite on the /tstt/ group */
#if defined(H5Gopen_vers) && H5Gopen_vers > 1  
  group_id = H5Gopen2( file_ptr->hdf_handle, ROOT_GROUP, H5P_DEFAULT );
#else
  group_id = H5Gopen( file_ptr->hdf_handle, ROOT_GROUP );
#endif
  rval = mhdf_create_scalar_attrib( group_id, 
                                    MAX_ID_ATTRIB, 
                                    H5T_NATIVE_ULONG, 
                                    &file_ptr->max_id,
                                    status );
  H5Gclose( group_id );
  if (!rval)
  {
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  
    /* Create the type name list in file */
  enum_id = H5Tenum_create( H5T_NATIVE_UCHAR );
  if (enum_id < 0)
  {
    mhdf_setFail( status, "Failed to store elem type list." );
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  for (i = 0; i < elem_list_len; ++i)
  {
    if (!elem_type_list[i] || !*elem_type_list[i])
      continue;
      
    idx = (unsigned char)i;
    if ( H5Tenum_insert( enum_id, elem_type_list[i], &idx ) < 0)
    {
      mhdf_setFail( status, "Failed to store elem type list." );
      H5Fclose( file_ptr->hdf_handle );
      free( file_ptr );
      return NULL;
    }
  }
#if defined(H5Tcommit_vers) && H5Tcommit_vers > 1
  if (H5Tcommit2( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT ) < 0)  
#else
  if (H5Tcommit( file_ptr->hdf_handle, TYPE_ENUM_PATH, enum_id ) < 0)  
#endif
  {
    mhdf_setFail( status, "Failed to store elem type list." );
    H5Fclose( file_ptr->hdf_handle );
    free( file_ptr );
    return NULL;
  }
  H5Tclose( enum_id );
  
  API_END_H( 1 );
  return file_ptr;
}
예제 #18
0
// Author & Date:   Ehsan Azar   Nov 20, 2012
// Purpose: Create type for BmiTracking_t and commit
// Inputs:
//  loc    - where to add the type
//  dim    - dimension (1D, 2D or 3D)
//  width  - datapoint width in bytes
// Outputs:
//   Returns the type id
hid_t CreateTrackingType(hid_t loc, int dim, int width)
{
    herr_t ret;
    hid_t tid_coords;
    std::string strLabel = "BmiTracking";
    // e.g. for 1D (32-bit) fixed-length, type name will be "BmiTracking32_1D_t"
    //      for 2D (16-bit) fixed-length, type name will be "BmiTracking16_2D_t"

    switch (width)
    {
    case 1:
        strLabel += "8";
        tid_coords = H5Tcopy(H5T_NATIVE_UINT8);
        break;
    case 2:
        strLabel += "16";
        tid_coords = H5Tcopy(H5T_NATIVE_UINT16);
        break;
    case 4:
        strLabel += "32";
        tid_coords = H5Tcopy(H5T_NATIVE_UINT32);
        break;
    default:
        return 0;
        // should not happen
        break;
    }
    switch (dim)
    {
    case 1:
        strLabel += "_1D";
        break;
    case 2:
        strLabel += "_2D";
        break;
    case 3:
        strLabel += "_3D";
        break;
    default:
        return 0;
        // should not happen
        break;
    }
    strLabel += "_t";

    hid_t tid = -1;
    if(H5Lexists(loc, strLabel.c_str(), H5P_DEFAULT))
    {
        tid = H5Topen(loc, strLabel.c_str(), H5P_DEFAULT);
    } else {
        tid = H5Tcreate(H5T_COMPOUND, offsetof(BmiTracking_fl_t, coords) + dim * width * 1);
        ret = H5Tinsert(tid, "TimeStamp", offsetof(BmiTracking_fl_t, dwTimestamp), H5T_NATIVE_UINT32);
        ret = H5Tinsert(tid, "ParentID", offsetof(BmiTracking_fl_t, parentID), H5T_NATIVE_UINT16);
        ret = H5Tinsert(tid, "NodeCount", offsetof(BmiTracking_fl_t, nodeCount), H5T_NATIVE_UINT16);
        ret = H5Tinsert(tid, "ElapsedTime", offsetof(BmiTracking_fl_t, etime), H5T_NATIVE_UINT32);
        char corrd_labels[3][2] = {"x", "y", "z"};
        for (int i = 0; i < dim; ++i)
            ret = H5Tinsert(tid, corrd_labels[i], offsetof(BmiTracking_fl_t, coords) + i * width, tid_coords);
        ret = H5Tcommit(loc, strLabel.c_str(), tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    }

    H5Tclose(tid_coords);

    return tid;
}
예제 #19
0
파일: hdf5.c 프로젝트: leobago/fti
/*-------------------------------------------------------------------------*/
int FTI_WriteHDF5(FTIT_configuration* FTI_Conf, FTIT_execution* FTI_Exec,
        FTIT_topology* FTI_Topo, FTIT_checkpoint* FTI_Ckpt,
        FTIT_dataset* FTI_Data)
{
    FTI_Print("I/O mode: HDF5.", FTI_DBUG);
    char str[FTI_BUFS], fn[FTI_BUFS];
    int level = FTI_Exec->ckptLvel;
    if (level == 4 && FTI_Ckpt[4].isInline) { //If inline L4 save directly to global directory
        snprintf(fn, FTI_BUFS, "%s/%s", FTI_Conf->gTmpDir, FTI_Exec->meta[0].ckptFile);
    }
    else {
        snprintf(fn, FTI_BUFS, "%s/%s", FTI_Conf->lTmpDir, FTI_Exec->meta[0].ckptFile);
    }
    if( FTI_Exec->h5SingleFile ) {
        snprintf( fn, FTI_BUFS, "%s/%s-ID%08d.h5", FTI_Conf->h5SingleFileDir, FTI_Conf->h5SingleFilePrefix, FTI_Exec->ckptID );
    }

    hid_t file_id;
    
    //Creating new hdf5 file
    if( FTI_Exec->h5SingleFile ) { 
        hid_t plid = H5Pcreate( H5P_FILE_ACCESS );
        H5Pset_fapl_mpio(plid, FTI_COMM_WORLD, MPI_INFO_NULL);
        file_id = H5Fcreate(fn, H5F_ACC_TRUNC, H5P_DEFAULT, plid);       
        H5Pclose( plid );
    } else {
        file_id = H5Fcreate(fn, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    }
    if (file_id < 0) {
        sprintf(str, "FTI checkpoint file (%s) could not be opened.", fn);
        FTI_Print(str, FTI_EROR);

        return FTI_NSCS;
    }
    FTI_Exec->H5groups[0]->h5groupID = file_id;
    FTIT_H5Group* rootGroup = FTI_Exec->H5groups[0];

    int i;
    for (i = 0; i < rootGroup->childrenNo; i++) {
        FTI_CreateGroup(FTI_Exec->H5groups[rootGroup->childrenID[i]], file_id, FTI_Exec->H5groups);
    }

    // write data into ckpt file

    // create datatypes
    for (i = 0; i < FTI_Exec->nbVar; i++) {
        int toCommit = 0;
        if (FTI_Data[i].type->h5datatype < 0) {
            toCommit = 1;
        }
        sprintf(str, "Calling CreateComplexType [%d] with hid_t %ld", FTI_Data[i].type->id, (long)FTI_Data[i].type->h5datatype);
        FTI_Print(str, FTI_DBUG);
        FTI_CreateComplexType(FTI_Data[i].type, FTI_Exec->FTI_Type);
        if (toCommit == 1) {
            char name[FTI_BUFS];
            if (FTI_Data[i].type->structure == NULL) {
                //this is the array of bytes with no name
                sprintf(name, "Type%d", FTI_Data[i].type->id);
            } else {
                strncpy(name, FTI_Data[i].type->structure->name, FTI_BUFS);
            }
            herr_t res = H5Tcommit(FTI_Data[i].type->h5group->h5groupID, name, FTI_Data[i].type->h5datatype, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
            if (res < 0) {
                sprintf(str, "Datatype #%d could not be commited", FTI_Data[i].id);
                FTI_Print(str, FTI_EROR);
                int j;
                for (j = 0; j < FTI_Exec->H5groups[0]->childrenNo; j++) {
                    FTI_CloseGroup(FTI_Exec->H5groups[rootGroup->childrenID[j]], FTI_Exec->H5groups);
                }
                H5Fclose(file_id);
                return FTI_NSCS;
            }
        }
    }

    if( FTI_Exec->h5SingleFile ) { 
        FTI_CreateGlobalDatasets( FTI_Exec );
    }

    // write data
    for (i = 0; i < FTI_Exec->nbVar; i++) {
        int res;
        if( FTI_Exec->h5SingleFile ) { 
            res = FTI_WriteSharedFileData( FTI_Data[i] );
        } else {
            res = FTI_WriteHDF5Var(&FTI_Data[i]); 
        }
        if ( res != FTI_SCES ) {
            sprintf(str, "Dataset #%d could not be written", FTI_Data[i].id);
            FTI_Print(str, FTI_EROR);
            int j;
            for (j = 0; j < FTI_Exec->H5groups[0]->childrenNo; j++) {
                FTI_CloseGroup(FTI_Exec->H5groups[rootGroup->childrenID[j]], FTI_Exec->H5groups);
            }
            H5Fclose(file_id);
            return FTI_NSCS;
        }
    }
    
    for (i = 0; i < FTI_Exec->nbVar; i++) {
        FTI_CloseComplexType(FTI_Data[i].type, FTI_Exec->FTI_Type);
    }

    int j;
    for (j = 0; j < FTI_Exec->H5groups[0]->childrenNo; j++) {
        FTI_CloseGroup(FTI_Exec->H5groups[rootGroup->childrenID[j]], FTI_Exec->H5groups);
    }
    
    if( FTI_Exec->h5SingleFile ) { 
        FTI_CloseGlobalDatasets( FTI_Exec );
    }

    // close file
    FTI_Exec->H5groups[0]->h5groupID = -1;
    if (H5Fclose(file_id) < 0) {
        FTI_Print("FTI checkpoint file could not be closed.", FTI_EROR);
        return FTI_NSCS;
    }


    return FTI_SCES;
}
예제 #20
0
/*-------------------------------------------------------------------------*/
int FTI_WriteHdf5Var(int varID, FTIT_configuration* FTI_Conf, FTIT_execution* FTI_Exec,
        FTIT_topology* FTI_Topo, FTIT_checkpoint* FTI_Ckpt,
        FTIT_dataset* FTI_Data)
{

    if ( FTI_Exec->iCPInfo.status == FTI_ICP_FAIL ) {
        return FTI_NSCS;
    }

    char str[FTI_BUFS];

    hid_t file_id;
    memcpy( &file_id, FTI_Exec->iCPInfo.fh, sizeof(FTI_H5_FH) );

    FTIT_H5Group* rootGroup = FTI_Exec->H5groups[0];

    // write data into ckpt file
    int i;
    for (i = 0; i < FTI_Exec->nbVar; i++) {
        if( FTI_Data[i].id == varID ) {
            int toCommit = 0;
            if (FTI_Data[i].type->h5datatype < 0) {
                toCommit = 1;
            }
            sprintf(str, "Calling CreateComplexType [%d] with hid_t %ld", FTI_Data[i].type->id, (long)FTI_Data[i].type->h5datatype);
            FTI_Print(str, FTI_DBUG);
            FTI_CreateComplexType(FTI_Data[i].type, FTI_Exec->FTI_Type);
            if (toCommit == 1) {
                char name[FTI_BUFS];
                if (FTI_Data[i].type->structure == NULL) {
                    //this is the array of bytes with no name
                    sprintf(name, "Type%d", FTI_Data[i].type->id);
                } else {
                    strncpy(name, FTI_Data[i].type->structure->name, FTI_BUFS);
                }
                herr_t res = H5Tcommit(FTI_Data[i].type->h5group->h5groupID, name, FTI_Data[i].type->h5datatype, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
                if (res < 0) {
                    sprintf(str, "Datatype #%d could not be commited", FTI_Data[i].id);
                    FTI_Print(str, FTI_EROR);
                    int j;
                    for (j = 0; j < FTI_Exec->H5groups[0]->childrenNo; j++) {
                        FTI_CloseGroup(FTI_Exec->H5groups[rootGroup->childrenID[j]], FTI_Exec->H5groups);
                    }
                    H5Fclose(file_id);
                    return FTI_NSCS;
                }
            }
            //convert dimLength array to hsize_t
            if ( FTI_Try(FTI_WriteHDF5Var(&FTI_Data[i]) , "Writing data to HDF5 filesystem") != FTI_SCES){
                sprintf(str, "Dataset #%d could not be written", FTI_Data[i].id);
                FTI_Print(str, FTI_EROR);
                int j;
                for (j = 0; j < FTI_Exec->H5groups[0]->childrenNo; j++) {
                    FTI_CloseGroup(FTI_Exec->H5groups[rootGroup->childrenID[j]], FTI_Exec->H5groups);
                }
                H5Fclose(file_id);
                return FTI_NSCS;
            }
        }
    }

    FTI_Exec->iCPInfo.result = FTI_SCES;
    return FTI_SCES;

}