arldatastream.hh 3.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef RADIX_RADIXIO_ARLDATASTREAM_HH_
#define RADIX_RADIXIO_ARLDATASTREAM_HH_

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <memory>
#include <sstream>
#include <string>
#include <vector>

#include "radixcore/visibility.hh"

namespace radix
{
//
17
// Forward declare ARLRecordHeader and ARLIndexHeader
18
struct ARLIndexHeader;
19
struct ARLRecordHeader;
20
21
22
23
24
25
26
27
28

class RADIX_PUBLIC ARLDataStream
{
  // forward declare private implementation
  class PImpl;
  // unique pointer to private implmentation
  std::unique_ptr<PImpl, void (*)(PImpl*)> p;

 private:
29
30
  static const int indexHeaderLength = 50, recordHeaderLength = 108;

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  /**
   * @brief expand Expands string of 50 characters to an ARLIndexHeader
   * @param val String for expansion
   * @param index ARLIndexHeader
   */
  static void expand(const std::string& val, ARLIndexHeader& index);

  /**
   * @brief expand Expands string of 108 characters to ARLHeader
   * @param val String for expansion
   * @param index ALRIndexHeader required for determining grid domain extending
   * beyond 3 digits
   * @param header ARLHeader
   */
  static void expand(const std::string& val, const ARLIndexHeader& index,
46
                     ARLRecordHeader& header);
47
48
49
50
51
52
53
54
55
56
57

 public:
  ARLDataStream() = delete;
  ARLDataStream(const std::string& file);

  /**
   * @brief read_index_header Reads a single index header from the stream
   * @param iheader ARLIndexHeader&
   * @return
   */
  bool read_index_header(ARLIndexHeader& iheader);
58
59

  bool write_index_header(const ARLIndexHeader& iheader);
60
  /**
61
62
   * @brief read_next_index_header Sets the stream position to that of the next
   * index header and reads that header
63
64
65
66
67
68
   * @return
   */
  bool read_next_index_header(ARLIndexHeader& iheader);

  bool read_record_header(const ARLIndexHeader& iheader,
                          ARLRecordHeader& rheader);
69
70
  bool write_record_header(const ARLIndexHeader& iheader,
                           const ARLRecordHeader& rheader);
71
72
73
74
75
76
77

  /**
   * @brief read_record Reads a single record from the stream
   * @param ARLRecord& record
   *
   * @return bool on if inventory was populated
   */
78
79
80
  bool read_record(const ARLIndexHeader& iheader,
                   const ARLRecordHeader& rheader,
                   std::vector<std::vector<double> >& record);
81
82

  // TODO
83
84
85
  bool write_record(const ARLIndexHeader& iheader,
                    const ARLRecordHeader& rheader,
                    const std::vector<std::vector<double> >& record);
86
87
88

};  // class ARLDataStream

89
struct RADIX_PUBLIC ARLRecordHeader
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
{
 public:
  bool prime;
  bool latlon;
  bool gbldat;
  bool global;
  int icx;
  int mn;
  float pole_lat;
  float pole_lon;
  float ref_lon;
  float ref_lat;
  float size;
  float orient;
  float tang_lat;
  float sync_xp;
  float sync_yp;
  float sync_lat;
  float sync_lon;
  float dummy;
  int nx;
  int ny;
  int nz;
  int z_flag;
  int lenh;
  std::string model_id;
};  // ARLHeader

struct RADIX_PUBLIC ARLIndexHeader
{
 public:
  int year;
  int month;
  int day;
  int hour;
  int ic;
  int il;
  int nexp;
  float prec;
  float var1;
  std::string cgrid;
  std::string kvar;
};

}  // namespace radix

136
137
//#include "arldatastream.i.hh"

138
#endif /** RADIX_RADIXIO_ARLDATASTREAM_HH_ */