Back to index

salome-med  6.5.0
MEDconnLire.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 <string.h>
00023 #include <stdlib.h>
00024 
00025 extern int mode_interlace; 
00026 
00027 namespace med_2_1{
00028 
00029 med_err 
00030 MEDconnLire(med_idt fid,char *maa,med_int mdim,med_int *connectivite,med_mode_switch mode_switch,
00031             med_int * pfltabtmp, med_size psizetmp,
00032             med_entite_maillage type_ent, med_geometrie_element type_geo,med_connectivite type_conn)
00033 {
00034   med_idt maaid,entid,geoid;
00035   med_err ret;
00036   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00037   char nom_ent[MED_TAILLE_NOM_ENTITE+1];
00038   char nom_geo[MED_TAILLE_NOM_ENTITE+1];
00039   char nom_dataset[MED_TAILLE_NOM_ENTITE+1];
00040   med_ssize * pfltab = NULL;
00041   med_size    psize;
00042   int dim,nnoe,ndes;
00043   int nsup = 0;
00044   int taille;  
00045   int i;
00046   
00047   /*
00048    * On inhibe le gestionnaire d'erreur HDF 5
00049    */
00050   _MEDmodeErreurVerrouiller();
00051   
00052   /*
00053    * Si le maillage n'existe pas => erreur
00054    */
00055   strcpy(chemin,MED_MAA);
00056   strcat(chemin,maa);
00057   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00058     return -1;
00059 
00060   /*
00061    * On met a jour le nom du Data Group representant
00062    * le type des entites
00063    */
00064    if ((ret = _MEDnomEntite(nom_ent,type_ent)) < 0)
00065      return -1;
00066    /*
00067     * Si le Data Group des entites n'existe pas => erreur
00068     */
00069    if ((entid = _MEDdatagroupOuvrir(maaid,nom_ent)) < 0)
00070      return -1;
00071 
00072    /*
00073     * si le Data Group du type geometrique n'existe pas => erreur
00074     */
00075    if ((ret = _MEDnomGeometrie(nom_geo,type_geo)) < 0)
00076      return -1;
00077    if ((geoid = _MEDdatagroupOuvrir(entid,nom_geo)) < 0)
00078      return -1;
00079 
00080    /*
00081     * Si le Data Set de la connectivite n'existe pas => erreur
00082     * Si oui => on le lit
00083     */
00084    if ((ret=_MEDparametresGeometrie(type_ent,type_geo,&dim,&nnoe,&ndes))<0)
00085      return -1;
00086    if (mdim == 2 || mdim == 3)
00087      if (type_ent == MED_MAILLE && dim == 1)
00088        nsup = 1;
00089    if (mdim == 3)
00090      if (type_ent == MED_MAILLE && dim == 2)
00091        nsup = 1;
00092 
00093 
00094    psize = psizetmp;
00095    switch(type_conn)
00096      {
00097      case MED_NOD :
00098        strcpy(nom_dataset,MED_NOM_NOD);
00099        taille = nsup + nnoe;
00100        break;
00101 
00102      case MED_DESC :
00103        strcpy(nom_dataset,MED_NOM_DES);
00104        taille = nsup + ndes;
00105        if ( psizetmp != MED_NOPF ) {  
00106          psize = psizetmp;
00107          pfltab = (med_ssize *) malloc (sizeof(med_ssize)*(size_t)psize);
00108          for (i=0;i<psizetmp;i++)
00109            pfltab[i] = (med_ssize) (pfltabtmp[i]);
00110        };
00111        
00112        break;
00113        
00114      default :
00115        return -1;
00116      }
00117 
00118 
00119 #if defined(HAVE_F77INT64)
00120    if ((ret = _MEDdatasetNumLire(geoid,nom_dataset,MED_INT64,
00121                                  mode_switch,(med_size)taille,MED_ALL,
00122                                  psize,pfltab,MED_NOPG,
00123                                  (unsigned char*) connectivite)) < 0)
00124      return -1;
00125 #else
00126    if ((ret = _MEDdatasetNumLire(geoid,nom_dataset,MED_INT32,
00127                                  mode_switch,(med_size) taille,MED_ALL,
00128                                  psize,pfltab,MED_NOPG,
00129                                  (unsigned char*) connectivite)) < 0)
00130      return -1;
00131 #endif 
00132 
00133    /*
00134     * On ferme tout 
00135     */
00136 
00137    if ( (psize != MED_NOPF) && (type_conn == MED_DESC) ) free(pfltab);
00138   
00139    if ((ret = _MEDdatagroupFermer(geoid)) < 0)
00140      return -1;
00141    if ((ret = _MEDdatagroupFermer(entid)) < 0)
00142      return -1;
00143    if ((ret = _MEDdatagroupFermer(maaid)) < 0)
00144      return -1;
00145 
00146    return 0; 
00147 }
00148 
00149 }