Loading...
Searching...
No Matches
fileio-read.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood 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
43namespace rack {
44
45
47/*
48class CmdInputSelect : public drain::BasicCommand {
49
50public:
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
65class CmdInputPrefix : public drain::SimpleCommand<std::string> {
66
67public:
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
90class CmdInputFile : public drain::SimpleCommand<std::string> {
91
92public:
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 // Essentially calls readFile
105 void exec() const;
106
107 // Called by exec, allowing recursion (esp. by readListFile)
108 void readFile(const std::string & fileName) const;
109
110protected:
111
112 // \param COMBINE - force appending new file to a volume (even if origin or time differ)
113
115
119 void readFileH5(const std::string & fullFilename, int maxTimeDiffMinutes = 0) const;
120 // void readListFile(const std::string & fullFilename) const;
121 void readListFile(const drain::FilePath & path) const;
122 void readTextFile(const std::string & fullFilename) const;
123 void readImageFile(const std::string & fullFilename) const;
124
125 //void readFileAndAppendH5(const std::string & fullFilename) const;
126
127 void appendCartesianH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
128 void attachCartesianH5(Hi5Tree & srcRoot, Hi5Tree & dstRoot) const;
129
130 void appendPolarH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
131 //void appendPolarH5OLD(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
132
133 typedef std::map<std::string, ODIMPathElem> quantity_map;
134
135 void updateData(Hi5Tree & srcData, const std::string & srcKey, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
136 // void updateDataNEW(Hi5Tree & srcData, const ODIMPathElem & srcElem, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
137
138
139 void updateQuality(Hi5Tree & srcData, Hi5Tree & dstData) const;
140
141
142 template <class OD> // const drain::VariableMap & rootProperties,
143 void deriveImageODIM( const drain::image::Image &srcImage,
144 OD & odim) const {
145 // See also EncodingODIM copyFro
146 const drain::image::Geometry & g = srcImage.getGeometry();
147 odim.setGeometry(g.getWidth(), g.getHeight());
148 odim.type = drain::Type::getTypeChar(srcImage.getType());
149 //odim.updateFromMap(rootProperties);
150 odim.updateFromMap(srcImage.properties);
151 if (odim.scaling.scale == 0){
152 if (!odim.quantity.empty())
153 getQuantityMap().setQuantityDefaults(odim, odim.quantity);
154 }
155
156 //odim.copyToData(dst);
157
158 }
159
160};
161
162
163
165
169class CmdInputSelect : public drain::SimpleCommand<std::string> {
170
171public:
172
173 inline
174 CmdInputSelect() : drain::SimpleCommand<std::string>(__FUNCTION__, "Selector for input data."){
175 };
176
177 inline
178 void exec() const {
179 getContext<RackContext>().inputSelect = value;
180 }
181};
182
183
184} // rack
185
186
187
188/*
189template <class OD>
190void CmdInputFile::deriveImageODIM(){
191}
192*/
193
194#endif
195
196// Rack
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:54
A single-parameter command.
Definition Command.h:467
Definition Geometry.h:143
FlexVariableMap properties
Container for user-defined KEY=VALUE metadata.
Definition ImageFrame.h:364
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:183
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:584
void attachCartesianH5(Hi5Tree &srcRoot, Hi5Tree &dstRoot) const
Definition fileio-read.cpp:543
void exec() const
Run the command with current parameter values.
Definition fileio-read.cpp:58
void readFileH5(const std::string &fullFilename, int maxTimeDiffMinutes=0) const
Read cartesian or polar data (sweep, volume).
Definition fileio-read.cpp:177
void readImageFile(const std::string &fullFilename) const
Definition fileio-read.cpp:1166
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:169
void exec() const
Run the command with current parameter values.
Definition fileio-read.h:178
bool setQuantityDefaults(EncodingODIM &dst, const std::string &quantity, const std::string &values="") const
Sets default values of given quantity without assigning the quantity. Optionally overrides with user ...
Definition QuantityMap.cpp:207
Definition DataSelector.cpp:44
QuantityMap & getQuantityMap()
Definition QuantityMap.cpp:279