4 #include <boost/function.hpp> 5 #include <blitz/array.h> 6 #include <boost/shared_ptr.hpp> 7 #include <boost/bind.hpp> 8 #include <boost/lambda/lambda.hpp> 9 #include <boost/any.hpp> 18 template<
class T>
class LevelPad {
20 LevelPad(
const boost::function<blitz::Array<T, 1> ()>& F, T Fill,
int Fullsize)
21 : f(F), fill(Fill), fullsize(Fullsize) {}
22 blitz::Array<T, 1> operator()()
const 24 blitz::Array<T, 1> res(fullsize);
26 blitz::Array<T, 1> t = f();
27 res(blitz::Range(0, t.rows() - 1)) = t;
31 boost::function<blitz::Array<T, 1> ()> f;
36 template<
class T>
class LevelPad2 {
38 LevelPad2(
const boost::function<blitz::Array<T, 2> ()>& F, T Fill,
int Fullsize)
39 : f(F), fill(Fill), fullsize(Fullsize) {}
40 blitz::Array<T, 2> operator()()
const 42 blitz::Array<T, 2> res(fullsize);
44 blitz::Array<T, 2> t = f();
45 res(blitz::Range(0, t.rows() - 1),
46 blitz::Range(0, t.rows() - 1)) = t;
50 boost::function<blitz::Array<T, 2> ()> f;
105 virtual void print(std::ostream& Os)
const { Os <<
"Output";}
113 template<
class S,
class T,
int D>
void 115 blitz::Array<T, D> (S::*Pmf)()
const,
118 boost::function<blitz::Array<T, D> ()> f = boost::bind(Pmf, Src);
119 register_data_source(Dataset_name, f);
129 template<
class S,
class T>
void 131 blitz::Array<T, 1> (S::*Pmf)()
const,
136 boost::function<blitz::Array<T, 1> ()> f = boost::bind(Pmf, Src);
137 boost::function<blitz::Array<T, 1> ()> f2 =
138 LevelPad<T>(f, Fill_value, Full_size);
139 register_data_source(Dataset_name, f2);
142 template<
class S,
class T>
void 144 blitz::Array<T, 2> (S::*Pmf)()
const,
149 boost::function<blitz::Array<T, 2> ()> f = boost::bind(Pmf, Src);
150 boost::function<blitz::Array<T, 2> ()> f2 =
151 LevelPad2<T>(f, Fill_value, Full_size);
152 register_data_source(Dataset_name, f2);
161 template<
class S,
class T>
void 166 boost::function<T ()> f = boost::bind(Pmf, Src);
167 register_data_source(Dataset_name, f);
174 template<
class T,
int D>
void 176 const blitz::Array<T, D>& Val)
178 boost::function<blitz::Array<T, D> ()> f =
179 boost::lambda::constant(Val.copy());
180 register_data_source(Dataset_name, f);
187 template<
class T>
void 191 boost::function<T ()> f = boost::lambda::constant(Val);
192 register_data_source(Dataset_name, f);
201 boost::function<T> f)
202 { func[Dataset_name] = f;}
204 void write_best_attempt();
231 virtual void write_data(
const std::string& Dataset_name,
int Val) = 0;
232 virtual void write_data(
const std::string& Dataset_name, int64_t Val) = 0;
233 virtual void write_data(
const std::string& Dataset_name,
double Val) = 0;
234 virtual void write_data(
const std::string& Dataset_name,
235 const std::string& Val) = 0;
236 virtual void write_data(
const std::string& Dataset_name,
237 const char* Val) = 0;
238 virtual void write_data(
const std::string& Dataset_name,
239 const blitz::Array<int, 1>& Val) = 0;
240 virtual void write_data(
const std::string& Dataset_name,
241 const blitz::Array<std::string, 1>& Val) = 0;
242 virtual void write_data(
const std::string& Dataset_name,
243 const blitz::Array<const char*, 1>& Val) = 0;
244 virtual void write_data(
const std::string& Dataset_name,
245 const blitz::Array<double, 1>& Val) = 0;
246 virtual void write_data(
const std::string& Dataset_name,
247 const blitz::Array<int, 2>& Val) = 0;
248 virtual void write_data(
const std::string& Dataset_name,
249 const blitz::Array<std::string, 2>& Val) = 0;
250 virtual void write_data(
const std::string& Dataset_name,
251 const blitz::Array<const char*, 2>& Val) = 0;
252 virtual void write_data(
const std::string& Dataset_name,
253 const blitz::Array<double, 2>& Val) = 0;
254 virtual void write_data(
const std::string& Dataset_name,
255 const blitz::Array<int, 3>& Val) = 0;
256 virtual void write_data(
const std::string& Dataset_name,
257 const blitz::Array<std::string, 3>& Val) = 0;
258 virtual void write_data(
const std::string& Dataset_name,
259 const blitz::Array<const char*, 3>& Val) = 0;
260 virtual void write_data(
const std::string& Dataset_name,
261 const blitz::Array<double, 3>& Val) = 0;
264 void pass_to_write_t(
const std::string& Dataset_name, boost::any* D);
265 void pass_to_write(
const std::string& Dataset_name, boost::any* D);
266 std::map<std::string, boost::any> func;
281 virtual void write_data(
const std::string& Dataset_name,
int Val)
282 { ((T*)
this)->write_data_t(Dataset_name, Val); }
283 virtual void write_data(
const std::string& Dataset_name, int64_t Val)
284 { ((T*)
this)->write_data_t(Dataset_name, Val); }
285 virtual void write_data(
const std::string& Dataset_name,
double Val)
286 { ((T*)
this)->write_data_t(Dataset_name, Val); }
288 const std::string& Val)
289 { ((T*)
this)->write_data_t(Dataset_name, Val); }
292 { ((T*)
this)->write_data_t(Dataset_name, Val); }
294 const blitz::Array<int, 1>& Val)
295 { ((T*)
this)->write_data_t(Dataset_name, Val); }
297 const blitz::Array<std::string, 1>& Val)
298 { ((T*)
this)->write_data_t(Dataset_name, Val); }
300 const blitz::Array<const char*, 1>& Val)
301 { ((T*)
this)->write_data_t(Dataset_name, Val); }
303 const blitz::Array<double, 1>& Val)
304 { ((T*)
this)->write_data_t(Dataset_name, Val); }
306 const blitz::Array<int, 2>& Val)
307 { ((T*)
this)->write_data_t(Dataset_name, Val); }
309 const blitz::Array<std::string, 2>& Val)
310 { ((T*)
this)->write_data_t(Dataset_name, Val); }
312 const blitz::Array<const char*, 2>& Val)
313 { ((T*)
this)->write_data_t(Dataset_name, Val); }
315 const blitz::Array<double, 2>& Val)
316 { ((T*)
this)->write_data_t(Dataset_name, Val); }
318 const blitz::Array<int, 3>& Val)
319 { ((T*)
this)->write_data_t(Dataset_name, Val); }
321 const blitz::Array<std::string, 3>& Val)
322 { ((T*)
this)->write_data_t(Dataset_name, Val); }
324 const blitz::Array<const char*, 3>& Val)
325 { ((T*)
this)->write_data_t(Dataset_name, Val); }
327 const blitz::Array<double, 3>& Val)
328 { ((T*)
this)->write_data_t(Dataset_name, Val); }
335 virtual double f()
const = 0;
342 virtual blitz::Array<double,1> f()
const = 0;
349 virtual blitz::Array<double,2> f()
const = 0;
void register_data_source(const std::string &Dataset_name, boost::function< T > f)
Most general way to enter a Data source.
void register_data_source(const std::string &Dataset_name, const T &Val)
Handling for when data is constant.
virtual void write_data(const std::string &Dataset_name, const blitz::Array< double, 3 > &Val)
virtual void write_data(const std::string &Dataset_name, const blitz::Array< double, 2 > &Val)
void register_data_source(const std::string &Dataset_name, T(S::*Pmf)() const, const boost::shared_ptr< S > &Src)
A common way to supply the metadata source is with a shared_ptr to an object, and a pointer to a memb...
void register_data_source_pad(const std::string &Dataset_name, blitz::Array< T, 1 >(S::*Pmf)() const, const boost::shared_ptr< S > &Src, int Full_size, T Fill_value)
There are several fields that are generated on the active levels only.
virtual void print(std::ostream &Os) const
virtual void write_data(const std::string &Dataset_name, int Val)
Various write functions that derived classes.
virtual void write_data(const std::string &Dataset_name, const blitz::Array< const char *, 3 > &Val)
This is a Mixin for classes that can be printed.
virtual void write_data(const std::string &Dataset_name, const blitz::Array< const char *, 2 > &Val)
virtual void write_data(const std::string &Dataset_name, int64_t Val)
virtual void write_data(const std::string &Dataset_name, const blitz::Array< std::string, 3 > &Val)
void register_data_source(const std::string &Dataset_name, const blitz::Array< T, D > &Val)
Handling for when data is constant.
virtual void write_data(const std::string &Dataset_name, const blitz::Array< int, 3 > &Val)
Most of the time the write_data needed by Output is best done through a template. ...
virtual void write_data(const std::string &Dataset_name, const char *Val)
virtual void write_data(const std::string &Dataset_name, const blitz::Array< const char *, 1 > &Val)
This is the base class for classes that write output for Level 2 Full Physics.
virtual void write_data(const std::string &Dataset_name, double Val)
Contains classes to abstract away details in various Spurr Radiative Transfer software.
virtual void write_data(const std::string &Dataset_name, const std::string &Val)
void register_data_source(const std::string &Dataset_name, blitz::Array< T, D >(S::*Pmf)() const, const boost::shared_ptr< S > &Src)
A common way to supply the metadata source is with a shared_ptr to an object, and a pointer to a memb...
virtual void end_because_of_error()
Notify when an error occurred.
For use with SWIG, it is useful to have a base class that everything can be cast to.
virtual void end_write()
Notify when we are done.
virtual void write_data(const std::string &Dataset_name, const blitz::Array< int, 2 > &Val)
virtual ~OutputTemplate()
virtual void start_write()
Notify derived class that we are starting to write data.
virtual void write_data(const std::string &Dataset_name, const blitz::Array< int, 1 > &Val)
virtual void write_data(const std::string &Dataset_name, const blitz::Array< double, 1 > &Val)
void register_data_source_pad(const std::string &Dataset_name, blitz::Array< T, 2 >(S::*Pmf)() const, const boost::shared_ptr< S > &Src, int Full_size, T Fill_value)
virtual void write_data(const std::string &Dataset_name, const blitz::Array< std::string, 1 > &Val)
virtual void write_data(const std::string &Dataset_name, const blitz::Array< std::string, 2 > &Val)