Commit edb975b07daca23af35014528d1992c5b90b1807
1 parent
6d242237
created a stim::envi default constructor and fixed a seg fault when an unopened file is closed
Showing
1 changed file
with
13 additions
and
8 deletions
Show diff stats
stim/envi/envi.h
... | ... | @@ -61,6 +61,11 @@ class envi{ |
61 | 61 | |
62 | 62 | public: |
63 | 63 | |
64 | + /// Default constructor | |
65 | + envi(){ | |
66 | + file = NULL; //set the file pointer to NULL | |
67 | + } | |
68 | + | |
64 | 69 | envi_header header; |
65 | 70 | |
66 | 71 | void* malloc_spectrum(){ |
... | ... | @@ -979,12 +984,13 @@ public: |
979 | 984 | } |
980 | 985 | |
981 | 986 | /// Closes the ENVI file. |
982 | - bool close(){ | |
987 | + void close(){ | |
988 | + if(file == NULL) return; | |
983 | 989 | if(header.interleave == envi_header::BSQ){ |
984 | 990 | if(header.data_type ==envi_header::float32) |
985 | - return ((bsq<float>*)file)->close(); | |
991 | + ((bsq<float>*)file)->close(); | |
986 | 992 | else if(header.data_type == envi_header::float64) |
987 | - return ((bsq<double>*)file)->close(); | |
993 | + ((bsq<double>*)file)->close(); | |
988 | 994 | else{ |
989 | 995 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
990 | 996 | exit(1); |
... | ... | @@ -993,9 +999,9 @@ public: |
993 | 999 | |
994 | 1000 | else if(header.interleave == envi_header::BIL){ |
995 | 1001 | if(header.data_type ==envi_header::float32) |
996 | - return ((bil<float>*)file)->close(); | |
1002 | + ((bil<float>*)file)->close(); | |
997 | 1003 | else if(header.data_type == envi_header::float64) |
998 | - return ((bil<double>*)file)->close(); | |
1004 | + ((bil<double>*)file)->close(); | |
999 | 1005 | else{ |
1000 | 1006 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
1001 | 1007 | exit(1); |
... | ... | @@ -1004,15 +1010,14 @@ public: |
1004 | 1010 | |
1005 | 1011 | else if(header.interleave == envi_header::BIP){ |
1006 | 1012 | if(header.data_type ==envi_header::float32) |
1007 | - return ((bip<float>*)file)->close(); | |
1013 | + ((bip<float>*)file)->close(); | |
1008 | 1014 | else if(header.data_type == envi_header::float64) |
1009 | - return ((bip<double>*)file)->close(); | |
1015 | + ((bip<double>*)file)->close(); | |
1010 | 1016 | else{ |
1011 | 1017 | std::cout<<"ERROR: unidentified data type"<<std::endl; |
1012 | 1018 | exit(1); |
1013 | 1019 | } |
1014 | 1020 | } |
1015 | - return false; | |
1016 | 1021 | } |
1017 | 1022 | |
1018 | 1023 | /// Retrieve a single pixel and stores it in pre-allocated memory. | ... | ... |