stormcontgrid.hpp
Go to the documentation of this file.
1// $Id: stormcontgrid.hpp 1190 2013-07-03 10:57:27Z ulvmoen $
2
3// Copyright (c) 2011, Norwegian Computing Center
4// All rights reserved.
5// Redistribution and use in source and binary forms, with or without modification,
6// are permitted provided that the following conditions are met:
7// • Redistributions of source code must retain the above copyright notice, this
8// list of conditions and the following disclaimer.
9// • Redistributions in binary form must reproduce the above copyright notice, this list of
10// conditions and the following disclaimer in the documentation and/or other materials
11// provided with the distribution.
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
13// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
15// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
17// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
20// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
22#ifndef NRLIB_STORMCONTGRID_HPP
23#define NRLIB_STORMCONTGRID_HPP
24
25#include <string>
26
27#include "../volume/volume.hpp"
28#include "../grid/grid.hpp"
29#include "../iotools/fileio.hpp"
30
31namespace NRLib {
32 class StormContGrid : public Grid<float>, public Volume {
33 public:
35
36 explicit StormContGrid(const std::string& filename, Endianess file_format = END_BIG_ENDIAN);
37 explicit StormContGrid(size_t nx = 0, size_t ny = 0, size_t nz = 0);
38 explicit StormContGrid(const Volume &vol, const Grid<float> & grid);
39 explicit StormContGrid(const Volume &vol, size_t nx = 0, size_t ny = 0, size_t nz = 0);
40
41 void SetMissingCode(float missing_code)
42 { missing_code_ = missing_code; }
43
44 float GetMissingCode() const
45 { return missing_code_; }
46
47 bool IsMissing(float val) const
48 { return val == missing_code_; }
49
51 { file_format_ = format; }
52
54 { return file_format_; }
55
56 void SetModelFileName(const std::string& filename)
57 { model_file_name_ = filename; }
58
60 { return model_file_name_; }
61
63 { variable_name_ = name; }
64
66 { return variable_name_; }
67
68 void SetZoneNumber(int zone_number)
69 { zone_number_ = zone_number; }
70
71 int GetZoneNumber() const
72 { return zone_number_; }
73
76 void WriteToFile(const std::string& filename,
77 const std::string& predefinedHeader = "",
78 bool plainAscii=false,
79 Endianess file_format = END_BIG_ENDIAN,
80 bool remove_path = true) const;
81
82 void WriteToSgriFile(const std::string & file_name,
83 const std::string & file_name_header,
84 const std::string & label,
85 double simbox_dz,
86 Endianess file_format = END_BIG_ENDIAN) const;
87
90 void ReadFromFile(const std::string& filename, bool commonPath = true, Endianess file_format = END_BIG_ENDIAN);
91
92 double GetDX() const { return GetLX() / GetNI(); }
93 double GetDY() const { return GetLY() / GetNJ(); }
94 size_t FindIndex(double x, double y, double z) const;
95 void FindIndex( double x, double y, double z, size_t& i_out, size_t& j_out, size_t& k_out) const;
96 void FindXYIndex(double x, double y, size_t& i_out, size_t& j_out) const;
97
98 void FindZInterpolatedIndex(const double & x,
99 const double & y,
100 const double & z,
101 size_t & ind1,
102 size_t & ind2,
103 double & t) const;
104
105 float GetValueZInterpolatedFromIndex(const size_t & ind1,
106 const size_t & ind2,
107 const double & t) const;
108
109 double GetValueZInterpolatedFromIndexNoMissing(const size_t & ind1,
110 const size_t & ind2,
111 const double & t) const;
112
113 float GetValueInterpolated(const int & i,
114 const int & j,
115 const float & k_value) const;
116
117 double GetAvgRelThick() const;
118
119 float GetValueZInterpolated(double x, double y, double z)const;
120 float GetValueClosestInZ(double x, double y, double z)const;
121 double GetZMin()const { return Volume::GetZMin(GetNI(), GetNJ()); }
122 double GetZMax()const { return Volume::GetZMax(GetNI(), GetNJ()); }
123
124 void FindCenterOfCell(size_t i, size_t j, size_t k,
125 double& x, double& y, double& z) const;
126
127 void WriteCravaFile(const std::string & file_name,
128 double inline_0,
129 double crossline_0,
130 double il_step_x,
131 double il_step_y,
132 double xl_step_x,
133 double xl_step_y);
134
135 private:
136 double RecalculateLZ();
137 void ReadSgriHeader(std::ifstream &headerFile, std::string &binFileName);
138 void ReadSgriBinaryFile(const std::string& filename);
139
140 double GetRelThick(int i, int j) const;
141 double GetRelThick(double x, double y) const;
142
143 FileFormat file_format_;
144 float missing_code_;
145 int zone_number_;
146 std::string model_file_name_;
147 std::string variable_name_;
148};
149
150}
151
152#endif // NRLIB_STORMCONTGRID_HPP
const char *const name
Definition: cJSON.h:258
char const int const cJSON_bool format
Definition: cJSON.h:161
const char *const string
Definition: cJSON.h:170
Definition: grid.hpp:35
size_t GetNJ() const
Definition: grid.hpp:70
size_t GetNI() const
Definition: grid.hpp:69
Definition: stormcontgrid.hpp:32
void FindCenterOfCell(size_t i, size_t j, size_t k, double &x, double &y, double &z) const
StormContGrid(const Volume &vol, size_t nx=0, size_t ny=0, size_t nz=0)
bool IsMissing(float val) const
Definition: stormcontgrid.hpp:47
float GetMissingCode() const
Definition: stormcontgrid.hpp:44
float GetValueInterpolated(const int &i, const int &j, const float &k_value) const
void ReadFromFile(const std::string &filename, bool commonPath=true, Endianess file_format=END_BIG_ENDIAN)
void SetMissingCode(float missing_code)
Definition: stormcontgrid.hpp:41
double GetDX() const
Definition: stormcontgrid.hpp:92
int GetZoneNumber() const
Definition: stormcontgrid.hpp:71
void SetVariableName(const std::string &name)
Definition: stormcontgrid.hpp:62
double GetAvgRelThick() const
double GetDY() const
Definition: stormcontgrid.hpp:93
void FindIndex(double x, double y, double z, size_t &i_out, size_t &j_out, size_t &k_out) const
double GetZMin() const
Definition: stormcontgrid.hpp:121
void FindZInterpolatedIndex(const double &x, const double &y, const double &z, size_t &ind1, size_t &ind2, double &t) const
void WriteToSgriFile(const std::string &file_name, const std::string &file_name_header, const std::string &label, double simbox_dz, Endianess file_format=END_BIG_ENDIAN) const
float GetValueClosestInZ(double x, double y, double z) const
void FindXYIndex(double x, double y, size_t &i_out, size_t &j_out) const
StormContGrid(size_t nx=0, size_t ny=0, size_t nz=0)
StormContGrid(const Volume &vol, const Grid< float > &grid)
FileFormat
Definition: stormcontgrid.hpp:34
@ STORM_ASCII
Definition: stormcontgrid.hpp:34
@ STORM_BINARY
Definition: stormcontgrid.hpp:34
FileFormat GetFormat() const
Definition: stormcontgrid.hpp:53
size_t FindIndex(double x, double y, double z) const
void SetZoneNumber(int zone_number)
Definition: stormcontgrid.hpp:68
double GetValueZInterpolatedFromIndexNoMissing(const size_t &ind1, const size_t &ind2, const double &t) const
StormContGrid(const std::string &filename, Endianess file_format=END_BIG_ENDIAN)
std::string GetModelFileName() const
Definition: stormcontgrid.hpp:59
std::string GetVariableName() const
Definition: stormcontgrid.hpp:65
double GetZMax() const
Definition: stormcontgrid.hpp:122
void WriteToFile(const std::string &filename, const std::string &predefinedHeader="", bool plainAscii=false, Endianess file_format=END_BIG_ENDIAN, bool remove_path=true) const
void WriteCravaFile(const std::string &file_name, double inline_0, double crossline_0, double il_step_x, double il_step_y, double xl_step_x, double xl_step_y)
float GetValueZInterpolatedFromIndex(const size_t &ind1, const size_t &ind2, const double &t) const
void SetFormat(FileFormat format)
Definition: stormcontgrid.hpp:50
float GetValueZInterpolated(double x, double y, double z) const
void SetModelFileName(const std::string &filename)
Definition: stormcontgrid.hpp:56
Definition: volume.hpp:31
double GetLX() const
Definition: volume.hpp:62
double GetLY() const
Definition: volume.hpp:63
double GetZMin(size_t nx, size_t ny) const
Get extreme values of z for volume, with nx, ny resolution.
double GetZMax(size_t nx, size_t ny) const
Definition: exception.hpp:31
Endianess
Definition: fileio.hpp:36
@ END_BIG_ENDIAN
Definition: fileio.hpp:37
x y * z
Definition: exprtk.hpp:9663
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)