# MEDequivalenceCorrespondenceWr.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2012  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
    00041 med_err
    00042 MEDequivalenceCorrespondenceWr(const med_idt            fid,
    00043                                const char * const       meshname,
    00044                                const char * const       equivname,
    00045                                const med_int            numdt,
    00046                                const med_int            numit,
    00047                                const med_entity_type    entitype,
    00048                                const med_geometry_type  geotype,
    00049                                const med_int const      nentity,
    00050                                const med_int * const    correspondence) {
    00051
    00052   med_access_mode     _MED_ACCESS_MODE;
    00053   med_idt            _root=0,_eqid=0,_meshid=0,_cstpid=0,_datagroup2=0;
    00054   med_idt            _dataset=0;
    00055   med_err            _ret=-1;
    00056   char               _path[MED_TAILLE_EQS+2*MED_NAME_SIZE+2]=MED_EQS;
    00057   char               _computationstepname[2*MED_MAX_PARA+1]="";
    00058   char               _datagroupname2[2*MED_TAILLE_NOM_ENTITE+2]="";
    00059   char               _geotypename   [MED_TAILLE_NOM_ENTITE+1]="";
    00060   med_sorting_type   _sortingtype=0;
    00061   med_filter         _filter        = MED_FILTER_INIT;
    00062   med_int             _geotype  = MED_NONE;
    00063   med_int             _entitype = entitype;
    00064
    00065   if ( entitype == MED_NODE_ELEMENT ) _geotype=MED_NODE ;
    00066
    00067   if ( (geotype / 100 ) > 2 )  {
    00068     MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_GEOMETRIC,MED_ERR_EQUIVALENCE_MSG);
    00069     SSCRUTE(equivname);ISCRUTE_int(geotype);
    00070     goto ERROR;
    00071   }
    00072
    00073   if ( entitype != MED_NODE ) _geotype=geotype ;
    00074
    00075   /*
    00076    * On inhibe le gestionnaire d'erreur
    00077    */
    00078   _MEDmodeErreurVerrouiller();
    00079  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    00080
    00081   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    00082     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00083     goto ERROR;
    00084   }
    00085
    00086   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    00087     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00088     ISCRUTE_int(_MED_ACCESS_MODE);
    00089     goto ERROR;
    00090   }
    00091
    00092   /*
    00093    * Ouverture du dataGroup /EQS/
    00094    */
    00095   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0) {
    00096     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
    00097     goto ERROR;
    00098   }
    00099
    00100   /*
    00101    * Ouverture du dataGroup <meshname>
    00102    */
    00103   if ((_meshid = _MEDdatagroupOuvrir(_root,meshname)) < 0) {
    00104     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,meshname);
    00105     SSCRUTE(_path);goto ERROR;
    00106   }
    00107
    00108   strcat(_path,meshname);
    00109
    00110   /*
    00111    * Ouverure du datagroup "/EQS/<meshname>/<equivname>"
    00112    */
    00113   if ((_eqid = _MEDdatagroupOuvrir(_meshid,equivname)) < 0) {
    00114       MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,equivname);
    00115       SSCRUTE(_path);goto ERROR;
    00116   }
    00117
    00118   strcat(_path,"/");
    00119   strcat(_path,equivname);
    00120
    00121   if ( MEDmeshSortingTypeRd(fid,meshname,&_sortingtype) < 0 ) {
    00122     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API," MEDmeshSortingTypeRd");
    00123     SSCRUTE(meshname);ISCRUTE_int(_sortingtype);goto ERROR;
    00124   }
    00125
    00126   _MEDgetComputationStepName(_sortingtype,numdt,numit,_computationstepname);
    00127
    00128   if ((_cstpid = _MEDdatagroupOuvrir(_eqid,_computationstepname)) < 0)
    00129     if ((_cstpid = _MEDdatagroupCreer(_eqid,_computationstepname)) < 0 ) {
    00130       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_computationstepname);
    00131       SSCRUTE(_path);goto ERROR;
    00132     }
    00133
    00134   /*Cree ou ouvre l'attribut MED_NOM_NDT pour �criture */
    00135   if ( _MEDattributeIntWr(_cstpid,MED_NOM_NDT,&numdt) < 0) {
    00136     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
    00137     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00138     goto ERROR;
    00139   }
    00140
    00141
    00142   /*Cree ou ouvre l'attribut MED_NOM_NOR pour �criture */
    00143   if ( _MEDattributeIntWr(_cstpid,MED_NOM_NOR,&numit) < 0) {
    00144     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
    00145     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00146     goto ERROR;
    00147   }
    00148
    00149   /*Cree ou ouvre l'attribut MED_NOM_PDT pour �criture */
    00150   /*   if ( _MEDattrFloatEcrire(_cstpid,MED_NOM_PDT,&dt2) < 0) { */
    00151   /*  goto ERROR; */
    00152   /*   } */
    00153
    00154   /*
    00155    *  Creation/Ouverture du datagroup de niveau <entitype>[.<geotype>]
    00156    */
    00157   if (_MEDgetEntityTypeName(_datagroupname2,entitype) < 0) {
    00158     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
    00159     ISCRUTE_int(entitype);SSCRUTE(equivname);goto ERROR;
    00160   }
    00161   if ( entitype != MED_NODE ) {
    00162     if ( _MEDgetInternalGeometryTypeName(_geotypename,geotype) < 0) {
    00163       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
    00164       ISCRUTE_int(geotype);SSCRUTE(equivname);goto ERROR;
    00165     }
    00166       strcat(_datagroupname2,".");
    00167       strcat(_datagroupname2,_geotypename);
    00168   }
    00169
    00170   if ( (_datagroup2 = _MEDdatagroupOuvrir(_cstpid,_datagroupname2)) < 0)
    00171     if ((_datagroup2 = _MEDdatagroupCreer(_cstpid,_datagroupname2)) < 0) {
    00172       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
    00173       SSCRUTE(_path);SSCRUTE(equivname);goto ERROR;
    00174     }
    00175
    00176   /*Cree ou ouvre l'attribut MED_NOM_ENT pour �criture */
    00177   if (_MEDattributeIntWr(_datagroup2,MED_NOM_ENT,&_entitype) < 0) {
    00178     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_ENT);
    00179     ISCRUTE(_entitype);goto ERROR;
    00180   }
    00181
    00182   /*Cree ou ouvre l'attribut MED_NOM_GEO pour �criture */
    00183   if (_MEDattributeIntWr(_datagroup2,MED_NOM_GEO,&_geotype) < 0) {
    00184     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
    00185     ISCRUTE(_geotype);goto ERROR;
    00186   }
    00187
    00188
    00189   if ( MEDfilterEntityCr(fid, nentity, 1, 2, MED_ALL_CONSTITUENT,
    00190                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00191                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00192     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00193     goto ERROR;
    00194   }
    00195
    00196   if ( _MEDdatasetWr(_datagroup2,MED_NOM_COR,MED_INTERNAL_INT,&_filter, correspondence) < 0) {
    00197     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COR);
    00198     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00199     goto ERROR;
    00200   }
    00201
    00202   if ( MEDfilterClose(&_filter) < 0 ) {
    00203     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_EQUIVALENCE_MSG);
    00204     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00205     goto ERROR;
    00206   }
    00207
    00208   if ((_dataset = _MEDdatasetOuvrir(_datagroup2,MED_NOM_COR)) < 0) {
    00209     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATASET,MED_NOM_COR);
    00210     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
    00211     goto ERROR;
    00212   }
    00213
    00214   if ( _MEDattributeIntWr(_dataset,MED_NOM_NBR,&nentity) < 0) {
    00215     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_EQUIVALENCE_MSG);
    00216     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
    00217     SSCRUTE(MED_NOM_NBR);ISCRUTE(nentity);goto ERROR;
    00218   }
    00219
    00220
    00221
    00222   _ret=0;
    00223  ERROR:
    00224
    00225   if (_dataset>0)     if (_MEDdatasetFermer(_dataset) < 0) {
    00226     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATASET,MED_NOM_COR);
    00227     ISCRUTE_id(_dataset);
    00228   }
    00229
    00230   if (_datagroup2>0)            if (_MEDdatagroupFermer(_datagroup2) < 0) {
    00231     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
    00232     ISCRUTE_id(_datagroup2);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00233   }
    00234
    00235   if (_cstpid>0)            if (_MEDdatagroupFermer(_cstpid) < 0) {
    00236     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_computationstepname);
    00237     ISCRUTE_id(_cstpid);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00238   }
    00239
    00240   if (_eqid>0)            if (_MEDdatagroupFermer(_eqid) < 0) {
    00241     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,equivname);
    00242     ISCRUTE_id(_eqid);SSCRUTE(_path);
    00243   }
    00244
    00245   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
    00246     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
    00247     ISCRUTE_id(_meshid);
    00248   }
    00249
    00250   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    00251     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_EQS);
    00252     ISCRUTE_id(_root);
    00253   }
    00254
    00255   return _ret;
    00256 }