-
Notifications
You must be signed in to change notification settings - Fork 1
brownjm/Parameters
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Copyright (C) 2015 Jeffrey M Brown This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with This program. If not, see <http://www.gnu.org/licenses/>. The Parameters class provides a simple way to manage input files commonly used in simulations. Parameter files contain key=value pairs that can be grouped under sections, denoted by square braces: [section]. Comments are also allowed. Any text after a hash symbol # is ignored. An example input file would contain: # this is a comment [time] N = 1024 # another comment dt = 0.1 [space] N = 256 dx = 1e-6 [output] filename = mydata.dat These pairs will be stored in a map with each section name prepended to the keys. The above input file would be stored in a std::map as: time/N : 1024 time/dt : 0.1 space/N : 256 space/dx : 1e-6 output/filename : mydata.dat To read an input file, create a parameters object: Parameters::Parameters params(filename); To use a value associated with a particular key, first create a variable in your program and then call the get member function: double dt; // dt = 0.0 params.get("time/dt", dt) // dt = 0.1 Parameters uses templates and stringstreams in order to decipher the type. You can also get a Parameters object of a particular section using: Parameters::Parameters p = params.getSection("space")
About
A simple tool for reading parameters from an input file into a C++ program - useful for simulations!
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published