MEDchampEcr231.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2015  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 #include <string.h>
00023 #include <stdlib.h>
00024 
00025 /*
00026  * - Nom de la fonction : MEDchampEcr
00027  * - Description : ecriture d'un Champ Résultat
00028  * - Parametres :
00029  *     - fid      (IN)  : ID du fichier HDF courant
00030  *     - maa      (IN)  : le nom du maillage sur lequel s'applique le champ (eventuellement distant)
00031  *     - cha      (IN)  : le nom du champ 
00032  *     - val      (IN)  : valeurs du champ à stocker
00033  *     - interlace(IN)  : entrelacement utilisé en mémoire {MED_FULL_INTERLACE,MED_NO_INTERLACE} 
00034  *     - nbelem   (IN)  : nombre d'éléments (prend en compte le nbre 
00035  *                         de points de Gauss (c'est demandé à l'utilisateur ds la doc) 
00036                            mais pas le nbre de composantes)
00037  *     - locname  (IN)  : clé utilisée pour la définition de la localisation 
00038                           des points de GAUSS (MED_NOGAUSS si aucun, MED_GAUSS_ELNO si les points de Gauss
00039  *                        portent sur les noeuds de l'element). La localisation doit exister 
00040  *                        avant l'appel à MEDchampEcr.
00041  *     - numco    (IN)  : n° de la composante à stocker (MED_ALL si toutes)
00042  *     - profil   (IN)  : nom du profil utilisé (MED_NOPFL si inutilisé)
00043  *     - pflmod   (IN)  : Indique comment lire les informations en mémoire { MED_COMPACT, MED_GLOBAL }. 
00044  *     - type_ent (IN)  : entité concerné par le champ {MED_NOEUD,MED_ARETE,MED_FACE,MED_MAILLE}
00045  *     - type_geo (IN)  : type géométrique de l'entité concerné {MED_POINT,MED_SEG2 ......}
00046  *     - numdt    (IN)  : n° du pas de temps (MED_NOPDT si aucun)
00047  *     - dt_unit  (IN)  : chaine de taille MED_NOMP indiquant l'unité du champ
00048  *     - dt       (IN)  : valeur du pas de temps 
00049  *     - numo     (IN)  : n° d'ordre utilisé MED_NONOR si inutile
00050  * - Resultat : 0 en cas de succes, -1 sinon
00051  */ 
00052 
00053 void  MEDchampEcr231(int dummy,...) {
00054 
00055 
00056   med_idt                    fid ;
00057   char *                     maa ;
00058   char *                     cha ;
00059   unsigned char *            val ;
00060   med_mode_switch      interlace ;
00061   med_int                 nbelem ;
00062   char *                 locname ;
00063   med_int                  numco ;
00064   char *                  profil ;
00065   med_mode_profil         pflmod ;
00066   med_entite_maillage   type_ent ;
00067   med_geometrie_element type_geo ;
00068   med_int                  numdt ;
00069   char *                 dt_unit ;
00070   med_float                   dt ;
00071   med_int                   numo ;
00072   med_err *                 fret ;
00073 
00074   med_err ret=-1;
00075   med_idt gid=0,datagroup1=0,datagroup2=0,datagroup3=0,attr=0,gid_loc=0;
00076   med_int ncomp=0, chtype=0, i=0, ngauss=0, pfluse=0;
00077   char nomdatagroup1[2*MED_TAILLE_NOM_ENTITE+2]="";
00078   char nomdatagroup2[2*MED_MAX_PARA+1]="";
00079 /*   char maaNoBlc   [MED_TAILLE_NOM+1]=""; */
00080   char pflname   [MED_TAILLE_NOM+1]="";
00081   char locname_i [MED_TAILLE_NOM+1]="";
00082   char maillage[MED_TAILLE_NOM+1]="";
00083   char tmp1[MED_TAILLE_NOM_ENTITE+1]="";
00084   med_size dimd[1],psize=0,lsize=0;
00085   med_int   *pfltabtmp=0;
00086   med_size *pfltab=0;
00087   char chemin[MED_TAILLE_CHA+MED_TAILLE_NOM+1]="";
00088   char chemin_loc[MED_TAILLE_GAUSS+MED_TAILLE_NOM+1]=""; 
00089   med_geometrie_element type_geo_g;
00090   med_int type_geo_g_int=0;
00091   med_mode_acces MED_MODE_ACCES;
00092 
00093   va_list params;
00094   va_start(params,dummy);
00095 
00096   fid = va_arg(params,med_idt);
00097   maa = va_arg(params,char *);
00098   cha = va_arg(params,char *);
00099   val = va_arg(params,  unsigned char *);
00100   interlace = va_arg(params,med_mode_switch);
00101   nbelem = va_arg(params,med_int);
00102   locname = va_arg(params,char *);
00103   numco = va_arg(params,med_int);
00104   profil = va_arg(params,char *);
00105   pflmod = va_arg(params,med_mode_profil);
00106   type_ent = va_arg(params,med_entite_maillage);
00107   type_geo = va_arg(params,med_geometrie_element);
00108   numdt = va_arg(params,med_int);
00109   dt_unit = va_arg(params,char *);
00110   dt = va_arg(params,med_float);
00111   numo = va_arg(params,med_int);
00112   fret = va_arg(params,med_err *);
00113 
00114   /*
00115    * On inhibe le gestionnaire d'erreur HDF 5
00116    */
00117   _MEDmodeErreurVerrouiller();
00118 if (MEDcheckVersion(fid) < 0) {*fret=-1;return;}
00119 
00120 
00121   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00122     MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
00123     goto ERROR;
00124   }
00125 
00126   if ( MED_MODE_ACCES == MED_LECTURE) {
00127     MESSAGE("Impossible d'écrire un champ en mode MED_LECTURE : ");
00128     goto ERROR;
00129   };
00130 
00131 
00132   /* 
00133    * Si le Data Group CHA n'existe pas => erreur
00134    */
00135   strcpy(chemin,MED_CHA);
00136   strcat(chemin,cha);
00137   if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00138     goto ERROR;
00139 
00140   /* Lecture de l'attribut MED_NOM_NCO */
00141   if (_MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp) < 0)
00142     goto ERROR;
00143 
00144   /* Lecture de l'attribut MED_NOM_TYP */
00145   if ( _MEDattrEntierLire(gid,MED_NOM_TYP,&chtype) < 0)
00146     goto ERROR;
00147  
00148 
00149   
00150   /* 
00151    *  Creation/Ouverture du datagroup de niveau 1 <type_ent>[.<type_geo>] 
00152    */
00153   if ( type_ent == MED_NOEUD_MAILLE ) {
00154     SSCRUTE("L'écriture aux noeuds des éléments n'est pas disponible.");
00155     goto ERROR;
00156   }
00157 
00158   if (_MEDnomEntite(nomdatagroup1,type_ent) < 0)
00159     goto ERROR;
00160 
00161   if ( type_ent != MED_NOEUD ) {
00162     if ( _MEDnomGeometrie(tmp1,type_geo) < 0)
00163       goto ERROR;
00164     strcat(nomdatagroup1,".");
00165     strcat(nomdatagroup1,tmp1);
00166   }
00167   datagroup1 = 0;
00168   if ( (datagroup1 = _MEDdatagroupOuvrir(gid,nomdatagroup1)) < 0) 
00169     if ((datagroup1 = _MEDdatagroupCreer(gid,nomdatagroup1)) < 0)
00170       goto ERROR;
00171   
00172 
00173   /* 
00174    * Creation/Ouverture du datagroup de niveau 2 <numdt>.<numoo> 
00175    */
00176  
00177   sprintf(nomdatagroup2,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
00178 
00179   datagroup2 = 0;   
00180   if ( (datagroup2 = _MEDdatagroupOuvrir(datagroup1,nomdatagroup2)) < 0 )    
00181     if ((datagroup2 = _MEDdatagroupCreer(datagroup1,nomdatagroup2)) < 0 )   
00182       goto ERROR;   
00183   
00184   /*Cree ou ouvre l'attribut MED_NOM_NDT pour écriture */
00185   if ( _MEDattrEntierEcrire(datagroup2,MED_NOM_NDT,&numdt) < 0)
00186     goto ERROR;
00187   
00188   /*Cree ou ouvre l'attribut MED_NOM_PDT pour écriture */
00189   if ( _MEDattrFloatEcrire(datagroup2,MED_NOM_PDT,&dt) < 0)
00190     goto ERROR;
00191     
00192   /*Cree ou ouvre l'attribut MED_NOM_NOR pour écriture */
00193   if (_MEDattrEntierEcrire(datagroup2,MED_NOM_NOR,&numo) < 0)
00194     goto ERROR;
00195   
00196   /*Cree ou ouvre l'attribut  MED_NOM_UNI pour écriture */ 
00197   if ( numdt == MED_NOPDT ) {
00198     if ( _MEDattrStringEcrire(datagroup2,MED_NOM_UNI,MED_TAILLE_PNOM,MED_PNOM_BLANC) < 0)
00199       goto ERROR;
00200   } else
00201     if ( _MEDattrStringEcrire(datagroup2,MED_NOM_UNI,MED_TAILLE_PNOM,dt_unit) < 0)
00202       goto ERROR;  
00203 
00204 
00205   /*
00206    * Si c'est la première référence à un maillage, initialise l'attribut MED_MAA à ce maillage
00207    */
00208   if ((attr = _MEDattrOuvrir(datagroup2,MED_NOM_MAI)) < 0 ) {
00209     if (_MEDattrStringEcrire(datagroup2,MED_NOM_MAI,MED_TAILLE_NOM,maa) < 0)
00210       goto ERROR;
00211   } else {   
00212     if ( _MEDattrFermer(attr) < 0) goto ERROR;
00213   }
00214       
00215   
00216 
00217   /* 
00218    * Cree ou ouvre le datagroup de niveau 3 <maa> 
00219    */
00220 /*   if (_MEDcstring(maa,maaNoBlc) <0) { */
00221 /*     MESSAGE("Erreur à la convertion du nom du maillage : "); */
00222 /*     SSCRUTE(maaNoBlc); */
00223 /*     goto ERROR; */
00224 /*    } */
00225   NOFINALBLANK(maa,ERROR)
00226 
00227   datagroup3 = 0;   
00228   if (((datagroup3 = _MEDdatagroupOuvrir(datagroup2,maa)) > 0)    
00229       && ( MED_MODE_ACCES == MED_LECTURE_AJOUT )) {
00230     MESSAGE("Impossible de créer une reference à un maillage existant en mode MED_LECTURE_AJOUT :");
00231     goto ERROR;   
00232   } else   
00233     if (datagroup3 < 0)
00234       if ((datagroup3 = _MEDdatagroupCreer(datagroup2,maa)) < 0)   
00235         goto ERROR;   
00236   
00237   /*Cree ou ouvre l'attribut MED_NOM_NBR */
00238   if ( _MEDattrEntierEcrire(datagroup3,MED_NOM_NBR,&nbelem) < 0)
00239     goto ERROR;
00240 
00241   /*Cree ou ouvre  l'attribut MED_NOM_PFL   */ 
00242   pfluse = 0;
00243   if ( strlen(profil) == 0)   /* idem MED_NOPFL*/
00244     /* Ecriture de MED_NOPFLi car MED_NOM_PFL est forcément de taille MED_TAILLE_NOM*/
00245     strncpy(pflname,MED_NOPFLi,MED_TAILLE_NOM+1);
00246   else {
00247     strncpy(pflname,profil,MED_TAILLE_NOM);
00248     pflname[MED_TAILLE_NOM]='\0';
00249     pfluse = 1;
00250   }
00251   if ( _MEDattrStringEcrire(datagroup3,MED_NOM_PFL,MED_TAILLE_NOM,pflname) < 0){
00252     MESSAGE("Erreur d'écriture de l'attribut pflname : ");
00253     SSCRUTE(chemin); goto ERROR;
00254   }
00255 
00256   /* Lit le nombre de points de gauss et vérifie   */
00257   /* que la localisation porte sur le meme type géométrique  */
00258   
00259   if ( strlen(locname) == 0 ) {
00260     /* Ecriture de MED_NOGAUSSi car MED_NOM_GAUSS est forcément de taille MED_TAILLE_NOM*/
00261     strcpy(locname_i,MED_NOGAUSSi);
00262     ngauss = MED_NOPG ;
00263   } else if (! strcmp(locname,MED_GAUSS_ELNO)) { 
00264     /* Les points de Gauss sont définis sur les noeuds de l'element (mot cle) */
00265     /* le nombre de points de Gauss est egal au nombre de noeuds de l'element */
00266     ngauss = type_geo % 100;
00267     strcpy(locname_i,locname);
00268 
00269   } else { 
00270     strcpy(locname_i,locname);
00271 
00272     strcpy(chemin_loc,MED_GAUSS);
00273     strcat(chemin_loc,locname_i);
00274     
00275     if ((gid_loc = _MEDdatagroupOuvrir(fid,chemin_loc)) < 0) {
00276       MESSAGE("Ouverture du datagroup : ");
00277       SSCRUTE(chemin_loc); goto ERROR;
00278     }
00279     
00280     if (_MEDattrEntierLire(gid_loc,MED_NOM_NBR,&ngauss) < 0) {
00281       MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NBR : ");
00282       ISCRUTE(ngauss);goto ERROR;
00283     };
00284     
00285     
00286     if (_MEDattrEntierLire(gid_loc,MED_NOM_GEO,&type_geo_g_int) < 0) {
00287       MESSAGE("Erreur à la lecture de l'attribut MED_NOM_GEO : ");
00288       ISCRUTE(type_geo_g_int);goto ERROR;
00289     };
00290     type_geo_g = type_geo_g_int;
00291 
00292     if ( type_geo_g != type_geo ) {
00293       MESSAGE("Erreur, la localisation ne porte pas sur le meme type géométrique : ");
00294       SSCRUTE(locname);ISCRUTE_int(type_geo);ISCRUTE_int(type_geo_g);goto ERROR;
00295     };
00296     
00297   }
00298   
00299   /* Cree ou ouvre l'attribut MED_NOM_GAU         */ 
00300   /* Ecriture de la localisation des pts de gauss  */
00301   if ( _MEDattrStringEcrire(datagroup3,MED_NOM_GAU,MED_TAILLE_NOM,locname_i) < 0) {
00302     MESSAGE("Erreur d'écriture de l'attribut MED_NOM_GAU : ");
00303     SSCRUTE(locname); goto ERROR;
00304   }
00305 
00306   /* Cree ou ouvre l'attribut MED_NOM_NGA         */ 
00307   /* Ecriture de l'attribut portant le nombre de points de gauss  */
00308   if ( _MEDattrEntierEcrire(datagroup3,MED_NOM_NGA,&ngauss) < 0) {
00309     MESSAGE("Erreur d'écriture de l'attribut MED_NOM_NGA : ");
00310     ISCRUTE(ngauss); goto ERROR;
00311   }
00312 
00313   /*Determination de la taille dimd[0] du dataset à stocker*/
00314   dimd[0] = nbelem*ncomp;
00315 
00316   /* Gestion des profils*/
00317   if ( pfluse ) {
00318    
00319     if ( ( i = MEDnValProfil(fid,pflname) ) < 0 ) {
00320       MESSAGE("Erreur à la lecture du nombre de valeurs sur le profil : ");
00321       SSCRUTE(pflname);
00322       goto ERROR;
00323     } else
00324       psize = i;
00325     
00326     pfltabtmp = (med_int *)   malloc (sizeof(med_int)*psize);
00327     pfltab    = (med_size *) malloc (sizeof(med_size)*psize);
00328     if (MEDprofilLire(fid,pfltabtmp,pflname) < 0) {
00329       MESSAGE("Erreur à la lecture du profil : ");
00330       SSCRUTE(pflname);goto ERROR;
00331     };
00332     for (i=0;i<psize;i++)
00333       pfltab[i] = (med_size) pfltabtmp[i];
00334     
00335   }
00336   else
00337     psize = MED_NOPF;
00338   
00339   
00340   /*
00341    * Ecriture du champ
00342    */
00343  
00344   switch(chtype)
00345     {
00346     case MED_FLOAT64 :
00347       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_FLOAT64,interlace,
00348                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0) {
00349         MESSAGE("Impossible d'ecrire le dataset : ");
00350         SSCRUTE(MED_NOM_CO);ISCRUTE((int)(dimd[0])); goto ERROR;
00351       }
00352       break;
00353       
00354     case MED_INT32 :
00355 #if defined(HAVE_F77INT64) 
00356       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_INT64,interlace,
00357                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0) {
00358         MESSAGE("Impossible d'ecrire le dataset : ");
00359         SSCRUTE(MED_NOM_CO);ISCRUTE((int)(dimd[0])); goto ERROR;
00360       }
00361 #else
00362       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_INT32,interlace,
00363                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0){
00364         MESSAGE("Impossible d'ecrire le dataset : ");
00365         SSCRUTE(MED_NOM_CO);ISCRUTE((int)(dimd[0])); goto ERROR;
00366       }
00367 #endif
00368       break;
00369 
00370     case MED_INT64 :
00371 #if defined(HAVE_F77INT64) 
00372       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_INT64,interlace,
00373                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0){
00374         MESSAGE("Impossible d'ecrire le dataset : ");
00375         SSCRUTE(MED_NOM_CO);ISCRUTE(dimd); goto ERROR;
00376       }
00377 #else
00378       MESSAGE("Impossible d'ecrire le dataset de type MED_INT64 sur une plateforme autre que IRIX64 et OSF1 !");
00379       goto ERROR;
00380 #endif
00381       break;   
00382 
00383     default :
00384       goto ERROR;
00385     }
00386 
00387   /*
00388    * On ferme tout 
00389    */
00390 
00391   ret = 0;
00392 
00393  ERROR:
00394   
00395   if ( pfluse ) { free(pfltab); free(pfltabtmp);}
00396   
00397   if (datagroup3>0)     if (_MEDdatagroupFermer(datagroup3) < 0) {
00398     MESSAGE("Impossible de fermer le datagroup : ");
00399     ISCRUTE_int(datagroup3); ret = -1; 
00400   }
00401   
00402   if (datagroup2>0)     if (_MEDdatagroupFermer(datagroup2) < 0) {
00403     MESSAGE("Impossible de fermer le datagroup : ");
00404     ISCRUTE_int(datagroup2); ret = -1; 
00405   }
00406 
00407   if (datagroup1>0)     if (_MEDdatagroupFermer(datagroup1) < 0) {
00408     MESSAGE("Impossible de fermer le datagroup : ");
00409     ISCRUTE_int(datagroup1); ret = -1; 
00410   }
00411   
00412   if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
00413     MESSAGE("Impossible de fermer le datagroup : ");
00414     ISCRUTE_id(gid); ret = -1;
00415   }
00416   
00417   if (gid_loc>0)     if (_MEDdatagroupFermer(gid_loc) < 0) {
00418     MESSAGE("Impossible de fermer le datagroup : ");
00419     ISCRUTE_id(gid_loc); ret = -1; 
00420   }
00421 
00422   va_end(params);
00423   *fret = ret;
00424   return;
00425 }
00426 

Généré le Thu Oct 8 14:26:16 2015 pour MED fichier par  doxygen 1.6.1