forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExodusFormatter.C
81 lines (69 loc) · 2.08 KB
/
ExodusFormatter.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
// MOOSE includes
#include "ExodusFormatter.h"
#include "Parser.h"
#include "MooseApp.h"
#include "SystemInfo.h"
#include "CommandLine.h"
#include "ActionWarehouse.h"
#include "libmesh/exodusII.h"
// C++
#include <sstream>
#include <vector>
ExodusFormatter::ExodusFormatter() : InputFileFormatter(false) {}
void
ExodusFormatter::printInputFile(ActionWarehouse & wh)
{
_ss << "####################\n"
<< "# Created by MOOSE #\n"
<< "####################\n";
// Grab the command line arguments first
_ss << "### Command Line Arguments ###\n";
if (wh.mooseApp().commandLine())
{
for (const auto & arg : wh.mooseApp().commandLine()->getArguments())
_ss << " " << arg;
}
if (wh.mooseApp().getSystemInfo() != NULL)
{
_ss << "### Version Info ###\n" << wh.mooseApp().getSystemInfo()->getInfo() << "\n";
}
_ss << "### Input File ###" << std::endl;
wh.printInputFile(_ss);
}
void
ExodusFormatter::format()
{
std::string s;
_input_file_record.clear();
while (std::getline(_ss, s))
{
// MAX_LINE_LENGTH is from ExodusII
if (s.length() > MAX_LINE_LENGTH)
{
const std::string continuation("...");
const size_t cont_len = continuation.length();
size_t num_lines = s.length() / (MAX_LINE_LENGTH - cont_len) + 1;
std::string split_line;
for (size_t j = 0, l_begin = 0; j < num_lines; ++j, l_begin += MAX_LINE_LENGTH - cont_len)
{
size_t l_len = MAX_LINE_LENGTH - cont_len;
if (s.length() < l_begin + l_len)
l_len = s.length() - l_begin;
split_line = s.substr(l_begin, l_len);
if (l_begin + l_len != s.length())
split_line += continuation;
_input_file_record.push_back(split_line);
}
}
else
_input_file_record.push_back(s);
}
}