00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MESGERR
00020 #define MESGERR 1
00021 #endif
00022
00023
00024 #include "med_config.h"
00025 #include "med_outils.h"
00026 #include <string.h>
00027
00028
00029
00030
00031
00032 #include "med21.h"
00033 #include "med_hdfi21.h"
00034 #include "MAJ_21_22.h"
00035
00036 void MAJ_21_22_familles_maillage(med_idt mid)
00037 {
00038 med_idt fid, gid;
00039 char *nouvelle_chaine;
00040 int n;
00041 med_size dimd[1];
00042 med_err ret;
00043 int i;
00044 char chemin[MED_TAILLE_FAS+2*MED_TAILLE_NOM+1];
00045 char nom[MED_TAILLE_NOM+1];
00046 char *noeuds, *elements;
00047 int nnoeuds = 0;
00048 int nelements = 0;
00049 med_int numero;
00050 char *groupe_noeuds = "NOEUD";
00051 char *groupe_elements = "ELEME";
00052 char *nom_famille_zero = "FAMILLE_ZERO";
00053 char famille0[MED_TAILLE_NOM+1]="";
00054 med_int zero=0;
00055 int *index_noeuds, *index_elements;
00056 char stockage[MED_TAILLE_DESC]="";
00057 med_float *valr;
00058
00059
00060 fid = _MEDdatagroupOuvrir(mid,"FAS");
00061 if (fid < 0) {
00062 MESSAGE("Le datagroup contenant les familles n'existe pas, medimport le crée");
00063 fid = _MEDdatagroupCreer(mid,"FAS");
00064 EXIT_IF(fid < 0,"Creation du groupe HDF des familles",NULL);
00065 }
00066 n = 0;
00067 _MEDnObjets(fid,".",&n);
00068 EXIT_IF(n < 0,"Lecture du nombre de famille",NULL);
00069
00070 noeuds = (char *) malloc(n*MED_TAILLE_NOM+1);
00071 EXIT_IF(noeuds == NULL,NULL,NULL);
00072 index_noeuds = (int *) malloc(sizeof(int)*(n+1));
00073 EXIT_IF(index_noeuds == NULL,NULL,NULL);
00074 elements = (char *) malloc(n*MED_TAILLE_NOM+1);
00075 EXIT_IF(elements == NULL,NULL,NULL);
00076 index_elements = (int *) malloc(sizeof(int)*(n+1));
00077 EXIT_IF(index_elements == NULL,NULL,NULL);
00078
00079
00080
00081 for (i=0;i<n;i++) {
00082 ret = _MEDobjetIdentifier(fid,".",i,nom);
00083 EXIT_IF(ret < 0,"Identification d'une famille",NULL);
00084
00085
00086 gid = _MEDdatagroupOuvrir(fid,nom);
00087 EXIT_IF(gid < 0,"Ouverture de l'accès à la famille",nom);
00088
00089
00090 ret = _MEDattrEntierLire(gid,(char *)(MED_NOM_NUM),&numero);
00091 EXIT_IF(ret < 0,"Lecture du numéro de la famille",nom);
00092
00093
00094 ret = _MEDdatagroupFermer(gid);
00095 EXIT_IF(ret < 0,"Fermeture de l'accès à la famille",nom);
00096
00097 if (numero == 0)
00098 strcpy(famille0,nom);
00099
00100 if (numero < 0) {
00101 if (nelements == 0) {
00102 *(index_elements) = 0;
00103 strcpy(elements,nom);
00104 }
00105 else
00106 strcat(elements,nom);
00107 nelements ++;
00108 *(index_elements+nelements) = strlen(nom) + *(index_elements+nelements-1);
00109 }
00110
00111 if (numero > 0) {
00112 if (nnoeuds == 0) {
00113 strcpy(noeuds,nom);
00114 *(index_noeuds) = 0;
00115 }
00116 else
00117 strcat(noeuds,nom);
00118 nnoeuds++;
00119 *(index_noeuds+nnoeuds) = strlen(nom) + *(index_noeuds+nnoeuds-1);
00120 }
00121 }
00122
00123
00124 if ( strlen(famille0) ) {
00125 ret = H5Gmove(fid,famille0,nom_famille_zero);
00126 EXIT_IF(ret < 0,"Normalisation de la famille ZERO",NULL);
00127 } else {
00128 MESSAGE("La famille zéro n'existe pas, medimport la crée.");
00129 gid = _MEDdatagroupCreer(fid,nom_famille_zero);
00130 EXIT_IF(gid < 0,"Creation de la famille zéro",NULL);
00131 ret = _MEDattrEntierEcrire(gid,(char *)(MED_NOM_NUM),&zero);
00132 EXIT_IF(ret < 0,"Ecriture du numéro de la famille zéro",nom_famille_zero);
00133 ret = _MEDdatagroupFermer(gid);
00134 EXIT_IF(ret < 0,"Fermeture de l'accès à la famille zéro",nom);
00135 }
00136
00137
00138 gid = _MEDdatagroupCreer(fid,groupe_noeuds);
00139 EXIT_IF(gid < 0,"Creation du grupe HDF pour les familles de noeuds",NULL);
00140 ret = _MEDdatagroupFermer(gid);
00141 EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles de noeuds",NULL);
00142 gid = _MEDdatagroupCreer(fid,groupe_elements);
00143 EXIT_IF(gid < 0,"Creation du groupe HDF pour les familles d'éléments",NULL);
00144 ret = _MEDdatagroupFermer(gid);
00145 EXIT_IF(ret < 0,"Fermeture du groupe HDF pour les familles d'éléments",NULL);
00146
00147
00148
00149 for (i=0;i<nnoeuds;i++) {
00150 strncpy(nom,noeuds+*(index_noeuds+i),*(index_noeuds+i+1)-*(index_noeuds+i));
00151 nom[*(index_noeuds+i+1)-*(index_noeuds+i)] = '\0';
00152 strcpy(stockage,groupe_noeuds);
00153 strcat(stockage,"/");
00154 strcat(stockage,nom);
00155 ret = H5Gmove(fid,nom,stockage);
00156 EXIT_IF(ret < 0,"Normalisation de la famille",nom);
00157 }
00158
00159 for (i=0;i<nelements;i++) {
00160 strncpy(nom,elements+*(index_elements+i),*(index_elements+i+1)-*(index_elements+i));
00161 nom[*(index_elements+i+1)-*(index_elements+i)] = '\0';
00162 strcpy(stockage,groupe_elements);
00163 strcat(stockage,"/");
00164 strcat(stockage,nom);
00165 ret = H5Gmove(fid,nom,stockage);
00166 EXIT_IF(ret < 0,"Normalisation de la famille",nom);
00167 }
00168
00169
00170 free(noeuds);
00171 free(index_noeuds);
00172 free(elements);
00173 free(index_elements);
00174
00175
00176 ret = _MEDdatagroupFermer(fid);
00177 EXIT_IF(ret < 0,"Fermeture du groupe HDF 'FAS'",NULL);
00178 }