# MEDsubdomainCorrespondenceWr.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
    00046 med_err
    00047 MEDsubdomainCorrespondenceWr(const med_idt            fid,
    00048                              const char * const       localmeshname,
    00049                              const char * const       jointname,
    00050                              const med_int            numdt,
    00051                              const med_int            numit,
    00052                              const med_entity_type    localentitype,
    00053                              const med_geometry_type  localgeotype,
    00054                              const med_entity_type    remoteentitype,
    00055                              const med_geometry_type  remotegeotype,
    00056                              const med_int            nentity,
    00057                              const med_int * const    correspondence) {
    00058
    00059   med_access_mode     _MED_ACCESS_MODE;
    00060   med_idt            _root=0,_jntid=0,_meshid=0,_cstpid=0,_datagroup2=0;
    00061   med_idt            _dataset=0;
    00062   med_err            _ret=-1;
    00063   char               _path[MED_TAILLE_JNT+2*MED_NAME_SIZE+2]=MED_JNT;
    00064   char               _computationstepname[2*MED_MAX_PARA+1]="";
    00065   char               _datagroupname2[4*MED_TAILLE_NOM_ENTITE+4]="";
    00066   char               _localgeotypename   [MED_TAILLE_NOM_ENTITE+1]="";
    00067   char               _remotegeotypename  [MED_TAILLE_NOM_ENTITE+1]="";
    00068   med_sorting_type   _sortingtype=0;
    00069   med_filter         _filter        = MED_FILTER_INIT;
    00070   med_int            _localgeotype   = MED_NONE;
    00071   med_int            _localentitype  = localentitype;
    00072   med_int            _remotegeotype  = MED_NONE;
    00073   med_int            _remoteentitype = remoteentitype;
    00074
    00075   if ( localentitype == MED_NODE_ELEMENT ) _localgeotype=MED_NODE ;
    00076
    00077
    00078   if ( localentitype  != MED_NODE ) _localgeotype  = localgeotype ;
    00079   if ( remoteentitype != MED_NODE ) _remotegeotype = remotegeotype ;
    00080
    00081   /*
    00082    * On inhibe le gestionnaire d'erreur
    00083    */
    00084   _MEDmodeErreurVerrouiller();
    00085  if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    00086
    00087   if ( (_MED_ACCESS_MODE = _MEDmodeAcces(fid) ) == MED_ACC_UNDEF ) {
    00088     MED_ERR_(_ret,MED_ERR_UNRECOGNIZED,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00089     goto ERROR;
    00090   }
    00091
    00092   if ( _MED_ACCESS_MODE == MED_ACC_RDONLY) {
    00093     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ACCESSMODE,MED_ERR_FILE_MSG);
    00094     ISCRUTE_int(_MED_ACCESS_MODE);
    00095     goto ERROR;
    00096   }
    00097
    00098   /*
    00099    * Ouverture du dataGroup /JNT/
    00100    */
    00101   if ((_root = _MEDdatagroupOuvrir(fid,_path)) < 0) {
    00102     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,_path);
    00103     goto ERROR;
    00104   }
    00105
    00106   /*
    00107    * Ouverture du dataGroup <meshname>
    00108    */
    00109   if ((_meshid = _MEDdatagroupOuvrir(_root,localmeshname)) < 0) {
    00110     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,localmeshname);
    00111     SSCRUTE(_path);goto ERROR;
    00112   }
    00113
    00114   strcat(_path,localmeshname);
    00115
    00116   /*
    00117    * Ouverture du data Group "/JNT/<localmeshname>/<jointname>"
    00118    */
    00119   if ((_jntid = _MEDdatagroupOuvrir(_meshid,jointname)) < 0) {
    00120       MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,jointname);
    00121       SSCRUTE(_path);goto ERROR;
    00122   }
    00123
    00124   strcat(_path,"/");
    00125   strcat(_path,jointname);
    00126
    00127   if ( MEDmeshSortingTypeRd(fid,localmeshname,&_sortingtype) < 0 ) {
    00128     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API," MEDmeshSortingTypeRd");
    00129     SSCRUTE(localmeshname);ISCRUTE_int(_sortingtype);goto ERROR;
    00130   }
    00131
    00132   _MEDgetComputationStepName(_sortingtype,numdt,numit,_computationstepname);
    00133
    00134   if ((_cstpid = _MEDdatagroupOuvrir(_jntid,_computationstepname)) < 0)
    00135     if ((_cstpid = _MEDdatagroupCreer(_jntid,_computationstepname)) < 0 ) {
    00136       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_computationstepname);
    00137       SSCRUTE(_path);goto ERROR;
    00138     }
    00139
    00140   /*Cree ou ouvre l'attribut MED_NOM_NDT pour �criture */
    00141   if ( _MEDattributeIntWr(_cstpid,MED_NOM_NDT,&numdt) < 0) {
    00142     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
    00143     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00144     goto ERROR;
    00145   }
    00146
    00147
    00148   /*Cree ou ouvre l'attribut MED_NOM_NOR pour �criture */
    00149   if ( _MEDattributeIntWr(_cstpid,MED_NOM_NOR,&numit) < 0) {
    00150     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
    00151     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00152     goto ERROR;
    00153   }
    00154
    00155
    00156   /*
    00157    *  Creation/Ouverture du datagroup de niveau
    00158    *   <localentitype>[.<localgeotype>].<remoteentitype>[.<remotegeotype>]
    00159    */
    00160   if (_MEDgetEntityTypeName(_datagroupname2,localentitype) < 0) {
    00161     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
    00162     ISCRUTE_int(localentitype);SSCRUTE(jointname);goto ERROR;
    00163   }
    00164   if ( localentitype != MED_NODE ) {
    00165     if ( _MEDgetInternalGeometryTypeName(_localgeotypename,localgeotype) < 0) {
    00166       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
    00167       ISCRUTE_int(localgeotype);SSCRUTE(jointname);goto ERROR;
    00168     }
    00169       strcat(_datagroupname2,".");
    00170       strcat(_datagroupname2,_localgeotypename);
    00171   }
    00172
    00173   strcat(_datagroupname2,".");
    00174
    00175   if (_MEDgetEntityTypeName(&_datagroupname2[strlen(_datagroupname2)],remoteentitype) < 0) {
    00176     MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_ENTITY,MED_ERR_VALUE_MSG);
    00177     ISCRUTE_int(remoteentitype);SSCRUTE(jointname);goto ERROR;
    00178   }
    00179   if ( remoteentitype != MED_NODE ) {
    00180     if ( _MEDgetInternalGeometryTypeName(_remotegeotypename,remotegeotype) < 0) {
    00181       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GEOMETRIC,MED_ERR_VALUE_MSG);
    00182       ISCRUTE_int(remotegeotype);SSCRUTE(jointname);goto ERROR;
    00183     }
    00184       strcat(_datagroupname2,".");
    00185       strcat(_datagroupname2,_remotegeotypename);
    00186   }
    00187
    00188
    00189   if ( (_datagroup2 = _MEDdatagroupOuvrir(_cstpid,_datagroupname2)) < 0)
    00190     if ((_datagroup2 = _MEDdatagroupCreer(_cstpid,_datagroupname2)) < 0) {
    00191       MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_datagroupname2);
    00192       SSCRUTE(_path);SSCRUTE(jointname);goto ERROR;
    00193     }
    00194
    00195   /*Cree ou ouvre l'attribut MED_NOM_ENT pour �criture */
    00196   if (_MEDattributeIntWr(_datagroup2,MED_NOM_ENT,&_localentitype) < 0) {
    00197     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_ENT);
    00198     ISCRUTE(_localentitype);goto ERROR;
    00199   }
    00200
    00201   /*Cree ou ouvre l'attribut MED_NOM_GEO pour �criture */
    00202   if (_MEDattributeIntWr(_datagroup2,MED_NOM_GEO,&_localgeotype) < 0) {
    00203     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
    00204     ISCRUTE(_localgeotype);goto ERROR;
    00205   }
    00206
    00207   /*Cree ou ouvre l'attribut MED_NOM_END pour �criture */
    00208   if (_MEDattributeIntWr(_datagroup2,MED_NOM_END,&_remoteentitype) < 0) {
    00209     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_END);
    00210     ISCRUTE(_remoteentitype);goto ERROR;
    00211   }
    00212
    00213   /*Cree ou ouvre l'attribut MED_NOM_GED pour �criture */
    00214   if (_MEDattributeIntWr(_datagroup2,MED_NOM_GED,&_remotegeotype) < 0) {
    00215     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GED);
    00216     ISCRUTE(_remotegeotype);goto ERROR;
    00217   }
    00218
    00219
    00220   if ( MEDfilterEntityCr(fid, nentity, 1, 2, MED_ALL_CONSTITUENT,
    00221                          MED_NO_INTERLACE,MED_UNDEF_PFLMODE,
    00222                          MED_NO_PROFILE, MED_UNDEF_SIZE, NULL, &_filter) < 0 ) {
    00223     MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,MED_ERR_INTERNAL_MSG);
    00224     goto ERROR;
    00225   }
    00226
    00227   if ( _MEDdatasetWr(_datagroup2,MED_NOM_COR,MED_INTERNAL_INT,&_filter, correspondence) < 0) {
    00228     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_DATASET,MED_NOM_COR);
    00229     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00230     goto ERROR;
    00231   }
    00232
    00233   if ( MEDfilterClose(&_filter) < 0 ) {
    00234     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,MED_ERR_SUBDOMAINJOINT_MSG);
    00235     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00236     goto ERROR;
    00237   }
    00238
    00239   if ((_dataset = _MEDdatasetOuvrir(_datagroup2,MED_NOM_COR)) < 0) {
    00240     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATASET,MED_NOM_COR);
    00241     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
    00242     goto ERROR;
    00243   }
    00244
    00245   if ( _MEDattributeIntWr(_dataset,MED_NOM_NBR,&nentity) < 0) {
    00246     MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_SUBDOMAINJOINT_MSG);
    00247     SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);SSCRUTE(_datagroupname2);
    00248     SSCRUTE(MED_NOM_NBR);ISCRUTE(nentity);goto ERROR;
    00249   }
    00250
    00251
    00252
    00253   _ret=0;
    00254  ERROR:
    00255
    00256   if (_dataset>0)     if (_MEDdatasetFermer(_dataset) < 0) {
    00257     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATASET,MED_NOM_COR);
    00258     ISCRUTE_id(_dataset);
    00259   }
    00260
    00261   if (_datagroup2>0)            if (_MEDdatagroupFermer(_datagroup2) < 0) {
    00262     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroupname2);
    00263     ISCRUTE_id(_datagroup2);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00264   }
    00265
    00266   if (_cstpid>0)            if (_MEDdatagroupFermer(_cstpid) < 0) {
    00267     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_computationstepname);
    00268     ISCRUTE_id(_cstpid);SSCRUTE(_path);ISCRUTE(numdt);ISCRUTE(numit);
    00269   }
    00270
    00271   if (_jntid>0)            if (_MEDdatagroupFermer(_jntid) < 0) {
    00272     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,jointname);
    00273     ISCRUTE_id(_jntid);SSCRUTE(_path);
    00274   }
    00275
    00276   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
    00277     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,localmeshname);
    00278     ISCRUTE_id(_meshid);
    00279   }
    00280
    00281   if (_root>0)            if (_MEDdatagroupFermer(_root) < 0) {
    00282     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_JNT);
    00283     ISCRUTE_id(_root);
    00284   }
    00285
    00286   return _ret;
    00287 }