Arcane  4.2.3.0
Developer documentation
Loading...
Searching...
No Matches
ParamFile.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ParamFile.cc (C) 2000-2026 */
9/* */
10/* Reader of parameter files. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/launcher/internal/ParamFile.h"
15
16#include "arcane/launcher/ArcaneLauncher.h"
17
18#include "arcane/utils/PlatformUtils.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/CommandLineArguments.h"
21#include "arcane/utils/JSONReader.h"
22#include "arccore/common/ArcaNetReader.h"
23
24#include <iostream>
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
36{
37 public:
38
39 ArgsFill(CommandLineArguments& args)
40 : m_args(args)
41 {}
42
43 public:
44
45 void readFilePart(JSONValue file_part);
46 void readArcanePart(JSONValue arcane_part);
47 String name() const { return m_name; }
48
49 private:
50
52 StringBuilder m_name;
53};
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58void ParamFile::ArgsFill::
59readFilePart(const JSONValue file_part)
60{
61 const JSONValue dataset = file_part.child("name");
62 if (!dataset.isNull()) {
63 m_name += " -> \"";
64 m_name += dataset.valueAsStringView();
65 m_name += "\"";
66 }
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72void ParamFile::ArgsFill::
73readArcanePart(const JSONValue arcane_part)
74{
75 const JSONValue dataset = arcane_part.child("dataset");
76 if (!dataset.isNull()) {
77 m_args.addParameterLine(String::format("CaseDatasetFileName={0}", dataset.value()));
78 //std::cout << "Dataset : " << dataset.value() << std::endl;
79 }
80
81 const JSONValue arcane_params = arcane_part.child("options");
82
83 if (!arcane_params.isNull()) {
84 const JSONKeyValueList params = arcane_params.keyValueChildren();
85
86 for (auto elem : params) {
87 m_args.addParameterLine(String::format("{0}={1}", elem.name(), elem.value().valueAsStringView()));
88 // std::cout << "Elem : " << elem.name() << " -- val : " << elem.value().valueAsStringView() << std::endl;
89 }
90 }
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99void ParamFile::
100editParams(const String& param_file_name, const String& variation)
101{
102 CommandLineArguments args = ArcaneLauncher::applicationInfo().commandLineArguments();
103
104 JSONDocument json_doc;
105 {
106 UniqueArray<Byte> bytes;
107
108 if (platform::readAllFile(param_file_name, false, bytes)) {
109 ARCANE_FATAL("Param file not available");
110 }
111
112 json_doc.parse(bytes, param_file_name, (JSONDocument::ParseCommentsFlag | JSONDocument::ParseNumbersAsStringsFlag));
113 }
114
115 ArcaNetReader reader(json_doc.root());
116 reader.init(variation, "arcane");
117 reader.read();
118
119 ArgsFill args_fill(args);
120
121 ArrayView<JSONValue> json_values = reader.jsonValues();
122 for (JSONValue elem : json_values) {
123 args_fill.readFilePart(reader.extractFilePart(elem));
124 args_fill.readArcanePart(reader.extractProgPart(elem));
125 }
126
127 std::cout << "ArcaNet path: " << args_fill.name() << std::endl;
128
129 if (reader.computePath()) {
130 std::cout << "ArcaNet full path: " << reader.path() << std::endl;
131 std::cout << "ArcaNet config part readed: " << reader.configPartName() << std::endl;
132 }
133
134 // StringList names;
135 // StringList values;
136 // args.fillParameters(names, values);
137 // for (Integer i = 0, n = names.count(); i < n; ++i) {
138 // std::cout << "Final Elem : " << names[i] << " -- val : " << values[i] << std::endl;
139 // }
140
142}
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147} // End namespace Arcane
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
void setCommandLineArguments(const CommandLineArguments &args)
Sets the command line arguments.
const CommandLineArguments & commandLineArguments() const
Command line arguments.
static ApplicationInfo & applicationInfo()
Application information.
@ ParseNumbersAsStringsFlag
Parse all numbers (ints/doubles) as strings.
@ ParseCommentsFlag
Allow one-line (//) and multi-line (/‍**/) comments.
StringView valueAsStringView() const
Value in StringView format. The string is empty if 'null()' is true.
bool isNull() const
True if the value is of 'null' type.
JSONValue child(StringView name) const
Child value with name name. Returns a null value if not found.
Unicode character string constructor.
bool readAllFile(StringView filename, bool is_binary, ByteArray &out_bytes)
Reads the content of a file and stores it in out_bytes.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --