Back to index

salome-med  6.5.0
MEDgridEcr.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_outils.hxx"
00020 #include "med.hxx"
00021 
00022 #include <cstring>
00023 
00024 namespace med_2_1{
00025 
00026 med_err 
00027 MEDgridEcr(med_idt fid, char *maa, med_int mdim, med_float *coo, med_int nb, med_int dim, med_mode_switch mode_coo,
00028            med_repere repere, char *nomcoo, char *unicoo, med_mode_acces mode )
00029 {
00030     /* ecriture des indices */
00031 
00032     med_idt  maaid, noeid, ds;
00033     char     chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00034     med_size dimd[1];
00035     char     *dataset;
00036     med_int  type_rep_int;
00037 
00038     /* On inhibe le gestionnaire d'erreur HDF */
00039     _MEDmodeErreurVerrouiller();
00040 
00041     /* Si le maillage n'existe pas => erreur */
00042     strcpy(chemin, MED_MAA);
00043     strcat(chemin, maa);
00044     maaid = _MEDdatagroupOuvrir(fid, chemin);
00045     if (maaid < 0) return(-1);
00046 
00047     /* Si le Data Group "NOE" n'existe pas on le cree */
00048     if ((noeid = _MEDdatagroupOuvrir(maaid, MED_NOM_NOE)) < 0) {
00049         if ((noeid = _MEDdatagroupCreer(maaid, MED_NOM_NOE)) < 0) {
00050             return(-1);
00051         };
00052     };
00053 
00054     switch (dim) {
00055         case 0 : {
00056             dataset = MED_NOM_IN1;
00057             break;
00058         };
00059         case 1 : {
00060             dataset = MED_NOM_IN2;
00061             break;
00062         };
00063         case 2 : {
00064             dataset = MED_NOM_IN3;
00065             break;
00066         };
00067         default : {
00068             return(-1);
00069         };
00070     };
00071 
00072     /* Creation du Data Set "IN1" ou "IN2" ou "IN3" */
00073     dimd[0] = nb;
00074     if (_MEDdatasetNumEcrire(noeid, dataset, MED_REEL64, mode_coo, 1, MED_ALL, MED_NOPF, 0, 0, dimd, (unsigned char*)coo, mode) < 0) {
00075         return(-1);
00076     };
00077 
00078     /* On re-ouvre le Data Set "IN1" ou "IN2" ou "IN3" pour y placer des attributs */
00079     if ((ds = _MEDdatasetOuvrir(noeid, dataset)) < 0) {
00080         return(-1);
00081     };
00082 
00083     /* Attribut NBR (nombre de noeuds) */
00084     if (_MEDattrEntierEcrire(ds, MED_NOM_NBR, &nb, mode) < 0) {
00085         return(-1);
00086     };
00087 
00088     /* L'attribut "REP" */
00089     type_rep_int = (med_int)repere;
00090     if (_MEDattrEntierEcrire(ds, MED_NOM_REP, &type_rep_int, mode) < 0) {
00091         return(-1);
00092     };
00093 
00094     /* Attribut "NOM" */
00095     if (_MEDattrStringEcrire(ds, MED_NOM_NOM, mdim*MED_TAILLE_PNOM, nomcoo, mode) < 0) {
00096         return(-1);
00097     };
00098 
00099     /* Attribut "UNI" */
00100     if (_MEDattrStringEcrire(ds, MED_NOM_UNI, mdim*MED_TAILLE_PNOM, unicoo, mode) < 0) {
00101         return(-1);
00102     };
00103 
00104     /* On ferme tout */
00105     if (_MEDdatasetFermer(ds)      < 0) return(-1);
00106     if (_MEDdatagroupFermer(noeid) < 0) return(-1);
00107     if (_MEDdatagroupFermer(maaid) < 0) return(-1);
00108     return(0);
00109 }
00110 
00111 }