Commit 37e618500a4753c3c255a0fa564d5d76d2e4c07f

Authored by David Mayerich
1 parent a7ed4b2e

added an is_open() boolean function

You can now test if an ENVI file has been opened.
stim/envi/binary.h
... ... @@ -3,8 +3,8 @@
3 3 #ifndef RTS_BINARY_H
4 4 #define RTS_BINARY_H
5 5  
6   -#include "../envi/envi_header.h"
7   -#include "../math/vector.h"
  6 +#include <stim/envi/envi_header.h>
  7 +#include <stim/math/vector.h>
8 8 #include <fstream>
9 9 #include <sys/stat.h>
10 10 #include <cstring>
... ... @@ -134,73 +134,6 @@ public:
134 134 }
135 135 }
136 136 }
137   -
138   - /*// this function updates the optimizer, given the number of bytes processed in an interval and time spent processing
139   - size_t update(size_t bytes_processed, size_t ms_spent){
140   - interval_B += bytes_processed; //increment the number of bytes processed
141   - interval_ms += ms_spent; //increment the number of milliseconds spent processing
142   -
143   - //if we have sufficient information to evaluate the optimization function at this point
144   - if(interval_ms >= window_ms){ //if sufficient time has passed to get a reliable Bps measurement
145   - size_t new_Bps = interval_B / interval_ms; //calculate the current Bps
146   -
147   - if(sample_step){ //if this is a sample step, collect the information for Bps = f(n0)
148   - Bps = new_Bps; //set the Bps to the evaluated value
149   - n[1] = n[0] - dn; //reduce the batch size by one delta to take a second sample
150   - if(n[1] == 0){ //if the resulting batch size is zero
151   - n[1] = 2*dn; //we're at the left edge: set the new sample point to 2*dn
152   - }
153   -
154   - interval_B = interval_ms = 0; //start a new interval at the new sample point
155   - sample_step = false; //next step will calculate the new batch size via optimization
156   - return n[1]; //return the new batch size
157   - }
158   - else{ //if we have sufficient information to evaluate the derivative and optimize
159   - double f = (double)new_Bps; //we have evaluated the function at this location
160   - double fprime;
161   - if(n[1] < n[0] ){ //if the new point is less than the previous point (usually the case)
162   - fprime = (double)(Bps - new_Bps) / (double)dn; //calculate the forward difference
163   - }
164   - else{ //if the new point is larger (only happens at the minimum limit)
165   - fprime = (double)(new_Bps - Bps) / (double)dn; //calculate the backward difference
166   - }
167   - size_t bestn = n[1] - (size_t)(f / fprime); //calculate the best value for B using Newton's method
168   - n[0] = round_limit( (size_t)bestn ); //set the new dependent point
169   - sample_step = true; //the next step will be a sample step
170   - }
171   -
172   - }
173   - if(sample_step) return n[0];
174   - return n[1]; //insufficient information, keep the same batch size
175   - }*/
176   -
177   - /*size_t update(size_t bytes_processed, size_t ms_spent){
178   - interval_B += bytes_processed; //increment the number of bytes processed
179   - interval_ms += ms_spent; //increment the number of milliseconds spent processing
180   -
181   - //if( Bps[0] == 0 ){ //if the left boundary hasn't been processed
182   -
183   -
184   - //if we have sufficient information to evaluate the optimization function at this point
185   - if(interval_ms >= window_ms){
186   - size_t new_Bps = interval_B / interval_ms; //calculate the current Bps
187   -
188   - if(Bps[0] == 0) //if the left interval Bps hasn't been calculated
189   - Bps[0] = interval_B / interval_ms; //that is the interval being processed
190   - else
191   - Bps[1] = interval_B / interval_ms; //otherwise the right interval is being processed
192   -
193   - if(Bps[0] != 0 && Bps[1] != 0){ //if both intervals have been processed
194   -
195   -
196   - }
197   - }*/
198   -
199   - /*size_t update(size_t bytes_processed, size_t ms_spent, size_t& data_rate, bool VERBOSE){
200   - size_t time = update(bytes_processed, ms_spent, VERBOSE);
201   - data_rate = Bps[0];
202   - return time;
203   - }*/
204 137 };
205 138  
206 139 /** This class manages the streaming of large multidimensional binary files.
... ... @@ -356,6 +289,10 @@ public:
356 289 return test_file_size();
357 290 }
358 291  
  292 + bool is_open() {
  293 + return file.is_open();
  294 + }
  295 +
359 296 /// Creates a new binary file for streaming
360 297  
361 298 /// @param filename is the name of the binary file to be created
... ...
stim/envi/bsq.h
1 1 #ifndef STIM_BSQ_H
2 2 #define STIM_BSQ_H
3 3  
4   -#include "../envi/envi_header.h"
5   -#include "../envi/hsi.h"
6   -#include "../envi/bil.h"
  4 +#include <stim/envi/envi_header.h>
  5 +#include <stim/envi/hsi.h>
  6 +#include <stim/envi/bil.h>
7 7 #include <cstring>
8 8 #include <utility>
9 9 #include <vector>
... ...
stim/envi/envi.h
1 1 #ifndef STIM_ENVI_H
2 2 #define STIM_ENVI_H
3 3  
4   -#include "../envi/envi_header.h"
5   -#include "../envi/bsq.h"
6   -#include "../envi/bip.h"
7   -#include "../envi/bil.h"
8   -#include "../math/fd_coefficients.h"
  4 +#include <stim/envi/envi_header.h>
  5 +#include <stim/envi/bsq.h>
  6 +#include <stim/envi/bip.h>
  7 +#include <stim/envi/bil.h>
  8 +#include <stim/math/fd_coefficients.h>
9 9 #include <stim/parser/filename.h>
10 10 #include <stim/util/filesize.h>
11 11 #include <iostream>
... ... @@ -71,7 +71,7 @@ public:
71 71 file = NULL; //set the file pointer to NULL
72 72 }
73 73  
74   - envi(std::string filename, std::string headername){
  74 + envi(std::string filename, std::string headername) : envi(){
75 75 header.load(headername);
76 76  
77 77 fname = filename; //save the filename
... ... @@ -80,8 +80,36 @@ public:
80 80 }
81 81 //used to test if the current ENVI file is valid
82 82 operator bool(){
83   - if(file == NULL) return false;
84   - return true;
  83 + if (header.interleave == envi_header::BSQ) { //if the infile is bsq file
  84 + if (header.data_type == envi_header::float32)
  85 + return ((bsq<float>*)file)->is_open();
  86 + else if (header.data_type == envi_header::float64)
  87 + return ((bsq<double>*)file)->is_open();
  88 + else
  89 + std::cout << "ERROR: unidentified data type" << std::endl;
  90 + }
  91 +
  92 + else if (header.interleave == envi_header::BIL) { //if the infile is bil file
  93 + if (header.data_type == envi_header::float32)
  94 + return ((bil<float>*)file)->is_open();
  95 + else if (header.data_type == envi_header::float64)
  96 + return ((bil<double>*)file)->is_open();
  97 + else
  98 + std::cout << "ERROR: unidentified data type" << std::endl;
  99 + }
  100 +
  101 + else if (header.interleave == envi_header::BIP) { //if the infile is bip file
  102 + if (header.data_type == envi_header::float32)
  103 + return ((bip<float>*)file)->is_open();
  104 + else if (header.data_type == envi_header::float64)
  105 + return ((bip<double>*)file)->is_open();
  106 + else
  107 + std::cout << "ERROR: unidentified data type" << std::endl;
  108 + }
  109 + else {
  110 + std::cout << "ERROR: unidentified file type" << std::endl;
  111 + exit(1);
  112 + }
85 113 }
86 114  
87 115 //test to determine if the specified file is an ENVI file
... ...
stim/envi/hsi.h
1 1 #ifndef STIM_HSI_H
2 2 #define STIM_HSI_H
3 3  
4   -#include "../envi/envi_header.h"
5   -#include "../envi/binary.h"
  4 +#include <stim/envi/envi_header.h>
  5 +#include <stim/envi/binary.h>
6 6 #include <cstring>
7 7 #include <utility>
8 8  
... ...