MEDscalaireEntierEcr.c
Aller à la documentation de ce fichier.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #include <med.h>
00020 #include <med_config.h>
00021 #include <med_outils.h>
00022 
00023 #include <string.h>
00024 #include <stdlib.h>
00025 
00026 med_err
00027 MEDscalaireEntierEcr(med_idt fid, char *scalaire,med_int val, med_int numdt, char *dt_unit, med_float dt, med_int numo)
00028 {
00029   med_err ret = 0;
00030   med_idt gid,datagroup;
00031   char nomdatagroup[2*MED_MAX_PARA+1];
00032   char chemin[MED_TAILLE_NUM_DATA+MED_TAILLE_NOM+1];
00033   med_int type;
00034   med_mode_acces MED_MODE_ACCES;
00035 
00036   
00037 
00038 
00039   _MEDmodeErreurVerrouiller();
00040 if (MEDcheckVersion(fid) < 0) return -1;
00041 
00042 
00043   if ( (MED_MODE_ACCES = _MEDmodeAcces(fid) ) == MED_UNDEF_MODE_ACCES ) {
00044     MESSAGE("Impossible de déterminer le mode d'acces au fichier ");
00045     return -1;
00046   }
00047 
00048   
00049 
00050 
00051   strcpy(chemin,MED_NUM_DATA);
00052   strcat(chemin,scalaire);
00053   if ((gid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00054     return -1;
00055 
00056   
00057   sprintf(nomdatagroup,"%*li%*li",MED_MAX_PARA,(long ) numdt,MED_MAX_PARA,(long ) numo);
00058 
00059   
00060   datagroup = 0;   
00061   if (((datagroup = _MEDdatagroupOuvrir(gid,nomdatagroup)) > 0)    
00062       && ( MED_MODE_ACCES == MED_LECTURE_AJOUT ))   
00063     return -1;   
00064   else   
00065     if (datagroup < 0)
00066       if ((datagroup = _MEDdatagroupCreer(gid,nomdatagroup)) < 0)   
00067         return -1;   
00068   
00069   
00070   if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NDT,&numdt)) < 0)
00071     return -1;
00072   
00073   
00074   if ((ret = _MEDattrFloatEcrire(datagroup,MED_NOM_PDT,&dt)) < 0)
00075     return -1;
00076     
00077   
00078   if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_NOR,&numo)) < 0)
00079     return -1;
00080 
00081    
00082   if ( numdt == MED_NOPDT ) {
00083     if ((ret = _MEDattrStringEcrire(datagroup,MED_NOM_UNI,MED_TAILLE_PNOM,MED_PNOM_BLANC)) < 0)
00084       return -1;
00085   } else
00086     if ((ret = _MEDattrStringEcrire(datagroup,MED_NOM_UNI,MED_TAILLE_PNOM,dt_unit)) < 0)
00087       return -1;
00088 
00089   
00090 
00091 
00092   if ((ret = _MEDattrEntierLire(gid,MED_NOM_TYP,&type)) < 0)
00093     return -1;
00094   switch(type) 
00095     {
00096     case MED_INT :
00097     case MED_INT32 :
00098     case MED_INT64 :
00099       if ((ret = _MEDattrEntierEcrire(datagroup,MED_NOM_VAL,&val)) < 0)
00100         return -1;      
00101       break;
00102 
00103     default :
00104       return -1;
00105     }
00106 
00107   
00108 
00109 
00110   if ((ret = _MEDdatagroupFermer(datagroup)) < 0)
00111     return -1;
00112   if ((ret = _MEDdatagroupFermer(gid)) < 0)
00113     return -1;
00114 
00115   return ret;
00116 }