PSCF v1.3
fieldIoUtil.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "fieldIoUtil.h"
9
10namespace Pscf {
11namespace Prdc {
12
13 /*
14 * Read the number of basis functions from a field file header.
15 */
16 int readNBasis(std::istream& in)
17 {
18
19 // Read the label, which can be N_star or N_basis
20 std::string label;
21 in >> label;
22 UTIL_ASSERT(in.good());
23 if (label != "N_star" && label != "N_basis") {
24 std::string msg = "\n";
25 msg += "Error reading field file:\n";
26 msg += "Expected N_basis or N_star, but found [";
27 msg += label;
28 msg += "]";
29 UTIL_THROW(msg.c_str());
30 }
31
32 // Read the value of nBasis
33 int nBasis;
34 in >> nBasis;
35 UTIL_CHECK(in.good());
36 UTIL_CHECK(nBasis > 0);
37
38 return nBasis;
39 }
40
41 /*
42 * Write the number of basis functions to a field file header.
43 */
44 void writeNBasis(std::ostream& out, int nBasis)
45 {
46 out << "N_basis " << std::endl
47 << " " << nBasis << std::endl;
48 }
49
50} // namespace Prdc
51} // 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.
int readNBasis(std::istream &in)
Read the number of basis functions from a basis field file header.
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1