MEDchampEcr231.c

Aller à la documentation de ce fichier.
00001 /*  This file is part of MED.
00002  *
00003  *  COPYRIGHT (C) 1999 - 2012  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_mode_acces MED_MODE_ACCES;
00091 
00092   va_list params;
00093   va_start(params,dummy);
00094 
00095   fid = va_arg(params,med_idt);
00096   maa = va_arg(params,char *);
00097   cha = va_arg(params,char *);
00098   val = va_arg(params,  unsigned char *);
00099   interlace = va_arg(params,med_mode_switch);
00100   nbelem = va_arg(params,med_int);
00101   locname = va_arg(params,char *);
00102   numco = va_arg(params,med_int);
00103   profil = va_arg(params,char *);
00104   pflmod = va_arg(params,med_mode_profil);
00105   type_ent = va_arg(params,med_entite_maillage);
00106   type_geo = va_arg(params,med_geometrie_element);
00107   numdt = va_arg(params,med_int);
00108   dt_unit = va_arg(params,char *);
00109   dt = va_arg(params,med_float);
00110   numo = va_arg(params,med_int);
00111   fret = va_arg(params,med_err *);
00112 
00113   /*
00114    * On inhibe le gestionnaire d'erreur HDF 5
00115    */
00116   _MEDmodeErreurVerrouiller();
00117 if (MEDcheckVersion(fid) < 0) {*fret=-1;return;}
00118 
00119 
00120   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00121     MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
00122     goto ERROR;
00123   }
00124 
00125   if ( MED_MODE_ACCES == MED_LECTURE) {
00126     MESSAGE("Impossible d'écrire un champ en mode MED_LECTURE : ");
00127     goto ERROR;
00128   };
00129 
00130 
00131   /* 
00132    * Si le Data Group CHA n'existe pas => erreur
00133    */
00134   strcpy(chemin,MED_CHA);
00135   strcat(chemin,cha);
00136   if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00137     goto ERROR;
00138 
00139   /* Lecture de l'attribut MED_NOM_NCO */
00140   if (_MEDattrEntierLire(gid,MED_NOM_NCO,&ncomp) < 0)
00141     goto ERROR;
00142 
00143   /* Lecture de l'attribut MED_NOM_TYP */
00144   if ( _MEDattrEntierLire(gid,MED_NOM_TYP,&chtype) < 0)
00145     goto ERROR;
00146  
00147 
00148   
00149   /* 
00150    *  Creation/Ouverture du datagroup de niveau 1 <type_ent>[.<type_geo>] 
00151    */
00152   if ( type_ent == MED_NOEUD_MAILLE ) {
00153     SSCRUTE("L'écriture aux noeuds des éléments n'est pas disponible.");
00154     goto ERROR;
00155   }
00156 
00157   if (_MEDnomEntite(nomdatagroup1,type_ent) < 0)
00158     goto ERROR;
00159 
00160   if ( type_ent != MED_NOEUD ) {
00161     if ( _MEDnomGeometrie(tmp1,type_geo) < 0)
00162       goto ERROR;
00163     strcat(nomdatagroup1,".");
00164     strcat(nomdatagroup1,tmp1);
00165   }
00166   datagroup1 = 0;
00167   if ( (datagroup1 = _MEDdatagroupOuvrir(gid,nomdatagroup1)) < 0) 
00168     if ((datagroup1 = _MEDdatagroupCreer(gid,nomdatagroup1)) < 0)
00169       goto ERROR;
00170   
00171 
00172   /* 
00173    * Creation/Ouverture du datagroup de niveau 2 <numdt>.<numoo> 
00174    */
00175  
00176   sprintf(nomdatagroup2,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
00177 
00178   datagroup2 = 0;   
00179   if ( (datagroup2 = _MEDdatagroupOuvrir(datagroup1,nomdatagroup2)) < 0 )    
00180     if ((datagroup2 = _MEDdatagroupCreer(datagroup1,nomdatagroup2)) < 0 )   
00181       goto ERROR;   
00182   
00183   /*Cree ou ouvre l'attribut MED_NOM_NDT pour écriture */
00184   if ( _MEDattrEntierEcrire(datagroup2,MED_NOM_NDT,&numdt) < 0)
00185     goto ERROR;
00186   
00187   /*Cree ou ouvre l'attribut MED_NOM_PDT pour écriture */
00188   if ( _MEDattrFloatEcrire(datagroup2,MED_NOM_PDT,&dt) < 0)
00189     goto ERROR;
00190     
00191   /*Cree ou ouvre l'attribut MED_NOM_NOR pour écriture */
00192   if (_MEDattrEntierEcrire(datagroup2,MED_NOM_NOR,&numo) < 0)
00193     goto ERROR;
00194   
00195   /*Cree ou ouvre l'attribut  MED_NOM_UNI pour écriture */ 
00196   if ( numdt == MED_NOPDT ) {
00197     if ( _MEDattrStringEcrire(datagroup2,MED_NOM_UNI,MED_TAILLE_PNOM,MED_PNOM_BLANC) < 0)
00198       goto ERROR;
00199   } else
00200     if ( _MEDattrStringEcrire(datagroup2,MED_NOM_UNI,MED_TAILLE_PNOM,dt_unit) < 0)
00201       goto ERROR;  
00202 
00203 
00204   /*
00205    * Si c'est la première référence à un maillage, initialise l'attribut MED_MAA à ce maillage
00206    */
00207   if ((attr = _MEDattrOuvrir(datagroup2,MED_NOM_MAI)) < 0 ) {
00208     if (_MEDattrStringEcrire(datagroup2,MED_NOM_MAI,MED_TAILLE_NOM,maa) < 0)
00209       goto ERROR;
00210   } else {   
00211     if ( _MEDattrFermer(attr) < 0) goto ERROR;
00212   }
00213       
00214   
00215 
00216   /* 
00217    * Cree ou ouvre le datagroup de niveau 3 <maa> 
00218    */
00219 /*   if (_MEDcstring(maa,maaNoBlc) <0) { */
00220 /*     MESSAGE("Erreur à la convertion du nom du maillage : "); */
00221 /*     SSCRUTE(maaNoBlc); */
00222 /*     goto ERROR; */
00223 /*    } */
00224   NOFINALBLANK(maa,ERROR)
00225 
00226   datagroup3 = 0;   
00227   if (((datagroup3 = _MEDdatagroupOuvrir(datagroup2,maa)) > 0)    
00228       && ( MED_MODE_ACCES == MED_LECTURE_AJOUT )) {
00229     MESSAGE("Impossible de créer une reference à un maillage existant en mode MED_LECTURE_AJOUT :");
00230     goto ERROR;   
00231   } else   
00232     if (datagroup3 < 0)
00233       if ((datagroup3 = _MEDdatagroupCreer(datagroup2,maa)) < 0)   
00234         goto ERROR;   
00235   
00236   /*Cree ou ouvre l'attribut MED_NOM_NBR */
00237   if ( _MEDattrEntierEcrire(datagroup3,MED_NOM_NBR,&nbelem) < 0)
00238     goto ERROR;
00239 
00240   /*Cree ou ouvre  l'attribut MED_NOM_PFL   */ 
00241   pfluse = 0;
00242   if ( strlen(profil) == 0)   /* idem MED_NOPFL*/
00243     /* Ecriture de MED_NOPFLi car MED_NOM_PFL est forcément de taille MED_TAILLE_NOM*/
00244     strncpy(pflname,MED_NOPFLi,MED_TAILLE_NOM+1);
00245   else {
00246     strncpy(pflname,profil,MED_TAILLE_NOM);
00247     pflname[MED_TAILLE_NOM]='\0';
00248     pfluse = 1;
00249   }
00250   if ( _MEDattrStringEcrire(datagroup3,MED_NOM_PFL,MED_TAILLE_NOM,pflname) < 0){
00251     MESSAGE("Erreur d'écriture de l'attribut pflname : ");
00252     SSCRUTE(chemin); goto ERROR;
00253   }
00254 
00255   /* Lit le nombre de points de gauss et vérifie   */
00256   /* que la localisation porte sur le meme type géométrique  */
00257   
00258   if ( strlen(locname) == 0 ) {
00259     /* Ecriture de MED_NOGAUSSi car MED_NOM_GAUSS est forcément de taille MED_TAILLE_NOM*/
00260     strcpy(locname_i,MED_NOGAUSSi);
00261     ngauss = MED_NOPG ;
00262   } else if (! strcmp(locname,MED_GAUSS_ELNO)) { 
00263     /* Les points de Gauss sont définis sur les noeuds de l'element (mot cle) */
00264     /* le nombre de points de Gauss est egal au nombre de noeuds de l'element */
00265     ngauss = type_geo % 100;
00266     strcpy(locname_i,locname);
00267 
00268   } else { 
00269     strcpy(locname_i,locname);
00270 
00271     strcpy(chemin_loc,MED_GAUSS);
00272     strcat(chemin_loc,locname_i);
00273     
00274     if ((gid_loc = _MEDdatagroupOuvrir(fid,chemin_loc)) < 0) {
00275       MESSAGE("Ouverture du datagroup : ");
00276       SSCRUTE(chemin_loc); goto ERROR;
00277     }
00278     
00279     if (_MEDattrEntierLire(gid_loc,MED_NOM_NBR,&ngauss) < 0) {
00280       MESSAGE("Erreur à la lecture de l'attribut MED_NOM_NBR : ");
00281       ISCRUTE(ngauss);goto ERROR;
00282     };
00283     
00284     
00285     if (_MEDattrEntierLire(gid_loc,MED_NOM_GEO,&type_geo_g) < 0) {
00286       MESSAGE("Erreur à la lecture de l'attribut MED_NOM_GEO : ");
00287       ISCRUTE(type_geo);goto ERROR;
00288     };
00289     
00290     if ( type_geo_g != type_geo ) {
00291       MESSAGE("Erreur, la localisation ne porte pas sur le meme type géométrique : ");
00292       SSCRUTE(locname);ISCRUTE(type_geo);ISCRUTE(type_geo_g);goto ERROR;
00293     };
00294     
00295   }
00296   
00297   /* Cree ou ouvre l'attribut MED_NOM_GAU         */ 
00298   /* Ecriture de la localisation des pts de gauss  */
00299   if ( _MEDattrStringEcrire(datagroup3,MED_NOM_GAU,MED_TAILLE_NOM,locname_i) < 0) {
00300     MESSAGE("Erreur d'écriture de l'attribut MED_NOM_GAU : ");
00301     SSCRUTE(locname); goto ERROR;
00302   }
00303 
00304   /* Cree ou ouvre l'attribut MED_NOM_NGA         */ 
00305   /* Ecriture de l'attribut portant le nombre de points de gauss  */
00306   if ( _MEDattrEntierEcrire(datagroup3,MED_NOM_NGA,&ngauss) < 0) {
00307     MESSAGE("Erreur d'écriture de l'attribut MED_NOM_NGA : ");
00308     ISCRUTE(ngauss); goto ERROR;
00309   }
00310 
00311   /*Determination de la taille dimd[0] du dataset à stocker*/
00312   dimd[0] = nbelem*ncomp;
00313 
00314   /* Gestion des profils*/
00315   if ( pfluse ) {
00316    
00317     if ( ( i = MEDnValProfil(fid,pflname) ) < 0 ) {
00318       MESSAGE("Erreur à la lecture du nombre de valeurs sur le profil : ");
00319       SSCRUTE(pflname);
00320       goto ERROR;
00321     } else
00322       psize = i;
00323     
00324     pfltabtmp = (med_int *)   malloc (sizeof(med_int)*psize);
00325     pfltab    = (med_size *) malloc (sizeof(med_size)*psize);
00326     if (MEDprofilLire(fid,pfltabtmp,pflname) < 0) {
00327       MESSAGE("Erreur à la lecture du profil : ");
00328       SSCRUTE(pflname);goto ERROR;
00329     };
00330     for (i=0;i<psize;i++)
00331       pfltab[i] = (med_size) pfltabtmp[i];
00332     
00333   }
00334   else
00335     psize = MED_NOPF;
00336   
00337   
00338   /*
00339    * Ecriture du champ
00340    */
00341  
00342   switch(chtype)
00343     {
00344     case MED_FLOAT64 :
00345       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_FLOAT64,interlace,
00346                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0) {
00347         MESSAGE("Impossible d'ecrire le dataset : ");
00348         SSCRUTE(MED_NOM_CO);ISCRUTE((int)(dimd[0])); goto ERROR;
00349       }
00350       break;
00351       
00352     case MED_INT32 :
00353 #if defined(HAVE_F77INT64) 
00354       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_INT64,interlace,
00355                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0) {
00356         MESSAGE("Impossible d'ecrire le dataset : ");
00357         SSCRUTE(MED_NOM_CO);ISCRUTE((int)(dimd[0])); goto ERROR;
00358       }
00359 #else
00360       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_INT32,interlace,
00361                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0){
00362         MESSAGE("Impossible d'ecrire le dataset : ");
00363         SSCRUTE(MED_NOM_CO);ISCRUTE((int)(dimd[0])); goto ERROR;
00364       }
00365 #endif
00366       break;
00367 
00368     case MED_INT64 :
00369 #if defined(HAVE_F77INT64) 
00370       if ( _MEDdatasetNumEcrire(datagroup3,MED_NOM_CO,MED_INT64,interlace,
00371                                 ncomp,numco,psize,pflmod,0,pfltab,ngauss,dimd,val) < 0){
00372         MESSAGE("Impossible d'ecrire le dataset : ");
00373         SSCRUTE(MED_NOM_CO);ISCRUTE(dimd); goto ERROR;
00374       }
00375 #else
00376       MESSAGE("Impossible d'ecrire le dataset de type MED_INT64 sur une plateforme autre que IRIX64 et OSF1 !");
00377       goto ERROR;
00378 #endif
00379       break;   
00380 
00381     default :
00382       goto ERROR;
00383     }
00384 
00385   /*
00386    * On ferme tout 
00387    */
00388 
00389   ret = 0;
00390 
00391  ERROR:
00392   
00393   if ( pfluse ) { free(pfltab); free(pfltabtmp);}
00394   
00395   if (datagroup3>0)     if (_MEDdatagroupFermer(datagroup3) < 0) {
00396     MESSAGE("Impossible de fermer le datagroup : ");
00397     ISCRUTE_int(datagroup3); ret = -1; 
00398   }
00399   
00400   if (datagroup2>0)     if (_MEDdatagroupFermer(datagroup2) < 0) {
00401     MESSAGE("Impossible de fermer le datagroup : ");
00402     ISCRUTE_int(datagroup2); ret = -1; 
00403   }
00404 
00405   if (datagroup1>0)     if (_MEDdatagroupFermer(datagroup1) < 0) {
00406     MESSAGE("Impossible de fermer le datagroup : ");
00407     ISCRUTE_int(datagroup1); ret = -1; 
00408   }
00409   
00410   if (gid>0)     if (_MEDdatagroupFermer(gid) < 0) {
00411     MESSAGE("Impossible de fermer le datagroup : ");
00412     ISCRUTE_id(gid); ret = -1;
00413   }
00414   
00415   if (gid_loc>0)     if (_MEDdatagroupFermer(gid_loc) < 0) {
00416     MESSAGE("Impossible de fermer le datagroup : ");
00417     ISCRUTE_id(gid_loc); ret = -1; 
00418   }
00419 
00420   va_end(params);
00421   *fret = ret;
00422   return;
00423 }
00424 

Généré le Mon Nov 19 15:43:34 2012 pour MED fichier par  doxygen 1.6.1