Example #1
0
med_err _MEDsoftlinkDel(const med_idt               id,
			const char * const          softlinkname,
			med_bool                    linkmustexist
			) {

  med_err         _ret=-1;
  H5L_info_t      _linkinfo;


  if ( H5Lget_info( id, softlinkname,  &_linkinfo, H5P_DEFAULT ) >= 0 ) {
    if ( _linkinfo.type == H5L_TYPE_SOFT ) {
      if ( H5Ldelete(id,softlinkname,H5P_DEFAULT) < 0 ) {
	MED_ERR_(_ret,MED_ERR_DELETE,MED_ERR_LINK,softlinkname);
	goto ERROR;
      }
    } else if (linkmustexist) {
      MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_LINK,softlinkname);
      goto ERROR;
    }
  } else if (linkmustexist) {
    MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_LINK,softlinkname);
    goto ERROR;
  }

  _ret=0;
 ERROR:
  return _ret;
}
Example #2
0
int luaC_h5_open_group(lua_State *L)
{
  const char *gname = luaL_checkstring(L, 1);
  const char *mode  = luaL_checkstring(L, 2);

  hid_t grp = 0;

  if (PresentFile < 0) {
    luaL_error(L, "need an open file to open group\n");
  }
  else if (strcmp(mode, "w") == 0) {
    if (H5Lexists(PresentFile, gname, H5P_DEFAULT)) {
      H5Ldelete(PresentFile, gname, H5P_DEFAULT);
    }
    grp = H5Gcreate(PresentFile, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  }
  else if (strcmp(mode, "r+") == 0) {
    if (H5Lexists(PresentFile, gname, H5P_DEFAULT)) {
      grp = H5Gopen(PresentFile, gname, H5P_DEFAULT);
    }
    else {
      grp = H5Gcreate(PresentFile, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    }
  }
  else {
    luaL_error(L, "invalid group access mode '%s'\n", mode);
  }

  lua_pushnumber(L, grp);
  return 1;
}
Example #3
0
//--------------------------------------------------------------------------
// Function:	CommonFG::unlink
///\brief	Removes the specified name at this location.
///\param	name  - IN: Name of the object to be removed
///\exception	H5::FileIException or H5::GroupIException
// Programmer	Binh-Minh Ribler - 2000
// Modification
//	2007: QAK modified to use H5L APIs - BMR
//--------------------------------------------------------------------------
void CommonFG::unlink( const char* name ) const
{
   herr_t ret_value = H5Ldelete( getLocId(), name, H5P_DEFAULT );
   if( ret_value < 0 )
   {
      throwException("unlink", "H5Ldelete failed");
   }
}
Example #4
0
char HDocument::deleteObject(const std::string & path, hid_t parentId)
{
    if(parentId == 0) parentId = fFileId;
	if(H5Ldelete(parentId, path.c_str(), H5P_DEFAULT) < 0) {
		fCurrentError = eDeleteFailure;
		return 0;
	}
	return 1;
}
Example #5
0
    void DCDataSet::create(const CollectionType& colType,
            hid_t group, const Dimensions size, uint32_t ndims, bool compression)
    throw (DCException)
    {
        log_msg(2, "DCDataSet::create (%s, size %s)", name.c_str(), size.toString().c_str());

        if (opened)
            throw DCException(getExceptionString("create: dataset is already open"));

        // if the dataset already exists, remove/unlink it
        // note that this won't free the memory occupied by this
        // dataset, however, there currently is no function to delete
        // a dataset
        if (!checkExistence || (checkExistence && H5Lexists(group, name.c_str(), H5P_LINK_ACCESS_DEFAULT)))
            H5Ldelete(group, name.c_str(), H5P_LINK_ACCESS_DEFAULT);

        this->ndims = ndims;
        this->compression = compression;
        this->datatype = colType.getDataType();

        getLogicalSize().set(size);

        setChunking(colType.getSize());
        setCompression();

        if (getPhysicalSize().getScalarSize() != 0)
        {
            hsize_t *max_dims = new hsize_t[ndims];
            for (size_t i = 0; i < ndims; ++i)
                max_dims[i] = H5F_UNLIMITED;

            dataspace = H5Screate_simple(ndims, getPhysicalSize().getPointer(), max_dims);

            delete[] max_dims;
            max_dims = NULL;
        } else
            dataspace = H5Screate(H5S_NULL);



        if (dataspace < 0)
            throw DCException(getExceptionString("create: Failed to create dataspace"));

        // create the new dataset
        dataset = H5Dcreate(group, this->name.c_str(), this->datatype, dataspace,
                H5P_DEFAULT, dsetProperties, H5P_DEFAULT);

        if (dataset < 0)
            throw DCException(getExceptionString("create: Failed to create dataset"));

        isReference = false;
        opened = true;
    }
Example #6
0
//------------------------------------------------------------------------------
xdm::RefPtr< DatasetIdentifier > createDatasetIdentifier(
  const DatasetParameters& parameters ) {
  
  // check if the dataset already exists within the given parent
  htri_t exists = H5Lexists(
    parameters.parent,
    parameters.name.c_str(),
    H5P_DEFAULT );
  
  if ( exists ) {
    if ( parameters.mode == xdm::Dataset::kCreate ) {
      // the dataset exists and a create was requested, delete the existing one
      H5Ldelete( parameters.parent, parameters.name.c_str(), H5P_DEFAULT );
    } else {
      // read or modify access, open and return the existing dataset
      return openExistingDataset( parameters );
    }
  }

  // the dataset doesn't exist. Read only access is an error.
  if ( parameters.mode == xdm::Dataset::kRead ) {
    XDM_THROW( xdm::DatasetNotFound( parameters.name ) );
  }

  // Determine the dataset access properties based off chunking and compression
  // parameters.
  xdm::RefPtr< PListIdentifier > createPList( new PListIdentifier( H5P_DEFAULT ) );
  if ( parameters.chunked ) {
    createPList->reset( H5Pcreate( H5P_DATASET_CREATE ) );
    setupChunks( createPList->get(), parameters.chunkSize, parameters.dataspace );
    // Chunking is enabled, so check for compression and enable it if possible.
    if ( parameters.compress ) {
      setupCompression( createPList->get(), parameters.compressionLevel );
    }
  }

  // the mode is create or modify. In both cases we want to create it if it
  // doesn't yet exist. It is safe to create the dataset here because we deleted
  // the dataset earlier if it existed.
  hid_t datasetId = H5Dcreate(
    parameters.parent,
    parameters.name.c_str(),
    parameters.type,
    parameters.dataspace,
    H5P_DEFAULT,
    createPList->get(),
    H5P_DEFAULT );

  return xdm::RefPtr< DatasetIdentifier >( new DatasetIdentifier( datasetId ) );

}
Example #7
0
hdf5dataset::hdf5dataset(hdf5file &hfile, const std::string &name, hid_t type_id, hid_t space_id, bool overwrite): _type_id(type_id), _hfile(hfile), _name(name)
{
	hfile.touch_group_recursive(name);

	bool exists = H5Lexists(_hfile.handle(), name.c_str(), H5P_DEFAULT);
	if(exists && overwrite)
		H5Ldelete(_hfile.handle(), name.c_str(), H5P_DEFAULT);
	else if(exists && !overwrite)
		throw std::runtime_error("Dataset already exists (" + _hfile.filename() + ") in file (" + name + ")");

	_dataset_id = H5Dcreate(hfile.handle(), name.c_str(), type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
	_own_type_id = false;

	if(_dataset_id < 0)
		throw std::runtime_error("Error creating or opening dataset (" + _hfile.filename() + ") in file (" + name + ")");

}
Example #8
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Ldelete
 * Signature: (JLjava/lang/String;J)V
 */
JNIEXPORT void JNICALL
Java_hdf_hdf5lib_H5_H5Ldelete
    (JNIEnv *env, jclass clss, jlong loc_id, jstring name, jlong access_id)
{
    herr_t      status = -1;
    const char *lName;

    PIN_JAVA_STRING(name, lName);
    if (lName != NULL) {
        status = H5Ldelete((hid_t)loc_id, lName, (hid_t)access_id);

        UNPIN_JAVA_STRING(name, lName);

        if (status < 0)
            h5libraryError(env);
    }
} /* end Java_hdf_hdf5lib_H5_H5Ldelete */
Example #9
0
HDF5Err
HDF5Group::deleteSubtree(HDF5Id group_id, const char *group_name,
                         const H5L_info_t *NK_UNUSED_PARAM(group_info), 
                         void *NK_UNUSED_PARAM(op_data))
{
    // open the child group
    HDF5Group child_group;
    child_group.open(group_id, String(group_name));

    // iterate over the group's children
    HDF5Size iter_index = 0;
    H5Literate(child_group.id(), H5_INDEX_CRT_ORDER, H5_ITER_NATIVE, 
               &iter_index, deleteSubtree, NULL);

    // close the child group
    child_group.close();

    // delete the link
    H5Ldelete(group_id, group_name, H5P_DEFAULT);

    return 0;
}
Example #10
0
int
datErase(const HDSLoc   *locator, const char *name_str, int *status) {
  char groupstr[DAT__SZNAM+1];
  char cleanname[DAT__SZNAM+1];

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

  /* Validate input locator. */
  dat1ValidateLocator( "datErase", 1, locator, 0, status );

  /* containing locator must refer to a group */
  if (locator->group_id <= 0) {
    *status = DAT__OBJIN;
    emsRep("datErase_1", "Input object is not a structure",
           status);
    return *status;
  }

  /* Parent group for error reporting */
  datName( locator, groupstr, status);

  /* Ensure the name is cleaned up before we use it */
  dau1CheckName( name_str, 1, cleanname, sizeof(cleanname), status );

  CALLHDFQ( H5Ldelete( locator->group_id, cleanname, H5P_DEFAULT ));

  /* Remove the handle for the erased component and all sub-components */
  dat1EraseHandle( locator->handle, cleanname, status );

 CLEANUP:
  if (*status != SAI__OK) {
    emsRepf("datErase_2", "Error deleting component %s in group %s",
            status, name_str, groupstr);
  }
  return *status;
}
Example #11
0
void LocID::deleteLink(std::string name, hid_t plist) {
    HErr res = H5Ldelete(hid, name.c_str(), plist);
    res.check("LocIDL::deleteLink: Could not delete link: " + name);
}
Example #12
0
void hdf5_h5l_delete(value loc_v, value lapl_v, value name_v)
{
  CAMLparam3(loc_v, lapl_v, name_v);
  raise_if_fail(H5Ldelete(Hid_val(loc_v), String_val(name_v), H5P_opt_val(lapl_v)));
  CAMLreturn0;
}
void MAJ_236_300_champs(med_idt fid)
{
  med_err lret,ret;
  /*   med_idt         _datagroup=0; */
  med_field_type   typcha;
  char nomcha    [MED_NAME_SIZE+1]="";
  char _meshname [MED_NAME_SIZE+1]="";
  char _dtunit   [MED_SNAME_SIZE+1]="";
  char *comp= NULL, *unit= NULL;
  med_int   ncomp,ncha;
  med_int  _ncstp=0;
  med_bool _local=MED_FALSE;
  htri_t   _datasetexist;
  char _pathi[MED_TAILLE_CHA+1+MED_NAME_SIZE+1]=MED_CHA;
  char _pathf[MED_TAILLE_CHA+2+MED_NAME_SIZE+1]="/CHA_/";
  char _pathtmp[MED_TAILLE_CHA+3]="/CHA__/";
  int i,j;

  char nomlien[MED_NAME_SIZE+1]="";
  char * lien = NULL;
  med_int nln,nval;

  med_int  _nloc,_intgeotype,_sdim;
  char     _pathloc[MED_TAILLE_GAUSS+MED_NAME_SIZE+1]=MED_GAUSS;

  med_int  _npar,_numdt,_numit;
  char     _pathpari[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA;
  char     _pathparf[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA;
  int      _pathparlen;
  med_size _n=0;
  char     _cpstnamei[2*MED_MAX_PARA+1]="";
  char     _cpstnamef[2*MED_MAX_PARA+1]="";
  char     _uniname[MED_SNAME_SIZE+1]="";
/*   hid_t    _lac_plist_id; */
  hid_t    _lcp_plist_id;
  hid_t    _ocp_plist_id;
  med_bool _createunt = MED_TRUE;

  MAJ_version_num(fid,2,3,6);

  /* MAJ des varaibles scalaires */
  _npar = MEDnParameter(fid);
  if (_npar > 0) {
    fprintf(stdout,"  >>> Normalisation des paramètres scalaires\n");
    _pathparf[MED_TAILLE_NUM_DATA-2]='_';
/*     _lac_plist_id = H5Pcreate( H5P_LINK_ACCESS ); */
    _ocp_plist_id = H5Pcreate( H5P_OBJECT_COPY );
    _lcp_plist_id = H5Pcreate( H5P_LINK_CREATE );
    H5Pset_create_intermediate_group( _lcp_plist_id, 1 );
    H5Pset_copy_object( _ocp_plist_id, H5O_COPY_SHALLOW_HIERARCHY_FLAG);
  }

  for (i=0 ; i < _npar ; i++ ) {

    MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,i, &_pathpari[MED_TAILLE_NUM_DATA]) < 0,
		     MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari);


    strcpy(&_pathparf[MED_TAILLE_NUM_DATA],&_pathpari[MED_TAILLE_NUM_DATA]);
/*     SSCRUTE(_pathparf); */
/*     SSCRUTE(_pathpari); */

    /*Copie le group avec ses attributs et les objets de premier niveau.*/
    ret =  H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id);
/*     ret =  H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */
    EXIT_IF(ret < 0,"Copie du datagroup",_pathpari);

    _pathparlen=strlen(_pathpari);
    _pathpari[_pathparlen]='/';_pathparf[_pathparlen]='/';
    ++_pathparlen;
    _pathpari[_pathparlen]='\0';_pathparf[_pathparlen]='\0';

/*     SSCRUTE(_pathparf); */
/*     SSCRUTE(_pathpari); */

    ret =_MEDnObjects(fid,_pathpari, &_n);
    MED_ERR_EXIT_IF( (ret == (MED_ERR_COUNT + MED_ERR_DATAGROUP)), MED_ERR_COUNT,MED_ERR_PARAMETER,_pathpari);

    for (j=0 ; j < _n ; ++j ) {
      MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,j, &_pathpari[_pathparlen]) < 0,
		       MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari);

      MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NOR,
						MED_INTERNAL_INT,(unsigned char * const ) &_numit) < 0,
		       MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NOR);

      MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NDT,
						MED_INTERNAL_INT,(unsigned char * const ) &_numdt) < 0,
		       MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT);
      
      MED_ERR_EXIT_IF (_MEDattributeStringRdByName(fid,_pathpari,MED_NOM_UNI,
						MED_SNAME_SIZE,_uniname) < 0,
		       MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT);
      
      _MEDgetComputationStepName(MED_SORT_DTIT,_numdt,_numit,&_pathparf[_pathparlen]);
/*       strcat(_pathpari,"/"); */
/*       strcat(_pathparf,"/"); */
/*       SSCRUTE(_pathparf); */
/*       SSCRUTE(_pathpari); */

/*       ret =  H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id); */
/*       ret =  H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */
/*       H5Eprint1(stderr); */
/*       EXIT_IF(ret < 0,"Copie d'une étape de calcul du paramètre scalaire ",_pathpari); */

      /*On modifie temporairement _pathpari pour pointer dans _pathparf*/
      _pathpari[MED_TAILLE_NUM_DATA-2]='_';
/*       SSCRUTE(_pathparf); */
/*       SSCRUTE(_pathpari); */
      ret = H5Gmove(fid, _pathpari, _pathparf  );
      EXIT_IF(ret < 0,"Renommage de l'étape de calcul",_pathpari);
      _pathpari[MED_TAILLE_NUM_DATA-2]='A';


      MED_ERR_EXIT_IF(H5Adelete_by_name( fid, _pathparf, MED_NOM_UNI, H5P_DEFAULT ) < 0,
		      MED_ERR_DELETE,MED_ERR_ATTRIBUTE,_pathparf);

      _pathparf[_pathparlen]='\0';
      _pathpari[_pathparlen]='\0';
      if ( _createunt ) {
	MED_ERR_EXIT_IF (_MEDattributeStringWrByName(fid,_pathparf,MED_NOM_UNT, MED_SNAME_SIZE,_uniname) < 0,
			 MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_UNT);
	_createunt = MED_FALSE;
      }
    }
    _createunt = MED_TRUE;
    _pathpari[MED_TAILLE_NUM_DATA]='\0';
  }

  if ( _npar > 0 ) {

    _pathpari[MED_TAILLE_NUM_DATA]='\0';
    _pathparf[MED_TAILLE_NUM_DATA]='\0';
    MED_ERR_EXIT_IF ( H5Ldelete(fid,_pathpari,H5P_DEFAULT) < 0 ,
		      MED_ERR_DELETE,MED_ERR_LINK,_pathpari);

    ret = H5Gmove(fid, _pathparf, _pathpari  );
    EXIT_IF(ret < 0,"Renommage du group de paramètres scalaires",_pathparf);

  }

  /* MAJ des localisations */
  _nloc = MEDnLocalization(fid);
/*   ISCRUTE(_nloc); */
  if (_nloc > 0)
    fprintf(stdout,"  >>> Normalisation des localisations des points d'intégration\n");
  for (i=0 ; i < _nloc ; i++ ) {

/*     SSCRUTE(_pathloc); */
    MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathloc ,i, &_pathloc[MED_TAILLE_GAUSS]) < 0,
		     MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathloc);
/*     SSCRUTE(_pathloc); */
    MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathloc,MED_NOM_GEO,
					      MED_INTERNAL_INT,(unsigned char * const ) &_intgeotype) < 0,
		     MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
    _sdim = (_intgeotype/100);

    MED_ERR_EXIT_IF (_MEDattributeNumWrByName(fid,_pathloc,MED_NOM_DIM,
					      MED_INTERNAL_INT,(const unsigned char * const) &_sdim) < 0,
		     MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_DIM);

    MED_ERR_EXIT_IF ( _MEDattributeStringWrByName(fid,_pathloc,MED_NOM_INM,MED_NAME_SIZE,"") < 0,
		      MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_INM);
    _pathloc[MED_TAILLE_GAUSS]='\0';

  }

  /* MAJ des liens */
  nln = MEDnLink(fid);
  if (nln > 0)
    fprintf(stdout,"  >>> Normalisation des liens\n");
  for (i=1 ; i <= nln ; i++ ) {


    ret =  MEDlinkInfo(fid, i, nomlien, &nval);
    EXIT_IF(ret,"Erreur a la demande d'information sur le lien",NULL);

/*     printf("\t- Lien n°%i de nom |%s| et de taille "IFORMAT"\n",i,nomlien,nval); */

    lien = (char *) malloc((nval+1)*sizeof(char));
    EXIT_IF(lien == NULL,NULL,NULL);

    ret = MEDlinkRd(fid, nomlien, lien );
    EXIT_IF(ret,"Erreur a la lecture du lien : ",nomlien);

    MAJ_version_num(fid,3,0,8);
    ret = MED30linkWr(fid,nomlien,lien);
    EXIT_IF(ret,"Erreur a l'écrtiure du lien : ",nomlien);
    MAJ_version_num(fid,2,3,6);
 
    lien[nval] = '\0';
/*     printf("\t\t|%s|\n\n",lien); */

    free(lien);
  }

  /* combien de champs dans le fichier */
  ncha = MEDnField(fid);
  EXIT_IF(ncha < 0,"lors de la lecture du nombre de champs",NULL);

  /* MAJ des champs */
  for (i =0;i<ncha;i++) {
    lret = 0;

    /* Lecture du nombre de composantes */
    ncomp = MEDfieldnComponent(fid,i+1);
    if (ncomp < 0) {
      MESSAGE("Erreur à la lecture du nombre de composantes : "); ISCRUTE(ncomp);
      exit(1);
    }

    /* Lecture du type du champ, des noms des composantes et du nom de l'unité*/
    comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
    EXIT_IF(comp == NULL,NULL,NULL);
    unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1);
    EXIT_IF(unit == NULL,NULL,NULL);

    /*     ret = MED231champInfoEtRen(fid,i+1,nomcha,&typcha,comp,unit,ncomp); */
    ret = MEDfieldInfo(fid,i+1,nomcha,_meshname,&_local,&typcha,comp,unit,_dtunit,&_ncstp);
    MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha);

    /* creation du champ destination */
    MAJ_version_num(fid,3,0,8);

    EXIT_IF( H5Gmove(fid, _pathi, _pathtmp  ) < 0,"Switch to ",_pathtmp);
    _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );
    if (_datasetexist ) { EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathi); }

    MED_ERR_EXIT_IF( MEDfieldCr(fid,nomcha,typcha,ncomp,comp,unit,_dtunit,_meshname ) < 0,
		     MED_ERR_CREATE,MED_ERR_FIELD,_pathf);
    EXIT_IF( H5Gmove(fid, _pathi  , _pathf  ) < 0,"Switch to ",_pathf);
    EXIT_IF( H5Gmove(fid, _pathtmp, _pathi  ) < 0,"Switch to ",_pathi);

    MAJ_version_num(fid,2,3,6);

    free(comp);
    free(unit);

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux noeuds "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_CELL,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux mailles "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_FACE,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux faces "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_EDGE,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1);
    }

    lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE_ELEMENT,_ncstp, _pathi, _pathf);
    if (lret != 0) {
      MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1);
    }

  }
  _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT );

  if (_datasetexist ) {
    EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi);
    EXIT_IF( (H5Gmove(fid, _pathf, _pathi  ) < 0) ,"Switch to ",_pathf);
  }


}
Example #14
0
/****************************************************************
**
**  test_vl_rewrite(): Test basic VL string code.
**      Tests I/O on VL strings when lots of objects in the file
**      have been linked/unlinked.
**
****************************************************************/
static void test_vl_rewrite(void)
{
    hid_t file1, file2; /* File IDs */
    hid_t type;         /* VL string datatype ID */
    hid_t space;        /* Scalar dataspace */
    char name[256];     /* Buffer for names & data */
    int i;              /* Local index variable */
    herr_t ret;         /* Generic return value */

    /* Create the VL string datatype */
    type = H5Tcopy(H5T_C_S1);
    CHECK(type, FAIL, "H5Tcopy");

    ret = H5Tset_size(type, H5T_VARIABLE);
    CHECK(ret, FAIL, "H5Tset_size");

    /* Create the scalar dataspace */
    space = H5Screate(H5S_SCALAR);
    CHECK(space, FAIL, "H5Screate");

    /* Open the files */
    file1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    CHECK(file1, FAIL, "H5Fcreate");

    file2 = H5Fcreate(DATAFILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    CHECK(file1, FAIL, "H5Fcreate");

    /* Create in file 1 */
    for(i=0; i<REWRITE_NDATASETS; i++) {
        sprintf(name, "/set_%d", i);
        write_scalar_dset(file1, type, space, name, name);
    }

    /* Effectively copy data from file 1 to 2 */
    for(i=0; i<REWRITE_NDATASETS; i++) {
        sprintf(name, "/set_%d", i);
        read_scalar_dset(file1, type, space, name, name);
        write_scalar_dset(file2, type, space, name, name);
    }

    /* Read back from file 2 */
    for(i = 0; i < REWRITE_NDATASETS; i++) {
        sprintf(name, "/set_%d", i);
        read_scalar_dset(file2, type, space, name, name);
    } /* end for */

    /* Remove from file 2. */
    for(i = 0; i < REWRITE_NDATASETS; i++) {
        sprintf(name, "/set_%d", i);
        ret = H5Ldelete(file2, name, H5P_DEFAULT);
        CHECK(ret, FAIL, "H5Ldelete");
    } /* end for */

    /* Effectively copy from file 1 to file 2 */
    for(i = 0; i < REWRITE_NDATASETS; i++) {
        sprintf(name, "/set_%d", i);
        read_scalar_dset(file1, type, space, name, name);
        write_scalar_dset(file2, type, space, name, name);
    } /* end for */

    /* Close everything */
    ret = H5Tclose(type);
    CHECK(ret, FAIL, "H5Tclose");

    ret = H5Sclose(space);
    CHECK(ret, FAIL, "H5Sclose");

    ret = H5Fclose(file1);
    CHECK(ret, FAIL, "H5Fclose");

    ret = H5Fclose(file2);
    CHECK(ret, FAIL, "H5Fclose");

    return;
} /* end test_vl_rewrite() */
Example #15
0
int main (void)
{
  hid_t    file;
  hid_t    grp;
  hid_t    dataset, dataspace;
  hid_t    plist;
  
  herr_t   status;
  hsize_t  dims[2];
  hsize_t  cdims[2];
  
  int      idx_f, idx_g;
  
  /*
   * Create a file.
   */
  file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   * Create a group in the file.
   */
  grp = H5Gcreate(file, "/Data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   * Create dataset "Compressed Data" in the group using absolute
   * name. Dataset creation property list is modified to use
   * GZIP compression with the compression effort set to 6.
   * Note that compression can be used only when dataset is chunked.
   */
  dims[0] = 1000;
  dims[1] = 20;
  cdims[0] = 20;
  cdims[1] = 20;
  dataspace = H5Screate_simple(RANK, dims, NULL);
  plist     = H5Pcreate(H5P_DATASET_CREATE);
  H5Pset_chunk(plist, 2, cdims);
  H5Pset_deflate( plist, 6);
  dataset = H5Dcreate(file, "/Data/Compressed_Data", H5T_NATIVE_INT,
		       dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
  /*
   * Close the first dataset .
   */
  H5Sclose(dataspace);
  H5Dclose(dataset);
  
  /*
   * Create the second dataset.
   */
  dims[0] = 500;
  dims[1] = 20;
  dataspace = H5Screate_simple(RANK, dims, NULL);
  dataset = H5Dcreate(file, "/Data/Float_Data", H5T_NATIVE_FLOAT,
		       dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   *Close the second dataset and file.
   */
  H5Sclose(dataspace);
  H5Dclose(dataset);
  H5Pclose(plist);
  H5Gclose(grp);
  H5Fclose(file);
  
  /*
   * Now reopen the file and group in the file.
   */
  file = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
  grp  = H5Gopen(file, "Data", H5P_DEFAULT);
  
  /*
   * Access "Compressed_Data" dataset in the group.
   */
  dataset = H5Dopen(grp, "Compressed_Data", H5P_DEFAULT);
  if( dataset < 0) printf(" Dataset 'Compressed-Data' is not found. \n");
  printf("\"/Data/Compressed_Data\" dataset is open \n");
  
  /*
   * Close the dataset.
   */
  status = H5Dclose(dataset);
  
  /*
   * Create hard link to the Data group.
   */
  status = H5Lcreate_hard(file, "Data", H5L_SAME_LOC, "Data_new", H5P_DEFAULT, H5P_DEFAULT);
  
  /*
   * We can access "Compressed_Data" dataset using created
   * hard link "Data_new".
   */
  dataset = H5Dopen(file, "/Data_new/Compressed_Data", H5P_DEFAULT);
  if( dataset < 0) printf(" Dataset is not found. \n");
  printf("\"/Data_new/Compressed_Data\" dataset is open \n");
  
  /*
   * Close the dataset.
   */
  status = H5Dclose(dataset);
  
  
  /*
   * Use iterator to see the names of the objects in the root group.
   */
  idx_f = H5Literate(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
  
  /*
   * Unlink  name "Data" and use iterator to see the names
   * of the objects in the file root direvtory.
   */
  if(H5Ldelete(file, "Data", H5P_DEFAULT) < 0)
    printf(" H5Ldelete failed \n");
  else
    printf("\"Data\" is unlinked \n");
  
  idx_f = H5Literate(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
  
  /*
   * Use iterator to see the names of the objects in the group
   * /Data_new.
   */
  idx_g = H5Literate_by_name(grp, "/Data_new", H5_INDEX_NAME, H5_ITER_INC, NULL, group_info, NULL, H5P_DEFAULT);
  
  /*
   * Close the file.
   */
  
  H5Gclose(grp);
  H5Fclose(file);
  
  return 0;
}
Example #16
0
int main(void)
{
    hid_t fil,spc,set;
    hid_t cs6, cmp, fix;
    hid_t cmp1, cmp2, cmp3;
    hid_t plist;
    hid_t array_dt;

    hsize_t dim[2];
    hsize_t cdim[4];

    char string5[5];
    float fok[2] = {1234., 2341.};
    float fnok[2] = {5678., 6785.};
    float *fptr;

    char *data;
    char *mname;

    int result = 0;

    printf("%-70s", "Testing alignment in compound datatypes");

    strcpy(string5, "Hi!");
    HDunlink(fname);
    fil = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

    if (fil < 0) {
        puts("*FAILED*");
        return 1;
    }

    H5E_BEGIN_TRY {
        H5Ldelete(fil, setname, H5P_DEFAULT);
    } H5E_END_TRY;

    cs6 = H5Tcopy(H5T_C_S1);
    H5Tset_size(cs6, sizeof(string5));
    H5Tset_strpad(cs6, H5T_STR_NULLPAD);

    cmp = H5Tcreate(H5T_COMPOUND, sizeof(fok) + sizeof(string5) + sizeof(fnok));
    H5Tinsert(cmp, "Awkward length", 0, cs6);

    cdim[0] = sizeof(fok) / sizeof(float);
    array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
    H5Tinsert(cmp, "Ok", sizeof(string5), array_dt);
    H5Tclose(array_dt);

    cdim[0] = sizeof(fnok) / sizeof(float);
    array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
    H5Tinsert(cmp, "Not Ok", sizeof(fok) + sizeof(string5), array_dt);
    H5Tclose(array_dt);

    fix=h5tools_get_native_type(cmp);

    cmp1 = H5Tcreate(H5T_COMPOUND, sizeof(fok));

    cdim[0] = sizeof(fok) / sizeof(float);
    array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
    H5Tinsert(cmp1, "Ok", 0, array_dt);
    H5Tclose(array_dt);

    cmp2 = H5Tcreate(H5T_COMPOUND, sizeof(string5));
    H5Tinsert(cmp2, "Awkward length", 0, cs6);

    cmp3 = H5Tcreate(H5T_COMPOUND, sizeof(fnok));

    cdim[0] = sizeof(fnok) / sizeof(float);
    array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim);
    H5Tinsert(cmp3, "Not Ok", 0, array_dt);
    H5Tclose(array_dt);

    plist = H5Pcreate(H5P_DATASET_XFER);
    H5Pset_preserve(plist, 1);

    /*
     * Create a small dataset, and write data into it we write each field
     * in turn so that we are avoid alignment issues at this point
     */
    dim[0] = 1;
    spc = H5Screate_simple(1, dim, NULL);
    set = H5Dcreate2(fil, setname, cmp, spc, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

    H5Dwrite(set, cmp1, spc, H5S_ALL, plist, fok);
    H5Dwrite(set, cmp2, spc, H5S_ALL, plist, string5);
    H5Dwrite(set, cmp3, spc, H5S_ALL, plist, fnok);

    H5Dclose(set);

    /* Now open the set, and read it back in */
    data = malloc(H5Tget_size(fix));

    if(!data) {
        perror("malloc() failed");
        abort();
    }

    set = H5Dopen2(fil, setname, H5P_DEFAULT);

    H5Dread(set, fix, spc, H5S_ALL, H5P_DEFAULT, data);
    fptr = (float *)(data + H5Tget_member_offset(fix, 1));

    if(fok[0] != fptr[0] || fok[1] != fptr[1]
                    || fnok[0] != fptr[2] || fnok[1] != fptr[3]) {
        result = 1;
        printf("%14s (%2d) %6s = %s\n",
            mname = H5Tget_member_name(fix, 0), (int)H5Tget_member_offset(fix,0),
            string5, (char *)(data + H5Tget_member_offset(fix, 0)));
        free(mname);
        fptr = (float *)(data + H5Tget_member_offset(fix, 1));
        printf("Data comparison:\n"
            "%14s (%2d) %6f = %f\n"
            "                    %6f = %f\n",
            mname = H5Tget_member_name(fix, 1), (int)H5Tget_member_offset(fix,1),
            fok[0], fptr[0],
            fok[1], fptr[1]);
        free(mname);
        fptr = (float *)(data + H5Tget_member_offset(fix, 2));
        printf("%14s (%2d) %6f = %f\n"
            "                    %6f = %6f\n",
            mname = H5Tget_member_name(fix, 2), (int)H5Tget_member_offset(fix,2),
            fnok[0], fptr[0],
            fnok[1], fptr[1]);
        free(mname);

        fptr = (float *)(data + H5Tget_member_offset(fix, 1));
        printf("\n"
            "Short circuit\n"
            "                    %6f = %f\n"
            "                    %6f = %f\n"
            "                    %6f = %f\n"
            "                    %6f = %f\n",
            fok[0], fptr[0],
            fok[1], fptr[1],
            fnok[0], fptr[2],
            fnok[1], fptr[3]);
        puts("*FAILED*");
    } else {
        puts(" PASSED");
    }

    free(data);
    H5Sclose(spc);
    H5Tclose(cmp);
    H5Tclose(cmp1);
    H5Tclose(cmp2);
    H5Tclose(cmp3);
    H5Pclose(plist);
    H5Fclose(fil);
    HDunlink(fname);
    fflush(stdout);
    return result;
}
Example #17
0
 void DCGroup::remove(H5Handle base, std::string path)
 throw (DCException)
 {
     if (H5Ldelete(base, path.c_str(), H5P_LINK_ACCESS_DEFAULT) < 0)
         throw DCException(getExceptionString("failed to remove group", path));
 }
Example #18
0
static void hard_link_example(void)
{
    hid_t file_id;
    hid_t group_id;
    H5L_info_t li;
    /* Define the link class that we'll use to register "user-defined hard
     * links" using the callbacks we defined above.
     * A link class can have NULL for any callback except its traverse
     * callback.
     */
    const H5L_class_t UD_hard_class[1] = {{
        H5L_LINK_CLASS_T_VERS,      /* Version number for this struct.
                                     * This field is always H5L_LINK_CLASS_T_VERS */
        (H5L_type_t)UD_HARD_CLASS,  /* Link class id number. This can be any
                                     * value between H5L_TYPE_UD_MIN (64) and
                                     * H5L_TYPE_MAX (255). It should be a
                                     * value that isn't already being used by
                                     * another kind of link. We'll use 66. */
        "UD_hard_link",             /* Link class name for debugging  */
        UD_hard_create,             /* Creation callback              */
        NULL,                       /* Move callback                  */
        NULL,                       /* Copy callback                  */
        UD_hard_traverse,           /* The actual traversal function  */
        UD_hard_delete,             /* Deletion callback              */
        NULL                        /* Query callback                 */
    }};


    /* First, create a file and an object within the file for the link to
     * point to.
     */
    file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
    group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    H5Gclose(group_id);

    /* This is how we create a normal hard link to the group. This
     * creates a second "name" for the group.
     */
    H5Lcreate_hard(file_id, TARGET_GROUP, file_id, HARD_LINK_NAME, H5P_DEFAULT, H5P_DEFAULT);

    /* To do the same thing using a user-defined link, we first have to
     * register the link class we defined.
     */
    H5Lregister(UD_hard_class);

    /* Since hard links link by object address, we'll need to retrieve
     * the target group's address. We do this by calling H5Lget_info
     * on a hard link to the object.
     */
    H5Lget_info(file_id, TARGET_GROUP, &li, H5P_DEFAULT);

    /* Now create a user-defined link.  We give it the group's address
     * as its udata.
     */
    H5Lcreate_ud(file_id, UD_HARD_LINK_NAME, (H5L_type_t)UD_HARD_CLASS, &(li.u.address),
                 sizeof(li.u.address), H5P_DEFAULT, H5P_DEFAULT);

    /* The UD hard link has now incremented the group's reference count
     * like a normal hard link would.  This means that we can unlink the
     * other two links to that group and it won't be deleted until the
     * UD hard link is deleted.
     */
    H5Ldelete(file_id, TARGET_GROUP, H5P_DEFAULT);
    H5Ldelete(file_id, HARD_LINK_NAME, H5P_DEFAULT);

    /* The group is still accessible through the UD hard link. If this were
     * a soft link instead, the object would have been deleted when the last
     * hard link to it was unlinked. */
    group_id = H5Gopen2(file_id, UD_HARD_LINK_NAME, H5P_DEFAULT);

    /* The group is now open normally.  Don't forget to close it! */
    H5Gclose(group_id);

    /* Removing the user-defined hard link will delete the group. */
    H5Ldelete(file_id, UD_HARD_LINK_NAME, H5P_DEFAULT);

    H5Fclose(file_id);
}
Example #19
0
	/** Delete a child */
	void unlink(std::string const & name) {
		h5e::check_error(H5Ldelete(_self, name.c_str(), H5P_DEFAULT));
	}