Commit 8057237a7a52a0d9a288a315a5a8fcb222f18bca
1 parent
abdb93f5
added an envi::open() function that re-opens a previously opened file with minimal processing
Showing
1 changed file
with
25 additions
and
14 deletions
Show diff stats
stim/envi/envi.h
... | ... | @@ -18,6 +18,7 @@ namespace stim{ |
18 | 18 | class envi{ |
19 | 19 | |
20 | 20 | void* file; //void pointer to the relevant file reader (bip, bsq, or bil - with appropriate data type) |
21 | + std::string fname; //file name used for repeated opening and closing | |
21 | 22 | |
22 | 23 | public: |
23 | 24 | |
... | ... | @@ -131,22 +132,16 @@ public: |
131 | 132 | |
132 | 133 | } |
133 | 134 | |
134 | - /// Open an existing ENVI file given the filename and a header structure | |
135 | - | |
136 | - /// @param filename is the name of the ENVI binary file | |
137 | - /// @param header is an ENVI header structure | |
138 | - bool open(std::string filename, stim::envi_header h){ | |
139 | - allocate(); | |
140 | - | |
141 | - header = h; | |
135 | + /// Open a previously opened ENVI file | |
136 | + bool open(){ | |
142 | 137 | |
143 | 138 | //load the file |
144 | 139 | if(header.interleave == envi_header::BSQ) { //if the infile is bsq file |
145 | 140 | if(header.data_type == envi_header::float32) { |
146 | - return ((bsq<float>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
141 | + return ((bsq<float>*)file)->open(fname, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
147 | 142 | } |
148 | 143 | else if(header.data_type == envi_header::float64) { |
149 | - return ((bsq<double>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
144 | + return ((bsq<double>*)file)->open(fname, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
150 | 145 | } |
151 | 146 | else |
152 | 147 | return false; |
... | ... | @@ -154,10 +149,10 @@ public: |
154 | 149 | |
155 | 150 | else if(header.interleave == envi_header::BIL) { //if the infile is bil file |
156 | 151 | if(header.data_type == envi_header::float32) { |
157 | - return ((bil<float>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
152 | + return ((bil<float>*)file)->open(fname, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
158 | 153 | } |
159 | 154 | else if(header.data_type == envi_header::float64) { |
160 | - return ((bil<double>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
155 | + return ((bil<double>*)file)->open(fname, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
161 | 156 | } |
162 | 157 | else |
163 | 158 | return false; |
... | ... | @@ -165,10 +160,10 @@ public: |
165 | 160 | |
166 | 161 | else if(header.interleave == envi_header::BIP) { //if the infile is bip file |
167 | 162 | if(header.data_type == envi_header::float32) { |
168 | - return ((bip<float>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
163 | + return ((bip<float>*)file)->open(fname, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
169 | 164 | } |
170 | 165 | else if(header.data_type == envi_header::float64) { |
171 | - return ((bip<double>*)file)->open(filename, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
166 | + return ((bip<double>*)file)->open(fname, header.samples, header.lines, header.bands, header.header_offset, header.wavelength); | |
172 | 167 | } |
173 | 168 | else |
174 | 169 | return false; |
... | ... | @@ -176,6 +171,22 @@ public: |
176 | 171 | |
177 | 172 | return true; |
178 | 173 | |
174 | + | |
175 | + } | |
176 | + | |
177 | + /// Open an existing ENVI file given the filename and a header structure | |
178 | + | |
179 | + /// @param filename is the name of the ENVI binary file | |
180 | + /// @param header is an ENVI header structure | |
181 | + bool open(std::string filename, stim::envi_header h){ | |
182 | + allocate(); | |
183 | + | |
184 | + header = h; //store the header | |
185 | + fname = filename; //save the filename | |
186 | + | |
187 | + return open(); //open the ENVI file; | |
188 | + | |
189 | + | |
179 | 190 | } |
180 | 191 | |
181 | 192 | /// Open an existing ENVI file given the file and header names. | ... | ... |