Back to index

salome-med  6.5.0
MEDunvCr.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.hxx"
00020 #include "med_outils.hxx"
00021 
00022 #include <string.h>
00023 #include <stdlib.h>
00024 
00025 #include <stdio.h>
00026 #include <time.h>
00027 
00028 //#ifdef PPRO_NT
00029 #ifdef WIN32
00030 // Windows Header Files:
00031 #include <windows.h>
00032 #include <Lmcons.h>
00033 #include <sys/timeb.h>
00034 #else
00035 #include <sys/time.h>
00036 #endif
00037 
00038 namespace med_2_1{
00039 
00040 med_err 
00041 MEDunvCr(med_idt fid, char *maa)
00042 {
00043   med_idt maaid;
00044   char chemin [MED_TAILLE_MAA+MED_TAILLE_NOM+1];
00045   char nomu   [MED_TAILLE_LNOM+1];    
00046   time_t  temps;
00047 //#ifdef PPRO_NT
00048 #ifdef WIN32
00049   struct timeb   tp;
00050   char   lpBuffer [UNLEN+1];
00051   long   nSize   = UNLEN+1;
00052 #else
00053   struct timeval tp;
00054 #endif 
00055   med_err ret;
00056 
00057   /*
00058    * On inhibe le gestionnaire d'erreur
00059    */
00060   _MEDmodeErreurVerrouiller();
00061 
00062   /*
00063    * Si le maillage n'existe pas => erreur
00064    */
00065   strcpy(chemin,MED_MAA);
00066   strcat(chemin,maa);
00067   if ((maaid = _MEDdatagroupOuvrir(fid,chemin)) < 0)
00068       return -1;
00069 
00070   /*
00071    * Creation/Ecriture de l'attribut nom universel 
00072    */
00073   
00074 //#ifdef PPRO_NT
00075 #ifdef WIN32
00076   if ( GetUserName(lpBuffer,LPDWORD(&nSize)) == 0 ) return -1;
00077   if ( nSize > MED_TAILLE_NOM ) nSize = MED_TAILLE_NOM;
00078   strncpy(nomu,lpBuffer,nSize);
00079   strcat(nomu," ");
00080   temps=time(&temps);
00081   strcat(nomu,ctime(&temps));
00082   ftime(&tp);
00083   nSize = (long)strlen(nomu)-1;
00084   if ( sprintf(&nomu[nSize]," %hu",tp.millitm) < 0 ) return -1;
00085 #else
00086   if (cuserid(nomu) == (void*) NULL) return -1;
00087   strcat(nomu," ");
00088   temps=time(&temps);
00089   strcat(nomu,ctime(&temps));
00090   if ( gettimeofday(&tp,NULL) < 0 ) return -1;
00091   if ( sprintf(&nomu[strlen(nomu)-1]," %li",tp.tv_usec) < 0 ) return -1;
00092 #endif
00093   if ((ret = _MEDattrStringEcrire(maaid,MED_NOM_UNV,MED_TAILLE_LNOM,nomu,MED_REMP)) < 0) 
00094     return -1;
00095 
00096   /* 
00097    * Nettoyages divers
00098    */
00099   if ((ret = _MEDdatagroupFermer(maaid)) < 0)
00100     return -1;
00101  
00102   return 0;
00103 }
00104 
00105 }