Commit 41e2f5abf75c614eb8c667c116b1fe3375d7ad94

Authored by David Mayerich
1 parent 9d34229e

fixed finite mask bug, bypass file size detection because it doesn't work for large files

Showing 2 changed files with 20 additions and 4 deletions   Show diff stats
@@ -83,8 +83,22 @@ public: @@ -83,8 +83,22 @@ public:
83 return true; 83 return true;
84 } 84 }
85 85
  86 + static size_t file_size(std::string filename){
  87 + FILE *p_file = NULL;
  88 + p_file = fopen(filename.c_str(),"rb");
  89 + if(!p_file){
  90 + std::cout<<"ERROR: could not open "<<filename<<std::endl;
  91 + exit(1);
  92 + }
  93 + fseek(p_file,0,SEEK_END);
  94 + size_t size = ftell(p_file);
  95 + fclose(p_file);
  96 + return size;
  97 + }
  98 +
86 //test to determine if the specified file is an ENVI file 99 //test to determine if the specified file is an ENVI file
87 static bool is_envi(std::string fname, std::string hname = ""){ 100 static bool is_envi(std::string fname, std::string hname = ""){
  101 + return true;
88 stim::filename data_file(fname); 102 stim::filename data_file(fname);
89 stim::filename header_file; 103 stim::filename header_file;
90 if(hname == ""){ //if the header isn't provided 104 if(hname == ""){ //if the header isn't provided
@@ -97,11 +111,13 @@ public: @@ -97,11 +111,13 @@ public:
97 if(H.load(header_file) == false) //load the header file, if it doesn't load return false 111 if(H.load(header_file) == false) //load the header file, if it doesn't load return false
98 return false; 112 return false;
99 size_t targetBytes = H.data_bytes(); //get the number of bytes that SHOULD be in the data file 113 size_t targetBytes = H.data_bytes(); //get the number of bytes that SHOULD be in the data file
100 - std::ifstream infile(data_file.str(), std::ifstream::ate | std::ifstream::binary); //load the data file  
101 - if(!infile) return false; //if the data file doesn't load, return false  
102 - size_t bytes = infile.tellg(); //get the number of actual bytes in the file 114 + //std::ifstream infile(data_file.str(), std::ifstream::binary); //load the data file
  115 + //if(!infile) return false; //if the data file doesn't load, return false
  116 + //size_t bytes = infile.tellg(); //get the number of actual bytes in the file
  117 + size_t bytes = file_size(fname);
103 if(bytes != targetBytes) return false; //if the data doesn't match the header, return false 118 if(bytes != targetBytes) return false; //if the data doesn't match the header, return false
104 return true; //otherwise everything looks fine 119 return true; //otherwise everything looks fine
  120 +
105 } 121 }
106 122
107 123
@@ -142,7 +142,7 @@ public: @@ -142,7 +142,7 @@ public:
142 void mask_finite(unsigned char* out_mask, unsigned char* mask, bool PROGRESS = false){ 142 void mask_finite(unsigned char* out_mask, unsigned char* mask, bool PROGRESS = false){
143 size_t XY = X() * Y(); 143 size_t XY = X() * Y();
144 if(mask == NULL) //if no mask is provided 144 if(mask == NULL) //if no mask is provided
145 - memset(mask, 255, XY * sizeof(unsigned char)); //initialize the mask to 255 145 + memset(out_mask, 255, XY * sizeof(unsigned char)); //initialize the mask to 255
146 else //if a mask is provided 146 else //if a mask is provided
147 memcpy(out_mask, mask, XY * sizeof(unsigned char)); //initialize the current mask to that one 147 memcpy(out_mask, mask, XY * sizeof(unsigned char)); //initialize the current mask to that one
148 T* page = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate space for a page of data 148 T* page = (T*)malloc(R[0] * R[1] * sizeof(T)); //allocate space for a page of data