# MEDmeshNodeCoordinateWr.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 #include <string.h>
    00023 #include <stdlib.h>
    00024
    00044 med_err MEDmeshNodeCoordinateWr(const med_idt               fid,
    00045                                 const char*  const          meshname,
    00046                                 const med_int               numdt,
    00047                                 const med_int               numit,
    00048                                 const med_float             dt,
    00049                                 const med_switch_mode       switchmode,
    00050                                 const med_int               nentity,
    00051                                 const med_float* const      coordinate)
    00052 {
    00053   med_idt         _meshid      = 0;
    00054   med_idt         _datagroup1=0,_datagroup2=0,_datagroup3=0,_datagroup_trsf=0;
    00055   med_idt         _dataset_trsf = 0;
    00056   med_err         _ret         = -1;
    00057   med_grid_type   _gridtype    = MED_UNDEF_GRID_TYPE;
    00058   med_int         _intgridtype = 0;
    00059   med_int         _intmeshtype = 0;
    00060   med_int         _meshdim     = 0;
    00061   char            _meshpath   [MED_TAILLE_SUP_MAA+MED_NAME_SIZE+1]="";
    00062   char            _geotypename[MED_TAILLE_NOM_ENTITE+1]="";
    00063   char            _datagroup_trsfname[MED_TAILLE_NOM_ENTITE+MED_TAILLE_COOTRF+1]=MED_NOM_NOE MED_COOTRF;
    00064   int             _i=0;
    00065   med_bool        _isasupportmesh=MED_FALSE,_isasoftlink=MED_FALSE;
    00066   med_int         _0 = 0;
    00067   med_int         _medintgeotype = MED_NO_GEOTYPE;
    00068
    00069 if (_MEDcheckVersion30(fid) < 0) goto ERROR;
    00070
    00071   /* Ouverture du maillage de calcul ou du maillage support */
    00072   if ((_meshid=_MEDmeshDatagroupOpen(fid,meshname,_meshpath,&_isasupportmesh)) < 0) {
    00073     MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_DATAGROUP,MED_ERR_MESH_MSG);
    00074     SSCRUTE(_meshpath); goto ERROR;
    00075   }
    00076
    00077   /* Lecture du type de maillage (attribut MED_NOM_TYP)  */
    00078   if (_MEDattrEntierLire(_meshid,MED_NOM_TYP,&_intmeshtype) < 0) {
    00079     MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    00080     SSCRUTE(meshname);SSCRUTE(MED_NOM_TYP);ISCRUTE(_intmeshtype);goto ERROR;
    00081   }
    00082
    00083   /*Sortir en erreur si maillage support et numdt,numit != MED_NO_PDT,MED_NO_IT*/
    00084   /* Accès (création éventuelle) du datagroup numdt,numit */
    00085
    00086   if ( _isasupportmesh ) {
    00087     if (( numdt != MED_NO_DT) && (numit != MED_NO_IT) ) {
    00088       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_PARAMETER,MED_ERR_MESH_MSG);
    00089       SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);goto ERROR;
    00090     }
    00091   } else
    00092     if ( (_datagroup1 =_MEDmeshAssociatedGroupCr(fid, MED_MAA,
    00093                                                  meshname, numdt, numit, dt,MED_FALSE,
    00094                                                  "." ) ) < 0 ) {
    00095       MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAssociatedGroupCr");
    00096       goto ERROR;
    00097     }
    00098
    00099   /* Création de la structure de connectivité assoiciée aux grilles MED_CURVILLINEAR_GRID*/
    00100   if ( ( (med_mesh_type) _intmeshtype ) != MED_UNSTRUCTURED_MESH ) {
    00101
    00102     /* Lecture de l'attribut MED_NOM_GTY  */
    00103     if (_MEDattrEntierLire(_meshid,MED_NOM_GTY,&_intgridtype) < 0) {
    00104       MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    00105       SSCRUTE(meshname);SSCRUTE(MED_NOM_GTY);ISCRUTE_int(_gridtype);goto ERROR;
    00106     }
    00107     _gridtype= (med_grid_type) _intgridtype;
    00108
    00109     if ( _gridtype == MED_CURVILINEAR_GRID ) {
    00110
    00111       if ((_datagroup2 = _MEDdatagroupOuvrir(_datagroup1,MED_NOM_MAI)) < 0) {
    00112
    00113         if ((_datagroup2 = _MEDdatagroupCreer(_datagroup1,MED_NOM_MAI)) < 0) {
    00114           MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,MED_NOM_MAI);
    00115           SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
    00116           goto ERROR;
    00117         }
    00118
    00119         if ( _MEDattributeIntWr(_datagroup2,MED_NOM_CGT,&_0) < 0) {
    00120           MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    00121           SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
    00122           goto ERROR;
    00123         }
    00124
    00125         /* Lecture de l'attribut MED_NOM_DIM  */
    00126         if (_MEDattrEntierLire(_meshid,MED_NOM_DIM,&_meshdim) < 0) {
    00127           MED_ERR_(_ret,MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    00128           SSCRUTE(meshname);SSCRUTE(MED_NOM_DIM);ISCRUTE(_meshdim);goto ERROR;
    00129         }
    00130
    00131         switch ( _meshdim )  {
    00132         case 1 :
    00133           strcpy(_geotypename,MED_NOM_SE2);
    00134           _medintgeotype = MED_SEG2;
    00135           break;
    00136         case 2 :
    00137           strcpy(_geotypename,MED_NOM_QU4);
    00138           _medintgeotype = MED_QUAD4;
    00139           break;
    00140         case 3 : strcpy(_geotypename,MED_NOM_HE8);
    00141           break;
    00142           _medintgeotype = MED_HEXA8;
    00143         case 0 : strcpy(_geotypename,MED_NOM_PO1);
    00144           _medintgeotype = MED_POINT1;
    00145           break;
    00146         default :
    00147           MED_ERR_(_ret,MED_ERR_RANGE,MED_ERR_PARAMETER,"");
    00148           SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
    00149           goto ERROR;
    00150         }
    00151
    00152         if ((_datagroup3 = _MEDdatagroupCreer(_datagroup2,_geotypename)) < 0) {
    00153           MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_DATAGROUP,_geotypename);
    00154           SSCRUTE(meshname);ISCRUTE(numdt);ISCRUTE(numit);
    00155           goto ERROR;
    00156         }
    00157
    00158         if ( _MEDattributeStringWr(_datagroup3,MED_NOM_PFL,MED_NAME_SIZE,MED_NO_PROFILE_INTERNAL) < 0) {
    00159           MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    00160           SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);
    00161           goto ERROR;
    00162         }
    00163
    00164         if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGT,&_0) < 0) {
    00165           MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    00166           SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGT);
    00167           goto ERROR;
    00168         }
    00169
    00170         if ( _MEDattributeIntWr(_datagroup3,MED_NOM_CGS,&_0) < 0) {
    00171           MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_ERR_MESH_MSG);
    00172           SSCRUTE(meshname);ISCRUTE(numit);ISCRUTE(numdt);SSCRUTE(MED_NOM_CGS);
    00173           goto ERROR;
    00174         }
    00175
    00176         if (_MEDattributeIntWr(_datagroup3,MED_NOM_GEO,&_medintgeotype) < 0) {
    00177           MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_GEO);
    00178           ISCRUTE(_medintgeotype);
    00179           goto ERROR;
    00180         }
    00181
    00182       }
    00183     } else {
    00184       MED_ERR_(_ret,MED_ERR_INVALID,MED_ERR_GRIDTYPE,MED_ERR_MESH_MSG);
    00185       SSCRUTE(meshname);SSCRUTE(MED_NOM_GTY);ISCRUTE_int(_gridtype);goto ERROR;
    00186
    00187     }
    00188
    00189   }
    00190
    00191
    00192   /*Réinitialisation du lien MED_TRSF_NOM/MED_COORDINATE_TRSF s'il existe */
    00193   /*Si un dataset de transformation existe une erreur est générée par
    00194     _MEDsoftlinkDel */
    00195   if ( !_isasupportmesh)
    00196     if ((_datagroup_trsf = _MEDdatagroupOuvrir(_datagroup1,_datagroup_trsfname)) > 0) {
    00197
    00198       if ( _MEDisasoftlink(_datagroup_trsf, MED_NOM_TRF,MED_FALSE, &_isasoftlink ) < 0 ) {
    00199         MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_LINK,MED_NOM_COO);
    00200         goto ERROR;
    00201       }
    00202       if (_isasoftlink ) {
    00203         if (  _MEDsoftlinkDel(_datagroup_trsf,
    00204                               MED_NOM_TRF,
    00205                               MED_TRUE) < 0 ) {
    00206           MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDsoftlinkDel");
    00207           goto ERROR;
    00208         }
    00209       } else {
    00210         if ( (_dataset_trsf = _MEDdatasetOuvrir(_datagroup_trsf,MED_NOM_TRF)) >= 0 ) {
    00211           _MEDdatasetFermer(_dataset_trsf);
    00212           MED_ERR_(_ret,MED_ERR_NULL,MED_ERR_DATASET,MED_NOM_TRF);
    00213           goto ERROR;
    00214         }
    00215
    00216       }
    00217     }
    00218
    00219   /*Ecriture des coordonnées*/
    00220   if (  _MEDmeshAdvancedWr(fid,
    00221                             meshname,
    00222                             MED_COORDINATE,
    00223                             MED_NO_NAME,
    00224                             MED_INTERNAL_UNDEF,
    00225                             numdt,
    00226                             numit,
    00227                             dt,
    00228                             MED_NODE,
    00229                             MED_NONE,
    00230                             MED_NO_CMODE,
    00231                             MED_UNDEF_PFLMODE,
    00232                             MED_NO_PROFILE,
    00233                             switchmode,
    00234                             MED_ALL_CONSTITUENT,
    00235                             NULL,
    00236                             nentity,
    00237                            coordinate) < 0 ) {
    00238     MED_ERR_(_ret,MED_ERR_CALL,MED_ERR_API,"_MEDmeshAdvancedWr");
    00239     goto ERROR;
    00240
    00241   }
    00242
    00243
    00244   _ret = 0;
    00245
    00246  ERROR:
    00247
    00248   if (_datagroup_trsf>0)     if (_MEDdatagroupFermer(_datagroup_trsf) < 0) {
    00249     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_datagroup_trsfname);
    00250     ISCRUTE_id(_datagroup_trsf);
    00251   }
    00252
    00253   if (_datagroup3>0)     if (_MEDdatagroupFermer(_datagroup3) < 0) {
    00254     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_geotypename);
    00255     ISCRUTE_id(_datagroup3);
    00256   }
    00257
    00258   if (_datagroup2>0)     if (_MEDdatagroupFermer(_datagroup2) < 0) {
    00259     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,MED_NOM_MAI);
    00260     ISCRUTE_id(_datagroup2);
    00261   }
    00262
    00263   if (_datagroup1>0)     if (_MEDdatagroupFermer(_datagroup1) < 0) {
    00264     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,_meshpath);
    00265     ISCRUTE_id(_datagroup1);ISCRUTE(numdt);ISCRUTE(numit);
    00266   }
    00267
    00268   if (_meshid>0)            if (_MEDdatagroupFermer(_meshid) < 0) {
    00269     MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_DATAGROUP,meshname);
    00270     ISCRUTE_id(_meshid);
    00271   }
    00272
    00273   return _ret;
    00274 }