write_named_series.cc 3.1 KB
Newer Older
1
/*! \file write_named_series.cc
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 * \brief write named series to output file (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * \author Thomas Forbriger
 * \date 06/02/2019
 * 
 * write named series to output file (implementation)
 * 
 * Copyright (c) 2019 by Thomas Forbriger (BFO Schiltach) 
 *
 * ----
 * 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 2 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/>.
 * ----
 *
 * REVISIONS and CHANGES 
 *  - 06/02/2019   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define TF_WRITE_NAME_SERIES_CC_VERSION \
  "TF_WRITE_NAME_SERIES_CC   V1.0"

#include "croposp.h"
#include<iostream>
#include<fstream>

using std::cout;
using std::endl;

namespace croposp {

  void write_named_series(const std::string& filename,
                          const std::string& comment,
                          psd::TDseries f,
                          const TNamedSeriesVector& nsv,
                          const bool& verbose,
                          const bool& overwrite)
  {
    if (verbose)
    {
      cout << endl
        << "output to file " << filename << ":" << endl
        << comment << endl;
    }
    if (!overwrite)
    {
      std::ifstream file(filename.c_str(), std::ios_base::in);
      TFXX_assert((!file.good()),"ERROR: output file exists!");
    }
    TFXX_assert(nsv.size()>0, "data container is empty");
    std::ofstream os(filename.c_str());
    os << "# " << CROPOSP_VERSION << endl;
    os << "# " << comment << endl;
    for (unsigned int i=0; i<nsv.size(); ++i)
    {
      unsigned int fi=i+1;
      os << "# #" << fi << ": " << nsv[i].label << endl;
      TFXX_assert(nsv[i].series.size()==f.size(),
                  "series passed to output function are inconsistent")
    }
    // set first index to 0 - just in case
    f.shift(-f.first());
    unsigned int nsamples=nsv[0].series.size();
    for (unsigned int i=0; i<nsamples; ++i)
    {
      os << f(i);
      for (unsigned int j=0; j<nsv.size(); ++j)
      {
        const psd::TDseries::Tcoc& s=nsv[j].series;
        os << " " << s(i+s.first());
      }
      os << endl;
    }
  } // void write_named_series(const std::string& filename,
  //                         const std::string& comment,
  //                         psd::TDseries f,
  //                         const TNamedSeriesVector& nsv,
  //                         const bool& verbose,
  //                         const bool& overwrite=true)

} // namespace croposp

96
/* ----- END OF write_named_series.cc ----- */