fileio-read.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 
32 #ifndef RACK_FILE_IO_READ
33 #define RACK_FILE_IO_READ
34 
35 //#include <drain/prog/CommandRegistry.h>
36 #include <drain/prog/CommandInstaller.h>
37 #include <hi5/Hi5Read.h>
38 
39 //#include "data/Quantity.h"
40 
41 #include "resources.h"
42 
43 namespace rack {
44 
45 
47 /*
48 class CmdInputSelect : public drain::BasicCommand {
49 
50 public:
51 
52  CmdInputSelect() : drain::BasicCommand(__FUNCTION__, "Read ATTRIBUTES (1), DATA(2) or both (3)."){
53  //, "value", hi5::Reader::ATTRIBUTES|hi5::Reader::DATASETS, "flag"){};
54  getParameters().link("value", getResources().inputSelect = hi5::Reader::ATTRIBUTES|hi5::Reader::DATASETS, "flag");
55  }
56 
57 };
58 */
59 
61 
65 class CmdInputPrefix : public drain::SimpleCommand<std::string> {
66 
67 public:
68 
69  inline
70  CmdInputPrefix() : drain::SimpleCommand<std::string>(__FUNCTION__, "Path prefix for input files."){
71  //RackContext & ctx = getContext<RackContext>(); // DO NOT LINK, dynamic context!
72  //getParameters().link("path", getResources().inputPrefix = "");
73  };
74 
75  inline
76  void exec() const {
77  getContext<RackContext>().inputPrefix = value;
78  }
79 };
80 
81 
82 
84 
90 class CmdInputFile : public drain::SimpleCommand<std::string> {
91 
92 public:
93 
94  inline
95  CmdInputFile() : drain::SimpleCommand<std::string>(__FUNCTION__, "Read HDF5, text or image file",
96  "filename", "", "<filename>.[h5|hdf5|png|pgm|ppm|txt]"){ //, inputComplete(true) {
97  //execRoutine = true;
98  //this->section = drain::Static::get<drain::GeneralSection>().index | drain::Static::get<drain::TriggerSection>().index
99  };
100 
101 
102  //mutable bool inputComplete;
103 
104  void exec() const;
105 
106 protected:
107 
108  void readFileH5(const std::string & fullFilename) const;
109 
110  //void readFileAndAppendH5(const std::string & fullFilename) const;
111 
112  void appendCartesianH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
113  void attachCartesianH5(Hi5Tree & srcRoot, Hi5Tree & dstRoot) const;
114 
115  void appendPolarH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
116  //void appendPolarH5OLD(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
117 
118  typedef std::map<std::string, ODIMPathElem> quantity_map;
119 
120  void updateData(Hi5Tree & srcData, const std::string & srcKey, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
121  // void updateDataNEW(Hi5Tree & srcData, const ODIMPathElem & srcElem, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
122 
123 
124  void updateQuality(Hi5Tree & srcData, Hi5Tree & dstData) const;
125 
126 
127  void readTextFile(const std::string & fullFilename) const;
128 
129  void readImageFile(const std::string & fullFilename) const;
130 
131  template <class OD> // const drain::VariableMap & rootProperties,
132  void deriveImageODIM( const drain::image::Image &srcImage,
133  OD & odim) const {
134  // See also EncodingODIM copyFro
135  const drain::image::Geometry & g = srcImage.getGeometry();
136  odim.setGeometry(g.getWidth(), g.getHeight());
137  odim.type = drain::Type::getTypeChar(srcImage.getType());
138  //odim.updateFromMap(rootProperties);
139  odim.updateFromMap(srcImage.properties);
140  if (odim.scaling.scale == 0){
141  if (!odim.quantity.empty())
142  getQuantityMap().setQuantityDefaults(odim, odim.quantity);
143  }
144 
145  //odim.copyToData(dst);
146 
147  }
148 
149 };
150 
151 
152 
154 
158 class CmdInputSelect : public drain::SimpleCommand<std::string> {
159 
160 public:
161 
162  inline
163  CmdInputSelect() : drain::SimpleCommand<std::string>(__FUNCTION__, "Selector for input data."){
164  };
165 
166  inline
167  void exec() const {
168  getContext<RackContext>().inputSelect = value;
169  }
170 };
171 
172 
173 } // rack
174 
175 
176 
177 /*
178 template <class OD>
179 void CmdInputFile::deriveImageODIM(){
180 }
181 */
182 
183 #endif
184 
185 // Rack
A single-parameter command.
Definition: Command.h:501
Definition: Geometry.h:145
FlexVariableMap properties
Container for user-defined KEY=VALUE metadata.
Definition: ImageFrame.h:369
const std::type_info & getType() const
Get the storage type.
Definition: ImageLike.h:100
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
Input HDF5, PNG or text file.
Definition: fileio-read.h:90
void appendPolarH5(Hi5Tree &tmpSrc, Hi5Tree &dst) const
Add DATASET groups of srcRoot to dstRoot.
Definition: fileio-read.cpp:437
void attachCartesianH5(Hi5Tree &srcRoot, Hi5Tree &dstRoot) const
Definition: fileio-read.cpp:396
void exec() const
Run the command with current parameter values.
Definition: fileio-read.cpp:59
void readFileH5(const std::string &fullFilename) const
Reads hdf5 file and appends it to H5 structure. Works only with sweeps (SCAN), volume (PVOL) or Carte...
Definition: fileio-read.cpp:150
void readImageFile(const std::string &fullFilename) const
Definition: fileio-read.cpp:925
A debugging facility. Obsolete?
Definition: fileio-read.h:65
void exec() const
Run the command with current parameter values.
Definition: fileio-read.h:76
Data selector for subsequent input files.
Definition: fileio-read.h:158
void exec() const
Run the command with current parameter values.
Definition: fileio-read.h:167
bool setQuantityDefaults(EncodingODIM &dst, const std::string &quantity, const std::string &values="") const
Sets default values of given quantity - but not the quantity itself. Optionally overrides with user v...
Definition: QuantityMap.cpp:398
Definition: DataSelector.cpp:44