int MEDimport(char * filein, char * fileout) { med_idt fid, gid; med_err ret; med_int majeur, mineur, release; med_bool hdfok=MED_FALSE; med_bool medok=MED_FALSE; char *_fileout,*tmp=NULL; int _fileoutsize; bool hasfileout=false; char *commande; med_int nprofil; char chemin_profils[MED_TAILLE_PROFILS+1]; char chemin_liens[MED_TAILLE_LIENS+1]; char version[9]; int MAJ_21_22 = 0, MAJ_231_232 = 0, MAJ_236_300 = 0, MAJ_300_310 = 0, MAJ_310_320 = 0 ; #ifdef PPRO_NT char *drive, *dir, *ext; #endif unsigned char reponse='o'; med_bool _noversion=MED_FALSE; EXIT_IF(filein == NULL,"Le nom du fichier d'entrée est vide : ", filein); hasfileout = strcmp(fileout,""); if ( hasfileout ) { _fileoutsize = strlen(fileout); _fileout = fileout; } else { _fileoutsize = strlen(filein)+strlen(PACKAGE_VERSION); tmp = (char *) malloc(sizeof(char)*(_fileoutsize+1)); strcpy(tmp,filein); strcat(tmp,PACKAGE_VERSION); #ifdef PPRO_NT _splitpath( tmp, drive, dir, _fileout, ext ); #else _fileout = basename(tmp); #endif _fileoutsize = strlen(_fileout); } /* Test du format du fichier */ ret = MEDfileCompatibility(filein,&hdfok,&medok); if (ret < 0 ) { fprintf(stdout,">>> Attention le fichier %s ne contient pas de numéro de version. \n",filein); fprintf(stdout,">>> Le fichier %s est supposé être en version 2.1.1. \n",filein); /* PAs d'interactif dans une bibliothèque !*/ /* fprintf(stdout,">>> Voulez-vous essayer une conversion d'un fichier < 2.2 (o/n) ? "); */ /* scanf("%c",&reponse); */ if ( (reponse != 'o') && (reponse != 'O') && (reponse != 'y') && (reponse != 'Y') ) { EXIT_IF(MEDfileCompatibility(filein,&hdfok,&medok) < 0, "Erreur d'appel de MEDfileCompatibility : ", filein); } _noversion = MED_TRUE; } EXIT_IF( !hdfok , "Le fichier d'entrée n'est pas dans un format HDF compatible : ", filein); /* EXIT_IF( !medok , */ /* "MEDimport ne gère pas le format MED de ce fichier : ", filein); */ /* Creation et ouverture du fichier que l'on va convertir au format MED actuel */ commande = (char *) malloc(sizeof(char)*(strlen("cp ")+strlen(filein)+ strlen(" ")+_fileoutsize + 4 +1 ) ); EXIT_IF(commande == NULL,NULL,NULL); strcpy(commande,"cp \""); strcat(commande,filein); strcat(commande,"\" \""); strcat(commande,_fileout); strcat(commande,"\""); fprintf(stdout,">>> Creation du fichier %s : %s \n",_fileout,commande); system(commande); free(commande); commande = (char *) malloc(sizeof(char)*(strlen("chmod u+w \"") + _fileoutsize +1 +1 ) ); EXIT_IF(commande == NULL,NULL,NULL); strcpy(commande,"chmod u+w \""); strcat(commande,_fileout); strcat(commande,"\""); fprintf(stdout,">>> Chmod +w du fichier %s : %s \n",_fileout,commande); system(commande); free(commande); fid = MEDfileOpen(_fileout,MED_ACC_RDWR); EXIT_IF(fid < 0,"Ouverture du fichier : ", _fileout); /* Verification du numero de version */ if (! _noversion) ret = MEDfileNumVersionRd(fid,&majeur,&mineur,&release); else { ret=0; majeur=2; mineur=1; release=1; } sprintf(version, IFORMAT"_"IFORMAT"_"IFORMAT, majeur, mineur, release); EXIT_IF(ret < 0,"Lecture du numero de version de MED-fichier",NULL); if (strcmp(version, "2_2_0") < 0) MAJ_21_22 = 1; if (strcmp(version, "2_3_2") < 0) MAJ_231_232 = 1; if (strcmp(version, "3_0_0") < 0) MAJ_236_300 = 1; if (strcmp(version, "3_1_0") < 0) MAJ_300_310 = 1; if (strcmp(version, "3_2_0") < 0) MAJ_310_320 = 1; /* Ne pas oublier que la version cible du fichier à convertir est celui de la bibliothèque. */ if (MAJ_310_320 == 0) { fprintf(stdout,"Le fichier %s est déjà au bon format !!! \n",_fileout); ret = MEDfileClose(fid); EXIT_IF(ret < 0,"Fermeture du fichier",filein); return 0; } /* On avertit qu'on commence la conversion */ fprintf(stdout,">>> Lancement de la normalisation du fichier selon le format " PACKAGE_VERSION " ...\n"); /* On inhibe le gestionnaire d'erreur HDF5 */ _MEDmodeErreurVerrouiller(); /* Mise a jour du numero de version */ fprintf(stdout,"- Lancement de la mise à jour du numéro de version ... \n"); /* La mise à jour MAJ_version(fid); doit être différée pour que les majs des fichiers anciens fonctionnent correctement*/ /* MAJ_version(fid); */ MAJ_write_version_num(fid,2,3,6); fprintf(stdout," Numéro de version : ... OK ... \n"); if (MAJ_21_22) { /* Mise a jour des maillages : type = MED_NON_STRUCTURE, description, ... */ fprintf(stdout,"- Lancement de la mise à jour des maillages (21_22)... \n"); MAJ_21_22_maillages(fid); fprintf(stdout," Maillage(s) : ... OK ...\n"); /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (21_22)... \n"); MAJ_21_22_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); /* Mise a jour des profils eventuels */ nprofil = MEDnProfil(fid); if (nprofil > 0) { fprintf(stdout,"- Lancement de la mise à jour des profils (21_22)... \n"); MAJ_21_22_profils(fid,nprofil); fprintf(stdout," Profils(s) : ... OK ...\n"); } else { strncpy(chemin_profils,MED_PROFILS,MED_TAILLE_PROFILS-1); chemin_profils[MED_TAILLE_PROFILS-1] = '\0'; gid = _MEDdatagroupCreer(fid,chemin_profils); EXIT_IF(gid < 0,"Creation du groupe HDF sur les profils",chemin_profils); ret = _MEDdatagroupFermer(gid); EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les profils",chemin_profils); } /* On cree le groupe HDF pour les liens */ strncpy(chemin_liens,MED_LIENS,MED_TAILLE_LIENS-1); chemin_liens[MED_TAILLE_LIENS-1] = '\0'; gid = _MEDdatagroupCreer(fid,chemin_liens); EXIT_IF(gid < 0,"Creation du groupe HDF sur les liens",chemin_liens); ret = _MEDdatagroupFermer(gid); EXIT_IF(ret < 0,"Fermeture du groupe HDF sur les liens",chemin_liens); } if (MAJ_231_232) { /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (231_232)... \n"); MAJ_231_232_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); fprintf(stdout,"- Lancement de la mise à jour des noms de maillages (231_232)... \n"); MAJ_231_232_maillages(fid); fprintf(stdout," Noms(s) de maillage(s): ... OK ...\n"); } if (MAJ_236_300) { /* Le système de cache de version a été developpé à partir de la 3.0*/ /* Initialise le cache sur une 2.3.6 (cas d'absence d'INFO)*/ _MEDfileVersion(fid); /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (236_300)... \n"); MAJ_236_300_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); /* MAJ_version(fid); */ fprintf(stdout,"- Lancement de la mise à jour des maillages (236_300)... \n"); MAJ_236_300_maillages(fid); fprintf(stdout," Maillage(s): ... OK ...\n"); /* MAJ_version(fid); */ } if (MAJ_300_310) { /* Le système de cache de version a été developpé à partir de la 3.0*/ /* Initialise le cache sur une 3.0.8 (cas d'absence d'INFO)*/ /* s'il n'a pas déjà été instanciée ds les MAJ précédentes */ MAJ_write_version_num(fid,3,0,8); _MEDfileVersion(fid); /* Si le cache était dèjà instancié, met à jour le cache */ MAJ_version_num(fid,3,0,8); /* Mise a jour des champs */ fprintf(stdout,"- Lancement de la mise à jour des champs de résultats (300_310) ... \n"); MAJ_300_310_champs(fid); fprintf(stdout," Champs(s) : ... OK ...\n"); } if (MAJ_310_320) { /* Le système de cache de version a été developpé à partir de la 3.0*/ /* Initialise le cache sur une 3.0.8 (cas d'absence d'INFO)*/ /* s'il n'a pas été déjà été instanciée ds les MAJ_ précédentes */ MAJ_write_version_num(fid,3,1,0); _MEDfileVersion(fid); /* Si le cache était dèjà instancié, met à jour le cache */ MAJ_version_num(fid,3,1,0); /* Mise a jour des familles/groupes */ fprintf(stdout,"- Lancement de la mise à jour des familles/groupes (310_320) ... \n"); MAJ_310_320_familles(fid); fprintf(stdout," Famille(s)/Groupe(s) : ... OK ...\n"); } /* A l'écriture d'une nouvelle version de MAJ ex 310_320, il est necessaire de revisiter les appels à MAJ_version(fid) pour les remplacer par les appels MAJ_version(fid,3,1,Lastest31z) */ MAJ_version(fid); MAJ_write_version_num(fid,MED_NUM_MAJEUR,MED_NUM_MINEUR,MED_NUM_RELEASE); /* Fermeture du fichier */ ret = MEDfileClose(fid); EXIT_IF(ret < 0,"Fermeture du fichier",_fileout); /* On avertit que c'est fini */ fprintf(stdout,">>> Conversion du fichier %s au format MED V" PACKAGE_VERSION " terminée\n", _fileout); /* On libere la memoire */ if (!hasfileout) free(tmp); return 0; }
void MAJ_236_300_champs(med_idt fid) { med_err lret,ret; /* med_idt _datagroup=0; */ med_field_type typcha; char nomcha [MED_NAME_SIZE+1]=""; char _meshname [MED_NAME_SIZE+1]=""; char _dtunit [MED_SNAME_SIZE+1]=""; char *comp= NULL, *unit= NULL; med_int ncomp,ncha; med_int _ncstp=0; med_bool _local=MED_FALSE; htri_t _datasetexist; char _pathi[MED_TAILLE_CHA+1+MED_NAME_SIZE+1]=MED_CHA; char _pathf[MED_TAILLE_CHA+2+MED_NAME_SIZE+1]="/CHA_/"; char _pathtmp[MED_TAILLE_CHA+3]="/CHA__/"; int i,j; char nomlien[MED_NAME_SIZE+1]=""; char * lien = NULL; med_int nln,nval; med_int _nloc,_intgeotype,_sdim; char _pathloc[MED_TAILLE_GAUSS+MED_NAME_SIZE+1]=MED_GAUSS; med_int _npar,_numdt,_numit; char _pathpari[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA; char _pathparf[MED_TAILLE_NUM_DATA+MED_NAME_SIZE+1+2*MED_MAX_PARA+1+1]=MED_NUM_DATA; int _pathparlen; med_size _n=0; char _cpstnamei[2*MED_MAX_PARA+1]=""; char _cpstnamef[2*MED_MAX_PARA+1]=""; char _uniname[MED_SNAME_SIZE+1]=""; /* hid_t _lac_plist_id; */ hid_t _lcp_plist_id; hid_t _ocp_plist_id; med_bool _createunt = MED_TRUE; MAJ_version_num(fid,2,3,6); /* MAJ des varaibles scalaires */ _npar = MEDnParameter(fid); if (_npar > 0) { fprintf(stdout," >>> Normalisation des paramètres scalaires\n"); _pathparf[MED_TAILLE_NUM_DATA-2]='_'; /* _lac_plist_id = H5Pcreate( H5P_LINK_ACCESS ); */ _ocp_plist_id = H5Pcreate( H5P_OBJECT_COPY ); _lcp_plist_id = H5Pcreate( H5P_LINK_CREATE ); H5Pset_create_intermediate_group( _lcp_plist_id, 1 ); H5Pset_copy_object( _ocp_plist_id, H5O_COPY_SHALLOW_HIERARCHY_FLAG); } for (i=0 ; i < _npar ; i++ ) { MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,i, &_pathpari[MED_TAILLE_NUM_DATA]) < 0, MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari); strcpy(&_pathparf[MED_TAILLE_NUM_DATA],&_pathpari[MED_TAILLE_NUM_DATA]); /* SSCRUTE(_pathparf); */ /* SSCRUTE(_pathpari); */ /*Copie le group avec ses attributs et les objets de premier niveau.*/ ret = H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id); /* ret = H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */ EXIT_IF(ret < 0,"Copie du datagroup",_pathpari); _pathparlen=strlen(_pathpari); _pathpari[_pathparlen]='/';_pathparf[_pathparlen]='/'; ++_pathparlen; _pathpari[_pathparlen]='\0';_pathparf[_pathparlen]='\0'; /* SSCRUTE(_pathparf); */ /* SSCRUTE(_pathpari); */ ret =_MEDnObjects(fid,_pathpari, &_n); MED_ERR_EXIT_IF( (ret == (MED_ERR_COUNT + MED_ERR_DATAGROUP)), MED_ERR_COUNT,MED_ERR_PARAMETER,_pathpari); for (j=0 ; j < _n ; ++j ) { MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathpari ,j, &_pathpari[_pathparlen]) < 0, MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathpari); MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NOR, MED_INTERNAL_INT,(unsigned char * const ) &_numit) < 0, MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NOR); MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathpari,MED_NOM_NDT, MED_INTERNAL_INT,(unsigned char * const ) &_numdt) < 0, MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT); MED_ERR_EXIT_IF (_MEDattributeStringRdByName(fid,_pathpari,MED_NOM_UNI, MED_SNAME_SIZE,_uniname) < 0, MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_NDT); _MEDgetComputationStepName(MED_SORT_DTIT,_numdt,_numit,&_pathparf[_pathparlen]); /* strcat(_pathpari,"/"); */ /* strcat(_pathparf,"/"); */ /* SSCRUTE(_pathparf); */ /* SSCRUTE(_pathpari); */ /* ret = H5Ocopy(fid,_pathpari,fid,_pathparf,_ocp_plist_id,_lcp_plist_id); */ /* ret = H5Lcopy(fid,_pathpari,fid,_pathparf,_lcp_plist_id,_lac_plist_id); */ /* H5Eprint1(stderr); */ /* EXIT_IF(ret < 0,"Copie d'une étape de calcul du paramètre scalaire ",_pathpari); */ /*On modifie temporairement _pathpari pour pointer dans _pathparf*/ _pathpari[MED_TAILLE_NUM_DATA-2]='_'; /* SSCRUTE(_pathparf); */ /* SSCRUTE(_pathpari); */ ret = H5Gmove(fid, _pathpari, _pathparf ); EXIT_IF(ret < 0,"Renommage de l'étape de calcul",_pathpari); _pathpari[MED_TAILLE_NUM_DATA-2]='A'; MED_ERR_EXIT_IF(H5Adelete_by_name( fid, _pathparf, MED_NOM_UNI, H5P_DEFAULT ) < 0, MED_ERR_DELETE,MED_ERR_ATTRIBUTE,_pathparf); _pathparf[_pathparlen]='\0'; _pathpari[_pathparlen]='\0'; if ( _createunt ) { MED_ERR_EXIT_IF (_MEDattributeStringWrByName(fid,_pathparf,MED_NOM_UNT, MED_SNAME_SIZE,_uniname) < 0, MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_UNT); _createunt = MED_FALSE; } } _createunt = MED_TRUE; _pathpari[MED_TAILLE_NUM_DATA]='\0'; } if ( _npar > 0 ) { _pathpari[MED_TAILLE_NUM_DATA]='\0'; _pathparf[MED_TAILLE_NUM_DATA]='\0'; MED_ERR_EXIT_IF ( H5Ldelete(fid,_pathpari,H5P_DEFAULT) < 0 , MED_ERR_DELETE,MED_ERR_LINK,_pathpari); ret = H5Gmove(fid, _pathparf, _pathpari ); EXIT_IF(ret < 0,"Renommage du group de paramètres scalaires",_pathparf); } /* MAJ des localisations */ _nloc = MEDnLocalization(fid); /* ISCRUTE(_nloc); */ if (_nloc > 0) fprintf(stdout," >>> Normalisation des localisations des points d'intégration\n"); for (i=0 ; i < _nloc ; i++ ) { /* SSCRUTE(_pathloc); */ MED_ERR_EXIT_IF (_MEDobjectGetName(fid, _pathloc ,i, &_pathloc[MED_TAILLE_GAUSS]) < 0, MED_ERR_ACCESS,MED_ERR_DATAGROUP,_pathloc); /* SSCRUTE(_pathloc); */ MED_ERR_EXIT_IF (_MEDattributeNumRdByName(fid,_pathloc,MED_NOM_GEO, MED_INTERNAL_INT,(unsigned char * const ) &_intgeotype) < 0, MED_ERR_READ,MED_ERR_ATTRIBUTE,MED_NOM_GEO); _sdim = (_intgeotype/100); MED_ERR_EXIT_IF (_MEDattributeNumWrByName(fid,_pathloc,MED_NOM_DIM, MED_INTERNAL_INT,(const unsigned char * const) &_sdim) < 0, MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_DIM); MED_ERR_EXIT_IF ( _MEDattributeStringWrByName(fid,_pathloc,MED_NOM_INM,MED_NAME_SIZE,"") < 0, MED_ERR_WRITE,MED_ERR_ATTRIBUTE,MED_NOM_INM); _pathloc[MED_TAILLE_GAUSS]='\0'; } /* MAJ des liens */ nln = MEDnLink(fid); if (nln > 0) fprintf(stdout," >>> Normalisation des liens\n"); for (i=1 ; i <= nln ; i++ ) { ret = MEDlinkInfo(fid, i, nomlien, &nval); EXIT_IF(ret,"Erreur a la demande d'information sur le lien",NULL); /* printf("\t- Lien n°%i de nom |%s| et de taille "IFORMAT"\n",i,nomlien,nval); */ lien = (char *) malloc((nval+1)*sizeof(char)); EXIT_IF(lien == NULL,NULL,NULL); ret = MEDlinkRd(fid, nomlien, lien ); EXIT_IF(ret,"Erreur a la lecture du lien : ",nomlien); MAJ_version_num(fid,3,0,8); ret = MED30linkWr(fid,nomlien,lien); EXIT_IF(ret,"Erreur a l'écrtiure du lien : ",nomlien); MAJ_version_num(fid,2,3,6); lien[nval] = '\0'; /* printf("\t\t|%s|\n\n",lien); */ free(lien); } /* combien de champs dans le fichier */ ncha = MEDnField(fid); EXIT_IF(ncha < 0,"lors de la lecture du nombre de champs",NULL); /* MAJ des champs */ for (i =0;i<ncha;i++) { lret = 0; /* Lecture du nombre de composantes */ ncomp = MEDfieldnComponent(fid,i+1); if (ncomp < 0) { MESSAGE("Erreur à la lecture du nombre de composantes : "); ISCRUTE(ncomp); exit(1); } /* Lecture du type du champ, des noms des composantes et du nom de l'unité*/ comp = (char*) malloc(ncomp*MED_SNAME_SIZE+1); EXIT_IF(comp == NULL,NULL,NULL); unit = (char*) malloc(ncomp*MED_SNAME_SIZE+1); EXIT_IF(unit == NULL,NULL,NULL); /* ret = MED231champInfoEtRen(fid,i+1,nomcha,&typcha,comp,unit,ncomp); */ ret = MEDfieldInfo(fid,i+1,nomcha,_meshname,&_local,&typcha,comp,unit,_dtunit,&_ncstp); MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha); /* creation du champ destination */ MAJ_version_num(fid,3,0,8); EXIT_IF( H5Gmove(fid, _pathi, _pathtmp ) < 0,"Switch to ",_pathtmp); _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT ); if (_datasetexist ) { EXIT_IF( (H5Gmove(fid, _pathf, _pathi ) < 0) ,"Switch to ",_pathi); } MED_ERR_EXIT_IF( MEDfieldCr(fid,nomcha,typcha,ncomp,comp,unit,_dtunit,_meshname ) < 0, MED_ERR_CREATE,MED_ERR_FIELD,_pathf); EXIT_IF( H5Gmove(fid, _pathi , _pathf ) < 0,"Switch to ",_pathf); EXIT_IF( H5Gmove(fid, _pathtmp, _pathi ) < 0,"Switch to ",_pathi); MAJ_version_num(fid,2,3,6); free(comp); free(unit); lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE,_ncstp, _pathi, _pathf); if (lret != 0) { MESSAGE("Erreur à la lecture des champs aux noeuds "); exit(1); } lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_CELL,_ncstp, _pathi, _pathf); if (lret != 0) { MESSAGE("Erreur à la lecture des champs aux mailles "); exit(1); } lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_FACE,_ncstp, _pathi, _pathf); if (lret != 0) { MESSAGE("Erreur à la lecture des champs aux faces "); exit(1); } lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_DESCENDING_EDGE,_ncstp, _pathi, _pathf); if (lret != 0) { MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1); } lret = MAJ_236_300_fieldOnEntity( fid, nomcha, _meshname, typcha, ncomp, MED_NODE_ELEMENT,_ncstp, _pathi, _pathf); if (lret != 0) { MESSAGE("Erreur à la lecture des champs aux aretes "); exit(1); } } _datasetexist=H5Lexists( fid, _pathf, H5P_DEFAULT ); if (_datasetexist ) { EXIT_IF( (H5Ldelete(fid,_pathi, H5P_DEFAULT) < 0) ,"Delete ",_pathi); EXIT_IF( (H5Gmove(fid, _pathf, _pathi ) < 0) ,"Switch to ",_pathf); } }
med_err MAJ_236_300_fieldOnEntity(med_idt fid, const char * const nomcha, const char * const meshname, med_field_type typcha, med_int ncomp, med_entity_type entite, med_int ncstp, char * const _pathi, char * const _pathf) { med_err ret=-1; int i,j,k,l,m,n,nb_geo=0; med_int nbpdtnor=0,pflsize,*pflval,ngauss=0,ngroup,*vale=NULL,nval; med_int numdt=0,numo=0,_nprofile; med_int meshnumdt=0,meshnumit=0; med_float *valr=NULL,dt=0.0; unsigned char * _val=NULL; char pflname [MED_NAME_SIZE+1]=""; char locname [MED_NAME_SIZE+1]=""; char _meshname [MED_NAME_SIZE+1]=""; char _fieldname [MED_NAME_SIZE+1]=""; char _pathtmp[MED_FIELD_GRP_SIZE+3]="/CHA__/"; char _pathfb[MED_FIELD_GRP_SIZE+2+MED_NAME_SIZE+1]="/CHA_/"; char * lien = NULL; char dt_unit [MED_SNAME_SIZE+1]="unknown"; med_bool localmesh; med_int nmesh=0; hid_t _ocp_plist_id ; hid_t _lcp_plist_id ; int _isavlen=0; int _fsavlen=0; int _fieldnamelen=0; htri_t _groupexist; char _tmpmeshname[MED_NAME_SIZE+1]=""; med_bool _tmplocal=MED_FALSE; med_field_type _tmptypcha; char *_tmpcomp=NULL,*_tmpunit=NULL,_tmpdtunit[MED_SNAME_SIZE+1]=""; med_int _tmpncstp=0; med_geometry_type * type_geo; const char * const * AFF; const char * const * AFF_ENT=MED_GET_ENTITY_TYPENAME+1; switch (entite) { case MED_NODE : type_geo = MED_GET_NODE_GEOMETRY_TYPE; nb_geo = MED_N_NODE_FIXED_GEO; AFF = MED_GET_NODE_GEOMETRY_TYPENAME; break; case MED_CELL : case MED_NODE_ELEMENT : type_geo = MED_GET_CELL_GEOMETRY_TYPE; nb_geo = MED_N_CELL_FIXED_GEO; AFF = MED_GET_CELL_GEOMETRY_TYPENAME; break; case MED_DESCENDING_FACE : type_geo = MED_GET_FACE_GEOMETRY_TYPE; nb_geo = MED_N_FACE_FIXED_GEO; AFF = MED_GET_FACE_GEOMETRY_TYPENAME; break; case MED_DESCENDING_EDGE : type_geo = MED_GET_EDGE_GEOMETRY_TYPE; nb_geo = MED_N_EDGE_FIXED_GEO; AFF = MED_GET_EDGE_GEOMETRY_TYPENAME; break; } strcpy(_fieldname,nomcha); _isavlen=strlen(_pathi); _fsavlen=strlen(_pathf); _fieldnamelen=strlen(_fieldname); _ocp_plist_id = H5Pcreate( H5P_OBJECT_COPY ); _lcp_plist_id = H5Pcreate( H5P_LINK_CREATE ); /* Reconstruit les objets pointés par un lien symbolique */ H5Pset_copy_object( _ocp_plist_id, H5O_COPY_EXPAND_SOFT_LINK_FLAG ); /*Ne crée pas les liens intermédiaires */ H5Pset_create_intermediate_group(_lcp_plist_id, -1); /* Ne recopie pas en profondeur*/ H5Pset_copy_object( _ocp_plist_id, H5O_COPY_SHALLOW_HIERARCHY_FLAG); /* ISCRUTE(nbpdtnor); */ /* SSCRUTE(_fieldname); */ for (k=1;k<=nb_geo;k++) { /* Combien de (PDT,NOR) a lire */ nbpdtnor = ncstp; if (nbpdtnor < 1 ) continue; for (j=0;j<nbpdtnor;j++) { if ( MEDfield23ComputingStepMeshInfo(fid,nomcha,j+1, &numdt, &numo, &dt, &nmesh, _meshname,&localmesh, &meshnumdt, &meshnumit ) <0) { MESSAGE("Erreur a la demande d'information sur (pdt,nor) : "); ISCRUTE(numdt); ISCRUTE(numo);ISCRUTE(nmesh);SSCRUTE(_meshname);ISCRUTE_int(localmesh); ISCRUTE(meshnumdt);ISCRUTE(meshnumit); ret = -1; continue; } /* SSCRUTE(_meshname);SSCRUTE(AFF_ENT[(int)entite]);SSCRUTE(AFF[k]);ISCRUTE(nmesh); */ for (i=0;i< nmesh;++i) { if ( (_nprofile = MEDfield23nProfile(fid,nomcha,numdt,numo,entite,type_geo[k],i+1,_meshname, pflname,locname ) ) < 0 ) { MESSAGE("Erreur a la demande du nombre de profils referencés par le champ : "); SSCRUTE(nomcha); ISCRUTE(numdt); ISCRUTE(numo);SSCRUTE(_meshname); ISCRUTE_int(entite);ISCRUTE_int(type_geo[k]);SSCRUTE(pflname);SSCRUTE(locname); SSCRUTE(AFF_ENT[(int)entite]);SSCRUTE(AFF[k]); ret = -1; continue; }; /* ISCRUTE(_nprofile); */ /* SSCRUTE(_meshname); */ /* SSCRUTE(meshname); */ /* SSCRUTE(pflname); */ for (l=0;l<_nprofile;l++) { /* Si le maillage traité dans ce profil n'est pas celui par défaut : - Vérifie que le nom du champ pour ce maillage secondaire existe. - Initialise _fieldname au nom du champ qu'il faut traiter par la suite */ if (strcmp(_meshname,meshname)) { /* Lecture du type du champ, des noms des composantes et du nom de l'unité*/ _tmpcomp = (char*) malloc(ncomp*MED_SNAME_SIZE+1); EXIT_IF(_tmpcomp == NULL,NULL,NULL); _tmpunit = (char*) malloc(ncomp*MED_SNAME_SIZE+1); EXIT_IF(_tmpunit == NULL,NULL,NULL); /* Evite de passer les paramètres _tmpcomp,_tmpunit,_tmpdtunit,&_tmpncstp dans la fct MAJ_236...*/ ret = MEDfieldInfoByName(fid,nomcha, _tmpmeshname,&_tmplocal,&_tmptypcha,_tmpcomp,_tmpunit,_tmpdtunit,&_tmpncstp); MED_ERR_EXIT_IF(ret,MED_ERR_ACCESS,MED_ERR_FIELD,nomcha); /*Ne pose pas de problème de taille de chaîne car MED_NAME_SIZE a doublé en 3.0 */ _fieldname[_fieldnamelen]='_';strcpy(&_fieldname[_fieldnamelen+1],_meshname); MAJ_version_num(fid,3,0,8); /*Sauvegarde du champ initial dans _pathtmp*/ EXIT_IF( H5Gmove(fid, _pathi, _pathtmp ) < 0,"Switch to ",_pathtmp); EXIT_IF( H5Gmove(fid, _pathf, _pathi ) < 0 ,"Switch to ",_pathi); MED_ERR_EXIT_IF( MEDfieldCr(fid,_fieldname, _tmptypcha,ncomp,_tmpcomp,_tmpunit,_tmpdtunit,_meshname ) < 0, MED_ERR_CREATE,MED_ERR_FIELD,_fieldname); /*Rétablissement des chemins d'accès au champ initial et au champ cible temporaire*/ EXIT_IF( H5Gmove(fid, _pathi , _pathf ) < 0,"Switch to ",_pathf); EXIT_IF( H5Gmove(fid, _pathtmp, _pathi ) < 0,"Switch to ",_pathi); MAJ_version_num(fid,2,3,6); free(_tmpcomp); free(_tmpunit); } else { strcpy(_fieldname,nomcha); } /* SSCRUTE(_fieldname); */ if ( (nval = MEDfield23nValueWithProfile(fid, nomcha, numdt, numo, entite, type_geo[k],_meshname, l+1, MED_COMPACT_PFLMODE, pflname,&pflsize, locname, &ngauss) ) < 0 ) { MESSAGE("Erreur a la lecture du nombre de valeurs du champ : "); SSCRUTE(nomcha);ISCRUTE(numdt);ISCRUTE(numo);SSCRUTE(_meshname); ISCRUTE_int(entite);ISCRUTE_int(type_geo[k]); ret = -1; continue; }; /* ISCRUTE(nval); */ /* printf("\n +Pas de Temps n."IFORMAT" (%f) [%s], n. d'ordre "IFORMAT", avec "IFORMAT" valeur(s) par entité.\n",numdt,dt,dt_unit,numo,ngauss); */ /* printf("\t- Il y a "IFORMAT" entités qui portent des valeurs en mode %i. Chaque entite %s\ */ /* de type geometrique %s associes au profile |%s| a "IFORMAT" valeurs associées \n", */ /* nval,MED_COMPACT_PFLMODE,AFF_ENT[(int)entite],AFF[k],pflname,ngauss); */ /* printf("\t- Le maillage associé est |%s|\n",_meshname); */ /*Lecture des valeurs du champ */ if (typcha == MED_FLOAT64) { valr = (med_float*) calloc(ncomp*nval*ngauss,sizeof(med_float)); EXIT_IF(valr == NULL,NULL,NULL); if (MEDfield23ValueWithProfileRd(fid, nomcha, numdt,numo, entite,type_geo[k],_meshname, MED_COMPACT_PFLMODE, pflname, MED_NO_INTERLACE,MED_ALL_CONSTITUENT, (unsigned char*) valr) < 0 ) { MESSAGE("Erreur a la lecture des valeurs du champ : "); SSCRUTE(nomcha);ISCRUTE_int(entite);ISCRUTE_int(type_geo[k]); ISCRUTE(numdt);ISCRUTE(numo); ret = -1; } _val = (unsigned char*) valr; } else { vale = (med_int*) calloc(ncomp*nval*ngauss,sizeof(med_int)); EXIT_IF(vale == NULL,NULL,NULL); if (MEDfield23ValueWithProfileRd(fid, nomcha, numdt,numo, entite,type_geo[k],_meshname, MED_COMPACT_PFLMODE, pflname, MED_NO_INTERLACE,MED_ALL_CONSTITUENT, (unsigned char*) vale) < 0 ) { MESSAGE("Erreur a la lecture des valeurs du champ : "); SSCRUTE(nomcha);ISCRUTE_int(entite);ISCRUTE_int(type_geo[k]); ISCRUTE(numdt);ISCRUTE(numo); ret = -1; } _val = (unsigned char*) vale; } /* Ecriture du champ destination */ MAJ_version_num(fid,3,0,8); /*Sauvegarde du champ initial dans _pathtmp*/ EXIT_IF( H5Gmove(fid, _pathi, _pathtmp ) < 0,"Switch to ",_pathtmp); _groupexist=H5Lexists( fid, _pathf, H5P_DEFAULT ); EXIT_IF(!_groupexist,"Le champ devrait déjà existé",_pathf); /*Déplacement du champ cible temporaire au chemin des champs écrits par MED */ if (_groupexist ) { EXIT_IF( (H5Gmove(fid, _pathf, _pathi ) < 0) ,"Switch to ",_pathi); } /*Ecriture du champ cible au nouveau format*/ /* ISCRUTE(nval); */ MED_ERR_EXIT_IF( MEDfieldValueWithProfileWr(fid, _fieldname, numdt, numo, dt, entite,type_geo[k], MED_COMPACT_PFLMODE, pflname, locname, MED_NO_INTERLACE, MED_ALL_CONSTITUENT, nval, _val) < 0, MED_ERR_WRITE,MED_ERR_FIELD,_fieldname); free(_val); /*Rétablissement des chemins d'accès au champ initial et au champ cible temporaire*/ EXIT_IF( H5Gmove(fid, _pathi , _pathf ) < 0,"Switch to ",_pathf); EXIT_IF( H5Gmove(fid, _pathtmp, _pathi ) < 0,"Switch to ",_pathi); MAJ_version_num(fid,2,3,6); /* if ( strlen(locname) ) */ /* printf("\t- Modèle de localisation des points de Gauss de nom |%s|\n",locname); */ /* if (entite == MED_NODE_ELEMENT) */ /* ngroup = (type_geo[k] % 100); */ /* else */ /* ngroup = ngauss; */ /* switch (MED_NO_INTERLACE) { */ /* case MED_FULL_INTERLACE : */ /* printf("\t- Valeurs :\n\t"); */ /* for (m=0;m<(nval*ngauss)/ngroup;m++) { */ /* printf("|"); */ /* for (n=0;n<ngroup*ncomp;n++) */ /* if (typcha == MED_FLOAT64) */ /* printf(" %f ",*(valr+(m*ngroup*ncomp)+n)); */ /* else */ /* printf(" "IFORMAT" ",*(vale+(m*ngroup*ncomp)+n)); */ /* } */ /* break; */ /* case MED_NO_INTERLACE : */ /* printf("\t- Valeurs :\n\t"); */ /* for (m=0;m<ncomp;m++) { */ /* printf("|"); */ /* for (n=0;n<(nval*ngauss);n++) */ /* if (typcha == MED_FLOAT64) */ /* printf(" %f ",*(valr+(m*nval)+n)); */ /* else */ /* printf(" "IFORMAT" ",*(vale+(m*nval)+n)); */ /* } */ /* break; */ /* } */ /* printf("|\n"); */ /* if (typcha == MED_FLOAT64) { */ /* if ( valr ) {free(valr);valr = NULL;}} */ /* else */ /* if (vale) { free(vale);vale = NULL; } */ /* if (strcmp(pflname,MED_NO_PROFILE) == 0 ) */ /* printf("\t- Profil : MED_NO_PROFILE\n"); */ /* else { */ /* if ( (pflsize = MEDprofileSizeByName(fid,pflname)) <0 ) { */ /* MESSAGE("Erreur a la lecture du nombre de valeurs du profil : "); */ /* SSCRUTE(pflname); */ /* ret = -1; continue; */ /* } */ /* printf("\t- Profil : |%s| de taille "IFORMAT"\n",pflname,pflsize); */ /* pflval = (med_int*) malloc(sizeof(med_int)*pflsize); */ /* EXIT_IF(pflval == NULL,NULL,NULL); */ /* if ( MEDprofileRd(fid,pflname,pflval) <0) { */ /* MESSAGE("Erreur a la lecture des valeurs du profil : "); */ /* SSCRUTE(pflname); */ /* ret = -1; */ /* } */ /* printf("\t"); */ /* for (m=0;m<pflsize;m++) printf(" "IFORMAT" ",*(pflval+m)); */ /* printf("\n"); */ /* free(pflval); */ /* } */ } } } } /* fin for sur les mailles*/ ret = 0; ERROR: return ret; }