diff --git a/stim/envi/bip.h b/stim/envi/bip.h index 9de7311..703aa32 100644 --- a/stim/envi/bip.h +++ b/stim/envi/bip.h @@ -1236,7 +1236,6 @@ public: cublasHandle_t handle; std::ofstream target(outfile.c_str(), std::ios::binary); //open the target binary file - //std::string headername = outfile + ".hdr"; //the header file name progress = 0; //initialize the progress to zero (0) unsigned long long XY = X() * Y(); //calculate the number of elements in a band image @@ -1281,19 +1280,19 @@ public: return EXIT_FAILURE; } - T* temp = (T*)malloc(sizeof(T) * M); //allocate space for the projected pixel to be written on the disc - - for (unsigned long long xy = 0; xy < XY; xy++){ //for each pixel + T* temp = (T*)malloc(sizeof(T) * M); //allocate space for the projected pixel to be written on the disc + size_t i; + for (unsigned long long xy = 0; xy < XY; xy++){ //for each pixel if (mask == NULL || mask[xy] != 0){ - pixeld(s, xy); //retreive the spectrum at the current xy pixel location + pixeld(s, xy); //retreive the spectrum at the current xy pixel location stat = cublasSetVector((int)B, sizeof(double), s, 1, s_dev, 1); //copy the spectrum from the host to the device stat = cublasDaxpy(handle, (int)B, &axpy_alpha, center_dev, 1, s_dev, 1); //subtract the center (average) stat = cublasDgemv(handle,CUBLAS_OP_N,(int)M,(int)B,&axpy_alpha2,basis_dev,(int)M,s_dev,1,&axpy_beta,A_dev,1); //performs the matrix-vector multiplication - stat = cublasGetVector((int)B, sizeof(double), A_dev, 1, A, 1); //copy the projected pixel to the host (from GPU to CPU) - - std::copy(A, A + M, temp); //casting projected pixel from double to whatever T is + stat = cublasGetVector((int)B, sizeof(double), A_dev, 1, A, 1); //copy the projected pixel to the host (from GPU to CPU) + //std::copy(A, A + M, temp); + for(i = 0; i < M; i++) temp[i] = (T)A[i]; //casting projected pixel from double to whatever T is } target.write(reinterpret_cast(temp), sizeof(T) * M); //write the projected vector @@ -1310,7 +1309,7 @@ public: free(s); free(temp); target.close(); //close the output file - + return true; } #endif @@ -1360,7 +1359,7 @@ public: free(s); //free temporary storage arrays free(rs); target.close(); //close the output file - + return true; } diff --git a/stim/envi/bsq.h b/stim/envi/bsq.h index 697edc2..ae3492f 100644 --- a/stim/envi/bsq.h +++ b/stim/envi/bsq.h @@ -394,7 +394,7 @@ public: std::ofstream target(outname.c_str(), std::ios::binary); std::string headername = outname + ".hdr"; - size_t batches = ceil((double)(Y()) / (double)batch_slices); //calculate the number of batches + size_t batches = (size_t)ceil((double)(Y()) / (double)batch_slices); //calculate the number of batches T* ptrDst; T* ptrSrc; for(size_t c = 0; c < batches; c++){ diff --git a/stim/envi/envi.h b/stim/envi/envi.h index 0d365c3..5cc1e25 100644 --- a/stim/envi/envi.h +++ b/stim/envi/envi.h @@ -59,15 +59,17 @@ class envi{ for(size_t i = 0; i < len; i++) cast(&dst[i], &src[i]); } - + public: + envi_header header; + /// Default constructor envi(){ file = NULL; //set the file pointer to NULL } - envi_header header; + void* malloc_spectrum(){ return alloc_array(header.bands); @@ -1171,46 +1173,6 @@ public: return false; } - /// Retrieve a spectrum from the specified location - - /// @param ptr is a pointer to pre-allocated memory of size B*sizeof(T) - /// @param x is the x-coordinate of the spectrum - /// @param y is the y-coordinate of the spectrum - /*bool spectrum(void* ptr, unsigned long long x, unsigned long long y, bool PROGRESS = false){ - - if(header.interleave == envi_header::BSQ){ //if the infile is bsq file - if(header.data_type ==envi_header::float32) - return ((bsq*)file)->spectrum((float*)ptr, x, y, PROGRESS); - else if (header.data_type == envi_header::float64) - return ((bsq*)file)->spectrum((double*)ptr, x, y, PROGRESS); - else{ - std::cout << "ERROR: unidentified data type" << std::endl; - exit(1); - } - } - else if (header.interleave == envi_header::BIL){ - if (header.data_type == envi_header::float32) - return ((bil*)file)->spectrum((float*)ptr, x, y, PROGRESS); - else if (header.data_type == envi_header::float64) - return ((bil*)file)->spectrum((double*)ptr, x, y, PROGRESS); - else{ - std::cout << "ERROR: unidentified data type" << std::endl; - exit(1); - } - } - else if (header.interleave == envi_header::BIP){ - if (header.data_type == envi_header::float32) - return ((bip*)file)->spectrum((float*)ptr, x, y, PROGRESS); - else if (header.data_type == envi_header::float64) - return ((bip*)file)->spectrum((double*)ptr, x, y, PROGRESS); - else{ - std::cout << "ERROR: unidentified data type" << std::endl; - exit(1); - } - } - return false; - }*/ - // Retrieve a spectrum at the specified 1D location /// @param ptr is a pointer to pre-allocated memory of size B*sizeof(T) @@ -1274,50 +1236,6 @@ public: void spectrum(T* ptr, size_t x, size_t y, bool PROGRESS = false){ spectrum(ptr, y * header.samples + x, PROGRESS); - /*void* temp = alloc_array(header.bands); //allocate space for the output array - - if(header.interleave == envi_header::BSQ){ //if the infile is bsq file - if(header.data_type ==envi_header::float32){ - ((bsq*)file)->spectrum((float*)temp, x, y, PROGRESS); - cast(ptr, temp, header.bands); - } - else if (header.data_type == envi_header::float64){ - ((bsq*)file)->spectrum((double*)temp, x, y, PROGRESS); - cast(ptr, temp, header.bands); - } - else{ - std::cout << "ERROR: unidentified data type" << std::endl; - exit(1); - } - } - else if (header.interleave == envi_header::BIL){ - if (header.data_type == envi_header::float32){ - ((bil*)file)->spectrum((float*)temp, x, y, PROGRESS); - cast(ptr, temp, header.bands); - } - else if (header.data_type == envi_header::float64){ - ((bil*)file)->spectrum((double*)temp, x, y, PROGRESS); - cast(ptr, temp, header.bands); - } - else{ - std::cout << "ERROR: unidentified data type" << std::endl; - exit(1); - } - } - else if (header.interleave == envi_header::BIP){ - if (header.data_type == envi_header::float32){ - ((bip*)file)->spectrum((float*)temp, x, y, PROGRESS); - cast(ptr, temp, header.bands); - } - else if (header.data_type == envi_header::float64){ - ((bip*)file)->spectrum((double*)temp, x, y, PROGRESS); - cast(ptr, temp, header.bands); - } - else{ - std::cout << "ERROR: unidentified data type" << std::endl; - exit(1); - } - }*/ } /// Retrieve a single band (based on index) and stores it in pre-allocated memory. @@ -1405,14 +1323,6 @@ public: if (header.interleave == envi_header::BSQ){ std::cout<<"ERROR: calculating the covariance matrix for a BSQ file is impractical; convert to BIL or BIP first"<*)file)->co_matrix(co, avg, mask, PROGRESS); - else if (header.data_type == envi_header::float64) - return ((bsq*)file)->co_matrix(co, avg, mask, PROGRESS); - else{ - std::cout << "ERROR: unidentified data type" << std::endl; - exit(1); - }*/ } else if (header.interleave == envi_header::BIL){ if (header.data_type == envi_header::float32) -- libgit2 0.21.4