MEDmeshNodeCoordinateWr.c

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

Généré le Thu Jan 21 18:06:08 2016 pour MED fichier par  doxygen 1.6.1