NAPISD
PAHdb website C++ backend
Loading...
Searching...
No Matches
FileOutput.cpp
1#include "FileOutput.h"
2
3FileOutput::FileOutput(std::string_view filename) : _filename(filename) {}
4
5FileOutput::~FileOutput() {
6
7 if (_ofstr.is_open()) {
8
9 _ofstr.close();
10 }
11}
12
13void FileOutput::writeTableHeaderToDisk(
14 const std::vector<std::string> &header) {
15
16 try {
17
18 if (!_ofstr.is_open()) {
19
20 _ofstr.open(_filename.c_str(), std::ios::out);
21 }
22
23 for (const auto &record : header) {
24
25 _ofstr << record << '\n';
26 }
27
28 _ofstr.flush();
29 } catch (const std::exception &e) {
30
31 _ofstr.close();
32
33 throw(Exception(e.what()));
34 }
35}
36
37void FileOutput::writeTableToDisk(
38 const std::vector<std::vector<double>> &table) {
39
40 try {
41
42 if (!_ofstr.is_open()) {
43
44 _ofstr.open(_filename.c_str(), std::ios::out);
45 }
46
47 _ofstr.setf(std::ios::right);
48
49 _ofstr << std::setprecision(5) << std::showpoint << std::scientific;
50
51 size_t nj = table.size();
52
53 size_t ni = table.begin()->size();
54
55 try {
56
57 for (size_t i = 0; i < ni; i++) {
58
59 for (size_t j = 0; j < nj - 1; j++) {
60
61 _ofstr << std::setw(12) << table.at(j).at(i) << '\t';
62 }
63
64 _ofstr << std::setw(12) << table.at(nj - 1).at(i) << '\n';
65 }
66
67 _ofstr.flush();
68 } catch (const std::exception &e) {
69
70 _ofstr.close();
71
72 throw(Exception(e.what()));
73 }
74 } catch (const std::ofstream::failure &e) {
75
76 throw(Exception(e.what()));
77 }
78}

Since FY2019 the NASA Ames PAH IR Spectroscopic Database is being supported through a directed Work Package at NASA Ames titled: "Laboratory Astrophysics - The NASA Ames PAH IR Spectroscopic Database".
Since FY2023 the NASA Ames PAH IR Spectroscopic Database is being supported through the Laboratory Astrophysics Rd 2 directed Work Package at NASA Ames.
© Copyright 2021-2025, Christiaan Boersma