Back to index

salome-med  6.5.0
MEDnGrid.cxx
Go to the documentation of this file.
00001 /*************************************************************************
00002 * COPYRIGHT (C) 1999 - 2002  EDF R&D
00003 * THIS LIBRARY IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
00004 * IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE 
00005 * AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00006 * EITHER VERSION 2.1 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00007 *  
00008 * THIS LIBRARY IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
00009 * WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
00010 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
00011 * LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
00012 *
00013 * YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE
00014 * ALONG WITH THIS LIBRARY; IF NOT, WRITE TO THE FREE SOFTWARE FOUNDATION,
00015 * INC., 59 TEMPLE PLACE, SUITE 330, BOSTON, MA 02111-1307 USA
00016 *
00017 *************************************************************************/
00018 
00019 #include "med.hxx"
00020 #include "med_outils.hxx"
00021 
00022 #include <cstring>
00023 
00024 namespace med_2_1{
00025 
00026 med_int 
00027 MEDnGrid(med_idt fid, char *maa, med_grid n) 
00028 {
00029     med_idt maaid, entid, geoid, dataset;
00030     char    chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00031     char    nom_ent[MED_TAILLE_NOM_ENTITE+1];
00032     char    *nom_dataset;
00033     med_int  res = (-1);
00034 
00035     /* On inhibe le gestionnaire d'erreur HDF 5 */
00036     _MEDmodeErreurVerrouiller();
00037 
00038     /* Si le maillage n'existe pas => erreur */
00039     strcpy(chemin, MED_MAA);
00040     strcat(chemin, maa);
00041     maaid = _MEDdatagroupOuvrir(fid, chemin);
00042     if (maaid < 0) return(-1);
00043 
00044     switch (n) {
00045         case MED_FAM_NOEUD : {
00046             nom_dataset = MED_NOM_FAM;
00047             if (_MEDnomEntite(nom_ent, MED_NOEUD) < 0) return(-1);
00048             entid = _MEDdatagroupOuvrir(maaid, nom_ent);
00049             break;
00050         };
00051         case MED_FAM_ARETE : {
00052             nom_dataset = MED_NOM_FAM;
00053             if (_MEDnomEntite(nom_ent, MED_ARETE) < 0) return(-1);
00054             geoid = _MEDdatagroupOuvrir(maaid, nom_ent);
00055             if (geoid < 0) return(-1);
00056             if (_MEDnomGeometrie(nom_ent, MED_SEG2) < 0) return(-1);
00057             entid = _MEDdatagroupOuvrir(geoid, nom_ent);
00058             break;
00059         };
00060         case MED_FAM_FACE : {
00061             nom_dataset = MED_NOM_FAM;
00062             if (_MEDnomEntite(nom_ent, MED_FACE) < 0) return(-1);
00063             geoid = _MEDdatagroupOuvrir(maaid, nom_ent);
00064             if (geoid < 0) return(-1);
00065             if (_MEDnomGeometrie(nom_ent, MED_QUAD4) < 0) return(-1);
00066             entid = _MEDdatagroupOuvrir(geoid, nom_ent);
00067             break;
00068         };
00069         case MED_FAM_MAILLE : {
00070             nom_dataset = MED_NOM_FAM;
00071             if (_MEDnomEntite(nom_ent, MED_MAILLE) < 0) return(-1);
00072             geoid = _MEDdatagroupOuvrir(maaid, nom_ent);
00073             if (geoid < 0) return(-1);
00074             if (_MEDnomGeometrie(nom_ent, MED_HEXA8) < 0) return(-1);
00075             entid = _MEDdatagroupOuvrir(geoid, nom_ent);
00076             break;
00077         };
00078         case MED_GRID_NOEUD : {
00079             nom_dataset = MED_NOM_BOF;
00080             entid = _MEDdatagroupOuvrir(maaid, MED_NOM_NOE);
00081             break;
00082         };
00083         case MED_GRID_D1 : {
00084             nom_dataset = MED_NOM_IN1;
00085             entid = _MEDdatagroupOuvrir(maaid, MED_NOM_NOE);
00086             break;
00087         };
00088         case MED_GRID_D2 : {
00089             nom_dataset = MED_NOM_IN2;
00090             entid = _MEDdatagroupOuvrir(maaid, MED_NOM_NOE);
00091             break;
00092         };
00093         case MED_GRID_D3 : {
00094             nom_dataset = MED_NOM_IN3;
00095             entid = _MEDdatagroupOuvrir(maaid, MED_NOM_NOE);
00096             break;
00097         };
00098         default : {
00099             return(-1);
00100         };
00101     };
00102 
00103     if (entid < 0) return(-1);
00104     dataset = _MEDdatasetOuvrir(entid, nom_dataset);
00105     if (dataset < 0) return(-1);
00106     if (_MEDattrEntierLire(dataset, MED_NOM_NBR, &res) < 0) return(-1);
00107 
00108     /* On ferme tout */
00109     if (_MEDdatasetFermer(dataset) < 0) return(-1);
00110     if (_MEDdatagroupFermer(entid) < 0) return(-1);
00111     if (_MEDdatagroupFermer(maaid) < 0) return(-1);
00112 
00113     return(res);
00114 }
00115 
00116 }