Back to index

salome-med  6.5.0
MEDbodyFittedEcr.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 #if defined(HAVE_F77INT64)
00025 #define MED_INTEGER MED_INT64
00026 #else
00027 #define MED_INTEGER MED_INT32
00028 #endif
00029 
00030 namespace med_2_1{
00031 
00032 med_err 
00033 MEDbodyFittedEcr(med_idt fid, char *maa, med_int mdim, med_float *coo, med_int *nbr, med_mode_switch mode_coo,
00034                  med_repere repere, char *nomcoo, char *unicoo, med_int *fam, med_int nnoeuds, med_mode_acces mode )
00035 {
00036     /* ecriture des coordonnees */
00037     med_idt   maaid, noeid, dataset;
00038     med_size dimd[1];
00039     char     chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00040     med_int  type_rep_int;
00041     int      d;
00042     char     *ds;
00043 
00044     /* On inhibe le gestionnaire d'erreur HDF */
00045     _MEDmodeErreurVerrouiller();
00046 
00047     /* Si le maillage n'existe pas => erreur */
00048     strcpy(chemin, MED_MAA);
00049     strcat(chemin, maa);
00050     if ((maaid = _MEDdatagroupOuvrir(fid, chemin)) < 0) {
00051         return(-1);
00052     };
00053 
00054     /* Si le Data Group "NOE" n'existe pas on le cree */
00055     if ((noeid = _MEDdatagroupOuvrir(maaid, MED_NOM_NOE)) < 0) {
00056         if ((noeid = _MEDdatagroupCreer(maaid, MED_NOM_NOE)) < 0) {
00057             return(-1);
00058         };
00059     };
00060 
00061     /* Creation du Data Set "BOF" */
00062     dimd[0] = nnoeuds*mdim;
00063     if (_MEDdatasetNumEcrire(noeid, MED_NOM_BOF, MED_REEL64, mode_coo, mdim, MED_ALL, MED_NOPF, 0, 0, dimd, (unsigned char*)coo, mode) < 0) {
00064         return(-1);
00065     };
00066   
00067     /* On re-ouvre le Data Set "BOF" pour y placer des attributs */
00068     if ((dataset = _MEDdatasetOuvrir(noeid, MED_NOM_BOF)) < 0) {
00069         return(-1);
00070     };
00071 
00072     /* Attribut NBR (nombre de noeuds) */
00073     if (_MEDattrEntierEcrire(dataset, MED_NOM_NBR, &nnoeuds, mode) < 0) {
00074         return(-1);
00075     };
00076 
00077     /* L'attribut "REP" */
00078     type_rep_int = (med_int)repere;
00079     if (_MEDattrEntierEcrire(dataset, MED_NOM_REP, &type_rep_int, mode) < 0) {
00080         return(-1);
00081     };
00082 
00083     /* Attribut "NOM" */
00084     if (_MEDattrStringEcrire(dataset, MED_NOM_NOM, mdim*MED_TAILLE_PNOM, nomcoo, mode) < 0) {
00085         return(-1);
00086     };
00087 
00088     /* Attribut "UNI" */
00089     if (_MEDattrStringEcrire(dataset, MED_NOM_UNI, mdim*MED_TAILLE_PNOM, unicoo, mode) < 0) {
00090         return(-1);
00091     };
00092 
00093     if (_MEDdatasetFermer(dataset) < 0) return(-1);
00094 
00095     dimd[0] = 1;
00096     for (d=0; d<mdim; d++) {
00097         switch (d) {
00098             case 0 : {
00099                 ds = MED_NOM_IN1;
00100                 break;
00101             };
00102             case 1 : {
00103                 ds = MED_NOM_IN2;
00104                 break;
00105             };
00106             case 2 : {
00107                 ds = MED_NOM_IN3;
00108                 break;
00109             };
00110             default : {
00111                 return(-1);
00112             };
00113         };
00114 
00115         /* Creation du Data Set "IN1", "IN2", "IN3" contenant la taille du bodyfitted sur cette dimension */
00116         if (_MEDdatasetNumEcrire(noeid, ds, MED_INTEGER, mode_coo, MED_DIM1, MED_ALL, MED_NOPF, 0, 0, dimd, (unsigned char*)&nbr[d], mode) < 0) {
00117             return(-1);
00118         };
00119 
00120         /* On re-ouvre ce Data Set pour y placer des attributs */
00121         if ((dataset = _MEDdatasetOuvrir(noeid, ds)) < 0) {
00122             return(-1);
00123         };
00124 
00125         /* Attribut NBR (nombre de noeuds dans l'une des dimensions) */
00126         if (_MEDattrEntierEcrire(dataset, MED_NOM_NBR, &nbr[d], mode) < 0) {
00127             return(-1);
00128         };
00129 
00130         if (_MEDdatasetFermer(dataset) < 0) return(-1);
00131     };
00132 
00133     /* Ecriture des numeros de familles */
00134     if (MEDfamEcr(fid, maa, fam, nnoeuds, mode, MED_NOEUD, MED_POINT1) < 0) {
00135         return(-1);
00136     };
00137 
00138     /* On ferme tout */
00139     if (_MEDdatagroupFermer(noeid) < 0) return(-1);
00140     if (_MEDdatagroupFermer(maaid) < 0) return(-1);
00141     return(0);
00142 }
00143 
00144 }