PSCF v1.5.0
rFieldIo.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2026, David Morse (morse012@um.edu) and co-authors
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "rFieldIo.h"
9
10namespace Pscf {
11
12 /*
13 * Read the number of basis functions from a field file header.
14 */
15 int readNBasis(std::istream& in)
16 {
17
18 // Read the label, which can be N_star or N_basis
19 std::string label;
20 in >> label;
21 UTIL_ASSERT(in.good());
22 if (label != "N_star" && label != "N_basis") {
23 std::string msg = "\n";
24 msg += "Error reading field file:\n";
25 msg += "Expected N_basis or N_star, but found [";
26 msg += label;
27 msg += "]";
28 UTIL_THROW(msg.c_str());
29 }
30
31 // Read the value of nBasis
32 int nBasis;
33 in >> nBasis;
34 UTIL_CHECK(in.good());
35 UTIL_CHECK(nBasis > 0);
36
37 return nBasis;
38 }
39
40 /*
41 * Write the number of basis functions to a field file header.
42 */
43 void writeNBasis(std::ostream& out, int nBasis)
44 {
45 out << "N_basis " << std::endl
46 << " " << nBasis << std::endl;
47 }
48
49} // namespace Pscf
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:49
#define UTIL_ASSERT(condition)
Assertion macro suitable for debugging serial or parallel code.
Definition global.h:75
void writeNBasis(std::ostream &out, int nBasis)
Write the number of basis functions to a basis field file header.
Definition rFieldIo.cpp:43
int readNBasis(std::istream &in)
Read the number of basis functions from a basis field file header.
Definition rFieldIo.cpp:15
PSCF package top-level namespace.