+ INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
+
+ int option = 1 ;
+ if ( _PublisMeshIN != 0 ) option = 2 ;
+ HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
+
+// Valeurs par defaut des filtrages
+ myCase->SetPyram(0);
+
+ return HOMARD::HOMARD_Cas::_duplicate(myCase);
+}
+//=============================================================================
+HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
+//
+// nomCas : nom du cas a creer
+// DirNameStart : nom du répertoire contenant l'iteration de reprise
+//
+{
+ MESSAGE ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
+ std::string nomDirWork = getenv("PWD") ;
+ int codret ;
+
+ // A. Decodage du point de reprise
+ // A.1. Controle du répertoire de depart de l'iteration
+ codret = CHDIR(DirNameStart) ;
+ if ( codret != 0 )
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "The directory of the iteration does not exist.";
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ };
+ // A.2. Reperage des fichiers du répertoire de reprise
+ std::string file_configuration = "" ;
+ std::string file_maillage_homard = "" ;
+ int bilan ;
+#ifndef WIN32
+ DIR *dp;
+ struct dirent *dirp;
+ dp = opendir(DirNameStart);
+ while ( (dirp = readdir(dp)) != NULL )
+ {
+ std::string file_name(dirp->d_name);
+// MESSAGE ( file_name );
+ bilan = file_name.find("HOMARD.Configuration.") ;
+ if ( bilan != string::npos ) { file_configuration = file_name ; }
+ bilan = file_name.find("maill.") ;
+ if ( bilan != string::npos )
+ {
+ bilan = file_name.find(".hom.med") ;
+ if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
+ }
+ }
+ closedir(dp);
+#else
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATA ffd;
+ hFind = FindFirstFile(DirNameStart, &ffd);
+ if (INVALID_HANDLE_VALUE != hFind) {
+ while (FindNextFile(hFind, &ffd) != 0) {
+ if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
+ std::string file_name(ffd.cFileName);
+ bilan = file_name.find("HOMARD.Configuration.") ;
+ if ( bilan != string::npos ) { file_configuration = file_name ; }
+ bilan = file_name.find("maill.") ;
+ if ( bilan != string::npos )
+ {
+ bilan = file_name.find(".hom.med") ;
+ if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
+ }
+ }
+ FindClose(hFind);
+ }
+#endif
+ MESSAGE ( "==> file_configuration : " << file_configuration ) ;
+ MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
+ // A.3. Controle
+ if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ std::string text ;
+ if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
+ else { text = "The HOMARD mesh file cannot be found." ; }
+ es.text = CORBA::string_dup(text.c_str());
+ throw SALOME::SALOME_Exception(es);
+ }
+
+ // B. Lecture du fichier de configuration
+ // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
+ int NumeIter ;
+ int TypeExt = 0 ;
+ int TypeConf = 0 ;
+ int Pyram = 0 ;
+ char* MeshName ;
+ char* MeshFile ;
+ // le constructeur de ifstream permet d'ouvrir un fichier en lecture
+ std::ifstream fichier( file_configuration.c_str() );
+ if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
+ {
+ std::string ligne; // variable contenant chaque ligne lue
+ std::string mot_cle;
+ std::string argument;
+ int decalage;
+ // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
+ while ( std::getline( fichier, ligne ) )
+ {
+ // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
+ std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
+ ligne_bis >> mot_cle ;
+ // B.2. Des valeurs entieres : le second bloc de la ligne
+ if ( mot_cle == "NumeIter" )
+ {
+ ligne_bis >> NumeIter ;
+ NumeIter += 1 ;
+ }
+ // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
+ else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
+ {
+ ligne_bis >> argument ;
+
+ if ( mot_cle == "TypeConf" )
+ {
+ if ( argument == "conforme" ) { TypeConf = 1 ; }
+ else if ( argument == "non_conforme_1_noeud" ) { TypeConf = 2 ; }
+ else if ( argument == "non_conforme_1_arete" ) { TypeConf = 3 ; }
+ else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
+ }
+ else if ( mot_cle == "TypeElem" )
+ {
+ if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
+ else if ( argument == "HOMARD" ) { Pyram = 0 ; }
+ }
+ }
+ // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
+ // il faut les supprimer
+ else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
+ {
+ ligne_bis >> argument ;
+ if ( argument[0] == '"' ) { decalage = 1 ; }
+ else { decalage = 0 ; }
+ size_t size = argument.size() + 1 - 2*decalage ;
+
+ if ( mot_cle == "CCNoMNP1" )
+ {
+ MeshName = new char[ size ];
+ strncpy( MeshName, argument.c_str()+decalage, size );
+ MeshName[size-1] = '\0' ;
+ }
+ else if ( mot_cle == "CCMaiNP1" )
+ {
+ MeshFile = new char[ size ];
+ strncpy( MeshFile, argument.c_str()+decalage, size );
+ MeshFile[size-1] = '\0' ;
+ }
+ }
+ }
+ MESSAGE ( "==> TypeConf : " << TypeConf ) ;
+ MESSAGE ( "==> MeshName : " << MeshName ) ;
+ MESSAGE ( "==> MeshFile : " << MeshFile ) ;
+ MESSAGE ( "==> NumeIter : " << NumeIter ) ;
+ MESSAGE ( "==> Pyram : " << Pyram ) ;
+ }
+ else
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ std::string text = "The configuration file cannot be read." ;
+ es.text = CORBA::string_dup(text.c_str());
+ throw SALOME::SALOME_Exception(es);
+ }
+
+ // C. Creation effective du cas
+
+ int option = 1 ;
+ if ( _PublisMeshIN != 0 ) option = 2 ;
+ HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
+
+ // D. Parametrages lus dans le fichier de configuration
+
+ myCase->SetConfType (TypeConf) ;
+ myCase->SetExtType (TypeExt) ;
+ myCase->SetPyram (Pyram) ;
+
+ // E. Copie du fichier de maillage homard
+ // E.1. Répertoire associe au cas
+ char* nomDirCase = myCase->GetDirName() ;
+ // E.2. Répertoire associe a l'iteration de ce cas
+ char* IterName ;
+ IterName = myCase->GetIter0Name() ;
+ HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
+ char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
+ Iter->SetDirNameLoc(nomDirIter);
+ std::string nomDirIterTotal ;
+ nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
+#ifndef WIN32
+ if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
+#else
+ if (_mkdir(nomDirIterTotal.c_str()) != 0)
+#endif
+ {
+ MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ std::string text = "The directory for the computation cannot be created." ;
+ es.text = CORBA::string_dup(text.c_str());
+ throw SALOME::SALOME_Exception(es);
+ }
+ // E.3. Copie du maillage HOMARD au format MED
+ codret = CHDIR(DirNameStart) ;
+ std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
+ MESSAGE ( "commande : " << commande ) ;
+ codret = system(commande.c_str()) ;
+ MESSAGE ( "codret : " << codret ) ;
+ if ( codret != 0 )
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "The starting point for the case cannot be copied into the working directory.";
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ };
+
+ // F. Menage
+
+ delete[] MeshName ;
+ delete[] MeshFile ;
+
+ CHDIR(nomDirWork.c_str());
+ return HOMARD::HOMARD_Cas::_duplicate(myCase);
+}
+//=============================================================================
+HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
+//
+// nomCas : nom du cas a creer
+// DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
+//
+{
+ MESSAGE ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
+
+ std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
+
+ DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
+ HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
+
+ return HOMARD::HOMARD_Cas::_duplicate(myCase);
+}
+//=============================================================================
+HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
+//
+// nomCas : nom du cas a creer
+// DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
+// Number : numero de l'iteration de depart
+//
+{
+ MESSAGE ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
+ if ( Number < 0 )
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "The number of iteration must be positive.";
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ };
+
+ std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
+
+ DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
+ HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
+
+ return HOMARD::HOMARD_Cas::_duplicate(myCase);
+}
+//=============================================================================
+std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
+//
+// Retourne le nom du répertoire ou se trouve l'iteration voulue.
+// DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
+// Number : numero de l'iteration de depart ou -1 si on cherche la derniere
+//
+{
+ MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
+ std::string nomDirWork = getenv("PWD") ;
+ std::string DirNameStartIter ;
+ int codret ;
+ int NumeIterMax = -1 ;
+
+ // A.1. Controle du répertoire de depart du cas
+ codret = CHDIR(DirNameStart) ;
+ if ( codret != 0 )
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ es.text = "The directory of the case for the pursuit does not exist.";
+ throw SALOME::SALOME_Exception(es);
+ return 0;
+ };
+ // A.2. Reperage des sous-répertoire du répertoire de reprise
+ bool existe = false ;
+#ifndef WIN32
+ DIR *dp;
+ struct dirent *dirp;
+ dp = opendir(DirNameStart);
+ while ( (dirp = readdir(dp)) != NULL ) {
+ std::string DirName_1(dirp->d_name);
+#else
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATA ffd;
+ hFind = FindFirstFile(DirNameStart, &ffd);
+ if (INVALID_HANDLE_VALUE != hFind) {
+ while (FindNextFile(hFind, &ffd) != 0) {
+ std::string DirName_1 = "";
+ if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ DirName_1 = std::string(ffd.cFileName);
+ }
+#endif
+ if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
+ {
+ if ( CHDIR(DirName_1.c_str()) == 0 )
+ {
+// On cherche le fichier de configuration dans ce sous-répertoire
+ codret = CHDIR(DirNameStart);
+#ifndef WIN32
+ DIR *dp_1;
+ struct dirent *dirp_1;
+ dp_1 = opendir(DirName_1.c_str()) ;
+ while ( (dirp_1 = readdir(dp_1)) != NULL )
+ {
+ std::string file_name_1(dirp_1->d_name);
+#else
+ HANDLE hFind1 = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATA ffd1;
+ hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
+ while (FindNextFile(hFind1, &ffd1) != 0)
+ {
+ if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
+ std::string file_name_1(ffd1.cFileName);
+#endif
+ int bilan = file_name_1.find("HOMARD.Configuration.") ;
+ if ( bilan != string::npos )
+ {
+ // Decodage du fichier pour trouver le numero d'iteration
+ CHDIR(DirName_1.c_str()) ;
+
+ std::ifstream fichier( file_name_1.c_str() );
+ if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
+ {
+ int NumeIter ;
+ std::string ligne; // variable contenant chaque ligne lue
+ std::string mot_cle;
+ // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
+ while ( std::getline( fichier, ligne ) )
+ {
+ // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
+ std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
+ ligne_bis >> mot_cle ;
+ if ( mot_cle == "NumeIter" )
+ {
+ ligne_bis >> NumeIter ;
+ NumeIter += 1 ;
+// MESSAGE ( "==> NumeIter : " << NumeIter ) ;
+ if ( Number == - 1 )
+ {
+ if ( NumeIter >= NumeIterMax )
+ {
+ NumeIterMax = NumeIter ;
+ DirNameStartIter = DirName_1 ;
+ }
+ }
+ else
+ {
+ if ( NumeIter == Number )
+ {
+ DirNameStartIter = DirName_1 ;
+ existe = true ;
+ break ;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ SALOME::ExceptionStruct es;
+ es.type = SALOME::BAD_PARAM;
+ std::string text = "The configuration file cannot be read." ;
+ es.text = CORBA::string_dup(text.c_str());
+ throw SALOME::SALOME_Exception(es);
+ }
+ CHDIR(DirNameStart) ;
+ }
+ if ( existe ) { break ; }
+ }
+#ifndef WIN32
+ closedir(dp_1);
+#else
+ FindClose(hFind1);
+#endif
+ if ( existe ) { break ; }
+ }
+ }
+ }
+#ifndef WIN32
+ closedir(dp);
+#else
+ FindClose(hFind);
+#endif
+ CHDIR(nomDirWork.c_str());