Пример #1
0
//-*****************************************************************************
bool EquivalentDatatypes( hid_t iA, hid_t iB )
{
    if ( iA >= 0 && iB >= 0 )
    {
        if ( H5Tequal( iA, iB ) > 0 )
        {
            return true;
        }

        // If they're not equal, but they are both arrayed and
        // both have the same super type
        // and dimensions, they're equivalent
        if ( H5Tget_class( iA ) == H5T_ARRAY &&
             H5Tget_class( iB ) == H5T_ARRAY )
        {
            hid_t superA = H5Tget_super( iA );
            hid_t superB = H5Tget_super( iB );
            if ( superA >= 0 && superB >= 0 &&
                 H5Tequal( superA, superB ) > 0 )
            {
                Dimensions aDims;
                getDatatypeArrayDims( iA, aDims );
                Dimensions bDims;
                getDatatypeArrayDims( iB, bDims );
                if ( aDims == bDims )
                {
                    return true;
                }
            }
        }
    }
    return false;
}
Пример #2
0
int H5mdfile::H5_Dread(int argc, char **argv, Tcl_Interp *interp)
{
    /* Read h5-dataset and write to dataset array values */
    // Allocate memeory
    if(dset_data!=NULL) free(dset_data);

    if(H5Tequal(dataset_type_id, H5T_NATIVE_FLOAT))
    {
       dset_data=(float*) Utils::malloc(dset_data_size*sizeof(float));
       memset(dset_data,0,dset_data_size*sizeof(float));
    }
    else if(H5Tequal(dataset_type_id, H5T_NATIVE_DOUBLE))
    {
       dset_data=(double*) Utils::malloc(dset_data_size*sizeof(double));
       memset(dset_data,0,dset_data_size*sizeof(double));
    }
    else if(H5Tequal(dataset_type_id, H5T_NATIVE_INT))
    {
       dset_data=(int*) Utils::malloc(dset_data_size*sizeof(int));
       memset(dset_data,0,dset_data_size*sizeof(int));
    }
    else if(H5Tequal(dataset_type_id, H5T_C_S1))
    {
       dset_data = (h5string*) Utils::malloc(dset_data_size * sizeof(h5string));
    }
    else
    {
        Tcl_AppendResult(interp, "\nh5mdfile: No data type in H5_Dread given\n",(char *) NULL);
        return TCL_ERROR;
    }
    // Read h5-dataset
    status = H5Dread(dataset_id, dataset_type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT,dset_data);
    return TCL_OK;
}
Пример #3
0
int H5mdfile::H5_read_value(int argc, char **argv,Tcl_Interp *interp)
{
    /* Read value from dataset array and print it to Tcl */
    // Get array index
    int index=0;
    if(dataset_rank>=1) index+=atoi(argv[2+dataset_rank-0]);
    if(dataset_rank>=2) index+=atoi(argv[2+dataset_rank-1])*dims[dataset_rank-1];else goto label_index;
    if(dataset_rank>=3) index+=atoi(argv[2+dataset_rank-2])*dims[dataset_rank-1]*dims[dataset_rank-2];else goto label_index;
    if(dataset_rank>=4) index+=atoi(argv[2+dataset_rank-3])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3];else goto label_index;
    if(dataset_rank>=5) index+=atoi(argv[2+dataset_rank-4])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4];else goto label_index;
    if(dataset_rank>=6) index+=atoi(argv[2+dataset_rank-5])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4]*dims[dataset_rank-5];else goto label_index;
    if(dataset_rank>=7) index+=atoi(argv[2+dataset_rank-6])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4]*dims[dataset_rank-5]*dims[dataset_rank-6];else goto label_index;
    if(dataset_rank>=8) index+=atoi(argv[2+dataset_rank-7])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4]*dims[dataset_rank-5]*dims[dataset_rank-6]*dims[dataset_rank-7];else goto label_index;
    label_index:
    // Read single value from dataset array and print to Tcl
    if(H5Tequal(dataset_type_id, H5T_NATIVE_FLOAT))
    {
        dset_data_float = static_cast<float*>(dset_data);
        dset_data_singlevalue_float = dset_data_float[index];

        char buffer[TCL_DOUBLE_SPACE + TCL_INTEGER_SPACE + 2];
        Tcl_PrintDouble(interp, (double)dset_data_singlevalue_float, buffer);
        Tcl_AppendResult(interp, buffer, (char *)NULL);
        return TCL_OK;
    }
    if(H5Tequal(dataset_type_id, H5T_NATIVE_DOUBLE))
    {
        dset_data_double = static_cast<double*>(dset_data);
        dset_data_singlevalue_double = dset_data_double[index];

        char buffer[TCL_DOUBLE_SPACE + TCL_INTEGER_SPACE + 2];
        Tcl_PrintDouble(interp, dset_data_singlevalue_double, buffer);
        Tcl_AppendResult(interp, buffer, (char *)NULL);
        return TCL_OK;
    }
    if(H5Tequal(dataset_type_id, H5T_NATIVE_INT))
    {
        dset_data_int = static_cast<int*>(dset_data);
        dset_data_singlevalue_int = dset_data_int[index];

        char buffer[TCL_DOUBLE_SPACE + TCL_INTEGER_SPACE + 2];
        Tcl_PrintDouble(interp, (double)dset_data_singlevalue_int, buffer);
        Tcl_AppendResult(interp, buffer, (char *)NULL);
        return TCL_OK;
    }
    if(H5Tequal(dataset_type_id, H5T_C_S1))
    {
        dset_data_string = static_cast<h5string*>(dset_data);
        dset_data_singlevalue_string = dset_data_string[index];
        dataspace_simple_id = H5S_ALL;
        dataspace_id = H5S_ALL;
        Tcl_AppendResult(interp, dset_data_singlevalue_string, (char *)NULL);
        return TCL_OK;
    }
    return TCL_ERROR;
}
Пример #4
0
bool isCharType(hid_t dataType) {
  if (H5Tequal(dataType, H5T_NATIVE_CHAR)) {
    return true;
  }
      
  hid_t nativeType = H5Tget_native_type(dataType, H5T_DIR_ASCEND);
  bool answer = H5Tequal(nativeType, H5T_NATIVE_CHAR);
  
  H5Tclose(nativeType);
  return answer;
}
Пример #5
0
std::string hdf5attribute::read_as_string()
{
	std::string result;
	if(H5Tequal(_type_id, H5T_NATIVE_INT16))
		result = boost::lexical_cast<std::string>(read<short>());
	else if(H5Tequal(_type_id, H5T_NATIVE_INT32))
		result = boost::lexical_cast<std::string>(read<int>());
	else if(H5Tequal(_type_id, H5T_NATIVE_UINT32))
		result = boost::lexical_cast<std::string>(read<unsigned int>());
	else if(H5Tequal(_type_id, H5T_NATIVE_UINT16))
		result = boost::lexical_cast<std::string>(read<unsigned short>());
	else if(H5Tequal(_type_id, H5T_NATIVE_UINT8))
		result = boost::lexical_cast<std::string>(read<unsigned char>());
	else if(H5Tequal(_type_id, H5T_NATIVE_INT8))
		result = boost::lexical_cast<std::string>(read<char>());
	else if(H5Tequal(_type_id, H5T_NATIVE_FLOAT))
		result = boost::lexical_cast<std::string>(read<float>());
	else if(H5Tequal(_type_id, H5T_NATIVE_DOUBLE))
		result = boost::lexical_cast<std::string>(read<double>());
	else if(H5Tget_class(_type_id) == H5T_STRING)
		result = read<std::string>();
	else
		throw std::runtime_error("unknown type");
	return result;
}
Пример #6
0
/* Recursively hunt for a HDF type id. */
NC_TYPE_INFO_T *
nc4_rec_find_hdf_type(NC_GRP_INFO_T *start_grp, hid_t target_hdf_typeid)
{
   NC_GRP_INFO_T *g;
   NC_TYPE_INFO_T *type, *res;
   htri_t equal;

   assert(start_grp);

   /* Does this group have the type we are searching for? */
   for (type = start_grp->type; type; type = type->l.next)
   {
      if ((equal = H5Tequal(type->native_hdf_typeid ? type->native_hdf_typeid : type->hdf_typeid, target_hdf_typeid)) < 0)
	 return NULL;
      if (equal)
	 return type;
   }

   /* Shake down the kids. */
   if (start_grp->children)
      for (g = start_grp->children; g; g = g->l.next)
	 if ((res = nc4_rec_find_hdf_type(g, target_hdf_typeid)))
	    return res;

   /* Can't find it. Fate, why do you mock me? */
   return NULL;
}
Пример #7
0
//-*****************************************************************************
bool EquivalentDatatypes( hid_t iA, hid_t iB )
{
    if ( iA >= 0 && iB >= 0 && H5Tequal( iA, iB ) > 0 )
        return true;

    return false;
}
Пример #8
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;
}
Пример #9
0
/*-------------------------------------------------------------------------
* subroutine for test_text_dtype(): test_fps().
*-------------------------------------------------------------------------
*/
static int test_fps(void)
{
    hid_t   dtype;
    char*   dt_str;
    size_t  str_len;

    TESTING3("        text for floating-point types");

    if((dtype = H5LTtext_to_dtype("H5T_NATIVE_LDOUBLE\n", H5LT_DDL))<0)
        goto out;
    if(!H5Tequal(dtype, H5T_NATIVE_LDOUBLE))
        goto out;
    if(H5Tclose(dtype)<0)
        goto out;

    if((dtype = H5LTtext_to_dtype("H5T_IEEE_F32BE\n", H5LT_DDL))<0)
        goto out;
    if(!H5Tequal(dtype, H5T_IEEE_F32BE))
        goto out;

    if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
        goto out;
    dt_str = (char*)calloc(str_len, sizeof(char));
    if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0)
        goto out;
    if(strcmp(dt_str, "H5T_IEEE_F32BE"))
        goto out;
    free(dt_str);

    if(H5Tclose(dtype)<0)
        goto out;

    if((dtype = H5LTtext_to_dtype("H5T_IEEE_F64LE\n", H5LT_DDL))<0)
        goto out;
    if(!H5Tequal(dtype, H5T_IEEE_F64LE))
        goto out;
    if(H5Tclose(dtype)<0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    return -1;
}
Пример #10
0
/*-------------------------------------------------------------------------
* subroutine for test_text_dtype(): test_integers().
*-------------------------------------------------------------------------
*/
static int test_integers(void)
{
    hid_t   dtype;
    char*   dt_str;
    size_t  str_len;

    TESTING3("\n        text for integer types");

    if((dtype = H5LTtext_to_dtype("H5T_NATIVE_INT\n", H5LT_DDL))<0)
        goto out;
    if(!H5Tequal(dtype, H5T_NATIVE_INT))
        goto out;
    if(H5Tclose(dtype)<0)
        goto out;

    if((dtype = H5LTtext_to_dtype("H5T_STD_I8BE\n", H5LT_DDL))<0)
        goto out;
    if(!H5Tequal(dtype, H5T_STD_I8BE))
        goto out;

    if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0)
        goto out;
    dt_str = (char*)calloc(str_len, sizeof(char));
    if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0)
        goto out;
    if(strcmp(dt_str, "H5T_STD_I8BE"))
        goto out;
    free(dt_str);

    if(H5Tclose(dtype)<0)
        goto out;

    if((dtype = H5LTtext_to_dtype("H5T_STD_U16LE\n", H5LT_DDL))<0)
        goto out;
    if(!H5Tequal(dtype, H5T_STD_U16LE))
        goto out;
    if(H5Tclose(dtype)<0)
        goto out;

    PASSED();
    return 0;

out:
    H5_FAILED();
    return -1;
}
Пример #11
0
inline size_t max_value_of_type (hid_t type)
{
    if (H5Tequal(type, H5T_NATIVE_UCHAR)) {
        return std::numeric_limits<uint8_t>::max();
    } else
    if (H5Tequal(type, H5T_NATIVE_USHORT)) {
        return std::numeric_limits<uint16_t>::max();
    } else
    if (H5Tequal(type, H5T_NATIVE_UINT)) {
        return std::numeric_limits<uint32_t>::max();
    } else
    if (H5Tequal(type, H5T_NATIVE_ULONG)) {
        return std::numeric_limits<uint64_t>::max();
    } else {
        POMAGMA_ERROR("unknown type");
    }
}
Пример #12
0
	void compare_and_read_scalar_attribute_internal(hid_t attribute_id, hid_t type_id, hid_t expected_type, void* buffer)
	{
		if(H5Tequal(type_id, expected_type))
		{
			herr_t status = H5Aread(attribute_id, type_id, buffer);
			if(status >= 0)
				return;
		}
		throw std::runtime_error("type mismatch");
	}
Пример #13
0
int H5mdfile::H5_write_value(int argc, char **argv, Tcl_Interp *interp)
{
	/* Read value from Tcl and write it to dataset array */
	// Get array index
	int index=0;
	if(dataset_rank>=1) index+=atoi(argv[4+dataset_rank-0]);
	if(dataset_rank>=2) index+=atoi(argv[4+dataset_rank-1])*dims[dataset_rank-1];else goto label_index;
	if(dataset_rank>=3) index+=atoi(argv[4+dataset_rank-2])*dims[dataset_rank-1]*dims[dataset_rank-2];else goto label_index;
	if(dataset_rank>=4) index+=atoi(argv[4+dataset_rank-3])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3];else goto label_index;
	if(dataset_rank>=5) index+=atoi(argv[4+dataset_rank-4])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4];else goto label_index;
	if(dataset_rank>=6) index+=atoi(argv[4+dataset_rank-5])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4]*dims[dataset_rank-5];else goto label_index;
	if(dataset_rank>=7) index+=atoi(argv[4+dataset_rank-6])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4]*dims[dataset_rank-5]*dims[dataset_rank-6];else goto label_index;
	if(dataset_rank>=8) index+=atoi(argv[4+dataset_rank-7])*dims[dataset_rank-1]*dims[dataset_rank-2]*dims[dataset_rank-3]*dims[dataset_rank-4]*dims[dataset_rank-5]*dims[dataset_rank-6]*dims[dataset_rank-7];else goto label_index;
	label_index:
	// Write single value from Tcl to dataset array
	if(H5Tequal(dataset_type_id, H5T_NATIVE_FLOAT))
	{
		dset_data_float = static_cast<float*>(dset_data);
		dset_data_float[index]=(float)atof(argv[3]);
	}
	if(H5Tequal(dataset_type_id, H5T_NATIVE_DOUBLE))
	{
		dset_data_double = static_cast<double*>(dset_data);
		dset_data_double[index]=atof(argv[3]);
	}
	if(H5Tequal(dataset_type_id, H5T_NATIVE_INT))
	{
		dset_data_int = static_cast<int*>(dset_data);
		dset_data_int[index]=atoi(argv[3]);
	}
	
	if(H5Tis_variable_str(dataset_type_id)!=0)
	{
//		dset_data_string = static_cast<h5string*>(dset_data);
//        dset_data_chars=static_cast<char *>(dset_data);
        dset_data_chars=(char**) dset_data;
		dset_data_chars[index]=strdup(argv[3]);
	}
	return TCL_OK;
}
Пример #14
0
med_err _MED21attrNumLire(med_idt pere,med_type_champ type,char *nom,
			  unsigned char *val,hid_t hdf_file)
{
  med_idt attid;
  med_err ret;
  int type_hdf;

  if ((attid = H5Aopen_name(pere,nom)) < 0)
    return -1;

  switch(type) 
    {
    case MED_FLOAT64 :
      if (H5Tequal(hdf_file,H5T_IEEE_F64BE))
	type_hdf = H5T_IEEE_F64LE;
      if (H5Tequal(hdf_file,H5T_IEEE_F64LE))
	type_hdf = H5T_IEEE_F64BE;
      break;
      
    case MED_INT :
#if defined(HAVE_F77INT64)
      type_hdf = H5T_NATIVE_LONG; 
#else
      type_hdf = H5T_NATIVE_INT;
#endif
      break;
      
    default :
      return -1;
    }

  if ((ret = H5Aread(attid,type_hdf,val)) < 0)
    return -1;

  if ((ret = H5Aclose(attid)) < 0)
    return -1;

  return 0;
}
Пример #15
0
extern void
gridReaderHDF5_readIntoPatchForVar(gridReader_t reader,
                                   gridPatch_t  patch,
                                   int          idxOfVar)
{
	assert(reader != NULL);
	assert(reader->type = GRIDIO_TYPE_HDF5);
	assert(patch != NULL);
	assert(idxOfVar >= 0 && idxOfVar < gridPatch_getNumVars(patch));

	hid_t             dataSet;
	hid_t             dataSpaceFile, dataTypeFile;
	hid_t             dataSpacePatch, dataTypePatch;
	gridPointUint32_t idxLoPatch, dimsPatch;
	dataVar_t         var   = gridPatch_getVarHandle(patch, idxOfVar);
	void              *data = gridPatch_getVarDataHandle(patch, idxOfVar);

	gridPatch_getIdxLo(patch, idxLoPatch);
	gridPatch_getDims(patch, dimsPatch);

	dataSet        = H5Dopen(((gridReaderHDF5_t)reader)->file,
	                         dataVar_getName(var), H5P_DEFAULT);
	dataTypeFile   = H5Dget_type(dataSet);
	dataSpaceFile  = H5Dget_space(dataSet);

	dataTypePatch  = dataVar_getHDF5Datatype(var);
	dataSpacePatch = gridUtilHDF5_getDataSpaceFromDims(dimsPatch);

	gridUtilHDF5_selectHyperslab(dataSpaceFile, idxLoPatch, dimsPatch);

	if (H5Tequal(dataTypeFile, dataTypePatch)) {
		H5Dread(dataSet, dataTypeFile, dataSpacePatch,
		        dataSpaceFile, H5P_DEFAULT, data);
	} else {
		fprintf(stderr, "ERROR: Datatype in memory differs from file.\n");
		diediedie(EXIT_FAILURE);
	}

	H5Sclose(dataSpacePatch);
	H5Tclose(dataTypePatch);
	H5Sclose(dataSpaceFile);
	H5Tclose(dataTypeFile);
	H5Dclose(dataSet);
} /* gridReaderHDF5_readIntoPatchForVar */
Пример #16
0
static int
e5_convert_hdf_type(hid_t e5_type_id)
{
    if(H5Tequal(e5_type_id, H5T_STD_I32LE))
        return E5_TYPE_INT;
    else if(H5Tequal(e5_type_id, H5T_NATIVE_INT))
        return E5_TYPE_INT;
    else if(H5Tequal(e5_type_id, H5T_IEEE_F32LE))
        return E5_TYPE_FLOAT;
    else if(H5Tequal(e5_type_id, H5T_NATIVE_FLOAT))
        return E5_TYPE_FLOAT;
    else if(H5Tequal(e5_type_id, H5T_IEEE_F64LE))
        return E5_TYPE_DOUBLE;
    else if(H5Tequal(e5_type_id, H5T_NATIVE_DOUBLE))
        return E5_TYPE_DOUBLE;
    else if(H5Tequal(e5_type_id, H5T_C_S1 ))
        return E5_TYPE_FIXED_SIZE_STR;
    else
        return E5_TYPE_INVALID;

    return E5_TYPE_INVALID;
}
 static CollectionType* genType(hid_t datatype_id)
 {
     bool found = false;
     H5T_class_t h5_class = H5Tget_class(datatype_id);
     if(h5_class == H5T_ARRAY)
     {
         hid_t base = H5Tget_super(datatype_id);
         if(H5Tequal(base, H5T_NATIVE_HSIZE) == 1)
         {
             if(H5Tget_array_ndims(datatype_id) == 1)
             {
                 hsize_t adims_out[1];
                 H5Tget_array_dims(datatype_id, adims_out);
                 if(adims_out[0] == 3)
                     found = true;
             }
         }
         H5Tclose(base);
     }
     if(found)
         return new ColTypeDimArray;
     else
         return NULL;
 }
Пример #18
0
/*-------------------------------------------------------------------------
 * Function: print_type
 *
 * Purpose: Print name of datatype
 *
 * Return: void
 *
 * Programmer: Pedro Vicente, [email protected]
 *
 * Date: May 9, 2003
 *
 * Comments: Adapted from h5dump for H5T_INTEGER and H5T_FLOAT classes only
 *
 *-------------------------------------------------------------------------
 */
void print_type(hid_t type)
{
    switch (H5Tget_class(type))
    {
    default:
        return;
    case H5T_INTEGER:
        if (H5Tequal(type, H5T_STD_I8BE)) {
            printf("H5T_STD_I8BE");
        } else if (H5Tequal(type, H5T_STD_I8LE)) {
            printf("H5T_STD_I8LE");
        } else if (H5Tequal(type, H5T_STD_I16BE)) {
            printf("H5T_STD_I16BE");
        } else if (H5Tequal(type, H5T_STD_I16LE)) {
            printf("H5T_STD_I16LE");
        } else if (H5Tequal(type, H5T_STD_I32BE)) {
            printf("H5T_STD_I32BE");
        } else if (H5Tequal(type, H5T_STD_I32LE)) {
            printf("H5T_STD_I32LE");
        } else if (H5Tequal(type, H5T_STD_I64BE)) {
            printf("H5T_STD_I64BE");
        } else if (H5Tequal(type, H5T_STD_I64LE)) {
            printf("H5T_STD_I64LE");
        } else if (H5Tequal(type, H5T_STD_U8BE)) {
            printf("H5T_STD_U8BE");
        } else if (H5Tequal(type, H5T_STD_U8LE)) {
            printf("H5T_STD_U8LE");
        } else if (H5Tequal(type, H5T_STD_U16BE)) {
            printf("H5T_STD_U16BE");
        } else if (H5Tequal(type, H5T_STD_U16LE)) {
            printf("H5T_STD_U16LE");
        } else if (H5Tequal(type, H5T_STD_U32BE)) {
            printf("H5T_STD_U32BE");
        } else if (H5Tequal(type, H5T_STD_U32LE)) {
            printf("H5T_STD_U32LE");
        } else if (H5Tequal(type, H5T_STD_U64BE)) {
            printf("H5T_STD_U64BE");
        } else if (H5Tequal(type, H5T_STD_U64LE)) {
            printf("H5T_STD_U64LE");
        } else if (H5Tequal(type, H5T_NATIVE_SCHAR)) {
            printf("H5T_NATIVE_SCHAR");
        } else if (H5Tequal(type, H5T_NATIVE_UCHAR)) {
            printf("H5T_NATIVE_UCHAR");
        } else if (H5Tequal(type, H5T_NATIVE_SHORT)) {
            printf("H5T_NATIVE_SHORT");
        } else if (H5Tequal(type, H5T_NATIVE_USHORT)) {
            printf("H5T_NATIVE_USHORT");
        } else if (H5Tequal(type, H5T_NATIVE_INT)) {
            printf("H5T_NATIVE_INT");
        } else if (H5Tequal(type, H5T_NATIVE_UINT)) {
            printf("H5T_NATIVE_UINT");
        } else if (H5Tequal(type, H5T_NATIVE_LONG)) {
            printf("H5T_NATIVE_LONG");
        } else if (H5Tequal(type, H5T_NATIVE_ULONG)) {
            printf("H5T_NATIVE_ULONG");
        } else if (H5Tequal(type, H5T_NATIVE_LLONG)) {
            printf("H5T_NATIVE_LLONG");
        } else if (H5Tequal(type, H5T_NATIVE_ULLONG)) {
            printf("H5T_NATIVE_ULLONG");
        } else {
            printf("undefined integer");
        }
        break;
        
    case H5T_FLOAT:
        if (H5Tequal(type, H5T_IEEE_F32BE)) {
            printf("H5T_IEEE_F32BE");
        } else if (H5Tequal(type, H5T_IEEE_F32LE)) {
            printf("H5T_IEEE_F32LE");
        } else if (H5Tequal(type, H5T_IEEE_F64BE)) {
            printf("H5T_IEEE_F64BE");
        } else if (H5Tequal(type, H5T_IEEE_F64LE)) {
            printf("H5T_IEEE_F64LE");
        } else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
            printf("H5T_NATIVE_FLOAT");
        } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
            printf("H5T_NATIVE_DOUBLE");
#if H5_SIZEOF_LONG_DOUBLE !=0
        } else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) {
            printf("H5T_NATIVE_LDOUBLE");
#endif
        } else {
            printf("undefined float");
        }
        break;
        
    }/*switch*/
}
Пример #19
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
IDataArray::Pointer H5DataArrayReader::ReadNeighborListData(hid_t gid, const QString& name, bool metaDataOnly)
{

  herr_t err = -1;
  hid_t typeId = -1;
  H5T_class_t attr_type;
  size_t attr_size;
  QString res;

  QVector<hsize_t> dims; //Reusable for the loop
  IDataArray::Pointer iDataArray = IDataArray::NullPointer();
  //qDebug() << "Reading Attribute " << *iter ;
  typeId = QH5Lite::getDatasetType(gid, name);
  err = QH5Lite::getDatasetInfo(gid, name, dims, attr_type, attr_size);
  if(err < 0)
  {
    qDebug() << "Error in getAttributeInfo method in readUserMetaData." ;
  }
  else
  {
    QString classType;
    int version = 0;
    QVector<size_t> tDims;
    QVector<size_t> cDims;

    err = ReadRequiredAttributes(gid, name, classType, version, tDims, cDims);
    if(err < 0)
    {
      return iDataArray;
    }


    switch(attr_type)
    {
      case H5T_STRING:
        res.clear(); //Clear the string out first
        err = QH5Lite::readStringDataset(gid, name, res);
        break;
      case H5T_INTEGER:
        if(H5Tequal(typeId, H5T_STD_U8BE) || H5Tequal(typeId, H5T_STD_U8LE))
        {
          NeighborList<uint8_t>::Pointer ptr = NeighborList<uint8_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(H5Tequal(typeId, H5T_STD_U16BE) || H5Tequal(typeId, H5T_STD_U16LE))
        {
          NeighborList<uint16_t>::Pointer ptr = NeighborList<uint16_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(H5Tequal(typeId, H5T_STD_U32BE) || H5Tequal(typeId, H5T_STD_U32LE))
        {
          NeighborList<uint32_t>::Pointer ptr = NeighborList<uint32_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(H5Tequal(typeId, H5T_STD_U64BE) || H5Tequal(typeId, H5T_STD_U64LE))
        {
          NeighborList<uint64_t>::Pointer ptr = NeighborList<uint64_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(H5Tequal(typeId, H5T_STD_I8BE) || H5Tequal(typeId, H5T_STD_I8LE))
        {
          NeighborList<int8_t>::Pointer ptr = NeighborList<int8_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(H5Tequal(typeId, H5T_STD_I16BE) || H5Tequal(typeId, H5T_STD_I16LE))
        {
          NeighborList<int16_t>::Pointer ptr = NeighborList<int16_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(H5Tequal(typeId, H5T_STD_I32BE) || H5Tequal(typeId, H5T_STD_I32LE))
        {
          NeighborList<int32_t>::Pointer ptr = NeighborList<int32_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(H5Tequal(typeId, H5T_STD_I64BE) || H5Tequal(typeId, H5T_STD_I64LE))
        {
          NeighborList<int64_t>::Pointer ptr = NeighborList<int64_t>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else
        {
          qDebug() << "Unknown Type: " << typeId << " at " << name ;
          err = -1;
        }
        break;
      case H5T_FLOAT:
        if(attr_size == 4)
        {
          NeighborList<float>::Pointer ptr = NeighborList<float>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else if(attr_size == 8)
        {
          NeighborList<double>::Pointer ptr = NeighborList<double>::CreateArray(tDims, cDims, name, false);
          if(false == metaDataOnly)
          {
            ptr->readH5Data(gid);
          }
          iDataArray = ptr;
        }
        else
        {
          qDebug() << "Unknown Floating point type" ;
          err = -1;
        }
        break;
      default:
        qDebug() << "Error: readUserMetaData() Unknown attribute type: " << attr_type ;
        QH5Utilities::printHDFClassType(attr_type);
    }

    err = H5Tclose(typeId);
    //Close the H5A type Id that was retrieved during the loop
  }
  if (err < 0 )
  {
    iDataArray = IDataArray::NullPointer();
  }
  return iDataArray;
}
Пример #20
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
IDataArray::Pointer H5DataArrayReader::ReadIDataArray(hid_t gid, const QString& name, bool metaDataOnly)
{

  herr_t err = -1;
  //herr_t retErr = 1;
  hid_t typeId = -1;
  H5T_class_t attr_type;
  size_t attr_size;
  QString res;

  QVector<hsize_t> dims; //Reusable for the loop
  IDataArray::Pointer ptr = IDataArray::NullPointer();
  //qDebug() << "Reading Attribute " << *iter ;
  typeId = QH5Lite::getDatasetType(gid, name);
  if (typeId < 0)
  {
    return ptr;
  }
  // Get the HDF5 DataSet information. the dimensions will be the combined Tuple Dims and the Data Array Componenet dimes
  err = QH5Lite::getDatasetInfo(gid, name, dims, attr_type, attr_size);
  if(err < 0)
  {
    qDebug() << "Error in getAttributeInfo method in readUserMetaData." ;
  }
  else
  {
    QString classType;
    int version = 0;
    QVector<size_t> tDims;
    QVector<size_t> cDims;


    err = ReadRequiredAttributes(gid, name, classType, version, tDims, cDims);
    if(err < 0)
    {
      return ptr;
    }


    // Check to see if we are reading a bool array and if so read it and return
    if (classType.compare("DataArray<bool>") == 0)
    {
      if (metaDataOnly == false)
      {
        ptr = Detail::readH5Dataset<bool>(gid, name, tDims, cDims);
      }
      else
      {
        ptr = DataArray<bool>::CreateArray(tDims, cDims, name, false);
      }
      err = H5Tclose(typeId);
      return ptr; // <== Note early return here.
    }
    switch(attr_type)
    {
      case H5T_STRING:
        res.clear(); //Clear the string out first
        err = QH5Lite::readStringDataset(gid, name, res);
        //        if(err >= 0)
        //        {
        //          IDataArray::Pointer attr = MXAAsciiStringData::Create(res);
        //          attr->setName(name);
        //          attributes[*iter] = attr;
        //        }
        break;
      case H5T_INTEGER:
        //qDebug() << "User Meta Data Type is Integer" ;
        if(H5Tequal(typeId, H5T_STD_U8BE) || H5Tequal(typeId, H5T_STD_U8LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<uint8_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<uint8_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(H5Tequal(typeId, H5T_STD_U16BE) || H5Tequal(typeId, H5T_STD_U16LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<uint16_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<uint16_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(H5Tequal(typeId, H5T_STD_U32BE) || H5Tequal(typeId, H5T_STD_U32LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<uint32_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<uint32_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(H5Tequal(typeId, H5T_STD_U64BE) || H5Tequal(typeId, H5T_STD_U64LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<uint64_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<uint64_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(H5Tequal(typeId, H5T_STD_I8BE) || H5Tequal(typeId, H5T_STD_I8LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<int8_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<int8_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(H5Tequal(typeId, H5T_STD_I16BE) || H5Tequal(typeId, H5T_STD_I16LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<int16_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<int16_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(H5Tequal(typeId, H5T_STD_I32BE) || H5Tequal(typeId, H5T_STD_I32LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<int32_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<int32_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(H5Tequal(typeId, H5T_STD_I64BE) || H5Tequal(typeId, H5T_STD_I64LE))
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<int64_t>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<int64_t>::CreateArray(tDims, cDims, name, false);
          }
        }
        else
        {
          qDebug() << "Unknown Type: " << typeId << " at " << name ;
          err = -1;
        }
        break;
      case H5T_FLOAT:
        if(attr_size == 4)
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<float>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<float>::CreateArray(tDims, cDims, name, false);
          }
        }
        else if(attr_size == 8)
        {
          if (metaDataOnly == false)
          {
            ptr = Detail::readH5Dataset<double>(gid, name, tDims, cDims);
          }
          else
          {
            ptr = DataArray<double>::CreateArray(tDims, cDims, name, false);
          }
        }
        else
        {
          qDebug() << "Unknown Floating point type" ;
          err = -1;
        }
        break;
      default:
        qDebug() << "Error: readUserMetaData() Unknown attribute type: " << attr_type ;
        QH5Utilities::printHDFClassType(attr_type);
    }

    err = H5Tclose(typeId);
    //Close the H5A type Id that was retrieved during the loop
  }

  return ptr;
}
Пример #21
0
const char *HDF5Dataset::GetDataTypeName(hid_t TypeID)
{
    if( H5Tequal( H5T_NATIVE_CHAR,        TypeID ) )
	return "8-bit character";
    else if( H5Tequal( H5T_NATIVE_UCHAR,  TypeID ) ) 
	return "8-bit unsigned character";    
    else if( H5Tequal( H5T_NATIVE_SHORT,  TypeID ) )
	return "16-bit integer";
    else if( H5Tequal( H5T_NATIVE_USHORT, TypeID ) ) 
	return "16-bit unsigned integer";
    else if( H5Tequal( H5T_NATIVE_INT,    TypeID ) ) 
	return "32-bit integer";
    else if( H5Tequal( H5T_NATIVE_UINT,   TypeID ) ) 
	return "32-bit unsigned integer";
    else if( H5Tequal( H5T_NATIVE_LONG,   TypeID ) ) 
	return "32/64-bit integer";
    else if( H5Tequal( H5T_NATIVE_ULONG,  TypeID ) ) 
	return "32/64-bit unsigned integer";
    else if( H5Tequal( H5T_NATIVE_FLOAT,  TypeID ) ) 
	return "32-bit floating-point";
    else if( H5Tequal( H5T_NATIVE_DOUBLE, TypeID ) ) 
	return "64-bit floating-point";
    else if( H5Tequal( H5T_NATIVE_LLONG,  TypeID ) ) 
	return "64-bit integer";
    else if( H5Tequal( H5T_NATIVE_ULLONG, TypeID ) ) 
	return "64-bit unsigned integer";
    else if( H5Tequal( H5T_NATIVE_DOUBLE, TypeID ) ) 
        return "64-bit floating-point";
    
    return "Unknown";
}
Пример #22
0
	bool operator!=(proplist const & other) const {
		return h5e::check_error(H5Tequal(_self, other.hid()) <= 0);
	}
Пример #23
0
int diff_can_type( hid_t       f_tid1, /* file data type */
                   hid_t       f_tid2, /* file data type */
                   int         rank1,
                   int         rank2,
                   hsize_t     *dims1,
                   hsize_t     *dims2,
                   hsize_t     *maxdim1,
                   hsize_t     *maxdim2,
                   const char  *obj1_name,
                   const char  *obj2_name,
                   diff_opt_t  *options,
                   int         is_compound)
{


    H5T_class_t  tclass1;
    H5T_class_t  tclass2;
    int          maxdim_diff=0;          /* maximum dimensions are different */
    int          dim_diff=0;             /* current dimensions are different */
    int          i;
    int          can_compare = 1;        /* return value */

    /*-------------------------------------------------------------------------
    * check for the same class
    *-------------------------------------------------------------------------
    */

    if ((tclass1=H5Tget_class(f_tid1)) < 0)
        return -1;

    if ((tclass2=H5Tget_class(f_tid2)) < 0)
        return -1;

    if ( tclass1 != tclass2 )
    {

        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {

            if ( is_compound )
            {

                parallel_print("Not comparable: <%s> has a class %s and <%s> has a class %s\n",
                    obj1_name, get_class(tclass1),
                    obj2_name, get_class(tclass2) );

            }

            else

            {

                parallel_print("Not comparable: <%s> is of class %s and <%s> is of class %s\n",
                    obj1_name, get_class(tclass1),
                    obj2_name, get_class(tclass2) );

            }

        }


        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;
    }

    /*-------------------------------------------------------------------------
    * check for non supported classes
    *-------------------------------------------------------------------------
    */

    HDassert(tclass1==tclass2);
    switch (tclass1)
    {
    case H5T_INTEGER:
    case H5T_FLOAT:
    case H5T_COMPOUND:
    case H5T_STRING:
    case H5T_ARRAY:
    case H5T_BITFIELD:
    case H5T_OPAQUE:
    case H5T_ENUM:
    case H5T_VLEN:
    case H5T_REFERENCE:

        break;

    default: /*H5T_TIME */


        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {
            parallel_print("Not comparable: <%s> and <%s> are of class %s\n",
                obj1_name,obj2_name,get_class(tclass2) );
        }
        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;
    }

    /*-------------------------------------------------------------------------
    * check for equal file datatype; warning only
    *-------------------------------------------------------------------------
    */

    if ( (H5Tequal(f_tid1, f_tid2)==0) &&
        (options->m_verbose) && obj1_name && obj2_name)
    {

        H5T_class_t cl = H5Tget_class(f_tid1);


        parallel_print("Warning: different storage datatype\n");
        if ( cl == H5T_INTEGER || cl == H5T_FLOAT )
        {
            parallel_print("<%s> has file datatype ", obj1_name);
            print_type(f_tid1);
            parallel_print("\n");
            parallel_print("<%s> has file datatype ", obj2_name);
            print_type(f_tid2);
            parallel_print("\n");
        }



    }

    /*-------------------------------------------------------------------------
    * check for the same rank
    *-------------------------------------------------------------------------
    */


    if ( rank1 != rank2 )
    {

        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {
            parallel_print("Not comparable: <%s> has rank %d, dimensions ", obj1_name, rank1);
            print_dimensions(rank1,dims1);
            parallel_print(", max dimensions ");
            print_dimensions(rank1,maxdim1);
            parallel_print("\n" );
            parallel_print("and <%s> has rank %d, dimensions ", obj2_name, rank2);
            print_dimensions(rank2,dims2);
            parallel_print(", max dimensions ");
            print_dimensions(rank2,maxdim2);
            parallel_print("\n");
        }

        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;
    }

    /*-------------------------------------------------------------------------
    * check for different dimensions
    *-------------------------------------------------------------------------
    */

    HDassert(rank1==rank2);
    for ( i=0; i<rank1; i++)
    {
        if (maxdim1 && maxdim2)
        {
            if ( maxdim1[i] != maxdim2[i] )
                maxdim_diff=1;
        }
        if ( dims1[i] != dims2[i] )
            dim_diff=1;
    }

    /*-------------------------------------------------------------------------
    * current dimensions
    *-------------------------------------------------------------------------
    */

    if (dim_diff==1)
    {
        if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
        {
            parallel_print("Not comparable: <%s> has rank %d, dimensions ", obj1_name, rank1);
            print_dimensions(rank1,dims1);
            if (maxdim1 && maxdim2)
            {
                parallel_print(", max dimensions ");
                print_dimensions(rank1,maxdim1);
                parallel_print("\n" );
                parallel_print("and <%s> has rank %d, dimensions ", obj2_name, rank2);
                print_dimensions(rank2,dims2);
                parallel_print(", max dimensions ");
                print_dimensions(rank2,maxdim2);
                parallel_print("\n");
            }
        }


        can_compare = 0;
        options->not_cmp = 1;
        return can_compare;



    }

    /*-------------------------------------------------------------------------
    * maximum dimensions; just give a warning
    *-------------------------------------------------------------------------
    */
    if (maxdim1 && maxdim2 && maxdim_diff==1 && obj1_name )
    {
        if (options->m_verbose) {
            parallel_print( "Warning: different maximum dimensions\n");
            parallel_print("<%s> has max dimensions ", obj1_name);
            print_dimensions(rank1,maxdim1);
            parallel_print("\n");
            parallel_print("<%s> has max dimensions ", obj2_name);
            print_dimensions(rank2,maxdim2);
            parallel_print("\n");
        }
    }


    if ( tclass1 == H5T_COMPOUND )
    {

        int   nmembs1;
        int   nmembs2;
        int   j;
        hid_t memb_type1;
        hid_t memb_type2;

        nmembs1 = H5Tget_nmembers(f_tid1);
        nmembs2 = H5Tget_nmembers(f_tid2);

        if ( nmembs1 != nmembs2 )
        {

            if ( (options->m_verbose||options->m_list_not_cmp) && obj1_name && obj2_name)
            {
                parallel_print("Not comparable: <%s> has %d members ", obj1_name, nmembs1);
                parallel_print("<%s> has %d members ", obj2_name, nmembs2);
                parallel_print("\n");
            }

            can_compare = 0;
            options->not_cmp = 1;
            return can_compare;
        }

        for (j = 0; j < nmembs1; j++)
        {
            memb_type1 = H5Tget_member_type(f_tid1, (unsigned)j);
            memb_type2 = H5Tget_member_type(f_tid2, (unsigned)j);

            if (diff_can_type(memb_type1,
                memb_type2,
                rank1,
                rank2,
                dims1,
                dims2,
                maxdim1,
                maxdim2,
                obj1_name,
                obj2_name,
                options,
                1)!=1)
            {
                can_compare = 0;
                options->not_cmp = 1;
                H5Tclose(memb_type1);
                H5Tclose(memb_type2);
                return can_compare;
            }

            H5Tclose(memb_type1);
            H5Tclose(memb_type2);

        }





    }





    return can_compare;
}
Пример #24
0
 htri_t arma_H5Tequal(hid_t dtype_id1, hid_t dtype_id2)
   {
   return H5Tequal(dtype_id1, dtype_id2);
   }
Пример #25
0
herr_t HDF5AttrIterate( hid_t hH5ObjID, 
			const char *AttrName, 
			void *pDS )
{
    hid_t           hAttrID;
    hid_t           hAttrTypeID;
    hid_t           hAttrNativeType;
    hid_t           hAttrSpace;

    char           *szData = NULL;
    hsize_t        nSize[64];
    unsigned int            nAttrElmts;
    hsize_t        nAttrSize;
    hsize_t        i;
    void           *buf = NULL;
    unsigned int             nAttrDims;


    HDF5Dataset    *poDS;
    char           *szTemp = (char*) CPLMalloc( 8192 );
    char           *szValue = NULL;

    poDS = (HDF5Dataset *) pDS;
    sprintf( szTemp, "%s:%s", poDS->poH5CurrentObject->pszName, 
	     AttrName );

    hAttrID          = H5Aopen_name( hH5ObjID, AttrName );
    hAttrTypeID      = H5Aget_type( hAttrID );
    hAttrNativeType  = H5Tget_native_type( hAttrTypeID, H5T_DIR_DEFAULT );
    hAttrSpace       = H5Aget_space( hAttrID );
    nAttrDims        = H5Sget_simple_extent_dims( hAttrSpace, nSize, NULL );

    if( H5Tget_class( hAttrNativeType ) == H5T_STRING ) {
        nAttrSize = H5Aget_storage_size( hAttrID );
	szData = (char*) CPLMalloc((size_t) (nAttrSize+1));
	szValue = (char*) CPLMalloc((size_t) (nAttrSize+1));
	H5Aread( hAttrID, hAttrNativeType, szData  );
	szData[nAttrSize]='\0';
	sprintf( szValue, "%s", szData );

    }
    else {
	nAttrElmts = 1;
	for( i=0; i < nAttrDims; i++ ) {
	    nAttrElmts *= (int) nSize[i];
	}
	if( nAttrElmts > 0 ){
	    buf = (void *) CPLMalloc( nAttrElmts*
				      H5Tget_size( hAttrNativeType ));
	    szData = (char*) CPLMalloc( 8192 );
	    szValue = (char*) CPLMalloc( MAX_METADATA_LEN );
	    szData[0]='\0';
	    szValue[0] ='\0';
	    H5Aread( hAttrID, hAttrNativeType, buf );
	}
	if( H5Tequal( H5T_NATIVE_CHAR, hAttrNativeType ) ){
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%c ", ((char *) buf)[i]);
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_UCHAR,  hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%c", ((char *) buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_SHORT,  hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%d ", ((short *) buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_USHORT, hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%ud ", ((unsigned short *) buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_INT,    hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%d ", ((int *) buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_UINT,   hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%ud ", ((unsigned int *) buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_LONG,   hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%ld ", ((long *)buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_ULONG,  hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%ld ", ((unsigned long *)buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_FLOAT,  hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%f ",  ((float *)buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	else if( H5Tequal( H5T_NATIVE_DOUBLE, hAttrNativeType ) ) {
	    for( i=0; i < nAttrElmts; i++ ) {
		sprintf( szData, "%g ",  ((double *)buf)[i] );
		if( CPLStrlcat(szValue,szData,MAX_METADATA_LEN) >= MAX_METADATA_LEN )
		    CPLError( CE_Warning, CPLE_OutOfMemory,
			      "Header data too long. Truncated\n");
	    }
	}
	CPLFree( buf );

    }
    H5Sclose(hAttrSpace);
    H5Tclose(hAttrNativeType);
    H5Tclose(hAttrTypeID);
    H5Aclose( hAttrID );
    //printf( "%s = %s\n",szTemp, szValue );
    poDS->papszMetadata =
	CSLSetNameValue( poDS->papszMetadata, szTemp,  
			 CPLSPrintf( "%s", szValue ) );
    CPLFree( szTemp );
    CPLFree( szData );
    CPLFree( szValue );

    return 0;
}
Пример #26
0
void printType(hid_t dataType) {
  if (H5Tequal(dataType, H5T_IEEE_F64BE)) VsLog::debugLog() <<"H5T_IEEE_F64BE";
  else if (H5Tequal(dataType, H5T_NATIVE_CHAR)) VsLog::debugLog() <<"H5T_NATIVE_CHAR";
  else if (H5Tequal(dataType, H5T_NATIVE_SCHAR)) VsLog::debugLog() <<"H5T_NATIVE_SCHAR";
  else if (H5Tequal(dataType, H5T_NATIVE_UCHAR)) VsLog::debugLog() <<"H5T_NATIVE_UCHAR";
  else if (H5Tequal(dataType, H5T_NATIVE_SHORT)) VsLog::debugLog() <<"H5T_NATIVE_SHORT";
  else if (H5Tequal(dataType, H5T_NATIVE_USHORT)) VsLog::debugLog() <<"H5T_NATIVE_USHORT";
  else if (H5Tequal(dataType, H5T_NATIVE_INT)) VsLog::debugLog() <<"H5T_NATIVE_INT";
  else if (H5Tequal(dataType, H5T_NATIVE_UINT)) VsLog::debugLog() <<"H5T_NATIVE_UINT";
  else if (H5Tequal(dataType, H5T_NATIVE_LONG)) VsLog::debugLog() <<"H5T_NATIVE_LONG";
  else if (H5Tequal(dataType, H5T_NATIVE_ULONG)) VsLog::debugLog() <<"H5T_NATIVE_ULONG";
  else if (H5Tequal(dataType,H5T_NATIVE_LLONG)) VsLog::debugLog() <<"H5T_NATIVE_LLONG";
  else if (H5Tequal(dataType, H5T_NATIVE_ULLONG)) VsLog::debugLog() <<"H5T_NATIVE_ULLONG";
  else if (H5Tequal(dataType, H5T_NATIVE_FLOAT)) VsLog::debugLog() <<"H5T_NATIVE_FLOAT";
  else if (H5Tequal(dataType, H5T_NATIVE_DOUBLE)) VsLog::debugLog() <<"H5T_NATIVE_DOUBLE";
  else if (H5Tequal(dataType, H5T_NATIVE_LDOUBLE)) VsLog::debugLog() <<"H5T_NATIVE_LDOUBLE";
  else if (H5Tequal(dataType, H5T_NATIVE_HSIZE)) VsLog::debugLog() <<"H5T_NATIVE_HSIZE";
  else if (H5Tequal(dataType, H5T_NATIVE_HSSIZE)) VsLog::debugLog() <<"H5T_NATIVE_HSSIZE";
  else if (H5Tequal(dataType, H5T_NATIVE_HERR)) VsLog::debugLog() <<"H5T_NATIVE_HERR";
  else if (H5Tequal(dataType, H5T_NATIVE_HBOOL)) VsLog::debugLog() <<"H5T_NATIVE_HBOOL";
  else if (dataType == -1) VsLog::debugLog() <<"Negative 1";
  else VsLog::debugLog() <<"Unknown type";
}
Пример #27
0
int
main(void) {
   hid_t fid;                         /* File, group, datasets, datatypes */
   hid_t gid_a;                       /* and  dataspaces identifiers   */
   hid_t did_b, sid_b, tid_b;
   hid_t did_r, tid_r, sid_r;
   H5O_type_t obj_type;
   herr_t status;

   hobj_ref_t *wbuf; /* buffer to write to disk */
   hobj_ref_t *rbuf; /* buffer to read from disk */


   hsize_t dim_r[1];
   hsize_t dim_b[2];

   /*
    *  Create a file using default properties.
    */
   fid = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

   /*
    *  Create  group "A" in the file.
    */
   gid_a = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

  /*
   *  Create dataset "B" in the file.
   */
   dim_b[0] = 2;
   dim_b[1] = 6;
   sid_b = H5Screate_simple(2, dim_b, NULL);
   did_b = H5Dcreate2(fid, "B", H5T_NATIVE_FLOAT, sid_b, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

   /*
    *  Create dataset "R" to store references to the objects "A" and "B".
    */
   dim_r[0] = 2;
   sid_r = H5Screate_simple(1, dim_r, NULL);
   tid_r = H5Tcopy(H5T_STD_REF_OBJ);
   did_r = H5Dcreate2(fid, "R", tid_r, sid_r, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

   /*
    *  Allocate write and read buffers.
    */
   wbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
   rbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);

   /*
    *  Create references to the group "A" and dataset "B"
    *  and store them in the wbuf.
    */
   H5Rcreate(&wbuf[0], fid, "A", H5R_OBJECT, (hid_t)-1);
   H5Rcreate(&wbuf[1], fid, "B", H5R_OBJECT, (hid_t)-1);

   /*
    *  Write dataset R using default transfer properties.
    */
   status = H5Dwrite(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);

   /*
    *  Close all objects.
    */
   H5Gclose(gid_a);

   H5Sclose(sid_b);
   H5Dclose(did_b);

   H5Tclose(tid_r);
   H5Sclose(sid_r);
   H5Dclose(did_r);

   H5Fclose(fid);

   /*
    * Reopen the file.
    */
   fid = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);

   /*
    *  Open and read dataset "R".
    */
   did_r  = H5Dopen2(fid, "R", H5P_DEFAULT);
   status = H5Dread(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);

   /*
    * Find the type of referenced objects.
    */
    status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[0], &obj_type);
    if(obj_type == H5O_TYPE_GROUP)
        printf("First dereferenced object is a group. \n");

    status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[1], &obj_type);
    if(obj_type == H5O_TYPE_DATASET)
        printf("Second dereferenced object is a dataset. \n");

   /*
    *  Get datatype of the dataset "B"
    */
   did_b = H5Rdereference2(did_r, H5P_DEFAULT, H5R_OBJECT, &rbuf[1]);
   tid_b = H5Dget_type(did_b);
   if(H5Tequal(tid_b, H5T_NATIVE_FLOAT))
     printf("Datatype of the dataset is H5T_NATIVE_FLOAT.\n");
   printf("\n");

   /*
    * Close all objects and free memory buffers.
    */
   H5Dclose(did_r);
   H5Dclose(did_b);
   H5Tclose(tid_b);
   H5Fclose(fid);
   free(rbuf);
   free(wbuf);

   return 0;
 }
Пример #28
0
int
datMap(HDSLoc *locator, const char *type_str, const char *mode_str, int ndim,
       const hdsdim dims[], void **pntr, int *status) {

  int isprim = 0;
  char normtypestr[DAT__SZTYP+1];
  size_t nbytes = 0;
  hid_t h5type = 0;
  int isreg = 0;
  void *regpntr = NULL;
  void *mapped = NULL;
  hdsmode_t accmode = HDSMODE_UNKNOWN;
  haddr_t offset;
  hdsbool_t try_mmap = HDS_FALSE;
  unsigned intent = 0;
  size_t actbytes = 0;

  if (*status != SAI__OK) return *status;

  /* First have to validate the access mode */
  switch (mode_str[0]) {
  case 'R':
  case 'r':
    accmode = HDSMODE_READ;
    break;
  case 'U':
  case 'u':
    accmode = HDSMODE_UPDATE;
    break;
  case 'W':
  case 'w':
    accmode = HDSMODE_WRITE;
    break;
  default:
    *status = DAT__MODIN;
    emsRepf("datMap_6", "Unrecognized mode string '%s' for datMap",
            status, mode_str);
    goto CLEANUP;
  }

  /* Validate input locator. */
  dat1ValidateLocator( "datMap", 1, locator, (accmode & HDSMODE_READ), status );

  /* Get the HDF5 type code and confirm this is a primitive type */
  isprim = dau1CheckType( 1, type_str, &h5type, normtypestr,
                          sizeof(normtypestr), status );

  if (!isprim) {
    if (*status == SAI__OK) {
      *status = DAT__TYPIN;
      emsRepf("datMap_1", "datGet: Data type must be a primitive type and not '%s'",
              status, normtypestr);
    }
    goto CLEANUP;
  }

  /* Not allowed to map undefined data in READ or UPDATE mode */
  if (accmode == HDSMODE_UPDATE || accmode == HDSMODE_READ) {
    hdsbool_t defined;
    if (*status == SAI__OK) {
      datState( locator, &defined, status );
      if (!defined) {
        *status = DAT__UNSET;
        emsRepf("datMap_6bb", "Can not map an undefined primitive in mode '%s'",
                status, mode_str);
        goto CLEANUP;
      }
    }
  }

  /* How did we open this file? */
  CALLHDFQ( H5Fget_intent( locator->file_id, &intent ));
  if (accmode == HDSMODE_UPDATE || accmode == HDSMODE_WRITE) {
    /* Must check whether the file was opened for write */
    if ( intent == H5F_ACC_RDONLY ) {
      *status = DAT__ACCON;
      emsRepf("datMap_6b", "datMap: Can not map readonly locator in mode '%s'",
             status, mode_str);
      goto CLEANUP;
    }
  }

  /* Verify that the specified dimensions match the locator dimensions */
  if (*status == SAI__OK) {
    hdsdim locdims[DAT__MXDIM];
    int locndims;
    int i;
    datShape(locator, DAT__MXDIM, locdims, &locndims, status );

    /* Note that if we are mapping as a scalar the locator should
       refer to a single element */
    if (ndim == 0) {
      size_t nelem = 1;
      for (i=0; i<locndims; i++) {
        nelem *= locdims[i];
      }
      if (nelem != 1) {
        *status = DAT__DIMIN;
        emsRepf("datMap_6e", "datMap: Attempt to map as a scalar but locator"
                " refers to a primitive with %zu elements",
                status, nelem);
        goto CLEANUP;
      }
    } else {
      if (ndim != locndims) {
        *status = DAT__DIMIN;
        emsRepf("datMap_6c", "datMap: Dimensionality mismatch --"
                " requested number: %d locator number: %d", status,
                ndim, locndims );
        goto CLEANUP;
      }
      for (i=0; i<ndim; i++) {
        if ( locdims[i] != dims[i] ) {
          *status = DAT__DIMIN;
          emsRepf("datMap_6d", "datMap: Dimension %d has size %zu but requested size %zu",
                  status, i, (size_t)locdims[i], (size_t)dims[i]);
          goto CLEANUP;
        }
      }
    }
  }

  /* There is a super-special case for datMap when called with a map
     type of "_CHAR". In that case we need to work out the size ourselves
     and adjust the type size */
  if (strcmp( "_CHAR", normtypestr ) == 0 ) {
    size_t clen = 0;
    char tmpbuff[DAT__SZTYP+1];
    datClen( locator, &clen, status );
    CALLHDFQ( H5Tset_size( h5type, clen ) );
    one_snprintf( tmpbuff, sizeof(tmpbuff), "*%zu",
                  status, clen );
    one_strlcat( normtypestr, tmpbuff, DAT__SZTYP+1, status );
  }

  /* Now we want the HDSTYPE of the requested type so that we can work out how much
     memory we will need to allocate. */
  CALLHDFE( size_t, nbytes,
          H5Tget_size( h5type ),
          DAT__HDF5E,
          emsRep("datLen_size", "datMap: Error obtaining size of requested data type",
                 status)
          );

  {
    int i;
    if (ndim > 0) {
      for (i = 0; i < ndim; i++) {
        nbytes *= dims[i];
      }
    }
  }


  /* Work out whether memory mapping is possible -- at the moment
     I'm pretty sure the only safe use of mmap is when we are reading
     the data and the file itself was opened readonly. I'm not sure what happens
     if other components are removed or added -- will the offset change? Maybe we just try */
  offset = H5Dget_offset( locator->dataset_id );
  if (offset != HADDR_UNDEF) {
    hid_t dataset_h5type = 0;
    /* In theory we can do a memory map so now compare
       the data types of the request and the low-level dataset. */
    CALLHDFE( hid_t, dataset_h5type,
             H5Dget_type( locator->dataset_id ),
             DAT__HDF5E,
             emsRep("datMap_type", "datType: Error obtaining data type of dataset", status)
             );
    if (H5Tequal( dataset_h5type, h5type )) {
      try_mmap = HDS_TRUE;
    }
    H5Tclose(dataset_h5type);
  }

  /* If this is a locator to a slice then for now we can't memory map. In theory
     if we knew the slice was contiguous (e.g a vectorized slice, or a single
     plane of a cube then we could mmap it anyhow. We do not want to have to
     emulate HDF5 dataspaces here */
  if (locator->isslice) try_mmap = 0;

  /* There seem to be issues doing this on files opened for update/write.
     For now only allow mmap for files opened read only */
  if (intent != H5F_ACC_RDONLY) try_mmap = 0;

  /* If mmap has been disabled by tuning the environment we just force it off here. */
  if (!hds1GetUseMmap()) try_mmap = 0;

#if DEBUG_HDS
  {
    char *name_str;
    char * file_str;
    const char * reason;
    name_str = dat1GetFullName( locator->dataset_id, 0, NULL, status );
    file_str = dat1GetFullName( locator->dataset_id, 1, NULL, status );
    if (offset != HADDR_UNDEF) {
      reason = "[HAD offset]";
    } else {
      reason = "[no offset]";
    }
    if (!try_mmap) {
      printf("Will NOT attempt %s to mmap %s:%s\n",reason,file_str,name_str);
    } else {
      printf("WILL TRY %s to mmap OFFSET=%zu %s:%s\n", reason, (size_t)offset, file_str, name_str);
    }
    MEM_FREE(name_str);
  }
#endif

  if (try_mmap) {
    int fd = 0;
    int flags = 0;
    int prot = 0;
    hdsbool_t opened_fd = 0;

    if ( intent == H5F_ACC_RDONLY || accmode == HDSMODE_READ ) {
      flags |= O_RDONLY;
      prot = PROT_READ;
    } else {
      flags |= O_RDWR;
      prot = PROT_READ | PROT_WRITE;
    }

    if (*status == SAI__OK) {
      /* see what file driver we have */
      hid_t fapl_id = -1;
      hid_t fdriv_id = -1;
      void * file_handle = NULL;
      herr_t herr = -1;
      fapl_id = H5Fget_access_plist(locator->file_id);
      fdriv_id = H5Pget_driver(fapl_id);
      if (fdriv_id == H5FD_SEC2 || fdriv_id == H5FD_STDIO) {
        /* If this is a POSIX or STDIO driver we get the handle */
        herr = H5Fget_vfd_handle( locator->file_id, fapl_id, (void**)&file_handle);
        if (herr >= 0) {
          if (fdriv_id == H5FD_SEC2) {
            fd = *((int *)file_handle);
          } else if (fdriv_id == H5FD_STDIO) {
            FILE * fh = (FILE *)file_handle;
            fd = fileno(fh);
          }
        }
      }
      if (fapl_id > 0) H5Pclose( fapl_id );

      if (fd == 0) {
        /* We have to open the file ourselves! */
        char * fname = NULL;
        fname = dat1GetFullName( locator->dataset_id, 1, NULL, status );
        fd = open(fname, flags);
        opened_fd = 1;
        if (fname) MEM_FREE(fname);
      }
      if (fd > 0) {
        /* Set up for memory mapping */
        int mflags = 0;
        mflags = MAP_SHARED | MAP_FILE;
        if (*status == SAI__OK) {
          mapped = dat1Mmap( nbytes, prot, mflags, fd, offset, &isreg, &regpntr, &actbytes, status );
          if (*status == SAI__OK) {
            /* Store the file descriptor in the locator to allow us to close */
            if (mapped) {
              if (opened_fd) locator->fdmap = fd;
              locator->uses_true_mmap = 1;
            }
          } else {
            /* Not currently fatal -- we can try without the file */
            if (opened_fd) close(fd);
            emsAnnul(status);
          }
        }
      }
    }
  }

  /* If we have not been able to map anything yet, just get some memory. It is
     zeroed (for WRITE) to match mmap behavior. We rely on the OS to decide when it is reasonable
     to do an anonymous mmap. */

  if (!regpntr) {
    hdsbool_t mustget;
    mustget = (accmode == HDSMODE_READ || accmode == HDSMODE_UPDATE);

    if (mustget) {
      regpntr = cnfMalloc( nbytes );
    } else {
      regpntr = cnfCalloc( 1, nbytes );
    }
    if (!regpntr) {
      *status = DAT__NOMEM;
      emsRepf("datMap_cnf","datMap: Unable to allocate %zu bytes of memory",
              status, nbytes);
      goto CLEANUP;
    }

    /* Populate the memory - check with datState occurred earlier */
    if (mustget) {
      datGet( locator, normtypestr, ndim, dims, regpntr, status );
    }
  }

 CLEANUP:
  /* Cleanups that must happen always */
  if (h5type) H5Tclose(h5type);

  /* cleanups that only happen if status is bad */
  if (*status != SAI__OK) {
    if (mapped) {
      if (isreg == 1) cnfUregp( regpntr );
      if ( munmap( mapped, actbytes ) != 0 ) {
        emsSyser( "MESSAGE", errno );
        emsRep("datMap_4", "Error unmapping mapped memory: ^MESSAGE", status);
      }
      mapped = NULL;
    } else if (regpntr) {
      cnfFree( regpntr );
    }
    regpntr = NULL;
  }

  /* Update the locator to reflect the mapped status */
  if (*status == SAI__OK) {
    int i;
    locator->pntr = mapped;
    locator->regpntr = regpntr;
    locator->bytesmapped = actbytes;
    locator->accmode = accmode;

    /* In order to copy the data back into the underlying HDF5 dataset
       we need to store additional information about how this was mapped
       to allow us to either call datPut later on or at least a new
       dataspace. For now store the arguments so we can pass them straight
       to datPut */
    locator->ndims = ndim;
    for (i=0; i<ndim; i++) {
      (locator->mapdims)[i] = dims[i];
    }
    star_strlcpy( locator->maptype, normtypestr, sizeof(locator->maptype) );
  }

  /* Note that the returned pointer is not necessarily the same as the
     mapped pointer because of pagesize corrections */
  *pntr = regpntr;

  return *status;
}
Пример #29
0
bool DataType::equals (const DataType& other) const {
    return Exception::check ("H5Tequal", H5Tequal (handle (), other.handle ())) != 0;
}
Пример #30
0
/*-------------------------------------------------------------------------
 * Function:    h5tools_str_sprint
 *
 * Purpose: Renders the value pointed to by VP of type TYPE into variable
 *      length string STR.
 *
 * Return:  A pointer to memory containing the result or NULL on error.
 *
 * Programmer:  Robb Matzke
 *              Thursday, July 23, 1998
 *
 * Modifications:
 *      Robb Matzke, 1999-04-26
 *      Made this function safe from overflow problems by allowing it
 *      to reallocate the output string.
 *
 *      Robb Matzke, 1999-06-04
 *      Added support for object references. The new `container'
 *      argument is the dataset where the reference came from.
 *
 *      Robb Matzke, 1999-06-07
 *      Added support for printing raw data. If info->raw is non-zero
 *      then data is printed in hexadecimal format.
 *
 *  Robb Matzke, 2003-01-10
 *  Binary output format is dd:dd:... instead of 0xdddd... so it
 *  doesn't look like a hexadecimal integer, and thus users will
 *  be less likely to complain that HDF5 didn't properly byte
 *  swap their data during type conversion.
 *
 *  Robb Matzke, LLNL, 2003-06-05
 *  If TYPE is a variable length string then the pointer to
 *  the value to pring (VP) is a pointer to a `char*'.
 *
 *  PVN, 28 March 2006
 *  added H5T_NATIVE_LDOUBLE case
 *-------------------------------------------------------------------------
 */
char *
h5tools_str_sprint(h5tools_str_t *str, const h5tool_format_t *info, hid_t container,
                   hid_t type, void *vp, h5tools_context_t *ctx)
{
    size_t         n, offset, size=0, nelmts, start;
    char          *name;
    unsigned char *ucp_vp = (unsigned char *)vp;
    char          *cp_vp = (char *)vp;
    hid_t          memb, obj, region;
    unsigned       nmembs;
    static char    fmt_llong[8], fmt_ullong[8];
    H5T_str_t      pad;

    /*
     * some tempvars to store the value before we append it to the string to
     * get rid of the memory alignment problem
     */
    unsigned long long tempullong;
    long long          templlong;
    unsigned long      tempulong;
    long               templong;
    unsigned int       tempuint;
    int                tempint;

    /* Build default formats for long long types */
    if (!fmt_llong[0]) {
        sprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH);
        sprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH);
    }

    /* Append value depending on data type */
    start = h5tools_str_len(str);

    if (info->raw) {
        size_t i;

        n = H5Tget_size(type);
        if (1 == n) {
            h5tools_str_append(str, OPT(info->fmt_raw, "0x%02x"), ucp_vp[0]);
        }
        else {
            for (i = 0; i < n; i++) {
                if (i)
                    h5tools_str_append(str, ":");
                h5tools_str_append(str, OPT(info->fmt_raw, "%02x"), ucp_vp[i]);
            }
        }
    }
    else if (H5Tequal(type, H5T_NATIVE_FLOAT)) {
        float tempfloat;

        HDmemcpy(&tempfloat, vp, sizeof(float));
        h5tools_str_append(str, OPT(info->fmt_float, "%g"), tempfloat);
    }
    else if (H5Tequal(type, H5T_NATIVE_DOUBLE)) {
        double tempdouble;

        HDmemcpy(&tempdouble, vp, sizeof(double));
        h5tools_str_append(str, OPT(info->fmt_double, "%g"), tempdouble);
#if H5_SIZEOF_LONG_DOUBLE !=0
    }
    else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)) {
        long double templdouble;

        HDmemcpy(&templdouble, vp, sizeof(long double));
        h5tools_str_append(str, "%Lf", templdouble);
#endif
    }
    else if (info->ascii && (H5Tequal(type, H5T_NATIVE_SCHAR) ||
                             H5Tequal(type, H5T_NATIVE_UCHAR))) {
        h5tools_print_char(str, info, (char) (*ucp_vp));
    }
    else if (H5T_STRING == H5Tget_class(type)) {
        unsigned int i;
        char quote = '\0';
        char *s;

        quote = '\0';
        if (H5Tis_variable_str(type)) {
            /* cp_vp is the pointer into the struct where a `char*' is stored. So we have
             * to dereference the pointer to get the `char*' to pass to HDstrlen(). */
            s = *(char**) cp_vp;
            if (s != NULL)
                size = HDstrlen(s);
        }
        else {
            s = cp_vp;
            size = H5Tget_size(type);
        }
        pad = H5Tget_strpad(type);

        /* Check for NULL pointer for string */
        if (s == NULL) {
            h5tools_str_append(str, "NULL");
        }
        else {
            for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) {
                int j = 1;

                /*
                 * Count how many times the next character repeats. If the
                 * threshold is zero then that means it can repeat any number
                 * of times.
                 */
                if (info->str_repeat > 0)
                    while (i + j < size && s[i] == s[i + j])
                        j++;

                /*
                 * Print the opening quote.  If the repeat count is high enough to
                 * warrant printing the number of repeats instead of enumerating
                 * the characters, then make sure the character to be repeated is
                 * in it's own quote.
                 */
                if (info->str_repeat > 0 && j > info->str_repeat) {
                    if (quote)
                        h5tools_str_append(str, "%c", quote);

                    quote = '\'';
                    h5tools_str_append(str, "%s%c", i ? " " : "", quote);
                }
                else if (!quote) {
                    quote = '"';
                    h5tools_str_append(str, "%s%c", i ? " " : "", quote);
                }

                /* Print the character */
                h5tools_print_char(str, info, s[i]);

                /* Print the repeat count */
                if (info->str_repeat && j > info->str_repeat) {
#ifdef REPEAT_VERBOSE
                    h5tools_str_append(str, "%c repeats %d times", quote, j - 1);
#else
                    h5tools_str_append(str, "%c*%d", quote, j - 1);
#endif  /* REPEAT_VERBOSE */
                    quote = '\0';
                    i += j - 1;
                }

            }

            if (quote)
                h5tools_str_append(str, "%c", quote);

            if (i == 0)
                /*empty string*/
                h5tools_str_append(str, "\"\"");
        } /* end else */
    }
    else if (H5Tequal(type, H5T_NATIVE_INT)) {
        HDmemcpy(&tempint, vp, sizeof(int));
#ifdef H5_HAVE_H5DUMP_PACKED_BITS
        if(packed_bits_num)
            tempint = (tempint >> packed_data_offset) & packed_data_mask;
#endif
        h5tools_str_append(str, OPT(info->fmt_int, "%d"), tempint);
    }
    else if (H5Tequal(type, H5T_NATIVE_UINT)) {