예제 #1
0
/*
 * - Nom de la fonction : _MEDfichierCreer
 * - Description : creation d'un fichier HDF
 * - Parametres :
 *     - nom (IN) : le nom du fichier
 * - Resultat : ID du fichier en cas de succes, -1 sinon
 */ 
med_idt _MEDfichierCreer(char *nom, med_mode_acces mode)
{
  med_idt fid,gid;
  med_err ret;
  med_int majeur = 2;
  med_int mineur = 3; 
  med_int release = 6;

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();

  if ((fid = H5Fcreate(nom,H5F_ACC_TRUNC,
			       H5P_DEFAULT,H5P_DEFAULT)) < 0)
    return -1;

  _MEDsetModeAcces(fid,MED_LECTURE_ECRITURE);

  if ((gid = _MEDdatagroupCreer(fid,MED_INFOS)) < 0)
    return -1;

  /* Numero de versions de MED */
  if ((ret = _MEDattrEntierEcrire(gid,MED_NOM_MAJEUR,&majeur)) < 0)
    return -1;

  if ((ret = _MEDattrEntierEcrire(gid,MED_NOM_MINEUR,&mineur)) < 0)
    return -1;

  if ((ret = _MEDattrEntierEcrire(gid,MED_NOM_RELEASE,&release)) < 0)
    return -1;

  /* On ferme tout */
  if ((ret = _MEDdatagroupFermer(gid)) < 0)
    return -1;

  _MEDsetModeAcces(fid,mode);

  return fid;
}
예제 #2
0
med_geometry_type
MEDstructElementCr(const med_idt                 fid,
		   const char*             const modelname,
		   const med_int                 modeldim,
		   const char*             const supportmeshname,
		   const med_entity_type         sentitytype,
		   const med_geometry_type       sgeotype
		   )
{
  med_access_mode   _MED_ACCESS_MODE;
  med_err           _err=-1;
  med_idt           _root=0,_elemid=0;
  med_int           _ret=-1;
  char              _path[MED_TAILLE_STRCT+MED_NAME_SIZE+1]=MED_STRCT;
  med_size          _tmpn=0;
  med_geometry_type _stgeotype=0;
  med_int           _medintstgeotype = 0;
  med_int           _medintsgeotype  = sgeotype;
  med_int           _intentitytype   = sentitytype;
  med_int           _nnode=0,_ncell=0;
  med_bool          _chgt=MED_FALSE,_trsf=MED_FALSE;

/*   char           _entitytypename[MED_TAILLE_NOM_ENTITE+1]=""; */

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  /*
   * Si le DataGroup /STRUCT/ n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOpen(fid,_path)) < 0)
    if ((_root = _MEDdatagroupCrOrderCr(fid,_path)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
     goto ERROR;
    }

  NOFINALBLANK(modelname,ERROR);

  /*
   * Si le DataGroup /STRUCT/<modelname> n'existe pas, on le cree
   */
  if ((_elemid = _MEDdatagroupOpen(_root,modelname)) < 0) {
    if ((_elemid = _MEDdatagroupCreer(_root,modelname)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,modelname);
      SSCRUTE(_path);goto ERROR;
    }
  } else {
    /*
     * Lecture de l'attribut MED_NOM_NEO (num�ro de type g�om�trique associ� � un �l�ment de structure)
     */
    if ( _MEDattrEntierLire(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) {
      MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,_path);
      SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype);
      goto ERROR;
    }
    _stgeotype = _medintstgeotype;
  }
  strcat(_path,modelname);

  /*
   * Creation/Ecriture de l'attribut MED_NOM_DIM (dimension de l'�l�ment)
   */
  if ( _MEDattributeIntWr(_elemid,MED_NOM_DIM,&modeldim) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_DIM);ISCRUTE(modeldim);
    goto ERROR;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_NOM (nom du maillage support)
   */
  if ( _MEDattributeStringWr(_elemid,MED_NOM_NOM,MED_NAME_SIZE,supportmeshname) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_NOM);SSCRUTE(supportmeshname);
    goto ERROR;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_ENT (type d'entit� support)
   */
/*   if (_MEDgetEntityTypeName(_entitytypename,sentitytype) < 0) { */
/*     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG); */
/*     ISCRUTE_int(sentitytype);SSCRUTE(_entitytypename);SSCRUTE(_path); */
/*     goto ERROR; */
/*   } */

  if ( _MEDattributeIntWr(_elemid,MED_NOM_ENT,&_intentitytype) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_ENT);ISCRUTE(_intentitytype);
    goto ERROR;
  }

  /*
    Lecture dans le maillages support du nombre de noeuds
    S'il n'y a pas de maillage support : 1
  */
  if (strlen(supportmeshname)) {
    if ( (_nnode = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT,
				     MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,
				     &_chgt,&_trsf) )  <= 0) {
      MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
      ISCRUTE(_nnode);goto ERROR;
    }
  } else {
    _nnode=1;
  }

  if (strlen(supportmeshname)) {
    if ( (_ncell = MEDmeshnEntity(fid,supportmeshname,MED_NO_DT,MED_NO_IT,
				     MED_CELL,sgeotype,MED_CONNECTIVITY,MED_NODAL,
				     &_chgt,&_trsf) )  < 0) {
      MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDmeshnEntity");
      ISCRUTE(_ncell);goto ERROR;
    }
  } else {
    _ncell=0;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_GEO (type g�om�trique des mailles support)
   */
  _medintsgeotype = sgeotype;
  if ( _MEDattributeIntWr(_elemid,MED_NOM_GEO,&_medintsgeotype) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_GEO);ISCRUTE(_medintsgeotype);
    goto ERROR;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_NAV (nombre d'attributs variables associ�s � un �l�ment de structure)
   */
/*   if ( _MEDattributeIntWr(_elemid,MED_NOM_NAV,&nvariableattribute) < 0 ) { */
/*     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); */
/*     SSCRUTE(MED_NOM_NAV);ISCRUTE(nvariableattribute); */
/*     goto ERROR; */
/*   } */

  /*
   * Creation/Ecriture de l'attribut MED_NOM_NAC (nombre d'attributs constant associ�s � un �l�ment de structure)
   */
/*   if ( _MEDattributeIntWr(_elemid,MED_NOM_NAC,&nconstattribute) < 0 ) { */
/*     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); */
/*     SSCRUTE(MED_NOM_NAC);ISCRUTE(nconstattribute); */
/*     goto ERROR; */
/*   } */


  /*
   *  Nombre d'�l�ments de structure
   */
  if ( !_stgeotype ) {

    /*Si l'�l�ment de struture ne pr�-existait pas,
      il a �t� cr�e en d�but de proc�dure (il y a au moins 1 �l�ment dans le groupe) */
    if ((_err=_MEDnObjects(fid,MED_STRCT,&_tmpn)) <0) {
      MED_ERR_(_ret,MED_ERR_COUNT,MED_ERR_STRUCT,MED_STRCT);
      goto ERROR;
    }

    _stgeotype=_tmpn+MED_STRUCT_GEO_INTERNAL;
    _medintstgeotype=_stgeotype;

    /*
     * Ecriture de l'attribut MED_NOM_NEO (num�ro de type g�om�trique associ� � un �l�ment de structure)
     */
    if ( _MEDattributeIntWr(_elemid,MED_NOM_NEO,&_medintstgeotype) < 0 ) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
      SSCRUTE(MED_NOM_NEO);ISCRUTE(_medintstgeotype);
      goto ERROR;
    }
  }

  _ret = _stgeotype;

 ERROR:

  if (_elemid>0)     if (_MEDdatagroupFermer(_elemid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
    ISCRUTE_id(_elemid);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_STRCT);
    ISCRUTE_id(_root);
  }

  return _ret;

}
예제 #3
0
void
_MEDfieldCr31(int dummy, ...) {

  med_err _ret=-1;
  med_idt _root=0,_datagroup1=0;
  med_int _fieldtype ;
  char    _datagroupname1[MED_NAME_SIZE+1]="";
  med_access_mode _MED_ACCESS_MODE;


  MED_VARGS_DECL(const, med_idt           , , fid           );
  MED_VARGS_DECL(const, char * , const      , fieldname     );
  MED_VARGS_DECL(const, med_field_type    , , fieldtype     );
  MED_VARGS_DECL(const, med_int           , , ncomponent    );
  MED_VARGS_DECL(const, char *, const       , componentname );
  MED_VARGS_DECL(const, char *, const       , componentunit );
  MED_VARGS_DECL(const, char *, const       , dtunit        );
  MED_VARGS_DECL(const, char *, const       , meshname      );
  MED_VARGS_DECL(, med_err *              , , fret          );

  va_list params;
  va_start(params,dummy);

  MED_VARGS_DEF(const, med_idt           , , fid           );
  MED_VARGS_DEF(const, char * , const      , fieldname     );
  MED_VARGS_DEF(const, med_field_type,     , fieldtype     );
  MED_VARGS_DEF(const, med_int           , , ncomponent    );
  MED_VARGS_DEF(const, char *, const       , componentname );
  MED_VARGS_DEF(const, char *, const       , componentunit );
  MED_VARGS_DEF(const, char *, const       , dtunit        );
  MED_VARGS_DEF(const, char *, const       , meshname      );
  MED_VARGS_DEF(, med_err *              , , fret          );


 _MEDmodeErreurVerrouiller();

 _fieldtype = (med_int) fieldtype;

 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  /*
   * Si le DataGroup MED_FIELD_GRP n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOuvrir(fid,MED_FIELD_GRP)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,MED_FIELD_GRP)) < 0) {
     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_FIELD_GRP);
     goto ERROR;
    }

  NOFINALBLANK(fieldname,ERROR);
  /*
   * Si le Data Group "/CHA/<fieldname>" n'existe pas, on le cree
   */
  if ((_datagroup1 = _MEDdatagroupOuvrir(_root,fieldname)) < 0)
    if ((_datagroup1 = _MEDdatagroupCrOrderCr(_root,fieldname)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_FIELD_GRP);
      SSCRUTE(fieldname);goto ERROR;
    }


  /*
   * Les infos sur les composantes du champ
   */
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NCO,&ncomponent) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NCO);
    ISCRUTE(ncomponent);goto ERROR;
  }



  
  /* Tous les types med_field_type sont autorisés dans MEDfieldCr mais :
     Avant la 3.3.0 seuls les types : MED_FLOAT64,MED_INT32 et MED_INT64 étaient autorisés dans MEDfieldValueAdvancedWr 
       et seul le type med_int et med_float64 pouvaient être utilisés en C.

      A l'écriture, si med_int=int  les champs MED_INT32 étaient stockés en interne en HDFINT32bits
      A l'écriture, si med_int=long les champs MED_INT32 étaient stockés en interne en HDFINT64bits
      A la lecture : - si med_int=int  le champ MED_INT32 est relu en en HDFINT32bit avec conversion 64->32 si necessaire
                    - si med_int=long le champ MED_INT32 est relu en en HDFINT64bit avec conversion 32->64 si necessaire
      A l'écriture, si med_int=int les champs MED_INT64 étaient interdits
      A l'écriture, si med_int=long les champs MED_INT64 étaient stockés en interne en HDFINT64bits
      A la lecture : - si med_int=int  le champ MED_INT64 ne pouvait pas être relu (pour prevenir la perte d'information)
                    - si med_int=long le champ MED_INT64 est relu sans conversion

     Depuis la 3.3.0 en plus des types MED_FLOAT64,MED_INT32 et MED_INT64 les types MED_FLOAT32 et MED_INT sont autorisés dans MEDfieldValueAdvancedWr et aux types med_int et med_float64 utilisés en C sont ajoutés les types med_float32, med_int32 et med_int64.

     MED_INT32 :
      A l'écriture :  si med_int=int  les champs MED_INT32 sont toujours  stockés en interne en HDFINT32bits   (utiliser med_int32 ou med_int(!))
                      si med_int=long les champs MED_INT32 sont désormais stockés en interne en HDFINT32bits   (utiliser le type med_int64) et désormais 
      A la lecture :  si med_int=int  les champs MED_INT32 sont toujours  relus en HDFINT32bits sans conversion (utiliser med_int32 ou med_int(!))
                      si med_int=long les champs MED_INT32 sont désormais relus en HDFINT32bits sans conversion (utiliser le type med_int32)
     MED_INT64 :
      A l'écriture :  si med_int=int  les champs MED_INT64 sont désormais autorisés et stockés en interne en HDFINT64bits  (utiliser le type med_int64)
                      si med_int=long les champs MED_INT64 sont toujours  autorisés et stockés en interne en HDFINT64bits  (utiliser le type med_int64 ou med_int(!))
      A la lecture :  si med_int=int  les champs MED_INT64 sont désormais relus en HDFINT64bits sans conversion (utiliser le type med_int64)
                      si med_int=long les champs MED_INT64 sont toujours  relus en HDFINT64bits sans conversion  (utiliser le type med_int64 ou med_int(!))
    
     MED_INT :
      A l'écriture :  si med_int=int  les champs MED_INT sont désormais acceptés et stockés en interne en HDFINT32bits    (utiliser med_int ou med_int32(!))
                      si med_int=long les champs MED_INT sont désormais acceptés et stockés en interne en HDFINT64bits    (utiliser med_int ou med_int64(!)) 
      A la lecture :  si med_int=int  les champs MED_INT sont désormais acceptés et relus en HDFINT32bits avec conversion/maxint si necessaire (utiliser med_int ou med_int32(!))
                      si med_int=long les champs MED_INT sont désormais acceptés et relus en HDFINT64bits avec conversion        si necessaire (utiliser le type med_int32)
   

     Plateforme 32 bits : TODO si la plateforme est 32 bits, il faut .... ?
  */

  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_fieldtype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
    ISCRUTE(_fieldtype);goto ERROR;
  }
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_NOM,
			    MED_SNAME_SIZE*ncomponent,componentname) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOM);
    SSCRUTE(componentname);goto ERROR;
  }
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,
			    MED_SNAME_SIZE*ncomponent,componentunit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNI);
    SSCRUTE(componentunit);goto ERROR;
  }

  /*MODEL : MED_NOM_UNI vient du niveau en dessous
    Cree ou ouvre l'attribut  MED_NOM_UNI pour écriture
  */
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
    SSCRUTE(dtunit);goto ERROR;
  }

  /*MODEL : MED_NOM_MAI est écrit dans l'API de création de champ
   * Si c'est la première référence à un maillage, initialise l'attribut MED_MAI à ce maillage
   */
  NOFINALBLANK(meshname,ERROR);

  if (_MEDattributeStringWr(_datagroup1,MED_NOM_MAI,MED_NAME_SIZE,meshname) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_MAI);
    SSCRUTE(meshname);
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,meshname);
    goto ERROR;
  }


  /*
   * On ferme tout
   */

  _ret=0;
 ERROR:

  if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
    ISCRUTE_id(_datagroup1);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_FIELD_GRP);
    ISCRUTE_id(_root);
  }

  va_end(params);
  *fret = _ret;
  return;
}
예제 #4
0
med_err
MEDscalaireCr(med_idt fid,char *scalaire, med_type_champ type, char *desc)
{
  med_err ret=-1;
  med_idt root=0,gid=0;
  char chemin[MED_TAILLE_NUM_DATA+1];
  med_int _type = (med_int) type;
  med_mode_acces MED_MODE_ACCES;

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
    goto ERROR;
  }

  if ( MED_MODE_ACCES == MED_LECTURE ) {
    MESSAGE("Impossible de créer une variable scalaire en mode MED_LECTURE.");
    goto ERROR;
  };

  /* 
   * Si le Groupe  HDF "/NUM_DATA" n'existe pas, on le cree
   */
  strncpy(chemin,MED_NUM_DATA,MED_TAILLE_NUM_DATA-1);
  chemin[MED_TAILLE_NUM_DATA-1] = '\0';
  if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((root = _MEDdatagroupCreer(fid,chemin)) < 0){
      MESSAGE("Erreur à la création du datagroup : ");
      SSCRUTE(chemin);
      goto ERROR;
    }

  /* 
   * Si le groupe HDF "scalaire" n'existe pas, on le cree
   * Sinon => erreur
   */
  NOFINALBLANK(scalaire,ERROR);
  if ((gid = _MEDdatagroupCreer(root,scalaire)) < 0) {
    MESSAGE("Erreur à la création de la variable scalaire : ");
    SSCRUTE(scalaire);
    goto ERROR;
  }

  /* 
   * On stocke l'unite, et le type de la valeur scalaire
   */
  if ((ret = _MEDattrEntierEcrire(gid,MED_NOM_TYP,&_type)) < 0) {
    MESSAGE("Erreur à l'écriture du type de la varaible scalaire : ");
    ISCRUTE(_type);
    goto ERROR;
  }
  if ((ret = _MEDattrStringEcrire(gid,MED_NOM_DES,MED_TAILLE_DESC,desc)) < 0) {
    MESSAGE("Erreur à l'écriture de la description de la variable scalaire : ");
    SSCRUTE(desc);
    goto ERROR;
  }

  /*
   * On ferme tout
   */
  ret = 0;
 ERROR:
  if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(gid);ret=-1; 
  }
  
  if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(root);ret=-1; 
  }

  return ret;
}
예제 #5
0
void _MEDfileObjectsMount236(int dummy,...) {


  med_idt _ret = -1;
  med_idt _id, _rootId=0;
  char _mountPath[2*MED_NAME_SIZE+1];
  char _link[MED_NAME_SIZE+1];
  med_access_mode _accessMode;
  med_int  majeur=0, mineur=0, release=0;
  med_int  rfileversionMMR,rfileversionMM,rfileversionM;
  med_int  lfileversionMMR,lfileversionMM,lfileversionM;
  med_bool _datagroupexist=MED_FALSE,_isasoftlink=MED_FALSE;

  MED_VARGS_DECL(const, med_idt         , , fid           );
  MED_VARGS_DECL(const, med_idt         , , gid           );
  MED_VARGS_DECL(const, char*     , const , mountfilename );
  MED_VARGS_DECL(const, med_class       , , medclass      );
  MED_VARGS_DECL(, med_idt *             ,, fret          );

  va_list params;
  va_start(params,dummy);

  MED_VARGS_DEF(const, med_idt         , , fid           );
  MED_VARGS_DEF(const, med_idt         , , gid           );
  MED_VARGS_DEF(const, char*     , const , mountfilename );
  MED_VARGS_DEF(const, med_class       , , medclass      );
  MED_VARGS_DEF(, med_idt *             ,, fret          );

  _MEDmodeErreurVerrouiller();

  if ( MEDfileNumVersionRd(fid, &majeur, &mineur, &release) < 0) {
    MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd");
    ISCRUTE(majeur);ISCRUTE(mineur);ISCRUTE(release);
    goto ERROR;
  }
  lfileversionM   = 100*majeur;
  lfileversionMM  = 100*majeur+10*mineur;
  lfileversionMMR = lfileversionMM+release;

  /*
   * does the file exist ?
   */
  if (access(mountfilename,F_OK)) {
    MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_FILE,mountfilename);
    goto ERROR;
  }

  if ( (_accessMode = (med_access_mode)_MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_ACCESS,MED_ERR_FILE,"");
    ISCRUTE_int(_accessMode);
    goto ERROR;
  }

  /*
   * Open the file "mountfilename".
   */
  if ((_id = _MEDfileOpen(mountfilename,_accessMode)) < 0) {
    MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,mountfilename);
    goto ERROR;
  }

  if ( MEDfileNumVersionRd(_id, &majeur, &mineur, &release) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"MEDfileNumVersionRd");
    SSCRUTE(mountfilename);ISCRUTE(majeur);ISCRUTE(mineur); ISCRUTE(release);
    goto ERROR;
  }
  rfileversionM   = 100*majeur;
  rfileversionMM  = 100*majeur+10*mineur;
  rfileversionMMR = rfileversionMM+release;

  if ( !( ( (rfileversionMM >= 220) && (lfileversionMM >= 220)
	    && (rfileversionMMR <= 236) && (lfileversionMMR <= 236) ) 	  ) ){
	 MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_FILE,mountfilename);
	 ISCRUTE(rfileversionMMR);ISCRUTE(lfileversionMMR);
	 goto ERROR;
       }

  /*
   * Mount point creation in the local file
   */
  _rootId = _MEDdatagroupOuvrir(fid,MED_MNT);
  if (_rootId < 0)
    if ((_rootId = _MEDdatagroupCreer(fid,MED_MNT)) < 0) {
      MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,MED_MNT);
      goto ERROR;
    }

  /*
   * The file "mountfilename" is mounted in the local file
   */
  strncpy(_mountPath,MED_MNT,strlen(MED_MNT)-1);
  _mountPath[strlen(MED_MNT)-1] = '\0';
  if (_MEDfichierMonter(fid,_mountPath,_id) < 0) {
    MED_ERR_(_ret,MED_ERR_MOUNT,MED_ERR_FILE,mountfilename);
    goto ERROR;
  }


  /*
   * Give access to the class object in the local file
   */
  switch(medclass) {

  case MED_MESH :
    strcpy(_link,MED_MAA);
    break;

  case MED_FIELD :
    strcpy(_link,MED_CHA);
    break;

  default :
    goto ERROR;
  }

  strcat(_mountPath,_link);
  _mountPath[strlen(_mountPath)-1] = '\0';
  _link[strlen(_link)-1] = '\0';
  if (_MEDdatagroupLienCreer(fid,_mountPath,_link) < 0) {
    MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_LINK,_link);
    SSCRUTE(_mountPath);
    goto ERROR;
  }

  _ret = _id;
 ERROR:

  if (_rootId > 0)
    if (_MEDdatagroupFermer(_rootId) < 0) {
      MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,MED_MNT);
    }

  va_end(params);
  *fret = _ret;
  return;
}
예제 #6
0
med_err 
MEDconnEcr(med_idt fid,char *maa, med_int mdim, med_int *connectivite,med_mode_switch mode_switch,
	   med_int nbre, med_entite_maillage type_ent,
	   med_geometrie_element type_geo,med_connectivite type_conn)
{
  med_idt maaid, entid, geoid, dataset;
  med_err ret;
  med_size dimd[1];
  char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
  char nom_ent[MED_TAILLE_NOM_ENTITE+1];
  char nom_geo[MED_TAILLE_NOM_ENTITE+1];
  char nom_dataset[MED_TAILLE_NOM_ENTITE+1];
  int dim, nnoe, ndes;
  int taille;
  med_entite_maillage _type_ent=type_ent;

  if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;
 
  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  /*
   * Si le maillage n'existe pas => erreur
   */
  strcpy(chemin,MED_MAA);
  strcat(chemin,maa);
  if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
      return -1;

  /*
   * On met a jour le nom du Data Group representant
   * le type des entites
   */
   if ((ret = _MEDnomEntite(nom_ent,_type_ent)) < 0)
     return -1;
   /*
    * Si le Data Group des entites n'existe pas on le cree
    */
   if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
     if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
       return -1;

   /*
    * On cree s'il n'existe pas le Data Group du type geometrique
    */
  if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
     return -1;
   if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
     if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
       return -1;

   /*
    * On regarde si le Data Set existe et on le cree sinon
    */
   if ((ret=_MEDparametresGeometrie(_type_ent,type_geo,&dim,&nnoe,&ndes))<0)
     return -1;

   switch(type_conn)
     {
     case MED_NOD :
       strcpy(nom_dataset,MED_NOM_NOD);
       taille = nnoe;
       break;

     case MED_DESC :
       strcpy(nom_dataset,MED_NOM_DES);
       taille = ndes;
       break;
       
     default :
       return -1;
     }
   dimd[0] = nbre*taille;
#if defined(HAVE_F77INT64)
   ret = _MEDdatasetNumEcrire(geoid,nom_dataset,MED_INT64,mode_switch,(med_size)taille,MED_ALL,
                              MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				    (unsigned char*) connectivite);
#else
   ret = _MEDdatasetNumEcrire(geoid,nom_dataset,MED_INT32,mode_switch,(med_size)taille,MED_ALL,
                              MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				    (unsigned char*) connectivite);
#endif
  if (ret < 0 ) {
    MESSAGE("Impossible d'ecrire le dataset coon de taille  : ");
    ISCRUTE_int(taille); return -1;
  }

  /*
   * Attribut NBR (nombre de noeuds ou d'elements)
   */
   if ((dataset = _MEDdatasetOuvrir(geoid,nom_dataset)) < 0)
     return -1;
   if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&nbre)) < 0)
     return -1;

   /*
    * On ferme tout 
    */
   if ((ret = _MEDdatasetFermer(dataset)) < 0)
     return -1;
   if ((ret = _MEDdatagroupFermer(geoid)) < 0)
     return -1;
   if ((ret = _MEDdatagroupFermer(entid)) < 0)
     return -1;
   if ((ret = _MEDdatagroupFermer(maaid)) < 0)
     return -1;

  return 0; 
}
예제 #7
0
med_err
MEDindicesCoordEcr(med_idt fid,char *maillage,med_int mdim,med_float *indices,
		   med_int n,med_int axe,char *comp,char *unit)
{
  med_idt maaid, noeid, dataset;
  med_err ret;
  med_size dimd[1];
  char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
  char nom_dataset[MED_TAILLE_NOM_ENTITE+1];
  med_int att;
  med_maillage maillage_type;
  med_type_grille type;

  /*
   * Si axe > mdim => erreur
   */
  if (axe > mdim)
    return -1;

  /*
   * On inhibe le gestionnaire d'erreur HDF
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  /*
   * Si le maillage n'existe pas => erreur
   */
  strcpy(chemin,MED_MAA);
  strcat(chemin,maillage);
  if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
      return -1;

  /*
   * Si le maillage est de type MED_NON_STRUCTURE => erreur 
   */
  if ((ret = _MEDattrEntierLire(maaid,MED_NOM_TYP,&att)) < 0)
    return -1;
  maillage_type = (med_maillage) att;
  if (maillage_type == MED_NON_STRUCTURE)
    return -1;

  /*
   * Si la grille n'est pas de type MED_GRILLE_CARTESIENNE ou 
   * MED_GRILLE_POLAIRE => erreur
   */
  if ((ret = _MEDattrEntierLire(maaid,MED_NOM_GTY,&att)) < 0)
    return -1;
  /* sizeof(enum) tjrs = sizeof(int) en C, or
     sur machines 64 bits par défaut med_int==long (normalement 64bits),
     du coup sur  machines 64 bits _MEDattrEntierLire utilise
     le type hdf NATIVE_LONG, ce genere parfois un warning
  */
  type = (med_type_grille) att;
  if ((type != MED_GRILLE_CARTESIENNE) && (type != MED_GRILLE_POLAIRE))
    return -1;

  /*
   * Si le groupe HDF "NOE" n'existe pas => erreur
   */
  if ((noeid = _MEDdatagroupOuvrir(maaid,MED_NOM_NOE)) < 0)
    if ((noeid = _MEDdatagroupCreer(maaid,MED_NOM_NOE)) < 0)
      return -1;

  /*
   * On ecrit le tableau d'indice dans un dataset HDF
   */
  switch(axe) {

  case 1 :
    strcpy(nom_dataset,MED_NOM_IN1);
    break;

  case 2 :
    strcpy(nom_dataset,MED_NOM_IN2);
    break;

  case 3 :
    strcpy(nom_dataset,MED_NOM_IN3);
    break;

  default :
    return -1;

  }

  dimd[0] = n;
  if ((ret = _MEDdatasetNumEcrire(noeid,nom_dataset,MED_FLOAT64,MED_FULL_INTERLACE,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,
				  MED_NOPG,dimd,(unsigned char*) indices)) < 0)
    return -1;
  
  /*
   * On re-ouvre le dataset HDF pour y placer des attributs
   */
  if ((dataset = _MEDdatasetOuvrir(noeid,nom_dataset)) < 0)
    return -1;

  /*
   * Attribut NBR (taille du tableau d'indices)
   */
  if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n)) < 0)
    return -1;

  /*
   * Attribut "NOM" (nom de la composante)
   */
  if ((ret = _MEDattrStringEcrire(dataset,MED_NOM_NOM,MED_TAILLE_PNOM,comp)) < 0)
    return -1;

  /*
   * Attribut "UNI" (unite de la composante)
   */
  if ((ret = _MEDattrStringEcrire(dataset,MED_NOM_UNI,MED_TAILLE_PNOM,unit)) < 0)
    return -1;

  /*
   * On ferme tout
   */
  if ((ret = _MEDdatasetFermer(dataset)) < 0)
    return -1;
  if ((ret = _MEDdatagroupFermer(noeid)) < 0)
    return -1;
  if ((ret = _MEDdatagroupFermer(maaid)) < 0)
    return -1;

  return 0; 
}
예제 #8
0
파일: MEDlinkWr.c 프로젝트: mndjinga/CDMATH
med_err
MEDlinkWr(const med_idt        fid,
	  const char   * const meshname,
	  const char   * const link)
{
  med_access_mode _MED_ACCESS_MODE;
  med_idt        _lid=0, _root=0;
  med_err        _ret=-1;
  char           _path[MED_TAILLE_LIENS+MED_NAME_SIZE+1]=MED_LIENS;
  med_int        _n=0;
  med_filter     _filter        = MED_FILTER_INIT;

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  /*
   * Si le DataGroup /LIENS/ n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
      goto ERROR;
    }

  NOFINALBLANK(link,ERROR);
  /*
   * Si le DataGroup /LIENS/<meshname> n'existe pas, on le cree
   */
  if ((_lid = _MEDdatagroupOuvrir(_root,meshname)) < 0)
    if ((_lid = _MEDdatagroupCreer(_root,meshname)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
      SSCRUTE(_path);goto ERROR;
    }

  strcat(_path,meshname);


  /*
   * On stocke <n> sous forme d'attribut
   */
  _n = strlen(link);
  if (_MEDattributeIntWr(_lid,MED_NOM_NBR,&_n) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_LINK_MSG);
    SSCRUTE(_path);SSCRUTE(MED_NOM_NBR);ISCRUTE(_n);
    goto ERROR;
  }

  /*
   * On stocke le link dans un dataset
   */
  if ( MEDfilterEntityCr(fid,_n, 1, 1, MED_ALL_CONSTITUENT,
			 MED_NO_INTERLACE,MED_UNDEF_STMODE,
			 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    goto ERROR;
  }

/*   SSCRUTE(link); */
  if ( _MEDdatasetWr(_lid,MED_NOM_LIE,MED_INTERNAL_CHAR,&_filter, link) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_LIE);SSCRUTE(_path);
    goto ERROR;
  }

  if ( MEDfilterClose(&_filter) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_LINK_MSG); SSCRUTE(_path);
    goto ERROR;
  }


  _ret = 0;

 ERROR:

  if (_lid>0)            if (_MEDdatagroupFermer(_lid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
    ISCRUTE_id(_lid);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_LIENS);
    ISCRUTE_id(_root);
  }

  return _ret;

}
예제 #9
0
파일: MEDmonter.c 프로젝트: vejmarie/libMED
med_idt
MEDmonter(med_idt fid, const char *acces,med_type_donnee type)
{
  med_err ret;
  med_idt root,id, did;
  char chemin[MED_TAILLE_NOM+1];
  char acces_montage[2*MED_TAILLE_NOM+1];
  med_mode_acces MED_MODE_ACCES;

  /*
   * On inhibe le gestionnaire d'erreur HDF
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  /*
   * On regarde si le fichier de nom "acces" existe
   * Si ce n'est pas le cas => erreur
   */
  if (access(acces,F_OK))
    return -1;

  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
    return -1;
  }

  /*
   * On ouvre le fichier "acces" selon le mode d'acces MED_MODE_ACCES
   */
  if ((id = _MEDfichierOuvrir((char *)acces,MED_MODE_ACCES)) < 0)
    return -1;

  /* 
   * Si le point de montage n'existe pas dans le fichier local, on le cree
   */
  root = _MEDdatagroupOuvrir(fid,MED_MNT);
  if (root < 0)
    if ((root = _MEDdatagroupCreer(fid,MED_MNT)) < 0)
      return -1;
  if ((ret = _MEDdatagroupFermer(root)) < 0)
    return -1;

  /*
   * Montage du fichier (id) sur le point de montage local (fid)
   */
  strncpy(acces_montage,MED_MNT,strlen(MED_MNT)-1);
  acces_montage[strlen(MED_MNT)-1] = '\0';
  if ((ret = _MEDfichierMonter(fid,acces_montage,id)) < 0)
    return -1;

  /*
   * On cree un lien vers le point de montage
   * selon qu'on l'on veuille acceder aux champs
   * ou aux maillages du fichier "acces" que l'on vient
   * de monter sur le fichier local "fid"
   */
  switch(type) {

  case MED_MAILLAGE :
    strcpy(chemin,MED_MAA);
    break;

  case MED_CHAMP :
    strcpy(chemin,MED_CHA);
    break;

  default :
    return -1;
  }
  
  /* 
   * Creation du lien HDF vers le(s) champ(s) ou le(s) maillage(s) 
   * dans le fichier local :
   * - Si ce type de donnee existe deja en local => erreur
   * - Sinon on le cree le lien vers le point de montage
   */
  strcat(acces_montage,chemin);
  acces_montage[strlen(acces_montage)-1] = '\0';
  chemin[strlen(chemin)-1] = '\0';
  if ((ret = _MEDdatagroupLienCreer(fid,acces_montage,chemin)) < 0)
    return -1;

  /*
   * On renvoie l'ID du fichier "acces" que l'on vient de monter
   */
  return id;
}
예제 #10
0
med_err
MEDmeshComputationStepCr(const med_idt fid,
			 const char * const meshname,
			 const med_int numdt1,
			 const med_int numit1,
			 const med_int numdt2,
			 const med_int numit2,
			 const med_float dt2 )
{

  med_access_mode _MED_ACCESS_MODE;
  med_err  _ret=-1;
  med_idt  _meshid=0,_datagroup1=0,_datagroup2=0,_datagroup3=0;
  char     _meshpath [MED_MESH_SUPPORT_GRP_SIZE+MED_NAME_SIZE+1]="";
  char     _datagroupname [2*MED_MAX_PARA+1]="";
  char     _datagroupname2[2*MED_MAX_PARA+1]="";
  char     _datagroupname1bis[2*MED_MAX_PARA+1]="";
  char     _latestcpstname[2*MED_MAX_PARA+1]="";
  char*    _datagroupname1=_datagroupname;
  char     _datagroupname3[2*MED_MAX_PARA+1]="";
  char     _prevcpstname[2*MED_MAX_PARA+1]="";
  char     _pathsrc[MED_MESH_SUPPORT_GRP_SIZE+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]="";
  char     _pathdst[MED_MESH_SUPPORT_GRP_SIZE+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]="";
  med_bool _datagroup1exist = MED_TRUE;
  med_bool _isasupportmesh = MED_FALSE;
  med_int  _nextdt=MED_NO_DT, _nextit=MED_NO_IT,_pvdt=MED_NO_DT, _pvit=MED_NO_IT;
  med_int  _lastnumdt=MED_NO_DT, _lastnumit=MED_NO_IT;
  med_int  _numdt1=numdt1,_numit1=numit1;
  med_int  _false = 0;
  med_sorting_type _sortingtype;
  med_int          _intsortingtype;
  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

/*   strcat( _meshpath, meshname); */
/*   strcat( _pathsrc , meshname);strcat( _pathsrc , "/"); */
/*   strcat( _pathdst , meshname);strcat( _pathdst , "/"); */
/*   if ((_meshid = _MEDdatagroupOuvrir(fid,_meshpath)) < 0) { */
/*     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_meshpath); */
/*     SSCRUTE(_meshid);goto ERROR; */
/*   } */

  if ((_meshid=_MEDmeshDatagroupOpen(fid,meshname,_meshpath,&_isasupportmesh)) < 0) {
    MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
    SSCRUTE(_meshpath); goto ERROR;
  }
  strcat( _pathsrc , _meshpath);strcat( _pathsrc , "/");
  strcat( _pathdst , _meshpath);strcat( _pathdst , "/");

  if ( _MEDattrEntierLire(_meshid,MED_NOM_NXT,&_lastnumdt) < 0) {
/*     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG); */
/*     SSCRUTE(meshname);SSCRUTE(_meshpath);SSCRUTE(MED_NOM_NXT); */
/*     goto ERROR; */
    _lastnumdt = MED_NO_DT;
  }

  if ( _MEDattrEntierLire(_meshid,MED_NOM_NXI,&_lastnumit) < 0) {
/*     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG); */
/*     SSCRUTE(meshname);SSCRUTE(_meshpath);SSCRUTE(MED_NOM_NXI); */
/*     goto ERROR; */
    _lastnumit = MED_NO_IT;
  }

 if ( _MEDattrEntierLire(_meshid,MED_NOM_SRT,&_intsortingtype) < 0) {
   MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(MED_NOM_SRT);
    ISCRUTE(_intsortingtype);goto ERROR;
  }
  _sortingtype = (med_sorting_type) (_intsortingtype);

  _MEDgetComputationStepName(_sortingtype,numdt1,numit1,_datagroupname);
  _MEDgetComputationStepName(_sortingtype,numdt2,numit2,_datagroupname2);
  _MEDgetComputationStepName(_sortingtype,_lastnumdt,_lastnumit,_latestcpstname);

  /*
    L'utilisateur peut demander la création d'une nouvelle étape de calcul postérieure
    à toutes les autres en indiquant (numdt1 == numdt2) && (numit1 == numit2)
    Celà fonctionne aussi pour MED_NO_DT, NED_NO_IT
  */

  if ( (numdt1 == numdt2) && (numit1 == numit2) ) {
    _numdt1         = _lastnumdt;
    _numit1         = _lastnumit;
    _datagroupname1 = _latestcpstname;
  }
  /*Vérifie que le _datagroupname2 est bien postérieur ou égal au _datagroupname1
   REM: _datagroupname1 peut être la première/dernière séquence de calcul 
   ou une séquence intermédiaire */
  if ( strncmp(_datagroupname2,_datagroupname1,2*MED_MAX_PARA+2) < 0) {
    MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,_datagroupname2);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);goto ERROR;
  }

  strcat( _pathsrc , _datagroupname1 );strcat( _pathsrc , "/");
  strcat( _pathdst , _datagroupname2 );strcat( _pathdst , "/");

  /* On accepte l'absence de _datagroupname1 uniquement si
     numdt2 == MED_NO_DT && numit2 == MED_NO_IT */
  if ( (_datagroup1 = _MEDdatagroupOuvrir(_meshid,_datagroupname1)) < 0 ) {
    if ( (numdt2 != MED_NO_DT ) || (numit2 != MED_NO_IT) ) {
      MED_ERR_(_ret,MED_ERR_DOESNTEXIST,MED_ERR_COMPUTINGSTEP,_datagroupname1);
      SSCRUTE(meshname);goto ERROR;
      }
  }

  /*L'étape de calcul à créer ne doit pas déjà exister*/
  if ( (_datagroup2 = _MEDdatagroupOuvrir(_meshid,_datagroupname2)) >= 0 ) {
    MED_ERR_(_ret,MED_ERR_EXIST,MED_ERR_COMPUTINGSTEP,_datagroupname2);
    SSCRUTE(meshname);goto ERROR;
  }


  if ( _datagroup1 > 0 ) {


    /*Lecture NEXT et PREV du datagroup1 */
    if ( _MEDattrEntierLire(_datagroup1,MED_NOM_NXT,&_nextdt) < 0) {
      MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXT);
      goto ERROR;
    }

    if ( _MEDattrEntierLire(_datagroup1,MED_NOM_NXI,&_nextit) < 0) {
      MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXI);
      goto ERROR;
    }

    /* On vérifie que la nouvelle étape de calcul s'insère correctement :
       < au next du datagroup1 */
/*     if ( !((_nextdt == MED_NO_DT) && (_nextit == MED_NO_IT) )) { */
    if ( (_nextdt != MED_NO_DT) || (_nextit != MED_NO_IT) ) {
      _MEDgetComputationStepName(_sortingtype,_nextdt,_nextit,_datagroupname3);

      if ( strncmp(_datagroupname3,_datagroupname2,2*MED_MAX_PARA+2) <= 0) {
	MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,_datagroupname2);
	SSCRUTE(meshname);SSCRUTE(_datagroupname3);goto ERROR;
      }
    }

    /*On crée la nouvelle étape de calcul (au plus tard, après vérifs...)*/
    if ((_datagroup2 = _MEDdatagroupCreer(_meshid,_datagroupname2)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
      SSCRUTE(meshname);goto ERROR;
    }

    /*On crée les datagroups, attributs et liens sur les datatsets et les liens symboliques
      pour avoir une image de l'étape de calcul précedente.*/
    if ( _MEDvisit(fid,_pathsrc,_pathdst,(medvisitorfunc) _MEDlinkobjs ) < 0 ) {
      MED_ERR_(_ret,MED_ERR_VISIT,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_pathsrc);SSCRUTE(_pathdst);
      goto ERROR;
    }

    /*Ecriture NEXT et PREV du nouveau datagroup2 */
    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXT,&_nextdt) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXT);
      goto ERROR;
    }

    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXI,&_nextit) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXI);
      goto ERROR;
    }


    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVT,&_numdt1) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVT);
      goto ERROR;
    }

    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVI,&_numit1) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVI);
      goto ERROR;
    }


    /*Modification du NEXT du datagroup1 */
    if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NXT,&numdt2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXT);
      goto ERROR;
    }

    if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NXI,&numit2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXI);
      goto ERROR;
    }

    /*Modification de PREV du ( NEXT de datagroup1 ) s'il existe*/
    if (strlen(_datagroupname3) ) {

      if ( (_datagroup3 = _MEDdatagroupOuvrir(_meshid,_datagroupname3)) < 0 ) {
	MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_COMPUTINGSTEP,_datagroupname3);
	SSCRUTE(meshname);goto ERROR;
      }

      if ( _MEDattrEntierLire(_datagroup3,MED_NOM_PVT,&_pvdt) < 0) {
	MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVT);
	goto ERROR;
      }

      if ( _MEDattrEntierLire(_datagroup3,MED_NOM_PVI,&_pvit) < 0) {
	MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVI);
	goto ERROR;
      }
      _MEDgetComputationStepName(_sortingtype,_pvdt,_pvit,_datagroupname1bis);

      if ( strncmp(_datagroupname1,_datagroupname1bis,2*MED_MAX_PARA+2) != 0) {
	MED_ERR_(_ret,MED_ERR_NOTEQUAL,MED_ERR_COMPUTINGSTEP,_datagroupname1);
	SSCRUTE(meshname);SSCRUTE(_datagroupname1bis);goto ERROR;
      }

      if ( _MEDattributeIntWr(_datagroup3,MED_NOM_PVT,&numdt2) < 0) {
	MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVT);
	goto ERROR;
      }

      if ( _MEDattributeIntWr(_datagroup3,MED_NOM_PVI,&numit2) < 0) {
	MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_PVI);
	goto ERROR;
      }

    }

  } else { /* Création de la première étape de calcul  */

    /*On crée la nouvelle étape de calcul (au plus tard, après vérifs...) */
    if ((_datagroup2 = _MEDdatagroupCreer(_meshid,_datagroupname2)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
      SSCRUTE(meshname);goto ERROR;
    }

    /* Ecriture de MED_NO_IT, MED_NO_DT pour NEXT et PREV de la première
       étape de calcul */
    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXT,&numdt2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXT);
      goto ERROR;
    }

    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NXI,&numit2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXI);
      goto ERROR;
    }

    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVT,&numdt2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVT);
      goto ERROR;
    }

    if ( _MEDattributeIntWr(_datagroup2,MED_NOM_PVI,&numit2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PVI);
      goto ERROR;
    }

  }

  /*Cree ou ouvre l'attribut MED_NOM_NDT pour écriture */
  if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NDT,&numdt2) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NDT);
    ISCRUTE(numdt2);goto ERROR;
  }

  /*Cree ou ouvre l'attribut MED_NOM_PDT pour écriture */
  if ( _MEDattrFloatEcrire(_datagroup2,MED_NOM_PDT,&dt2) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_PDT);
    RSCRUTE(dt2);goto ERROR;
  }

  /*Cree ou ouvre l'attribut MED_NOM_NOR pour écriture */
  if ( _MEDattributeIntWr(_datagroup2,MED_NOM_NOR,&numit2) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NOR);
    ISCRUTE(numit2); goto ERROR;
  }

  /* Une nouvelle étape de calcul est vierge de toute modifiation*/
  if ( _MEDattributeIntWr(_datagroup2,MED_NOM_CGT,&_false) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname3);SSCRUTE(MED_NOM_CGT);
    goto ERROR;
  }


  /* Ecriture de NEXT et PREV  au niveau meshid (dernière étape de calcul créée */
  if ( strncmp(_datagroupname2,_latestcpstname,2*MED_MAX_PARA+2) >= 0) {

    if ( _MEDattributeIntWr(_meshid,MED_NOM_NXT,&numdt2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXT);
      goto ERROR;
    }

    if ( _MEDattributeIntWr(_meshid,MED_NOM_NXI,&numit2) < 0) {
      MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(_datagroupname2);SSCRUTE(MED_NOM_NXI);
      goto ERROR;
    }
  }

  _ret = 0;
 ERROR:

  if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname3);
    ISCRUTE_id(_datagroup3);
  }

  if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
    ISCRUTE_id(_datagroup2);
  }

  if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
    ISCRUTE_id(_datagroup1);
  }

  if (_meshid>0)     if (_MEDdatagroupFermer(_meshid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_meshpath);
    ISCRUTE_id(_meshid);
  }

  return _ret;
}
예제 #11
0
med_err 
MEDmaaCr(med_idt fid, char *maillage, med_int dim, med_maillage type,char *desc)
{
  med_idt maaid=0, root=0, entid=0, geoid=0 ;
  char chemin[MED_TAILLE_MAA+1];
  char nom_ent[MED_TAILLE_NOM_ENTITE+1];
  char nom_geo[MED_TAILLE_NOM_ENTITE+1];
  med_err ret=-1;
  med_int tmp;
  med_mode_acces MED_MODE_ACCES;

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
    goto ERROR;
  }

  if ( MED_MODE_ACCES == MED_LECTURE ) {
    MESSAGE("Impossible de créer un maillage en mode MED_LECTURE.");
    goto ERROR;
  };

  /*
   * Si la racine n'existe pas on la cree
   */
  strncpy(chemin,MED_MAA,strlen(MED_MAA)-1);
  chemin[MED_TAILLE_MAA-1] = '\0';
  if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
      MESSAGE("Erreur à la création du datagroup : ");
      SSCRUTE(chemin);
      goto ERROR;
    }

  /*
   * Création du maillage
   */
  NOFINALBLANK(maillage,ERROR);
  if ( (maaid = _MEDdatagroupCreer(root,maillage)) < 0) {
    MESSAGE("Erreur à la création du maillage : ");
    SSCRUTE(maillage);
    goto ERROR;
  }

  /*
   * Creation de l'attribut dimension
   */
  if ((ret = _MEDattrEntierEcrire(maaid,MED_NOM_DIM,&dim)) < 0) {
    MESSAGE("Erreur à l'écriture de la dimension du maillage : ");
    ISCRUTE(dim);
    goto ERROR;
  }
  
  /*
   * La description associee au maillage
   */
  if ((ret = _MEDattrStringEcrire(maaid,MED_NOM_DES,MED_TAILLE_DESC,desc)) < 0) {
    MESSAGE("Erreur à l'écriture de la description du maillage : ");
    SSCRUTE(desc);
    goto ERROR;
  }

  /*
   * Creation de l'attribut correspondant au type du maillage (MED_STRUCTURE, MED_NON_STRUCTURE)
   */
  tmp = (med_int) type;
  if ((ret = _MEDattrEntierEcrire(maaid,MED_NOM_TYP,&tmp)) < 0) {
    MESSAGE("Erreur à l'écriture du type de maillage : ");
    ISCRUTE(tmp);
    goto ERROR;
  }

  if ( type == MED_STRUCTURE )  {

    strcpy(nom_ent,MED_NOM_MAI);
    if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0) {
      MESSAGE("Impossible de Cr\351er le datagroup :");
      SSCRUTE(nom_ent);
      MESSAGE("pour le maillage structur\351 :");
      SSCRUTE(maillage);
      goto ERROR;
    }

    switch ( dim )  {
    case 1 : strcpy(nom_geo,MED_NOM_SE2);
      break;
    case 2 : strcpy(nom_geo,MED_NOM_QU4);
      break;
    case 3 : strcpy(nom_geo,MED_NOM_HE8);
      break;
    case 0 : strcpy(nom_geo,MED_NOM_PO1);
      break;
    default :
      MESSAGE("La dimension doit être comprise entre 0 et 3");
      goto ERROR;
    }

    if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0) {
      MESSAGE("Impossible de Créer le datagroup :");
      SSCRUTE(nom_geo);
      MESSAGE("pour le maillage structuré :");
      SSCRUTE(maillage);
      goto ERROR;
    }
  }

  /* 
   * Nettoyages divers
   */
  ret = 0;
 ERROR:
  if (geoid>0)     if (_MEDdatagroupFermer(geoid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(geoid);ret = -1; 
  }

  if (entid>0)     if (_MEDdatagroupFermer(entid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(entid);ret = -1; 
  }

  if (maaid>0)     if (_MEDdatagroupFermer(maaid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(maaid);ret = -1; 
  }
  
  if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(root); ret = -1; 
  }

  return ret;
}
예제 #12
0
파일: MEDnumEcr.c 프로젝트: mndjinga/CDMATH
med_err 
MEDnumEcr(med_idt fid,char *maa, med_int *num, med_int n,
	  med_entite_maillage type_ent,med_geometrie_element type_geo)
{
  med_idt root, maaid, entid, geoid, dataset;
  med_err ret;
  med_size dimd[1];
  char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
  char nom_ent[MED_TAILLE_NOM_ENTITE+1];
  char nom_geo[MED_TAILLE_NOM_ENTITE+1];
  med_entite_maillage _type_ent=type_ent;

  if ( type_ent == MED_NOEUD_MAILLE ) _type_ent=MED_NOEUD ;

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;
 

  /*
   * Si le maillage n'existe pas => erreur
   */
  strcpy(chemin,MED_MAA);
  strcat(chemin,maa);
  if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
      return -1;

  /*
   * On met a jour le nom du Data Group representant
   * le type des entites
   */
   if ((ret = _MEDnomEntite(nom_ent,_type_ent)) < 0)
     return -1;

   /*
    * Si le Data Group des entites n'existe pas on le cree
    */
   if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
     if ((root = _MEDdatagroupCreer(maaid,nom_ent)) < 0)
       return -1;

   /*
    * Pour les mailles, les faces et le aretes, on cree
    * s'il n'existe pas le Data Group du type geometrique
    */
   if ((_type_ent==MED_MAILLE)||(_type_ent==MED_FACE)||(_type_ent==MED_ARETE))
     {
       if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
	 return -1;

       if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
	 if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0)
	   return -1;
     }
   else 
     geoid = -1;

   /*
    * Creation du Data Set "NUM" 
    */
   if (geoid == -1)
     root = entid;
   else
     root = geoid;
   dimd[0] = n;
#if defined(HAVE_F77INT64)
   if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_NUM,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				(unsigned char*) num)) < 0)
     return -1;
#else
   if ((ret = _MEDdatasetNumEcrire(root,MED_NOM_NUM,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				(unsigned char*) num)) < 0)
     return -1;
#endif

  /*
   * Attribut NBR (nombre de noeuds)
   */
   if ((dataset = _MEDdatasetOuvrir(root,MED_NOM_NUM)) < 0)
     return -1;
   if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n)) < 0)
     return -1;

   /*
    * On ferme tout
    */
   if ((ret = _MEDdatasetFermer(dataset)) < 0)
     return -1;
   if (geoid != -1)
     if ((ret = _MEDdatagroupFermer(geoid)) < 0)
       return -1;
   if ((ret = _MEDdatagroupFermer(entid)) < 0)
     return -1;
   if ((ret = _MEDdatagroupFermer(maaid)) < 0)
     return -1; 

  return 0; 
}
예제 #13
0
void
_MEDfieldCr30(int dummy, ...) {

  med_err _ret=-1;
  med_idt _root=0,_datagroup1=0;
  med_int _fieldtype;
  char    _datagroupname1[MED_NAME_SIZE+1]="";
  med_access_mode _MED_ACCESS_MODE;


  MED_VARGS_DECL(const, med_idt           , , fid           );
  MED_VARGS_DECL(const, char * , const      , fieldname     );
  MED_VARGS_DECL(const, med_field_type    , , fieldtype     );
  MED_VARGS_DECL(const, med_int           , , ncomponent    );
  MED_VARGS_DECL(const, char *, const       , componentname );
  MED_VARGS_DECL(const, char *, const       , componentunit );
  MED_VARGS_DECL(const, char *, const       , dtunit        );
  MED_VARGS_DECL(const, char *, const       , meshname      );
  MED_VARGS_DECL(, med_err *              , , fret          );

  va_list params;
  va_start(params,dummy);

  MED_VARGS_DEF(const, med_idt           , , fid           );
  MED_VARGS_DEF(const, char * , const      , fieldname     );
  MED_VARGS_DEF(const, med_field_type,     , fieldtype     );
  MED_VARGS_DEF(const, med_int           , , ncomponent    );
  MED_VARGS_DEF(const, char *, const       , componentname );
  MED_VARGS_DEF(const, char *, const       , componentunit );
  MED_VARGS_DEF(const, char *, const       , dtunit        );
  MED_VARGS_DEF(const, char *, const       , meshname      );
  MED_VARGS_DEF(, med_err *              , , fret          );


 _MEDmodeErreurVerrouiller();

 _fieldtype = (med_int) fieldtype;

 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  /*
   * Si le DataGroup MED_FIELD_GRP n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOuvrir(fid,MED_FIELD_GRP)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,MED_FIELD_GRP)) < 0) {
     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_FIELD_GRP);
     goto ERROR;
    }

  NOFINALBLANK(fieldname,ERROR);
  /*
   * Si le Data Group "/CHA/<fieldname>" n'existe pas, on le cree
   */
  if ((_datagroup1 = _MEDdatagroupOuvrir(_root,fieldname)) < 0)
    if ((_datagroup1 = _MEDdatagroupCreer(_root,fieldname)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_FIELD_GRP);
      SSCRUTE(fieldname);goto ERROR;
    }


  /*
   * Les infos sur les composantes du champ
   */
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NCO,&ncomponent) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NCO);
    ISCRUTE(ncomponent);goto ERROR;
  }
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_fieldtype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
    ISCRUTE(_fieldtype);goto ERROR;
  }
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_NOM,
			    MED_SNAME_SIZE*ncomponent,componentname) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOM);
    SSCRUTE(componentname);goto ERROR;
  }
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,
			    MED_SNAME_SIZE*ncomponent,componentunit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNI);
    SSCRUTE(componentunit);goto ERROR;
  }

  /*MODEL : MED_NOM_UNI vient du niveau en dessous
    Cree ou ouvre l'attribut  MED_NOM_UNI pour écriture
  */
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
    SSCRUTE(dtunit);goto ERROR;
  }

  /*MODEL : MED_NOM_MAI est écrit dans l'API de création de champ
   * Si c'est la première référence à un maillage, initialise l'attribut MED_MAI à ce maillage
   */
  NOFINALBLANK(meshname,ERROR);

  if (_MEDattributeStringWr(_datagroup1,MED_NOM_MAI,MED_NAME_SIZE,meshname) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_FIELD_MSG);
    SSCRUTE(fieldname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_MAI);
    SSCRUTE(meshname);
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,meshname);
    goto ERROR;
  }


  /*
   * On ferme tout
   */

  _ret=0;
 ERROR:

  if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
    ISCRUTE_id(_datagroup1);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_FIELD_GRP);
    ISCRUTE_id(_root);
  }

  va_end(params);
  *fret = _ret;
  return;
}
예제 #14
0
med_err MEDmeshNodeCoordinateWr(const med_idt               fid,
				const char*  const          meshname,
				const med_int               numdt,
				const med_int               numit,
				const med_float             dt,
				const med_switch_mode       switchmode,
				const med_int               nentity,
				const med_float* const      coordinate)
{
  med_idt         _meshid      = 0;
  med_idt         _datagroup1=0,_datagroup2=0,_datagroup3=0,_datagroup_trsf=0;
  med_idt         _dataset_trsf = 0;
  med_err         _ret         = -1;
  med_grid_type   _gridtype    = MED_UNDEF_GRID_TYPE;
  med_int         _intgridtype = 0;
  med_int         _intmeshtype = 0;
  med_int         _meshdim     = 0;
  char            _meshpath   [MED_TAILLE_SUP_MAA+MED_NAME_SIZE+1]="";
  char            _geotypename[MED_TAILLE_NOM_ENTITE+1]="";
  char            _datagroup_trsfname[MED_TAILLE_NOM_ENTITE+MED_TAILLE_COOTRF+1]=MED_NOM_NOE MED_COOTRF;
  int             _i=0;
  med_bool        _isasupportmesh=MED_FALSE,_isasoftlink=MED_FALSE;
  med_int         _0 = 0;
  med_int         _medintgeotype = MED_NO_GEOTYPE;

if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  /* Ouverture du maillage de calcul ou du maillage support */
  if ((_meshid=_MEDmeshDatagroupOpen(fid,meshname,_meshpath,&_isasupportmesh)) < 0) {
    MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
    SSCRUTE(_meshpath); goto ERROR;
  }

  /* Lecture du type de maillage (attribut MED_NOM_TYP)  */
  if (_MEDattrEntierLire(_meshid,MED_NOM_TYP,&_intmeshtype) < 0) {
    MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(MED_NOM_TYP);ISCRUTE(_intmeshtype);goto ERROR;
  }

  /*Sortir en erreur si maillage support et numdt,numit != MED_NO_PDT,MED_NO_IT*/
  /* Accès (création éventuelle) du datagroup numdt,numit */

  if ( _isasupportmesh ) {
    if (( numdt != MED_NO_DT) && (numit != MED_NO_IT) ) {
      MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);goto ERROR;
    }
  } else
    if ( (_datagroup1 =_MEDmeshAssociatedGroupCr(fid, MED_MAA,
						 meshname, numdt, numit, dt,MED_FALSE,
						 "." ) ) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAssociatedGroupCr");
      goto ERROR;
    }

  /* Création de la structure de connectivité assoiciée aux grilles MED_CURVILLINEAR_GRID*/
  if ( ( (med_mesh_type) _intmeshtype ) != MED_UNSTRUCTURED_MESH ) {

    /* Lecture de l'attribut MED_NOM_GTY  */
    if (_MEDattrEntierLire(_meshid,MED_NOM_GTY,&_intgridtype) < 0) {
      MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(MED_NOM_GTY);ISCRUTE_int(_gridtype);goto ERROR;
    }
    _gridtype= (med_grid_type) _intgridtype;

    if ( _gridtype == MED_CURVILINEAR_GRID ) {

      if ((_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,MED_NOM_MAI)) < 0) {

	if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) {
	  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_NOM_MAI);
	  SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
	  goto ERROR;
	}

	if ( _MEDattributeIntWr(_datagroup2,MED_NOM_CGT,&_0) < 0) {
	  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	  SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
	  goto ERROR;
	}

	/* Lecture de l'attribut MED_NOM_DIM  */
	if (_MEDattrEntierLire(_meshid,MED_NOM_DIM,&_meshdim) < 0) {
	  MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	  SSCRUTE(meshname);SSCRUTE(MED_NOM_DIM);ISCRUTE(_meshdim);goto ERROR;
	}

	switch ( _meshdim )  {
	case 1 :
	  strcpy(_geotypename,MED_NOM_SE2);
	  _medintgeotype = MED_SEG2;
	  break;
	case 2 :
	  strcpy(_geotypename,MED_NOM_QU4);
	  _medintgeotype = MED_QUAD4;
	  break;
	case 3 : strcpy(_geotypename,MED_NOM_HE8);
	  break;
	  _medintgeotype = MED_HEXA8;
	case 0 : strcpy(_geotypename,MED_NOM_PO1);
	  _medintgeotype = MED_POINT1;
	  break;
	default :
	  MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
	  SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
	  goto ERROR;
	}

	if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) {
	  MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename);
	  SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
	  goto ERROR;
	}

	if ( _MEDattributeStringWr(_datagroup3,MED_NOM_PFL,MED_NAME_SIZE,MED_NO_PROFILE_INTERNAL) < 0) {
	  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	  SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);
	  goto ERROR;
	}

	if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGT,&_0) < 0) {
	  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	  SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
	  goto ERROR;
	}

	if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGS,&_0) < 0) {
	  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
	  SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGS);
	  goto ERROR;
	}

	if (_MEDattributeIntWr(_datagroup3,MED_NOM_GEO,&_medintgeotype) < 0) {
	  MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
	  ISCRUTE(_medintgeotype);
	  goto ERROR;
	}

      }
    } else {
      MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
      SSCRUTE(meshname);SSCRUTE(MED_NOM_GTY);ISCRUTE_int(_gridtype);goto ERROR;

    }

  }


  /*Réinitialisation du lien MED_TRSF_NOM/MED_COORDINATE_TRSF s'il existe */
  /*Si un dataset de transformation existe une erreur est générée par
    _MEDsoftlinkDel */
  if ( !_isasupportmesh)
    if ((_datagroup_trsf = _MEDdatagroupOuvrir(_datagroup1,_datagroup_trsfname)) > 0) {

      if ( _MEDisasoftlink(_datagroup_trsf, MED_NOM_TRF,MED_FALSE, &_isasoftlink ) < 0 ) {
	MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_LINK,MED_NOM_COO);
	goto ERROR;
      }
      if (_isasoftlink ) {
	if (  _MEDsoftlinkDel(_datagroup_trsf,
			      MED_NOM_TRF,
			      MED_TRUE) < 0 ) {
	  MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDsoftlinkDel");
	  goto ERROR;
	}
      } else {
	if ( (_dataset_trsf = _MEDdatasetOuvrir(_datagroup_trsf,MED_NOM_TRF)) >= 0 ) {
	  _MEDdatasetFermer(_dataset_trsf);
	  MED_ERR_(_ret,MED_ERR_NULL,MED_ERR_DATASET,MED_NOM_TRF);
	  goto ERROR;
	}

      }
    }

  /*Ecriture des coordonnées*/
  if (  _MEDmeshAdvancedWr(fid,
			    meshname,
			    MED_COORDINATE,
			    MED_NO_NAME,
			    MED_INTERNAL_UNDEF,
			    numdt,
			    numit,
			    dt,
			    MED_NODE,
			    MED_NONE,
			    MED_NO_CMODE,
			    MED_UNDEF_PFLMODE,
			    MED_NO_PROFILE,
			    switchmode,
			    MED_ALL_CONSTITUENT,
			    NULL,
			    nentity,
			   coordinate) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAdvancedWr");
    goto ERROR;

  }


  _ret = 0;

 ERROR:

  if (_datagroup_trsf>0)     if (_MEDdatagroupFermer(_datagroup_trsf) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroup_trsfname);
    ISCRUTE_id(_datagroup_trsf);
  }

  if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename);
    ISCRUTE_id(_datagroup3);
  }

  if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI);
    ISCRUTE_id(_datagroup2);
  }

  if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_meshpath);
    ISCRUTE_id(_datagroup1);ISCRUTE(numdt);ISCRUTE(numit);
  }

  if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
    ISCRUTE_id(_meshid);
  }

  return _ret;
}
예제 #15
0
void
MEDfamCr231(int dummy,...)
{

  med_idt fid;
  char    *maa;
  char    *famille;
  med_int numero; 
  med_int *attr_ident;
  med_int *attr_val;
  char    *attr_desc; 
  med_int n_attr;
  char    *groupe; 
  med_int n_groupe;
  med_err *fret ;

  med_idt root=0, datagroup=0, famid=0;
  med_err ret=-1;
  med_size dimd[1];
  char chemin[MED_TAILLE_MAA+MED_TAILLE_FAS+MED_TAILLE_FAS_ENTITE+MED_TAILLE_NOM+1];
  char tmp[MED_TAILLE_FAS+1];
  char stockage[MED_TAILLE_FAS_ENTITE+1] = "NONE";
  med_mode_acces MED_MODE_ACCES;

  va_list params;
  va_start(params,dummy);

  fid        = va_arg(params,  med_idt );
  maa        = va_arg(params,  char*   );
  famille    = va_arg(params,  char*   );
  numero     = va_arg(params,  med_int ); 
  attr_ident = va_arg(params,  med_int*);
  attr_val   = va_arg(params,  med_int*);
  attr_desc  = va_arg(params,  char*   ); 
  n_attr     = va_arg(params,  med_int );
  groupe     = va_arg(params,  char*   ); 
  n_groupe   = va_arg(params,  med_int );
  fret       = va_arg(params,  med_err*);

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) {*fret=-1;return;}


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
    goto ERROR;
  }

  if ( MED_MODE_ACCES == MED_LECTURE) {
    MESSAGE("Impossible de créer une famille en mode MED_LECTURE.");
    goto ERROR;
  };

  /* 
   * Si le Data Group FAS n'existe pas, on le cree
   */
  strcpy(chemin,MED_MAA);
  /*  BUG NON CORRIGE en 2.3.1 à cause
      des noms de familles crées en F77
      NOFINALBLANK(maa,ERROR);*/
  strcat(chemin,maa);
  strncpy(tmp,MED_FAS,MED_TAILLE_FAS-1);
  tmp[MED_TAILLE_FAS-1] = '\0';
  strcat(chemin,tmp);

  if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
      MESSAGE("Erreur à la création du datagroup : ");
      SSCRUTE(chemin);
      goto ERROR;
    }

  
  /*
   * Le lieu de stockage varie selon le signe du "numero"
   * de famille
   * = 0 => FAMILLE NEUTRE
   * > 0 => FAMILLE DE NOEUD 
   * < 0 => FAMILLE DE MAILLE/FACE/ARETE
   */

  if (numero != 0) {
   if ((ret = _MEDdatagroupFermer(root)) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(root);ret = -1; 
    goto ERROR;
   }

    if (numero > 0) 
      strncpy(stockage,MED_FAS_NOEUD,MED_TAILLE_FAS_ENTITE-1);
    
    if (numero < 0) 
      strncpy(stockage,MED_FAS_ELEME,MED_TAILLE_FAS_ENTITE-1);

    stockage[MED_TAILLE_FAS_ENTITE-1] = '\0'; 
    strcat(chemin,stockage);

    if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
      if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
	MESSAGE("Erreur à la création du datagroup : ");
	SSCRUTE(chemin);
	goto ERROR;
      }
  } 

    
  /*
   * Si le Data Group de meme nom que famille existe => erreur
   * Sinon on le cree
   */

  /*
   * POUR LA FAMILLE DE NUMERO 0, ON FORCE LE NOM 
   */
  if (numero == 0)
    strcpy(famille,FAMILLE_ZERO);
  
  /*
   * Création de la famille
   */
  if ((famid = _MEDdatagroupCreer(root,famille)) < 0) {
    MESSAGE("Erreur à la création du famille : ");
    SSCRUTE(famille);
    goto ERROR;
  }


  /*
   * L'attribut NUM
   */
  if ((ret = _MEDattrEntierEcrire(famid,MED_NOM_NUM,&numero)) < 0) {
    MESSAGE("Erreur à l'écriture du numéro de famille : ");
    ISCRUTE(numero);
    goto ERROR;
  }


  /*
   * Le Data Group "GRO"
   */
  if (n_groupe > 0)  {

    /*
     * On cree le Data Group 
     */
    if ((datagroup = _MEDdatagroupCreer(famid,MED_NOM_GRO)) < 0) {
      MESSAGE("Erreur à la création du datagroup : ");
      SSCRUTE(MED_NOM_GRO);
      goto ERROR;
    }
    /*
     * L'attribut "NBR"
     */
    if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NBR,&n_groupe)) < 0) {
      MESSAGE("Erreur à l'écriture du nombre de groupe : ");
      ISCRUTE(n_groupe);
      goto ERROR;
    }      
    /* 
     * Data Set des noms des groupes "NOM"
     */
    dimd[0] = n_groupe*MED_TAILLE_LNOM+1;
    if ((ret = _MEDdatasetStringEcrire(datagroup,MED_NOM_NOM,dimd,groupe))<0) {
      MESSAGE("Erreur à l'écriture des noms des groupes : ");
      SSCRUTE(groupe);
      goto ERROR;
    }      
    /* 
     * On ferme le Data Group
     */
    if ((ret = _MEDdatagroupFermer(datagroup)) < 0) {
      MESSAGE("Impossible de fermer le datagroup : ");
      ISCRUTE_int(datagroup);
      goto ERROR; 
    }

  }

  
  /*
   * Le Data Group "ATT"
   */
  
  if (n_attr > 0) {

    if ((datagroup = _MEDdatagroupCreer(famid,MED_NOM_ATT)) < 0) {
      MESSAGE("Erreur à la création du datagroup : ");
      SSCRUTE(MED_NOM_ATT);
      goto ERROR;
    } 
    /*
     * L'attribut "NBR"
     */
    if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NBR,&n_attr)) < 0) {
      MESSAGE("Erreur à l'écriture du nombre d'attributs : ");
      ISCRUTE(n_attr);
      goto ERROR;
    } 
    /*
     * Le Data Set "IDE"
     */
    dimd[0] = n_attr;
#if defined(HAVE_F77INT64)
    if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_IDE,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				    (unsigned char *)attr_ident)) < 0) {
      MESSAGE("Erreur à l'écriture du dataset : ");
      SSCRUTE(MED_NOM_IDE);
      goto ERROR;
    }    
#else
    if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_IDE,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				    (unsigned char *)attr_ident)) < 0) {
      MESSAGE("Erreur à l'écriture du dataset : ");
      SSCRUTE(MED_NOM_IDE);
      goto ERROR;
    }    
#endif
    /*
     * Le Data Set "VAL"
     */
    dimd[0] = n_attr;
#if defined(HAVE_F77INT64)
    if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_VAL,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				    (unsigned char*)attr_val)) < 0) {
      MESSAGE("Erreur à l'écriture du dataset : ");
      SSCRUTE(MED_NOM_VAL);
      goto ERROR;
    }    
#else
    if ((ret = _MEDdatasetNumEcrire(datagroup,MED_NOM_VAL,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				    (unsigned char*)attr_val)) < 0) {
      MESSAGE("Erreur à l'écriture du dataset : ");
      SSCRUTE(MED_NOM_VAL);
      goto ERROR;
    }    
#endif
    /*
     * Le Data Set "DES"
     */
    dimd[0] = n_attr*MED_TAILLE_DESC+1;
    if ((ret = _MEDdatasetStringEcrire(datagroup,MED_NOM_DES,dimd,attr_desc)) < 0) {
      MESSAGE("Erreur à l'écriture du dataset : ");
      SSCRUTE(MED_NOM_DES);
      goto ERROR;
    }    
    /* 
     * On ferme le Data Group
     */
    if ((ret = _MEDdatagroupFermer(datagroup)) < 0) {
      MESSAGE("Impossible de fermer le datagroup : ");
      ISCRUTE_int(datagroup);
      goto ERROR; 
    }
  }


  /* 
   * On ferme tout
   */ 
  ret=0;
 ERROR:
  if (famid>0)     if (_MEDdatagroupFermer(famid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(famid);ret = -1; 
  }
  
  if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(root); ret = -1; 
  }

  va_end(params);
  *fret = ret;
  return;
}
예제 #16
0
/**\ingroup MEDinterp
  \brief \MEDinterpCrBrief
  \param fid           \fid
  \param interpname    \interpname
  \param geotype       \geotype
  \param cellnode      \cellnode
  \param nvariable  \nvariable
  \param maxdegree     \maxdegree
  \param nmaxcoef      \nmaxcoef

  \return \error
  \details \MEDinterpCrDetails
  \see MEDinterpBaseFunctionWr
  \remarks
  \li \MEDinterpCrcellnodeCm1
  \li \MEDinterpCrcellnodeCm2
 */
med_err
MEDinterpCr(const med_idt                 fid,
	    const char*             const interpname,
	    const med_geometry_type       geotype,
	    const med_bool                cellnode,
	    const med_int                 nvariable,
	    const med_int                 maxdegree,
	    const med_int                 nmaxcoef
	    )
{
  med_access_mode   _MED_ACCESS_MODE;
  med_idt           _root=0,_interpid=0;
  med_int           _ret=-1;
  char              _path[MED_INTERPOLATION_GRP_SIZE+MED_NAME_SIZE+1]=MED_INTERPOLATION_GRP;
  med_int           _cellnodes = cellnode;
  med_int           _geotype = geotype;
  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  /*
   * Si le DataGroup /INTERP/ n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOpen(fid,_path)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
     goto ERROR;
    }

  NOFINALBLANK(interpname,ERROR);

  /*
   * Si le DataGroup /INTERP/<interpname> n'existe pas, on le cree
   */
  if ((_interpid = _MEDdatagroupOpen(_root,interpname)) < 0)
    if ((_interpid = _MEDdatagroupCreer(_root,interpname)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,interpname);
      SSCRUTE(_path);goto ERROR;
    }

  strcat(_path,interpname);

  /*
   * Creation/Ecriture de l'attribut MED_NOM_GEO
   */
  if ( _MEDattributeIntWr(_interpid,MED_NOM_GEO,&_geotype) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_GEO);ISCRUTE(_geotype);
    goto ERROR;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_NBB
   */
/*   if ( _MEDattributeIntWr(_interpid,MED_NOM_NBB,&nbasisfunc) < 0 ) { */
/*     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path); */
/*     SSCRUTE(MED_NOM_NBB);ISCRUTE(nbasisfunc); */
/*     goto ERROR; */
/*   } */

  /*
   * Creation/Ecriture de l'attribut MED_NOM_NBV
   */
  if ( _MEDattributeIntWr(_interpid,MED_NOM_NBV,&nvariable) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_NBV);ISCRUTE(nvariable);
    goto ERROR;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_MDG
   */
  if ( _MEDattributeIntWr(_interpid,MED_NOM_MDG,&maxdegree) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_MDG);ISCRUTE(maxdegree);
    goto ERROR;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_MCF
   */
  if ( _MEDattributeIntWr(_interpid,MED_NOM_MCF,&nmaxcoef) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_MCF);ISCRUTE(nmaxcoef);
    goto ERROR;
  }

  /*
   * Creation/Ecriture de l'attribut MED_NOM_FCN
   */
  if ( _MEDattributeIntWr(_interpid,MED_NOM_FCN,&_cellnodes) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,_path);
    SSCRUTE(MED_NOM_FCN);ISCRUTE(_cellnodes);
    goto ERROR;
  }

  _ret = 0;

 ERROR:

  if (_interpid>0)     if (_MEDdatagroupFermer(_interpid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
    ISCRUTE_id(_interpid);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_INTERPOLATION_GRP);
    ISCRUTE_id(_root);
  }

  return _ret;

}
예제 #17
0
med_err
MEDlienEcr(med_idt fid, char *lienval, char *maa)
{
  med_idt gid=0, chid=0, did=0;
  med_size dimd[1];
  med_err ret=-1;
  char chemin[MED_TAILLE_LIENS+1];
  med_int n ;
  
  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  /* 
   * Si le groupe "LIENS" n'existe pas, on le cree
   */
  strncpy(chemin,MED_LIENS,MED_TAILLE_LIENS-1);
  chemin[MED_TAILLE_LIENS-1] = '\0';
  if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
      MESSAGE("Impossible de creer le groupe MED_LIENS : ");
      SSCRUTE(chemin); goto ERROR;
    }

  /*
   * Si le groupe "maa" n'existe pas, on le cree
   * Sinon => erreur
   */
  NOFINALBLANK(maa,ERROR);
  if ((chid = _MEDdatagroupOuvrir(gid,maa)) < 0) 
    if ((chid = _MEDdatagroupCreer(gid,maa)) < 0) {
      MESSAGE("Erreur à la création du lien au maillage : ");
      SSCRUTE(maa);
      goto ERROR;
    }

  /*
   * On stocke "n" sous forme d'attribut
   */
  n = strlen(lienval);
  if ((ret = _MEDattrEntierEcrire(chid,MED_NOM_NBR,&n)) < 0) {
    MESSAGE("Erreur à l'écriture de l'attribut n : ");
    ISCRUTE(n); goto ERROR;
  }

  /*
   * On stocke le lienval dans un dataset
   */
  dimd[0] = n;
  if ((ret = _MEDdatasetStringEcrire(chid,MED_NOM_LIE,dimd,lienval))<0) {
    MESSAGE("Impossible d'ecrire le dataset lienval de taille  : ");
    ISCRUTE(n); goto ERROR;
  }

  /*
   * On ferme tout
   */
  ret =0;
 ERROR:
  if (chid>0)     if (_MEDdatagroupFermer(chid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(chid);ret=-1; 
  }
  
  if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(gid);ret=-1;
  }

  return ret;
}
예제 #18
0
med_err 
MEDjointEcr   (med_idt fid, char *maa, char *jn, med_int *corrtab, med_int n,
	       med_entite_maillage type_ent_local,   med_geometrie_element typ_geo_local,
	       med_entite_maillage type_ent_distant, med_geometrie_element typ_geo_distant)
	      
{
  med_entite_maillage _type_ent_local   = (med_entite_maillage) ( (int)(type_ent_local) % 10 );
  med_entite_maillage _type_ent_distant = (med_entite_maillage) ( (int)(type_ent_distant) % 10 );

  med_idt corrid, datagroup;
  med_err ret;
  char chemin[MED_TAILLE_MAA+MED_TAILLE_JNT+2*MED_TAILLE_NOM+1]; 
  char nomdatagroup[MED_TAILLE_NOM+1+MED_TAILLE_NOM+1];
  char tmp[MED_TAILLE_NOM_ENTITE+1];
  med_size dimd[1];
  med_mode_acces MED_MODE_ACCES;

/*   if (typ_geo_local   == MED_TETRA4 || typ_geo_local    == MED_TETRA10 || */
/*       typ_geo_local   == MED_HEXA8  || typ_geo_local    == MED_HEXA20  || */
/*       typ_geo_local   == MED_PENTA6 || typ_geo_local    == MED_PENTA15 || */
/*       typ_geo_local   == MED_PYRA5  || typ_geo_local    == MED_PYRA13  || */
/*       typ_geo_distant == MED_TETRA4 || typ_geo_distant == MED_TETRA10 || */
/*       typ_geo_distant == MED_HEXA8  || typ_geo_distant == MED_HEXA20  || */
/*       typ_geo_distant == MED_PENTA6 || typ_geo_distant == MED_PENTA15 || */
/*       typ_geo_distant == MED_PYRA5  || typ_geo_distant == MED_PYRA13) */
/*     return -1; */

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
    return -1;
  }

  /* 
   * Si le Data Group de "JNT" n'existe pas => erreur
   */
  strcpy(chemin,MED_MAA);
  strcat(chemin,maa);
  strcat(chemin,MED_JNT);
  strcat(chemin,jn);
  if ((corrid = _MEDdatagroupOuvrir(fid,chemin)) < 0) {
    MESSAGE(chemin);
    return -1;  
  }
  /*
   * Ecriture de la correspondance
   *   construction du tag HDF "reperant" la correspondance 
   *   
   */
  if ((ret = _MEDnomEntite(nomdatagroup,_type_ent_local)) < 0)
    return -1;
  if ((_type_ent_local != MED_NOEUD))
    {
      if ((ret = _MEDnomGeometrie(tmp,typ_geo_local)) < 0)
	return -1;
      strcat(nomdatagroup,".");
      strcat(nomdatagroup,tmp);
    }



  if ((ret = _MEDnomEntite(tmp,_type_ent_distant)) < 0)
    return -1;
  strcat(nomdatagroup,".");
  strcat(nomdatagroup,tmp);
  if ((_type_ent_distant != MED_NOEUD))
    {
      if ((ret = _MEDnomGeometrie(tmp,typ_geo_distant)) < 0)
	return -1;
      strcat(nomdatagroup,".");
      strcat(nomdatagroup,tmp);
    }

  datagroup = 0;


  /* 
   * Si la correspondance existe, on passe en mode
   * ajout ?????????
   */

  if (((datagroup = _MEDdatagroupOuvrir(corrid,nomdatagroup)) > 0) && 
      ( MED_MODE_ACCES == MED_LECTURE_AJOUT))
    return -1;
  else
    if (datagroup > 0)
      _MEDdatagroupFermer(datagroup);

  if ((datagroup = _MEDdatagroupCreer(corrid,nomdatagroup)) < 0)
    return -1;


  /*
   * L'attribut "NBR"
   */
  if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NBR,&n)) < 0)
    return -1;


  dimd[0] = 2*n;

#if defined(HAVE_F77INT64)
  if ((ret =  _MEDdatasetNumEcrire(datagroup,MED_NOM_COR,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				(unsigned char*) corrtab)) < 0)
    return -1;
#else
  if ((ret =  _MEDdatasetNumEcrire(datagroup,MED_NOM_COR,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
				(unsigned char*) corrtab)) < 0)
    return -1;
#endif

  /*
   * On ferme tout 
   */
  if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
    return -1;
  if ((ret = _MEDdatagroupFermer(corrid)) < 0)
    return -1;

  return 0; 
}
예제 #19
0
med_err
MEDparameterCr(const med_idt fid,
	       const char * const paramname, 
	       const med_parameter_type paramtype,
	       const char* const description,
	       const char * const dtunit
	      )
{
  med_err _ret=-1;
  med_idt _root=0,_datagroup1=0;
  med_access_mode _MED_ACCESS_MODE;
  char _datagroupname1    [MED_NAME_SIZE+1]="";
  med_int _paramtype = (med_int) paramtype;


 _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
 if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
   MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
   goto ERROR;
 }
  
 if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
   MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
   ISCRUTE_int(_MED_ACCESS_MODE);
   goto ERROR;
 }

  /*
   * Si le DataGroup MED_NUM_DATA n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOuvrir(fid,MED_NUM_DATA)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,MED_NUM_DATA)) < 0) {
     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_NUM_DATA);
     goto ERROR;
    }
  NOFINALBLANK(paramname,ERROR); 

  /*
   * Si le Data Group "/NUM_DATA/<paramname>" n'existe pas, on le cree
   */
  if ((_datagroup1 = _MEDdatagroupOuvrir(_root,paramname)) < 0)
    if ((_datagroup1 = _MEDdatagroupCreer(_root,paramname)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_NUM_DATA);
      SSCRUTE(paramname);goto ERROR;
    }
 
  /*
   * Ecriture des infos relatives au parametre : type, dtunit, description
   */
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_paramtype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    SSCRUTE(paramname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
    ISCRUTE(_paramtype);goto ERROR;
  }
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_DES,MED_COMMENT_SIZE,description) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    SSCRUTE(paramname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DES);
    SSCRUTE(description);goto ERROR;
  }
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PARAM_MSG);
    SSCRUTE(paramname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
    SSCRUTE(dtunit);goto ERROR;
  }

  _ret = 0;
 ERROR :

  if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname1);
    ISCRUTE_id(_datagroup1);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NUM_DATA);
    ISCRUTE_id(_root);
  }

  return _ret;
}
예제 #20
0
int MEDimport(char * filein, char *  fileout) {

  med_idt fid, gid;
  med_err ret;
  med_int majeur, mineur, release;
  med_bool hdfok=MED_FALSE;
  med_bool medok=MED_FALSE;
  char *_fileout,*tmp=NULL;
  int   _fileoutsize;
  bool  hasfileout=false;
  char *commande;
  med_int nprofil;
  char chemin_profils[MED_TAILLE_PROFILS+1];
  char chemin_liens[MED_TAILLE_LIENS+1];
  char version[9];
  int MAJ_21_22 = 0, MAJ_231_232 = 0, MAJ_236_300 = 0, MAJ_300_310 = 0, MAJ_310_320 = 0 ;
#ifdef PPRO_NT
  char *drive, *dir, *ext;
#endif
  unsigned char reponse='o';
  med_bool      _noversion=MED_FALSE;

  EXIT_IF(filein == NULL,"Le nom du fichier d'entrée est vide : ", filein);

  hasfileout = strcmp(fileout,"");
  if ( hasfileout ) {
    _fileoutsize = strlen(fileout);
    _fileout     = fileout;
  } else {
    _fileoutsize = strlen(filein)+strlen(PACKAGE_VERSION);
    tmp          = (char *) malloc(sizeof(char)*(_fileoutsize+1));
    strcpy(tmp,filein);
    strcat(tmp,PACKAGE_VERSION);
#ifdef PPRO_NT
    _splitpath( tmp, drive, dir, _fileout, ext );
#else
    _fileout     = basename(tmp);
#endif
    _fileoutsize = strlen(_fileout);

  }

  /* Test du format du fichier */

  ret = MEDfileCompatibility(filein,&hdfok,&medok);

  if (ret < 0 ) {
    fprintf(stdout,">>> Attention le fichier %s ne contient pas de numéro de version. \n",filein);
    fprintf(stdout,">>> Le fichier  %s est supposé être en version 2.1.1. \n",filein);
    /* PAs d'interactif dans une bibliothèque !*/
/*     fprintf(stdout,">>> Voulez-vous essayer une conversion d'un fichier  < 2.2 (o/n) ? "); */
/*     scanf("%c",&reponse); */
    if ( (reponse != 'o') && (reponse != 'O') && (reponse != 'y') && (reponse != 'Y') ) {
      EXIT_IF(MEDfileCompatibility(filein,&hdfok,&medok) < 0,
	      "Erreur d'appel de  MEDfileCompatibility : ", filein);
    }
    _noversion = MED_TRUE;
  }
  EXIT_IF( !hdfok ,
	  "Le fichier d'entrée n'est pas dans un format HDF compatible : ", filein);

/*   EXIT_IF( !medok , */
/* 	  "MEDimport ne gère pas le format  MED de ce fichier : ", filein); */

  /* Creation et ouverture du fichier que l'on va convertir au format MED actuel */
  commande = (char *) malloc(sizeof(char)*(strlen("cp ")+strlen(filein)+
					   strlen(" ")+_fileoutsize + 4 +1  ) );
  EXIT_IF(commande == NULL,NULL,NULL);
  strcpy(commande,"cp \"");
  strcat(commande,filein);
  strcat(commande,"\" \"");
  strcat(commande,_fileout);
  strcat(commande,"\"");
  fprintf(stdout,">>> Creation du fichier %s : %s \n",_fileout,commande);
  system(commande);
  free(commande);
  commande = (char *) malloc(sizeof(char)*(strlen("chmod u+w \"") + _fileoutsize +1 +1  ) );
  EXIT_IF(commande == NULL,NULL,NULL);
  strcpy(commande,"chmod u+w \"");
  strcat(commande,_fileout);
  strcat(commande,"\"");
  fprintf(stdout,">>> Chmod +w du fichier %s : %s \n",_fileout,commande);
  system(commande);
  free(commande);

  fid = MEDfileOpen(_fileout,MED_ACC_RDWR);
  EXIT_IF(fid < 0,"Ouverture du fichier : ", _fileout);

  /* Verification du numero de version */
  if (! _noversion)
    ret = MEDfileNumVersionRd(fid,&majeur,&mineur,&release);
  else {
    ret=0;
    majeur=2;
    mineur=1;
    release=1;
  }
  sprintf(version, IFORMAT"_"IFORMAT"_"IFORMAT, majeur, mineur, release);
  EXIT_IF(ret < 0,"Lecture du numero de version de MED-fichier",NULL);
  if (strcmp(version, "2_2_0") < 0)
    MAJ_21_22 = 1;
  if (strcmp(version, "2_3_2") < 0)
    MAJ_231_232 = 1;
  if (strcmp(version, "3_0_0") < 0)
    MAJ_236_300 = 1;
  if (strcmp(version, "3_1_0") < 0)
    MAJ_300_310 = 1;
  if (strcmp(version, "3_2_0") < 0)
    MAJ_310_320 = 1;

  /* Ne pas oublier que la version cible du fichier à convertir est celui de la bibliothèque. */
  if (MAJ_310_320 == 0) {
    fprintf(stdout,"Le fichier %s est déjà au bon format !!! \n",_fileout);
    ret = MEDfileClose(fid);
    EXIT_IF(ret < 0,"Fermeture du fichier",filein);
    return 0;
  }

  /* On avertit qu'on commence la conversion */
  fprintf(stdout,">>> Lancement de la normalisation du fichier selon le format " PACKAGE_VERSION " ...\n");

  /* On inhibe le gestionnaire d'erreur HDF5 */
  _MEDmodeErreurVerrouiller();

  /* Mise a jour du numero de version */
  fprintf(stdout,"- Lancement de la mise à jour du numéro de version ... \n");
  /*   La mise à jour MAJ_version(fid); doit être différée pour que les majs des fichiers anciens
       fonctionnent correctement*/
  /*   MAJ_version(fid); */
  MAJ_write_version_num(fid,2,3,6);
  fprintf(stdout,"  Numéro de version : ... OK ... \n");

  if (MAJ_21_22) {

    /* Mise a jour des maillages : type = MED_NON_STRUCTURE, description, ... */
    fprintf(stdout,"- Lancement de la mise à jour des maillages (21_22)... \n");
    MAJ_21_22_maillages(fid);
    fprintf(stdout,"  Maillage(s) : ... OK ...\n");

    /* Mise a jour des champs */
    fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (21_22)... \n");
    MAJ_21_22_champs(fid);
    fprintf(stdout,"  Champs(s) : ... OK ...\n");

    /* Mise a jour des profils eventuels */
    nprofil = MEDnProfil(fid);
    if (nprofil > 0) {
      fprintf(stdout,"- Lancement de la mise à jour des profils (21_22)... \n");
      MAJ_21_22_profils(fid,nprofil);
      fprintf(stdout,"  Profils(s) : ... OK ...\n");
    } else {
      strncpy(chemin_profils,MED_PROFILS,MED_TAILLE_PROFILS-1);
      chemin_profils[MED_TAILLE_PROFILS-1] = '\0';
      gid = _MEDdatagroupCreer(fid,chemin_profils);
      EXIT_IF(gid < 0,"Creation du groupe HDF sur les profils",chemin_profils);
      ret = _MEDdatagroupFermer(gid);
      EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les profils",chemin_profils);
    }

    /* On cree le groupe HDF pour les liens */
    strncpy(chemin_liens,MED_LIENS,MED_TAILLE_LIENS-1);
    chemin_liens[MED_TAILLE_LIENS-1] = '\0';
    gid = _MEDdatagroupCreer(fid,chemin_liens);
    EXIT_IF(gid < 0,"Creation du groupe HDF sur les liens",chemin_liens);
    ret = _MEDdatagroupFermer(gid);
    EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les liens",chemin_liens);
  }

  if (MAJ_231_232) {
    /* Mise a jour des champs */
    fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (231_232)... \n");
    MAJ_231_232_champs(fid);
    fprintf(stdout,"  Champs(s) : ... OK ...\n");
    fprintf(stdout,"- Lancement de la mise à jour des noms de maillages (231_232)... \n");
    MAJ_231_232_maillages(fid);
    fprintf(stdout,"  Noms(s) de maillage(s): ... OK ...\n");
  }

  if (MAJ_236_300) {
    /* Le système de cache de version a été developpé à partir de la 3.0*/
    /* Initialise le cache sur une 2.3.6 (cas d'absence d'INFO)*/
    _MEDfileVersion(fid);

    /* Mise a jour des champs */
    fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (236_300)... \n");
    MAJ_236_300_champs(fid);
    fprintf(stdout,"  Champs(s) : ... OK ...\n");

    /* MAJ_version(fid); */

    fprintf(stdout,"- Lancement de la mise à jour des maillages (236_300)... \n");
    MAJ_236_300_maillages(fid);
    fprintf(stdout,"  Maillage(s): ... OK ...\n");

    /* MAJ_version(fid);  */

  }

  if (MAJ_300_310) {
    /* Le système de cache de version a été developpé à partir de la 3.0*/
    /* Initialise le cache sur une 3.0.8 (cas d'absence d'INFO)*/
    /* s'il n'a pas déjà été instanciée ds les MAJ précédentes */
    MAJ_write_version_num(fid,3,0,8);
    _MEDfileVersion(fid);
    /* Si le cache était dèjà instancié, met à jour le cache */
    MAJ_version_num(fid,3,0,8);

    /* Mise a jour des champs */
    fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (300_310) ... \n");
    MAJ_300_310_champs(fid);
    fprintf(stdout,"  Champs(s) : ... OK ...\n");


  }

  if (MAJ_310_320) {
    /* Le système de cache de version a été developpé à partir de la 3.0*/
    /* Initialise le cache sur une 3.0.8 (cas d'absence d'INFO)*/
    /* s'il n'a pas été déjà été instanciée ds les MAJ_ précédentes */
    MAJ_write_version_num(fid,3,1,0);
    _MEDfileVersion(fid);
    /* Si le cache était dèjà instancié, met à jour le cache */
    MAJ_version_num(fid,3,1,0);

    /* Mise a jour des familles/groupes */
    fprintf(stdout,"- Lancement de la mise à jour des familles/groupes (310_320) ... \n");
    MAJ_310_320_familles(fid);
    fprintf(stdout,"  Famille(s)/Groupe(s) : ... OK ...\n");
  }

  /* A l'écriture d'une nouvelle version de MAJ ex 310_320,
   il est necessaire de revisiter les appels à MAJ_version(fid) pour
   les remplacer par les appels MAJ_version(fid,3,1,Lastest31z) */

  MAJ_version(fid);  
  MAJ_write_version_num(fid,MED_NUM_MAJEUR,MED_NUM_MINEUR,MED_NUM_RELEASE);

  /* Fermeture du fichier */
  ret = MEDfileClose(fid);
  EXIT_IF(ret < 0,"Fermeture du fichier",_fileout);

  /* On avertit que c'est fini */
  fprintf(stdout,">>> Conversion du fichier %s au format MED V" PACKAGE_VERSION " terminée\n",
	  _fileout);

  /* On libere la memoire */
  if (!hasfileout) free(tmp);

  return 0;
}
예제 #21
0
med_err MEDchampCr( med_idt fid,  char *  champ,  med_type_champ type,  char *  comp,
		    char *  unit, med_int ncomp)
{
  med_err ret=-1;
  med_idt root=0,gid=0;
  char chemin[MED_TAILLE_CHA+1];
  med_size dimd[1];
  med_int _type = (med_int) type;
  med_mode_acces MED_MODE_ACCES;

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
    goto ERROR;
  }

  if ( MED_MODE_ACCES == MED_LECTURE ) {
    MESSAGE("Impossible de créer un champ en mode MED_LECTURE.");
    goto ERROR;
  };
  
  /* 
   * Si le Data Group "/CHA/" n'existe pas, on le cree
   */
  strncpy(chemin,MED_CHA,MED_TAILLE_CHA-1);
  chemin[MED_TAILLE_CHA-1] = '\0';
  if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
      MESSAGE("Erreur à la création du datagroup : ");
      SSCRUTE(chemin);
      goto ERROR;
    }

  /* 
   * Si le Data Group cha n'existe pas, on le cree
   * Sinon => erreur
   */

  NOFINALBLANK(champ,ERROR);

  if ((gid = _MEDdatagroupCreer(root,champ)) < 0) {
    MESSAGE("Erreur à la création du champ : ");
    SSCRUTE(champ);
    goto ERROR;
  }

  /*
   * Les infos sur les composants du champ
   */
  if ( _MEDattrEntierEcrire(gid,MED_NOM_NCO,&ncomp) < 0 ) {
    MESSAGE("Erreur à l'écriture du nombre de composantes : ");
    ISCRUTE(ncomp);
    goto ERROR;
  }
  if ( _MEDattrEntierEcrire(gid,MED_NOM_TYP,&_type) < 0) {
    MESSAGE("Erreur à l'écriture du type du champ : ");
    ISCRUTE(_type);
    goto ERROR;
  }
  if ( _MEDattrStringEcrire(gid,MED_NOM_NOM,MED_TAILLE_PNOM*ncomp,comp) < 0) {
    MESSAGE("Erreur à l'écriture des noms des composantes : ");
    SSCRUTE(comp);
    goto ERROR;
  }
  if ( _MEDattrStringEcrire(gid,MED_NOM_UNI,MED_TAILLE_PNOM*ncomp,unit) < 0) {
    MESSAGE("Erreur à l'écriture des unités : ");
    SSCRUTE(unit);
    goto ERROR;
  }
  /*
   * On ferme tout
   */
  
  ret=0;
 ERROR:
  if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(gid);ret = -1; 
  }
  
  if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(root); ret = -1; 
  }

  return ret;
}
예제 #22
0
med_err
MEDscalaireEntierEcr(med_idt fid, char *scalaire,med_int val, med_int numdt, char *dt_unit, med_float dt, med_int numo)
{
  med_err ret = 0;
  med_idt gid,datagroup;
  char nomdatagroup[2*MED_MAX_PARA+1];
  char chemin[MED_TAILLE_NUM_DATA+MED_TAILLE_NOM+1];
  med_int type;
  med_mode_acces MED_MODE_ACCES;

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
    return -1;
  }

  /* 
   * Si le groupe HDF "scalaire"  n'existe pas => erreur
   */
  strcpy(chemin,MED_NUM_DATA);
  strcat(chemin,scalaire);
  if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    return -1;

  /* Creation du groupe HDF correspondant au couple <numdt>.<numoo> */
  sprintf(nomdatagroup,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);

  /* Cree ou ouvre le datagroup nomdatagroup */
  datagroup = 0;   
  if (((datagroup = _MEDdatagroupOuvrir(gid,nomdatagroup)) > 0)    
      && ( MED_MODE_ACCES == MED_LECTURE_AJOUT ))   
    return -1;   
  else   
    if (datagroup < 0)
      if ((datagroup = _MEDdatagroupCreer(gid,nomdatagroup)) < 0)   
	return -1;   
  
  /* Cree ou ouvre l'attribut MED_NOM_NDT */
  if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NDT,&numdt)) < 0)
    return -1;
  
  /* Cree ou ouvre l'attribut MED_NOM_PDT */
  if ((ret = _MEDattrFloatEcrire(datagroup,MED_NOM_PDT,&dt)) < 0)
    return -1;
    
  /* Cree ou ouvre l'attribut MED_NOM_NOR */
  if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NOR,&numo)) < 0)
    return -1;

  /* Cree ou ouvre l'attribut  MED_NOM_UNI */ 
  if ( numdt == MED_NOPDT ) {
    if ((ret = _MEDattrStringEcrire(datagroup,MED_NOM_UNI,MED_TAILLE_PNOM,MED_PNOM_BLANC)) < 0)
      return -1;
  } else
    if ((ret = _MEDattrStringEcrire(datagroup,MED_NOM_UNI,MED_TAILLE_PNOM,dt_unit)) < 0)
      return -1;

  /*
   * Ecriture de la valeur scalaire
   */
  if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&type)) < 0)
    return -1;
  switch(type) 
    {
    case MED_INT :
    case MED_INT32 :
    case MED_INT64 :
      if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_VAL,&val)) < 0)
	return -1;	
      break;

    default :
      return -1;
    }

  /*
   * On ferme tout 
   */
  if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
    return -1;
  if ((ret = _MEDdatagroupFermer(gid)) < 0)
    return -1;

  return ret;
}
예제 #23
0
med_err
MEDgaussEcr(med_idt fid, med_geometrie_element type_geo, med_float *refcoo, med_mode_switch mode_coo,
	    med_int ngauss, med_float *gscoo, med_float * wg, char * locname )
{
  med_idt gid=0, chid=0;
  med_size dimd[1];
  med_err ret = -1;
  med_int typegeo = -1;
  char chemin[MED_TAILLE_GAUSS+1]="";
  med_mode_acces MED_MODE_ACCES;

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
    goto ERROR;
  }

  /*
   * MED_GAUSS_ELNO est un mot cle reserve
   */
  if (! strcmp(locname,MED_GAUSS_ELNO)) {
    MESSAGE("MED_GAUSS_ELNO est un mot cle reserve : points Gauss sur les noeuds de l'element");
    goto ERROR;   
   }

  /* 
   * Si le groupe "GAUSS" n'existe pas, on le cree
   */
  strncpy(chemin,MED_GAUSS,MED_TAILLE_GAUSS-1);
  chemin[MED_TAILLE_GAUSS-1] = '\0';
  if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
      MESSAGE("Impossible de creer le groupe MED_GAUSS : ");
      SSCRUTE(chemin); goto ERROR;
    }
  
  /* 
   * Si le groupe <locname> n'existe pas, on le cree
   * Sinon => erreur
   */
  NOFINALBLANK(locname,ERROR);

  if ((chid = _MEDdatagroupOuvrir(gid,locname)) >= 0) {
    if ( MED_MODE_ACCES != MED_LECTURE_ECRITURE ) {
      MESSAGE("Le nom de localisation existe déjà : ");
      SSCRUTE(locname); goto ERROR;
    }
  } else
    if ((chid = _MEDdatagroupCreer(gid,locname)) < 0)
      goto ERROR;

  /*
   * On stocke <ngauss> sous forme d'attribut
   */
  if (_MEDattrEntierEcrire(chid,MED_NOM_NBR,&ngauss) < 0) {
    MESSAGE("Erreur à l'écriture de l'attribut MED_NOM_NBR : ");
    ISCRUTE(ngauss);goto ERROR;
  };

  /*
   * On stocke <type_geo> sous forme d'attribut
   */
  typegeo = (med_int) type_geo; 
  /* sizeof(enum) tjrs = sizeof(int) en C, or
     sur machines 64 bits par défaut med_int==long,
     du coup sur  machines 64 bits _MEDattrEntierEcrire utilise 
     le type hdf NATIVE_LONG, ce qui pose un problème qd on passe
     un enum.
  */
  if (_MEDattrEntierEcrire(chid,MED_NOM_GEO,&typegeo) < 0) {
    MESSAGE("Erreur à l'écriture de l'attribut MED_NOM_GEO : ");
    ISCRUTE(type_geo);goto ERROR;
  };


  /*
   * On stocke les coordonnées de référence dans un dataset
   */

  dimd[0] = (type_geo%100)*(type_geo/100);
  if ( _MEDdatasetNumEcrire(chid,MED_NOM_COO,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
			    (unsigned char*) refcoo)  < 0 ) {
    MESSAGE("Impossible d'ecrire le dataset : ");SSCRUTE(MED_NOM_COO);
    ISCRUTE_size(dimd[0]); goto ERROR;
  }

  /*
   * On stocke les points d'intégration dans un dataset
   */
   
  dimd[0] = ngauss*(type_geo/100);
  if ( _MEDdatasetNumEcrire(chid,MED_NOM_GAU,MED_FLOAT64,mode_coo,(type_geo/100),MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
			    (unsigned char*) gscoo)  < 0 ) {
    MESSAGE("Impossible d'ecrire le dataset : ");SSCRUTE(MED_NOM_GAU);
    ISCRUTE_size(dimd[0]); goto ERROR;
  }
  
  /*
   * On stocke les poids dans un dataset
   */
   
  dimd[0] = ngauss; 
  if ( _MEDdatasetNumEcrire(chid,MED_NOM_VAL,MED_FLOAT64,mode_coo,1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
			    (unsigned char*) wg)  < 0 ) {
    MESSAGE("Impossible d'ecrire le dataset : ");SSCRUTE(MED_NOM_VAL);
    ISCRUTE_size(dimd[0]); goto ERROR;
  }


  ret = 0;

 ERROR:
  
  /*
   * On ferme tout
   */
  
  if (chid>0)     if (_MEDdatagroupFermer(chid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(chid); ret = -1; 
  }

  if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(gid); ret = -1; 
  }
  
  return ret;
}
예제 #24
0
void 
MEDjointCr231(int dummy,...) {


  med_idt   fid      ;
  char *    maa_lcl  ;
  char *    jn       ;
  char *    desc     ;
  med_int   dom      ;
  char *    maa_dist ;
  med_err * fret     ;
 
  med_idt root=0,jntid=0;
  med_err ret=-1;
  char chemin[MED_TAILLE_MAA+MED_TAILLE_JNT+MED_TAILLE_NOM+1];
  char tmp[MED_TAILLE_JNT+1];
  med_int nbc=0;
  med_mode_acces MED_MODE_ACCES;

  va_list params;
  va_start(params,dummy);

  fid      = va_arg(params,med_idt);
  maa_lcl  = va_arg(params,char *);
  jn       = va_arg(params,char *);
  desc     = va_arg(params,char *);
  dom      = va_arg(params,med_int);
  maa_dist = va_arg(params,char*);
  fret     = va_arg(params,med_err *);

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) {*fret=-1;return;}


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
    goto ERROR;
  }

  if ( MED_MODE_ACCES == MED_LECTURE ) {
    MESSAGE("Impossible de créer un joint en mode MED_LECTURE.");
    goto ERROR;
  };

  /* 
   * Si le Data Group "JNT" n'existe pas, on le cree
   */
  strcpy(chemin,MED_MAA);
  NOFINALBLANK(maa_lcl,ERROR);
  strcat(chemin,maa_lcl);
  strncpy(tmp,MED_JNT,MED_TAILLE_JNT-1);
  tmp[MED_TAILLE_JNT-1] = '\0';
  strcat(chemin,tmp);
  if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
      MESSAGE("Erreur à la création du datagroup : ");
      SSCRUTE(chemin);
      goto ERROR;
    }

  /*
   * Si un joint du meme nom existe => erreur
   * Sinon on le cree
   */
  NOFINALBLANK(jn,ERROR);
  if ((jntid = _MEDdatagroupCreer(root,jn)) < 0) {
    MESSAGE("Erreur à la création du joint : ");
    SSCRUTE(jn);
    goto ERROR;
  }

  /*
   * L'attribut "DES"
   */
  if ((ret = _MEDattrStringEcrire(jntid,MED_NOM_DES,MED_TAILLE_DESC,desc)) < 0) {
    MESSAGE("Erreur à l'écriture de la description du joint : ");
    SSCRUTE(desc);
    goto ERROR;
  }

  /*
   * L'attribut "MAI"
   */
  /* BUG CORRIGE EN 232 MED_TAILLE_NOM au lieu de MED_TAILLE_MAA */
  /* conservé ici pour éviter de reprendre en lib2.3.2 un fichier 2.3.1
     en écrivant l'attribut avec une taille plus grande que celle des fichiers 2.3.1 */
  if ((ret = _MEDattrStringEcrire(jntid,MED_NOM_MAI,MED_TAILLE_MAA,maa_dist)) < 0) {
    MESSAGE("Erreur à l'écriture du nom du maillage distant : ");
    SSCRUTE(maa_dist);
    goto ERROR;
  }

  /*
   * L'attribut "DOM"
   */
  if ((ret = _MEDattrEntierEcrire(jntid,MED_NOM_DOM,&dom)) < 0) {
    MESSAGE("Erreur à l'écriture du domaine : ");
    ISCRUTE(dom);
    goto ERROR;
  }

  /*
   * On ferme tout 
   */
  ret=0;
 ERROR:

  if (jntid>0)     if (_MEDdatagroupFermer(jntid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(jntid);ret = -1; 
  }
  
  if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(root); ret = -1; 
  }

  va_end(params);
  *fret = ret;
  return;
}
예제 #25
0
med_err
MEDprofilEcr(med_idt fid,med_int *pflval,med_int n,char *profilname)
{
  med_idt gid, chid;
  med_size dimd[1];
  med_err ret=-1;
  char chemin[MED_TAILLE_PROFILS+1];
  med_mode_acces MED_MODE_ACCES;

  /*
   * On inhibe le gestionnaire d'erreur HDF 5
   */
  _MEDmodeErreurVerrouiller();
if (MEDcheckVersion(fid) < 0) return -1;


  if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
    MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
    goto ERROR;
  }

  /* 
   * Si le groupe "PROFILS" n'existe pas, on le cree
   */
  strncpy(chemin,MED_PROFILS,MED_TAILLE_PROFILS-1);
  chemin[MED_TAILLE_PROFILS-1] = '\0';
  if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    if ((gid = _MEDdatagroupCreer(fid,chemin)) < 0) {
      MESSAGE("Impossible de creer le groupe MED_PROFILS : ");
      SSCRUTE(chemin); goto ERROR;
    }

  /* 
   * Si le groupe "profilname" n'existe pas, on le cree
   * Sinon => erreur
   */
  NOFINALBLANK(profilname,ERROR);
  if ((chid = _MEDdatagroupOuvrir(gid,profilname)) >= 0) {
    if ( MED_MODE_ACCES != MED_LECTURE_ECRITURE ) {
      MESSAGE("Le profil existe déjà : ");
      SSCRUTE(profilname); goto ERROR;
    }
  } else
    if ((chid = _MEDdatagroupCreer(gid,profilname)) < 0)
      goto ERROR;

  /*
   * On stocke "n" sous forme d'attribut
   */
  if ((ret = _MEDattrEntierEcrire(chid,MED_NOM_NBR,&n)) < 0) {
    MESSAGE("Erreur à l'écriture de l'attribut MED_NOM_NBR : ");
    ISCRUTE(n); goto ERROR;
  };

  /*
   * On stocke le profil dans un dataset
   */
  dimd[0] = n;
#if defined(HAVE_F77INT64)
  ret =  _MEDdatasetNumEcrire(chid,MED_NOM_PFL,MED_INT64,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
			      (unsigned char*) pflval);
#else
  ret =  _MEDdatasetNumEcrire(chid,MED_NOM_PFL,MED_INT32,MED_NO_INTERLACE,MED_DIM1,MED_ALL,MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
			      (unsigned char*) pflval);
#endif
  if (ret < 0 ) {
    MESSAGE("Impossible d'ecrire le dataset pflval de taille  : ");
    ISCRUTE(n); goto ERROR;
  }

  ret = 0;
 ERROR:
  /*
   * On ferme tout
   */
  if (chid>0)     if (_MEDdatagroupFermer(chid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(chid); ret = -1;
  }

  if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
    MESSAGE("Impossible de fermer le datagroup : ");
    ISCRUTE_id(gid); ret = -1;
  }

  return ret;
}
예제 #26
0
med_err
MEDsubdomainCorrespondenceWr(const med_idt            fid,
			     const char * const       localmeshname,
			     const char * const       jointname,
			     const med_int            numdt,
			     const med_int            numit,
			     const med_entity_type    localentitype,
			     const med_geometry_type  localgeotype,
			     const med_entity_type    remoteentitype,
			     const med_geometry_type  remotegeotype,
			     const med_int            nentity,
			     const med_int * const    correspondence) {
  
  med_access_mode     _MED_ACCESS_MODE;
  med_idt            _root=0,_jntid=0,_meshid=0,_cstpid=0,_datagroup2=0;
  med_idt            _dataset=0;
  med_err            _ret=-1;
  char               _path[MED_TAILLE_JNT+2*MED_NAME_SIZE+2]=MED_JNT;
  char               _computationstepname[2*MED_MAX_PARA+1]="";
  char               _datagroupname2[4*MED_TAILLE_NOM_ENTITE+4]="";
  char               _localgeotypename   [MED_TAILLE_NOM_ENTITE+1]="";
  char               _remotegeotypename  [MED_TAILLE_NOM_ENTITE+1]="";
  med_sorting_type   _sortingtype=0;
  med_filter         _filter        = MED_FILTER_INIT;
  med_int            _localgeotype   = MED_NONE;
  med_int            _localentitype  = localentitype;
  med_int            _remotegeotype  = MED_NONE;
  med_int            _remoteentitype = remoteentitype;

  if ( localentitype == MED_NODE_ELEMENT ) _localgeotype=MED_NODE ;

 
  if ( localentitype  != MED_NODE ) _localgeotype  = localgeotype ;
  if ( remoteentitype != MED_NODE ) _remotegeotype = remotegeotype ;

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  /*
   * Ouverture du dataGroup /JNT/
   */
  if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0) {
    MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
    goto ERROR;
  }

  /*
   * Ouverture du dataGroup <meshname>
   */
  if ((_meshid = _MEDdatagroupOuvrir(_root,localmeshname)) < 0) {
    MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,localmeshname);
    SSCRUTE(_path);goto ERROR;
  }

  strcat(_path,localmeshname);

  /*
   * Ouverture du data Group "/JNT/<localmeshname>/<jointname>"
   */
  if ((_jntid = _MEDdatagroupOuvrir(_meshid,jointname)) < 0) {
      MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,jointname);
      SSCRUTE(_path);goto ERROR;
  }

  strcat(_path,"/");
  strcat(_path,jointname);

  if ( MEDmeshSortingTypeRd(fid,localmeshname,&_sortingtype) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API," MEDmeshSortingTypeRd");
    SSCRUTE(localmeshname);ISCRUTE_int(_sortingtype);goto ERROR;
  }

  _MEDgetComputationStepName(_sortingtype,numdt,numit,_computationstepname);

  if ((_cstpid = _MEDdatagroupOuvrir(_jntid,_computationstepname)) < 0)
    if ((_cstpid = _MEDdatagroupCreer(_jntid,_computationstepname)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_computationstepname);
      SSCRUTE(_path);goto ERROR;
    }

  /*Cree ou ouvre l'attribut MED_NOM_NDT pour �criture */
  if ( _MEDattributeIntWr(_cstpid,MED_NOM_NDT,&numdt) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
    SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    goto ERROR;
  }


  /*Cree ou ouvre l'attribut MED_NOM_NOR pour �criture */
  if ( _MEDattributeIntWr(_cstpid,MED_NOM_NOR,&numit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
    SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    goto ERROR;
  }


  /*
   *  Creation/Ouverture du datagroup de niveau
   *   <localentitype>[.<localgeotype>].<remoteentitype>[.<remotegeotype>]
   */
  if (_MEDgetEntityTypeName(_datagroupname2,localentitype) < 0) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
    ISCRUTE_int(localentitype);SSCRUTE(jointname);goto ERROR;
  }
  if ( localentitype != MED_NODE ) {
    if ( _MEDgetInternalGeometryTypeName(_localgeotypename,localgeotype) < 0) {
      MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
      ISCRUTE_int(localgeotype);SSCRUTE(jointname);goto ERROR;
    }
      strcat(_datagroupname2,".");
      strcat(_datagroupname2,_localgeotypename);
  }

  strcat(_datagroupname2,".");

  if (_MEDgetEntityTypeName(&_datagroupname2[strlen(_datagroupname2)],remoteentitype) < 0) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
    ISCRUTE_int(remoteentitype);SSCRUTE(jointname);goto ERROR;
  }
  if ( remoteentitype != MED_NODE ) {
    if ( _MEDgetInternalGeometryTypeName(_remotegeotypename,remotegeotype) < 0) {
      MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
      ISCRUTE_int(remotegeotype);SSCRUTE(jointname);goto ERROR;
    }
      strcat(_datagroupname2,".");
      strcat(_datagroupname2,_remotegeotypename);
  }


  if ( (_datagroup2 = _MEDdatagroupOuvrir(_cstpid,_datagroupname2)) < 0)
    if ((_datagroup2 = _MEDdatagroupCreer(_cstpid,_datagroupname2)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
      SSCRUTE(_path);SSCRUTE(jointname);goto ERROR;
    }

  /*Cree ou ouvre l'attribut MED_NOM_ENT pour �criture */
  if (_MEDattributeIntWr(_datagroup2,MED_NOM_ENT,&_localentitype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_ENT);
    ISCRUTE(_localentitype);goto ERROR;
  }

  /*Cree ou ouvre l'attribut MED_NOM_GEO pour �criture */
  if (_MEDattributeIntWr(_datagroup2,MED_NOM_GEO,&_localgeotype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
    ISCRUTE(_localgeotype);goto ERROR;
  }

  /*Cree ou ouvre l'attribut MED_NOM_END pour �criture */
  if (_MEDattributeIntWr(_datagroup2,MED_NOM_END,&_remoteentitype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_END);
    ISCRUTE(_remoteentitype);goto ERROR;
  }

  /*Cree ou ouvre l'attribut MED_NOM_GED pour �criture */
  if (_MEDattributeIntWr(_datagroup2,MED_NOM_GED,&_remotegeotype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GED);
    ISCRUTE(_remotegeotype);goto ERROR;
  }


  if ( MEDfilterEntityCr(fid, nentity, 1, 2, MED_ALL_CONSTITUENT,
			 MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
			 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    goto ERROR;
  }

  if ( _MEDdatasetWr(_datagroup2,MED_NOM_COR,MED_INTERNAL_INT,&_filter, correspondence) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COR);
    SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    goto ERROR;
  }

  if ( MEDfilterClose(&_filter) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_SUBDOMAINJOINT_MSG);
    SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    goto ERROR;
  }

  if ((_dataset = _MEDdatasetOuvrir(_datagroup2,MED_NOM_COR)) < 0) {
    MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATASET,MED_NOM_COR);
    SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
    goto ERROR;
  }

  if ( _MEDattributeIntWr(_dataset,MED_NOM_NBR,&nentity) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
    SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
    SSCRUTE(MED_NOM_NBR);ISCRUTE(nentity);goto ERROR;
  }



  _ret=0;
 ERROR:

  if (_dataset>0)     if (_MEDdatasetFermer(_dataset) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATASET,MED_NOM_COR);
    ISCRUTE_id(_dataset);
  }

  if (_datagroup2>0)            if (_MEDdatagroupFermer(_datagroup2) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
    ISCRUTE_id(_datagroup2);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
  }

  if (_cstpid>0)            if (_MEDdatagroupFermer(_cstpid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_computationstepname);
    ISCRUTE_id(_cstpid);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
  }

  if (_jntid>0)            if (_MEDdatagroupFermer(_jntid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,jointname);
    ISCRUTE_id(_jntid);SSCRUTE(_path);
  }

  if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,localmeshname);
    ISCRUTE_id(_meshid);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_JNT);
    ISCRUTE_id(_root);
  }

  return _ret;
}
예제 #27
0
med_err
MEDequivalenceCr(const med_idt      fid,
		 const char * const meshname,
		 const char * const equivname,
		 const char * const description)
{
  med_access_mode _MED_ACCESS_MODE;
  med_idt        _root=0,_eqid=0,_meshid=0;
  med_err        _ret=-1;
  char           _path[MED_TAILLE_EQS+MED_NAME_SIZE+1]=MED_EQS;

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  /*
   * Si le DataGroup /EQS/ n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
     goto ERROR;
    }

  NOFINALBLANK(meshname,ERROR);

  /*
   * Si le DataGroup /EQS/<meshname> n'existe pas, on le cree
   */
  if ((_meshid = _MEDdatagroupOuvrir(_root,meshname)) < 0)
    if ((_meshid = _MEDdatagroupCreer(_root,meshname)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
      SSCRUTE(_path);goto ERROR;
    }

  strcat(_path,meshname);
  NOFINALBLANK(equivname,ERROR);

  /*
   * Si le Data Group "/EQS/<meshname>/<equivname>" n'existe pas, on le cree
   */
  if ((_eqid = _MEDdatagroupOuvrir(_meshid,equivname)) < 0)
    if ((_eqid = _MEDdatagroupCreer(_meshid,equivname)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,equivname);
      SSCRUTE(_path);goto ERROR;
    }

 /*  if ( (_eqid = _MEDmeshAssociatedGroupCr(fid, */
/* 					  MED_EQS_NOM, */
/* 					  meshname, */
/* 					  numdt, */
/* 					  numit, */
/* 					  -1, */
/* 					  MED_FALSE, */
/* 					  equivalencename ) ) < 0)  { */
/*     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAssociatedGroupCr"); */
/*     SSCRUTE(MED_EQS_NOM);SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt); */
/*     SSCRUTE(equivalencename); */
/*     goto ERROR; */
/*   } */

  /*
   * L'attribut "DES"
   */
  if ((_ret = _MEDattributeStringWr(_eqid,MED_NOM_DES,MED_COMMENT_SIZE,
				   description)) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
    SSCRUTE(equivname);SSCRUTE(description);

    goto ERROR;
  }


  _ret=0;
 ERROR:

  if (_eqid>0)            if (_MEDdatagroupFermer(_eqid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,equivname);
    ISCRUTE_id(_eqid);SSCRUTE(_path);
  }

  if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_path);
    ISCRUTE_id(_eqid);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_EQS);
    ISCRUTE_id(_eqid);
  }

  return _ret;
}
예제 #28
0
med_err
MEDprofileWr(const med_idt        fid,
	     const char* const    profilename,
	     const med_int        profilesize,
	     const med_int* const profilearray)
{
  med_access_mode _MED_ACCESS_MODE;
  med_idt        _root=0,_pfid=0;
  med_err        _ret=-1;
  char           _path[MED_TAILLE_PROFILS+MED_NAME_SIZE+1]=MED_PROFILS;
  med_filter     _filter        = MED_FILTER_INIT;

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
 if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

 /*
   * Si le DataGroup /PROFILS/ n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,_path)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_path);
     goto ERROR;
    }

  NOFINALBLANK(profilename,ERROR);
  /*
   * Si le DataGroup /PROFILS/<profilename> n'existe pas, on le cree
   */
  if ((_pfid = _MEDdatagroupOuvrir(_root,profilename)) < 0)
    if ((_pfid = _MEDdatagroupCreer(_root,profilename)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,profilename);
      SSCRUTE(_path);goto ERROR;
    }

  strcat(_path,profilename);


  /*
   * On stocke "profilesize" sous forme d'attribut
   */
  if (_MEDattributeIntWr(_pfid,MED_NOM_NBR,&profilesize) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_PROFILE_MSG);
    SSCRUTE(profilename);SSCRUTE(MED_NOM_NBR);ISCRUTE(profilesize);
    goto ERROR;
  }

  /*
   * On stocke le profil dans un dataset
   */
  if ( MEDfilterEntityCr(fid, profilesize, 1, 1, MED_ALL_CONSTITUENT,
			 MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
			 MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    goto ERROR;
  }

  if ( _MEDdatasetWr(_pfid,MED_NOM_PFL,MED_INTERNAL_INT,&_filter, profilearray) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_PFL);SSCRUTE(_path);
    goto ERROR;
  }

  if ( MEDfilterClose(&_filter) < 0 ) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_PROFILE_MSG); SSCRUTE(_path);
    goto ERROR;
  }

  _ret = 0;

 ERROR:

  if (_pfid>0)            if (_MEDdatagroupFermer(_pfid) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,profilename);
    ISCRUTE_id(_pfid);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_PROFILS);
    ISCRUTE_id(_root);
  }

  return _ret;
}
예제 #29
0
med_err
_MEDmeshCr(const med_idt fid, const char * const root,
	   const char * const meshname, const med_int spacedim,
	   const med_int meshdim, const med_mesh_type meshtype,
	   const char * const description, const char * const dtunit,
	   const med_sorting_type sortingtype,
	   const med_axis_type axistype, const char * const axisname,
	   const char * const axisunit)
{

  med_access_mode _MED_ACCESS_MODE;
  med_err _ret=-1;
  med_idt _root=0,_datagroup1=0;
/* _datagroup2=0,_datagroup3=0; */
  med_int _intmeshtype    = (med_int) meshtype;
  med_int _intaxistype = (med_int) axistype;
  char    _datagroupname1[MED_NAME_SIZE+1]="";
/*   char    _geotypename[MED_NAME_SIZE_ENTITE+1]=""; */
  med_int _lastnumdt=MED_NO_DT, _lastnumit=MED_NO_IT;
  med_int _intsortingtype     =(med_int) MED_SORT_UNDEF;
  med_int _intexistingmeshtype=(med_int) MED_UNDEF_MESH_TYPE;
  med_mesh_type    _existingmeshtype    = meshtype;
  med_sorting_type _existingsortingtype = sortingtype;
  med_size         _nstep=0;

  /*
   * On inhibe le gestionnaire d'erreur
   */
  _MEDmodeErreurVerrouiller();
if (_MEDcheckVersion30(fid) < 0) goto ERROR;

  if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    goto ERROR;
  }

  if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    ISCRUTE_int(_MED_ACCESS_MODE);
    goto ERROR;
  }

  if ( sortingtype == MED_SORT_UNDEF) {
    MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,"sortingtype");
    ISCRUTE_int(sortingtype);
    goto ERROR;
  }

  /*
   * Si le DataGroup root n'existe pas, on le cree
   */
  if ((_root = _MEDdatagroupOuvrir(fid,root)) < 0)
    if ((_root = _MEDdatagroupCreer(fid,root)) < 0) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,root);
     goto ERROR;
    }

  NOFINALBLANK(meshname,ERROR);
  /*
   * Si le Data Group "/MAA.../<meshname>" n'existe pas, on le cree
   */
  if ((_datagroup1 = _MEDdatagroupOuvrir(_root,meshname)) < 0)
    if ((_datagroup1 = _MEDdatagroupCreer(_root,meshname)) < 0 ) {
      MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
      goto ERROR;
    }

  /*
   * Creation de l'attribut dimension du maillage
   */
  if (meshdim > spacedim) {
    MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"meshdim");
    ISCRUTE(meshdim);ISCRUTE(spacedim);
    SSCRUTE(root);SSCRUTE(meshname);goto ERROR;
  }

  /*
   * Creation de l'attribut dimension de l'espace
   */
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_ESP,&spacedim) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_ESP);
    ISCRUTE(spacedim);goto ERROR;
  }

  /*
   * Creation de l'attribut dimension du  maillage
   */
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_DIM,&meshdim) < 0 ) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DIM);
    ISCRUTE(meshdim);goto ERROR;
  }

  /* Lecture de l'attribut MED_NOM_TYP */
  if (_MEDattrEntierLire(_datagroup1,MED_NOM_TYP,&_intexistingmeshtype) >= 0)
    _existingmeshtype = (med_mesh_type) (_intexistingmeshtype);

  if ( _existingmeshtype != meshtype ) {
    MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_WRITE,MED_ERR_ATTRIBUTE_MSG);
    SSCRUTE(MED_NOM_TYP);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
    ISCRUTE_int(_existingmeshtype);ISCRUTE_int(meshtype);goto ERROR;
 
  }
  /*
   * Creation de l'attribut correspondant au type du maillage (MED_STRUCTURE, MED_NON_STRUCTURE)
   * L'attribut "TYP"
   */
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_intmeshtype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
    ISCRUTE(_intmeshtype);goto ERROR;
  }

  /*
   * La description associee au maillage
   */
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_DES,MED_COMMENT_SIZE,description) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DES);
    SSCRUTE(description);goto ERROR;
  }


  /*
   * Creation de l'attribut nom de l'unit~ des dates
   */
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
    SSCRUTE(dtunit);goto ERROR;
  }

  /*
   *  Test de l'existence de l'attribut de tri des s~quences de calcul
   */
  if ( _MEDattrEntierLire(_datagroup1,MED_NOM_SRT,&_intsortingtype) >= 0) {
    _existingsortingtype = (med_sorting_type) (_intsortingtype);
    /* Nombre d'~tapes de calcul existantes */
    _MEDnObjects(_datagroup1,".",&_nstep);
  }

  if ( (_existingsortingtype != sortingtype) && _nstep ) {
    MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,MED_ERR_ATTRIBUTE_MSG);
    SSCRUTE(MED_NOM_SRT);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
    ISCRUTE_int(_existingsortingtype);ISCRUTE_int(sortingtype);goto ERROR;
  }

  /*
   * Creation de l'attribut de tri des s~quences de calcul
   */

  _intsortingtype = sortingtype;
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_SRT,&_intsortingtype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_SRT);
    ISCRUTE_int(sortingtype);goto ERROR;
  }

  /*
   * Creation de l'attribut de la derni~re it~ration cr~e
   */
/*   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NXI,&_lastnumit) < 0) { */
/*     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG); */
/*     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXI); */
/*     ISCRUTE(_lastnumit);goto ERROR; */
/*   } */


  /*
   * L'attribut "REP"
   */
  if ( _MEDattributeIntWr(_datagroup1,MED_NOM_REP,&_intaxistype) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_REP);
    ISCRUTE(_intaxistype);goto ERROR;
  }

  /*
   * Attribut "NOM"
   */
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_NOM,spacedim*MED_SNAME_SIZE,axisname) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOM);
    SSCRUTE(axisname);goto ERROR;
  }

  /*
   * Attribut "UNI"
   */
  if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,spacedim*MED_SNAME_SIZE,axisunit) < 0) {
    MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNI);
    SSCRUTE(axisunit);goto ERROR;
  }

  /*
   * Cr~ation du datagroup des mailles associ~es ~ un maillage structur~
   * Cel~ permet d'utiliser les routines famille, num~ros/noms optionnels
   * de la m~me fa~on que pour les maillages non structur~s
   */
/*   if ( meshtype == MED_STRUCTURE )  { */

/*     if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) { */
/*       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,root); */
/*       SSCRUTE(meshname);SSCRUTE(MED_NOM_MAI);goto ERROR; */
/*     } */

/*     switch ( meshdim )  { */
/*     case 1 : strcpy(_geotypename,MED_NOM_SE2); */
/*       break; */
/*     case 2 : strcpy(_geotypename,MED_NOM_QU4); */
/*       break; */
/*     case 3 : strcpy(_geotypename,MED_NOM_HE8); */
/*       break; */
/*     case 0 : strcpy(_geotypename,MED_NOM_PO1); */
/*       break; */
/*     default : */
/*       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,""); */
/*       ISCRUTE(meshdim);SSCRUTE(root);SSCRUTE(meshname);goto ERROR; */
/*     } */

/*     if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) { */
/*       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename); */
/*       SSCRUTE(root);SSCRUTE(meshname);SSCRUTE(MED_NOM_MAI);ISCRUTE_int(_geotypename); */
/*       goto ERROR; */
/*     } */
/*   } */


  /*
   * Nettoyages divers
   */
  _ret = 0;

 ERROR:
/*   if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) { */
/*     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename); */
/*     ISCRUTE_id(_datagroup3); */
/*   } */

/*   if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) { */
/*     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI); */
/*     ISCRUTE_id(_datagroup2); */
/*   } */

  if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
    ISCRUTE_id(_datagroup1);
  }

  if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,root);
    ISCRUTE_id(_root);
  }

  return _ret;

}