tstArlDataStream.cc 4.05 KB
Newer Older
1
2
3
4
5
6
7
8
#include "gtest/gtest.h"

#include <vector>

#include "radixio/arldatastream.hh"

using namespace radix;

Purves, Murray's avatar
Purves, Murray committed
9
TEST(RadixIO, ReadArlElements)
10
{
Purves, Murray's avatar
Purves, Murray committed
11
12
  double tolerance = 0.001;

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
  std::string testFile = "/home/ohp/data/met/RP195111.gbl";
  ARLDataStream testStream(testFile);

  // Read the initial index header
  ARLIndexHeader testTopIndexHeader;
  bool success = testStream.read_index_header(testTopIndexHeader);
  ASSERT_TRUE(success);
  // Test the content
  EXPECT_EQ(51, testTopIndexHeader.year);
  EXPECT_EQ(11, testTopIndexHeader.month);
  EXPECT_EQ(1, testTopIndexHeader.day);
  EXPECT_EQ(0, testTopIndexHeader.hour);
  EXPECT_STREQ("INDX", testTopIndexHeader.kvar.c_str());

  ARLRecordHeader testRecordHeader;
  success = testStream.read_record_header(testTopIndexHeader, testRecordHeader);
  ASSERT_TRUE(success);
  // Test the content
  EXPECT_EQ(144, testRecordHeader.nx);
  EXPECT_EQ(73, testRecordHeader.ny);
  EXPECT_EQ(18, testRecordHeader.nz);

  // Read the data starting from the next index header
  ARLIndexHeader testIndexHeader;
  success = testStream.read_next_index_header(testIndexHeader);
  ASSERT_TRUE(success);
  // Test the content
  EXPECT_EQ(51, testIndexHeader.year);
  EXPECT_EQ(11, testIndexHeader.month);
  EXPECT_EQ(1, testIndexHeader.day);
  EXPECT_EQ(0, testIndexHeader.hour);
  EXPECT_STREQ("PRSS", testIndexHeader.kvar.c_str());
  // Read data
  std::vector<std::vector<double>> testRecord;
  success =
      testStream.read_record(testIndexHeader, testRecordHeader, testRecord);
Purves, Murray's avatar
Purves, Murray committed
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
  // Test content
  ASSERT_TRUE(success);
  ASSERT_EQ(testRecordHeader.nx, testRecord.size());
  ASSERT_EQ(testRecordHeader.ny, testRecord[0].size());
  EXPECT_NEAR(665.9, testRecord[0][0], 665.9 * tolerance);
  EXPECT_NEAR(665.9, testRecord[1][0], 665.9 * tolerance);
  EXPECT_NEAR(677.9, testRecord[0][1], 677.9 * tolerance);
  EXPECT_NEAR(677.9, testRecord[1][1], 677.9 * tolerance);
  EXPECT_NEAR(1013.9, testRecord[142][71], 1013.9 * tolerance);
  EXPECT_NEAR(1011.9, testRecord[143][71], 1011.9 * tolerance);
  EXPECT_NEAR(1015.9, testRecord[142][72], 1015.9 * tolerance);
  EXPECT_NEAR(1015.9, testRecord[143][72], 1015.9 * tolerance);

  // Try another one
  success = testStream.read_next_index_header(testIndexHeader);
  ASSERT_TRUE(success);
  // Test the content
  EXPECT_EQ(51, testIndexHeader.year);
  EXPECT_EQ(11, testIndexHeader.month);
  EXPECT_EQ(1, testIndexHeader.day);
  EXPECT_EQ(0, testIndexHeader.hour);
  EXPECT_STREQ("T02M", testIndexHeader.kvar.c_str());
  // Read data
  success =
      testStream.read_record(testIndexHeader, testRecordHeader, testRecord);
  // Test content
  ASSERT_TRUE(success);
  ASSERT_EQ(testRecordHeader.nx, testRecord.size());
  ASSERT_EQ(testRecordHeader.ny, testRecord[0].size());
  EXPECT_NEAR(233.4, testRecord[0][0], 233.4 * tolerance);
  EXPECT_NEAR(233.4, testRecord[1][0], 233.4 * tolerance);
  EXPECT_NEAR(227.1, testRecord[0][1], 227.1 * tolerance);
  EXPECT_NEAR(227.1, testRecord[1][1], 227.1 * tolerance);
  EXPECT_NEAR(236.0, testRecord[142][71], 236.0 * tolerance);
  EXPECT_NEAR(236.1, testRecord[143][71], 236.1 * tolerance);
  EXPECT_NEAR(240.6, testRecord[142][72], 240.6 * tolerance);
  EXPECT_NEAR(240.6, testRecord[143][72], 240.6 * tolerance);
86
}
Purves, Murray's avatar
Purves, Murray committed
87

88
89
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
TEST(RadixIO, WriteArlElements)
{
  double tolerance = 0.001;

  std::string testFile = "/home/ohp/data/met/RP195111.gbl";
  ARLDataStream testStream(testFile);

  // Read the initial index header
  ARLIndexHeader testTopIndexHeader;
  bool success = testStream.read_index_header(testTopIndexHeader);
  ASSERT_TRUE(success);

  ARLRecordHeader testRecordHeader;
  success = testStream.read_record_header(testTopIndexHeader, testRecordHeader);
  ASSERT_TRUE(success);

  // Read the data starting from the next index header
  ARLIndexHeader testIndexHeader;
  success = testStream.read_next_index_header(testIndexHeader);
  ASSERT_TRUE(success);
  // Read data
  std::vector<std::vector<double>> testRecord;
  success =
      testStream.read_record(testIndexHeader, testRecordHeader, testRecord);
  ASSERT_TRUE(success);

  // Write this data back out to a file
}

Purves, Murray's avatar
Purves, Murray committed
117
118
119
120
// TEST(RadixIO, ReadArlWholeFile)
//{

//}