3 #include <boost/regex.hpp> 14 int Statevector_size,
int Num_aerosol,
16 : num_level(Num_level), statevector_size(Statevector_size),
17 num_aerosol(Num_aerosol), num_band(Num_band)
29 int Statevector_size,
int Num_aerosol,
31 : num_level(Num_level), statevector_size(Statevector_size),
32 num_aerosol(Num_aerosol), num_band(Num_band), h(H)
37 void OutputHdf::initialize()
44 if(num_level == statevector_size ||
45 num_aerosol == statevector_size ||
46 num_aerosol == num_level) {
48 e <<
"The current implementation assumes Num_level, Statevector_size\n" 49 <<
"and Num_aerosol are all different. This is entirely to simplify\n" 50 <<
"the implementation, see the discussion in output_hdf.h. If\n" 51 <<
"needed, we could relax this constraint by changing the code.\n" 52 <<
"The values of Num_level = " << num_level <<
", Statevector_size = " 53 << statevector_size <<
",\n" 54 <<
"and Num_aerosol = " << num_aerosol <<
" violates this assumption.";
63 write_dimension_metadata();
64 write_shape_metadata();
81 void OutputHdf::write_dimension_metadata()
83 h->hdf_file().dimension_metadata(
"Retrieval",
84 "Number retrievals reported.", 1);
85 h->hdf_file().dimension_metadata(
"StateVectorElement",
86 "Retrieved state vector elements.", statevector_size);
87 h->hdf_file().dimension_metadata(
"Level",
88 "Atmospheric retrieval levels.", num_level);
89 h->hdf_file().dimension_metadata(
"Aerosol",
90 "Retrieved aerosol type.", num_aerosol);
91 h->hdf_file().dimension_metadata(
"Band",
92 "Spectral band.", num_band);
104 void OutputHdf::write_shape_metadata()
106 h->hdf_file().shape_metadata(
"Retrieval_Array",
"Retrieval");
107 h->hdf_file().shape_metadata(
108 "Retrieval_StateVectorElement_StateVectorElement_Array",
109 "Retrieval",
"StateVectorElement",
"StateVectorElement");
110 h->hdf_file().shape_metadata(
"Retrieval_Level_Array",
"Retrieval",
"Level");
111 h->hdf_file().shape_metadata(
"Retrieval_StateVectorElement_Array",
112 "Retrieval",
"StateVectorElement");
113 h->hdf_file().shape_metadata(
"Retrieval_Aerosol_Array",
"Retrieval",
"Aerosol");
114 h->hdf_file().shape_metadata(
"Retrieval_Band_Array",
"Retrieval",
"Band");
118 const std::string& Dataset_name, T Val)
120 h->hdf_file().write_field(Dataset_name, Val);
122 if(Dataset_name.find(
"/Metadata/") == std::string::npos)
123 h->hdf_file().write_attribute(Dataset_name +
"/Shape",
"Retrieval_Array");
125 h->hdf_file().write_attribute(Dataset_name +
"/Shape",
"Scalar");
129 const std::string& Dataset_name,
const blitz::Array<T, 1>& Val)
131 using namespace blitz;
135 Array<T, 2> val2(1, Val.rows());
136 val2(0, Range::all()) = Val;
137 h->hdf_file().write_field(Dataset_name, val2);
143 if(Val.rows() == statevector_size)
144 h->hdf_file().write_attribute(Dataset_name +
"/Shape",
145 "Retrieval_StateVectorElement_Array");
146 else if(Val.rows() == num_level)
147 h->hdf_file().write_attribute(Dataset_name +
"/Shape",
148 "Retrieval_Level_Array");
151 else if(boost::regex_match(Dataset_name,
152 boost::regex(
".*/num_colors_per_band")) ||
153 boost::regex_match(Dataset_name, boost::regex(
".*/Absco.*Scale")))
154 h->hdf_file().write_attribute(Dataset_name +
"/Shape",
155 "Retrieval_Band_Array");
156 else if(Val.rows() == num_aerosol)
157 h->hdf_file().write_attribute(Dataset_name +
"/Shape",
158 "Retrieval_Aerosol_Array");
162 const std::string& Dataset_name,
const blitz::Array<T, 2>& Val)
164 using namespace blitz;
168 Array<T, 3> val2(1, Val.rows(), Val.cols());
169 val2(0, Range::all(), Range::all()) = Val;
170 h->hdf_file().write_field(Dataset_name, val2);
176 if(Val.rows() == statevector_size &&
177 Val.cols() == statevector_size)
178 h->hdf_file().write_attribute(Dataset_name +
"/Shape",
179 "Retrieval_StateVectorElement_StateVectorElement_Array");
183 const std::string& Dataset_name,
const blitz::Array<T, 3>& Val)
185 using namespace blitz;
190 val2(1, Val.rows(), Val.cols(),
191 Val.extent(thirdDim));
192 val2(0, Range::all(), Range::all(), Range::all()) = Val;
193 h->hdf_file().write_field(Dataset_name, val2);
209 const std::string& Val);
214 const blitz::Array<int, 1>& Val);
216 const blitz::Array<std::string, 1>& Val);
218 const blitz::Array<const char*, 1>& Val);
220 const blitz::Array<double, 1>& Val);
223 const blitz::Array<int, 2>& Val);
225 const blitz::Array<std::string, 2>& Val);
227 const blitz::Array<const char*, 2>& Val);
229 const blitz::Array<double, 2>& Val);
232 const blitz::Array<int, 3>& Val);
234 const blitz::Array<std::string, 3>& Val);
236 const blitz::Array<const char*, 3>& Val);
238 const blitz::Array<double, 3>& Val);
virtual void end_because_of_error()
Notify when an error occurred.
To avoid creating files when an error occurs, we create the file with the name ".generating" appended...
This is the base of the exception hierarchy for Full Physics code.
Apply value function to a blitz array.
void write_data_t(const std::string &Dataset_name, T Val)
virtual void start_write()
Notify derived class that we are starting to write data.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
#define range_min_check(V, Min)
Range check.
OutputHdf(const std::string &Fname, int Num_level, int Statevector_size, int Num_aerosol, int Number_band)
Constructor. This takes the file name to write.