Debian Codegraph @

packages/nox/src-loca/src-epetra/continuation-manager/IOContFileUtils.C

raw
1 // @HEADER
2 // *****************************************************************************
3 // LOCA: Library of Continuation Algorithms Package
4 //
5 // Copyright 2001-2005 NTESS and the LOCA contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include "IOContFileUtils.H"
11
12 #include <fstream>
13 #include <iostream>
14 #include <sstream>
15
16 using namespace std;
17
18 bool WriteHeaderToContFile( const std::string & fileName,
19 const Teuchos::ParameterList & fileParams )
20 {
21 // The file to open
22 std::ofstream oFile(fileName.c_str());
23
24 // Writing the header
25 oFile << "#" << setw(6) << "ID";
26
27 // Looping on the parameters
28 Teuchos::ParameterList::ConstIterator i;
29 for (i = fileParams.begin(); i !=fileParams.end(); ++i)
30 oFile << setw(15) << fileParams.name(i);
31 oFile << std::endl;
32
33 // Closing
34 oFile.close();
35
36 return true;
37 }
38
39 bool UpdateContFile( const std::string & fileName,
40 const int & idStep,
41 const Teuchos::ParameterList & fileParams )
42 {
43
44 // The file to open
45 std::ofstream oFile(fileName.c_str(), ios_base::app);
46
47 // Writing the id
48 oFile << scientific << setw(7) << idStep;
49
50 // Looping on the parameters
51 Teuchos::ParameterList::ConstIterator i;
52 for (i = fileParams.begin(); i !=fileParams.end(); ++i)
53 oFile << scientific << setw(15) << fileParams.entry(i);
54 oFile << std::endl;
55
56 // Closing
57 oFile.close();
58
59 return true;
60 }
61
62 bool RestartContFile( const std::string & fileName, const int & idStep )
63 {
64 // Copying the continuation in a backup file
65 std::string fileNameBak = fileName + ".bak";
66 std::string command = "cp " + fileName + " " + fileNameBak;
67 TEUCHOS_ASSERT_EQUALITY(0, system(command.c_str()));
68
69 // String of the line to cut from
70 std::ostringstream os;
71 os << idStep + 1;
72 std::string lineNumber = os.str();
73
74 // Cutting the file
75 command = "sed '" + lineNumber + ",$ d' " + fileNameBak + " > " + fileName;
76 TEUCHOS_ASSERT_EQUALITY(0, system(command.c_str()));
77
78 return true;
79 }
80
81 bool TouchContFileParameters( Teuchos::ParameterList & fileParams )
82 {
83 // Either int or double type
84
85 // Looping the list
86 Teuchos::ParameterList::ConstIterator i;
87 for (i = fileParams.begin(); i !=fileParams.end(); ++i) {
88
89 if (fileParams.isType<int>(fileParams.name(i)))
90 fileParams.get<int>(fileParams.name(i));
91
92 if (fileParams.isType<double>(fileParams.name(i)))
93 fileParams.get<double>(fileParams.name(i));
94 }
95
96 return true;
97 }