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
62public:
63
64 static inline
65 bool check(const std::string & prefix){
66
67 drain::FilePath check(prefix);
68 if (check.str() != prefix){
70 mout.advice("initial file paths starting with '/' are handled absolute, not prefixed");
71 mout.warn("consider adjusting path ", prefix, " -> ", check.str());
72 return false;
73 }
74 else {
75 return true;
76 }
77 }
78
79};
80
82
86class CmdInputPrefix : public drain::SimpleCommand<std::string>, protected PrefixChecker {
87
88public:
89
90 inline
91 CmdInputPrefix() : drain::SimpleCommand<std::string>(__FUNCTION__, "Path prefix for input files."){
92 //RackContext & ctx = getContext<RackContext>(); // DO NOT LINK, dynamic context!
93 //getParameters().link("path", getResources().inputPrefix = "");
94 };
95
96 inline
97 void exec() const {
98 check(value);
99 getContext<RackContext>().inputPrefix = value;
100 }
101};
102
103
104
106
112class CmdInputFile : public drain::SimpleCommand<std::string> {
113
114public:
115
116 inline
117 CmdInputFile() : drain::SimpleCommand<std::string>(__FUNCTION__, "Read HDF5, text or image file",
118 "filename", "", "<filename>.[h5|hdf5|png|pgm|ppm|txt]"){ //, inputComplete(true) {
119 //execRoutine = true;
120 //this->section = drain::Static::get<drain::GeneralSection>().index | drain::Static::get<drain::TriggerSection>().index
121 };
122
123
124 //mutable bool inputComplete;
125
126 // Essentially calls readFile
127 void exec() const;
128
129 // Called by exec, allowing recursion (esp. by readListFile)
130 void readFile(const std::string & fileName) const;
131
132protected:
133
134 // \param COMBINE - force appending new file to a volume (even if origin or time differ)
135
137
141 void readFileH5(const std::string & fullFilename, int maxTimeDiffMinutes = 0) const;
142 // void readListFile(const std::string & fullFilename) const;
143 void readListFile(const drain::FilePath & path) const;
144 void readTextFile(const std::string & fullFilename) const;
145 void readImageFile(const std::string & fullFilename) const;
146
147 //void readFileAndAppendH5(const std::string & fullFilename) const;
148
149 void appendCartesianH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
150 void attachCartesianH5(Hi5Tree & srcRoot, Hi5Tree & dstRoot) const;
151
152 void appendPolarH5(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
153 //void appendPolarH5OLD(Hi5Tree & tmpSrc, Hi5Tree & dst) const;
154
155 typedef std::map<std::string, ODIMPathElem> quantity_map;
156
157 void updateData(Hi5Tree & srcData, const std::string & srcKey, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
158 // void updateDataNEW(Hi5Tree & srcData, const ODIMPathElem & srcElem, Hi5Tree & dstDataSet, const quantity_map & dstQuantityElems) const ;
159
160
161 void updateQuality(Hi5Tree & srcData, Hi5Tree & dstData) const;
162
163
164 template <class OD> // const drain::VariableMap & rootProperties,
165 void deriveImageODIM( const drain::image::Image &srcImage,
166 OD & odim) const {
167 // See also EncodingODIM copyFro
168 const drain::image::Geometry & g = srcImage.getGeometry();
169 odim.setGeometry(g.getWidth(), g.getHeight());
170 odim.type = drain::Type::getTypeChar(srcImage.getType());
171 //odim.updateFromMap(rootProperties);
172 odim.updateFromMap(srcImage.properties);
173 if (odim.scaling.scale == 0){
174 if (!odim.quantity.empty())
175 getQuantityMap().setQuantityDefaults(odim, odim.quantity);
176 }
177
178 //odim.copyToData(dst);
179
180 }
181
182};
183
184
185
187
191class CmdInputSelect : public drain::SimpleCommand<std::string> {
192
193public:
194
195 inline
196 CmdInputSelect() : drain::SimpleCommand<std::string>(__FUNCTION__, "Selector for input data."){
197 };
198
199 inline
200 void exec() const {
201 getContext<RackContext>().inputSelect = value;
202 }
203};
204
205
206} // rack
207
208
209
210/*
211template <class OD>
212void CmdInputFile::deriveImageODIM(){
213}
214*/
215
216#endif
217
218// Rack
Extracts and stores directory path, base filename and extension.
Definition FilePath.h:54
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
A single-parameter command.
Definition Command.h:487
Definition Geometry.h:143
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:112
void appendPolarH5(Hi5Tree &tmpSrc, Hi5Tree &dst) const
Add DATASET groups of srcRoot to dstRoot.
Definition fileio-read.cpp:626
void attachCartesianH5(Hi5Tree &srcRoot, Hi5Tree &dstRoot) const
Definition fileio-read.cpp:585
void exec() const
Run the command with current parameter values.
Definition fileio-read.cpp:59
void readFileH5(const std::string &fullFilename, int maxTimeDiffMinutes=0) const
Read cartesian or polar data (sweep, volume).
Definition fileio-read.cpp:212
void readImageFile(const std::string &fullFilename) const
Definition fileio-read.cpp:1222
Path prefix string for subsequent input files.
Definition fileio-read.h:86
void exec() const
Run the command with current parameter values.
Definition fileio-read.h:97
Data selector for subsequent input files.
Definition fileio-read.h:191
void exec() const
Run the command with current parameter values.
Definition fileio-read.h:200
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
A debugging facility. Obsolete?
Definition fileio-read.h:60
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:210
Definition AltitudeOp.cpp:42
QuantityMap & getQuantityMap()
Definition QuantityMap.cpp:282