# MEDcoordEcr.c

Aller à la documentation de ce fichier.

    00001 /*  This file is part of MED.
    00002  *
    00003  *  COPYRIGHT (C) 1999 - 2011  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
    00023 #include <stdlib.h>
    00024 #include <string.h>
    00025
    00026 med_err
    00027 MEDcoordEcr(med_idt fid, char *maa, med_int mdim, med_float *coo,
    00028             med_mode_switch mode_coo,med_int n,
    00029             med_repere type_rep, char *nom, char *unit)
    00030 {
    00031   med_idt maaid, noeid, dataset;
    00032   med_err ret;
    00033   med_size dimd[1];
    00034   char chemin[MED_TAILLE_MAA+MED_TAILLE_NOM+1];
    00035   med_int type_rep_int;
    00036   /*
    00037    * On inhibe le gestionnaire d'erreur HDF
    00038    */
    00039   _MEDmodeErreurVerrouiller();
    00040 if (MEDcheckVersion(fid) < 0) return -1;
    00041
    00042
    00043   /*
    00044    * Si le maillage n'existe pas => erreur
    00045    */
    00046   strcpy(chemin,MED_MAA);
    00047   strcat(chemin,maa);
    00048   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
    00049       return -1;
    00050
    00051   /*
    00052    * Si le Data Group "NOE" n'existe pas
    00053    * on le cree
    00054    */
    00055   if ((noeid = _MEDdatagroupOuvrir(maaid,MED_NOM_NOE)) < 0)
    00056     if ((noeid = _MEDdatagroupCreer(maaid,MED_NOM_NOE)) < 0)
    00057       return -1;
    00058
    00059   /*
    00060    * Creation du Data Set "COO"
    00061    */
    00062   dimd[0] = n*mdim;
    00063   if ((ret = _MEDdatasetNumEcrire(noeid,MED_NOM_COO,MED_FLOAT64,mode_coo,mdim,MED_ALL,
    00064                                   MED_NOPF,MED_NO_PFLMOD,0,0,MED_NOPG,dimd,
    00065                                   (unsigned char*) coo)) < 0)
    00066     return -1;
    00067
    00068   /*
    00069    * On re-ouvre le Data Set "COO" pour y placer des attributs
    00070    */
    00071   if ((dataset = _MEDdatasetOuvrir(noeid,MED_NOM_COO)) < 0)
    00072     return -1;
    00073
    00074   /*
    00075    * Attribut NBR (nombre de noeuds)
    00076    */
    00077   if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_NBR,&n)) < 0)
    00078     return -1;
    00079
    00080   /*
    00081    * L'attribut "REP"
    00082    */
    00083   type_rep_int = (med_int) type_rep;
    00084   if ((ret = _MEDattrEntierEcrire(dataset,MED_NOM_REP,&type_rep_int)) < 0)
    00085     return -1;
    00086
    00087   /*
    00088    * Attribut "NOM"
    00089    */
    00090   if ((ret = _MEDattrStringEcrire(dataset,MED_NOM_NOM,mdim*MED_TAILLE_PNOM,nom)) < 0)
    00091     return -1;
    00092
    00093   /*
    00094    * Attribut "UNI"
    00095    */
    00096   if ((ret = _MEDattrStringEcrire(dataset,MED_NOM_UNI,mdim*MED_TAILLE_PNOM,unit)) < 0)
    00097     return -1;
    00098
    00099   /*
    00100    * On ferme tout
    00101    */
    00102   if ((ret = _MEDdatasetFermer(dataset)) < 0)
    00103     return -1;
    00104   if ((ret = _MEDdatagroupFermer(noeid)) < 0)
    00105     return -1;
    00106   if ((ret = _MEDdatagroupFermer(maaid)) < 0)
    00107     return -1;
    00108
    00109   return 0;
    00110 }