MEDmaaCr.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  EDF R&D, CEA/DEN
00004  *  MED is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  MED is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with MED.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 
00023 #include <string.h>
00024 #include <stdlib.h>
00025 
00026 med_err 
00027 MEDmaaCr(med_idt fid, char *maillage, med_int dim, med_maillage type,char *desc)
00028 {
00029   med_idt maaid=0, root=0, entid=0, geoid=0 ;
00030   char chemin[MED_TAILLE_MAA+1];
00031   char nom_ent[MED_TAILLE_NOM_ENTITE+1];
00032   char nom_geo[MED_TAILLE_NOM_ENTITE+1];
00033   med_err ret=-1;
00034   med_int tmp;
00035   med_mode_acces MED_MODE_ACCES;
00036 
00037   /*
00038    * On inhibe le gestionnaire d'erreur
00039    */
00040   _MEDmodeErreurVerrouiller();
00041 if (MEDcheckVersion(fid) < 0) return -1;
00042 
00043 
00044   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00045     MESSAGE("Impossible de déterminer le mode d'acces au fichier.");
00046     goto ERROR;
00047   }
00048 
00049   if ( MED_MODE_ACCES == MED_LECTURE ) {
00050     MESSAGE("Impossible de créer un maillage en mode MED_LECTURE.");
00051     goto ERROR;
00052   };
00053 
00054   /*
00055    * Si la racine n'existe pas on la cree
00056    */
00057   strncpy(chemin,MED_MAA,strlen(MED_MAA)-1);
00058   chemin[MED_TAILLE_MAA-1] = '\0';
00059   if ((root = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00060     if ((root = _MEDdatagroupCreer(fid,chemin)) < 0) {
00061       MESSAGE("Erreur à la création du datagroup : ");
00062       SSCRUTE(chemin);
00063       goto ERROR;
00064     }
00065 
00066   /*
00067    * Création du maillage
00068    */
00069   NOFINALBLANK(maillage,ERROR);
00070   if ( (maaid = _MEDdatagroupCreer(root,maillage)) < 0) {
00071     MESSAGE("Erreur à la création du maillage : ");
00072     SSCRUTE(maillage);
00073     goto ERROR;
00074   }
00075 
00076   /*
00077    * Creation de l'attribut dimension
00078    */
00079   if ((ret = _MEDattrEntierEcrire(maaid,MED_NOM_DIM,&dim)) < 0) {
00080     MESSAGE("Erreur à l'écriture de la dimension du maillage : ");
00081     ISCRUTE(dim);
00082     goto ERROR;
00083   }
00084   
00085   /*
00086    * La description associee au maillage
00087    */
00088   if ((ret = _MEDattrStringEcrire(maaid,MED_NOM_DES,MED_TAILLE_DESC,desc)) < 0) {
00089     MESSAGE("Erreur à l'écriture de la description du maillage : ");
00090     SSCRUTE(desc);
00091     goto ERROR;
00092   }
00093 
00094   /*
00095    * Creation de l'attribut correspondant au type du maillage (MED_STRUCTURE, MED_NON_STRUCTURE)
00096    */
00097   tmp = (med_int) type;
00098   if ((ret = _MEDattrEntierEcrire(maaid,MED_NOM_TYP,&tmp)) < 0) {
00099     MESSAGE("Erreur à l'écriture du type de maillage : ");
00100     ISCRUTE(tmp);
00101     goto ERROR;
00102   }
00103 
00104   if ( type == MED_STRUCTURE )  {
00105 
00106     strcpy(nom_ent,MED_NOM_MAI);
00107     if ((entid = _MEDdatagroupCreer(maaid,nom_ent)) < 0) {
00108       MESSAGE("Impossible de Cr\351er le datagroup :");
00109       SSCRUTE(nom_ent);
00110       MESSAGE("pour le maillage structur\351 :");
00111       SSCRUTE(maillage);
00112       goto ERROR;
00113     }
00114 
00115     switch ( dim )  {
00116     case 1 : strcpy(nom_geo,MED_NOM_SE2);
00117       break;
00118     case 2 : strcpy(nom_geo,MED_NOM_QU4);
00119       break;
00120     case 3 : strcpy(nom_geo,MED_NOM_HE8);
00121       break;
00122     case 0 : strcpy(nom_geo,MED_NOM_PO1);
00123       break;
00124     default :
00125       MESSAGE("La dimension doit être comprise entre 0 et 3");
00126       goto ERROR;
00127     }
00128 
00129     if ((geoid = _MEDdatagroupCreer(entid,nom_geo)) < 0) {
00130       MESSAGE("Impossible de Créer le datagroup :");
00131       SSCRUTE(nom_geo);
00132       MESSAGE("pour le maillage structuré :");
00133       SSCRUTE(maillage);
00134       goto ERROR;
00135     }
00136   }
00137 
00138   /* 
00139    * Nettoyages divers
00140    */
00141   ret = 0;
00142  ERROR:
00143   if (geoid>0)     if (_MEDdatagroupFermer(geoid) < 0) {
00144     MESSAGE("Impossible de fermer le datagroup : ");
00145     ISCRUTE_id(geoid);ret = -1; 
00146   }
00147 
00148   if (entid>0)     if (_MEDdatagroupFermer(entid) < 0) {
00149     MESSAGE("Impossible de fermer le datagroup : ");
00150     ISCRUTE_id(entid);ret = -1; 
00151   }
00152 
00153   if (maaid>0)     if (_MEDdatagroupFermer(maaid) < 0) {
00154     MESSAGE("Impossible de fermer le datagroup : ");
00155     ISCRUTE_id(maaid);ret = -1; 
00156   }
00157   
00158   if (root>0)     if (_MEDdatagroupFermer(root) < 0) {
00159     MESSAGE("Impossible de fermer le datagroup : ");
00160     ISCRUTE_id(root); ret = -1; 
00161   }
00162 
00163   return ret;
00164 }
00165   
00166 
00167   

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1