_MEDmeshCr.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2011  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 _MEDmeshCr(const med_idt fid, const char * const root,
00028            const char * const meshname, const med_int spacedim,
00029            const med_int meshdim, const med_mesh_type meshtype,
00030            const char * const description, const char * const dtunit,
00031            const med_sorting_type sortingtype,
00032            const med_axis_type axistype, const char * const axisname,
00033            const char * const axisunit)
00034 {
00035 
00036   med_access_mode _MED_ACCESS_MODE;
00037   med_err _ret=-1;
00038   med_idt _root=0,_datagroup1=0;
00039 /* _datagroup2=0,_datagroup3=0; */
00040   med_int _intmeshtype    = (med_int) meshtype;
00041   med_int _intaxistype = (med_int) axistype;
00042   char    _datagroupname1[MED_NAME_SIZE+1]="";
00043 /*   char    _geotypename[MED_NAME_SIZE_ENTITE+1]=""; */
00044   med_int _lastnumdt=MED_NO_DT, _lastnumit=MED_NO_IT;
00045   med_int _intsortingtype     =(med_int) MED_SORT_UNDEF;
00046   med_int _intexistingmeshtype=(med_int) MED_UNDEF_MESH_TYPE;
00047   med_mesh_type    _existingmeshtype    = meshtype;
00048   med_sorting_type _existingsortingtype = sortingtype;;
00049   med_size         _nstep=0;
00050 
00051   /*
00052    * On inhibe le gestionnaire d'erreur
00053    */
00054   _MEDmodeErreurVerrouiller();
00055 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
00056 
00057   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
00058     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00059     goto ERROR;
00060   }
00061 
00062   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
00063     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
00064     ISCRUTE_int(_MED_ACCESS_MODE);
00065     goto ERROR;
00066   }
00067 
00068   if ( sortingtype == MED_SORT_UNDEF) {
00069     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,"sortingtype");
00070     ISCRUTE_int(sortingtype);
00071     goto ERROR;
00072   }
00073 
00074   /*
00075    * Si le DataGroup root n'existe pas, on le cree
00076    */
00077   if ((_root = _MEDdatagroupOuvrir(fid,root)) < 0)
00078     if ((_root = _MEDdatagroupCreer(fid,root)) < 0) {
00079       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,root);
00080      goto ERROR;
00081     }
00082 
00083   NOFINALBLANK(meshname,ERROR);
00084   /*
00085    * Si le Data Group "/MAA.../<meshname>" n'existe pas, on le cree
00086    */
00087   if ((_datagroup1 = _MEDdatagroupOuvrir(_root,meshname)) < 0)
00088     if ((_datagroup1 = _MEDdatagroupCreer(_root,meshname)) < 0 ) {
00089       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,meshname);
00090       goto ERROR;
00091     }
00092 
00093   /*
00094    * Creation de l'attribut dimension du maillage
00095    */
00096   if (meshdim > spacedim) {
00097     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"meshdim");
00098     ISCRUTE(meshdim);ISCRUTE(spacedim);
00099     SSCRUTE(root);SSCRUTE(meshname);goto ERROR;
00100   }
00101 
00102   /*
00103    * Creation de l'attribut dimension de l'espace
00104    */
00105   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_ESP,&spacedim) < 0 ) {
00106     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00107     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_ESP);
00108     ISCRUTE(spacedim);goto ERROR;
00109   }
00110 
00111   /*
00112    * Creation de l'attribut dimension du  maillage
00113    */
00114   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_DIM,&meshdim) < 0 ) {
00115     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00116     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DIM);
00117     ISCRUTE(meshdim);goto ERROR;
00118   }
00119 
00120   /* Lecture de l'attribut MED_NOM_TYP */
00121   if (_MEDattrEntierLire(_datagroup1,MED_NOM_TYP,&_intexistingmeshtype) >= 0)
00122     _existingmeshtype = (med_mesh_type) (_intexistingmeshtype);
00123 
00124   if ( _existingmeshtype != meshtype ) {
00125     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_WRITE,MED_ERR_ATTRIBUTE_MSG);
00126     SSCRUTE(MED_NOM_TYP);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
00127     ISCRUTE_int(_existingmeshtype);ISCRUTE_int(meshtype);goto ERROR;
00128  
00129   }
00130   /*
00131    * Creation de l'attribut correspondant au type du maillage (MED_STRUCTURE, MED_NON_STRUCTURE)
00132    * L'attribut "TYP"
00133    */
00134   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_TYP,&_intmeshtype) < 0) {
00135     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00136     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_TYP);
00137     ISCRUTE(_intmeshtype);goto ERROR;
00138   }
00139 
00140   /*
00141    * La description associee au maillage
00142    */
00143   if ( _MEDattributeStringWr(_datagroup1,MED_NOM_DES,MED_COMMENT_SIZE,description) < 0) {
00144     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00145     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_DES);
00146     SSCRUTE(description);goto ERROR;
00147   }
00148 
00149 
00150   /*
00151    * Creation de l'attribut nom de l'unit~ des dates
00152    */
00153   if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNT,MED_SNAME_SIZE,dtunit) < 0) {
00154     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00155     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNT);
00156     SSCRUTE(dtunit);goto ERROR;
00157   }
00158 
00159   /*
00160    *  Test de l'existence de l'attribut de tri des s~quences de calcul
00161    */
00162   if ( _MEDattrEntierLire(_datagroup1,MED_NOM_SRT,&_intsortingtype) >= 0) {
00163     _existingsortingtype = (med_sorting_type) (_intsortingtype);
00164     /* Nombre d'~tapes de calcul existantes */
00165     _MEDnObjects(_datagroup1,".",&_nstep);
00166   }
00167 
00168   if ( (_existingsortingtype != sortingtype) && _nstep ) {
00169     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_COMPUTINGSTEP,MED_ERR_ATTRIBUTE_MSG);
00170     SSCRUTE(MED_NOM_SRT);SSCRUTE(meshname);SSCRUTE(_datagroupname1);
00171     ISCRUTE_int(_existingsortingtype);ISCRUTE_int(sortingtype);goto ERROR;
00172   }
00173 
00174   /*
00175    * Creation de l'attribut de tri des s~quences de calcul
00176    */
00177 
00178   _intsortingtype = sortingtype;
00179   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_SRT,&_intsortingtype) < 0) {
00180     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00181     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_SRT);
00182     ISCRUTE_int(sortingtype);goto ERROR;
00183   }
00184 
00185   /*
00186    * Creation de l'attribut de la derni~re it~ration cr~e
00187    */
00188 /*   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_NXI,&_lastnumit) < 0) { */
00189 /*     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG); */
00190 /*     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NXI); */
00191 /*     ISCRUTE(_lastnumit);goto ERROR; */
00192 /*   } */
00193 
00194 
00195   /*
00196    * L'attribut "REP"
00197    */
00198   if ( _MEDattributeIntWr(_datagroup1,MED_NOM_REP,&_intaxistype) < 0) {
00199     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00200     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_REP);
00201     ISCRUTE(_intaxistype);goto ERROR;
00202   }
00203 
00204   /*
00205    * Attribut "NOM"
00206    */
00207   if ( _MEDattributeStringWr(_datagroup1,MED_NOM_NOM,spacedim*MED_SNAME_SIZE,axisname) < 0) {
00208     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00209     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_NOM);
00210     SSCRUTE(axisname);goto ERROR;
00211   }
00212 
00213   /*
00214    * Attribut "UNI"
00215    */
00216   if ( _MEDattributeStringWr(_datagroup1,MED_NOM_UNI,spacedim*MED_SNAME_SIZE,axisunit) < 0) {
00217     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
00218     SSCRUTE(meshname);SSCRUTE(_datagroupname1);SSCRUTE(MED_NOM_UNI);
00219     SSCRUTE(axisunit);goto ERROR;
00220   }
00221 
00222   /*
00223    * Cr~ation du datagroup des mailles associ~es ~ un maillage structur~
00224    * Cel~ permet d'utiliser les routines famille, num~ros/noms optionnels
00225    * de la m~me fa~on que pour les maillages non structur~s
00226    */
00227 /*   if ( meshtype == MED_STRUCTURE )  { */
00228 
00229 /*     if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) { */
00230 /*       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,root); */
00231 /*       SSCRUTE(meshname);SSCRUTE(MED_NOM_MAI);goto ERROR; */
00232 /*     } */
00233 
00234 /*     switch ( meshdim )  { */
00235 /*     case 1 : strcpy(_geotypename,MED_NOM_SE2); */
00236 /*       break; */
00237 /*     case 2 : strcpy(_geotypename,MED_NOM_QU4); */
00238 /*       break; */
00239 /*     case 3 : strcpy(_geotypename,MED_NOM_HE8); */
00240 /*       break; */
00241 /*     case 0 : strcpy(_geotypename,MED_NOM_PO1); */
00242 /*       break; */
00243 /*     default : */
00244 /*       MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,""); */
00245 /*       ISCRUTE(meshdim);SSCRUTE(root);SSCRUTE(meshname);goto ERROR; */
00246 /*     } */
00247 
00248 /*     if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) { */
00249 /*       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename); */
00250 /*       SSCRUTE(root);SSCRUTE(meshname);SSCRUTE(MED_NOM_MAI);ISCRUTE_int(_geotypename); */
00251 /*       goto ERROR; */
00252 /*     } */
00253 /*   } */
00254 
00255 
00256   /*
00257    * Nettoyages divers
00258    */
00259   _ret = 0;
00260 
00261  ERROR:
00262 /*   if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) { */
00263 /*     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename); */
00264 /*     ISCRUTE_id(_datagroup3); */
00265 /*   } */
00266 
00267 /*   if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) { */
00268 /*     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI); */
00269 /*     ISCRUTE_id(_datagroup2); */
00270 /*   } */
00271 
00272   if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
00273     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
00274     ISCRUTE_id(_datagroup1);
00275   }
00276 
00277   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
00278     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,root);
00279     ISCRUTE_id(_root);
00280   }
00281 
00282   return _ret;
00283 
00284 }
00285 

Généré le Mon May 16 17:10:22 2011 pour MED fichier par  doxygen 1.6.1