From 332925ad3ee1a2c21bda3f7b0630633752e47ca4 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 26 Jan 2017 22:21:58 -0600 Subject: [PATCH] added the ability to crop agilent binary files --- stim/envi/agilent_binary.h | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/stim/envi/agilent_binary.h b/stim/envi/agilent_binary.h index cd298e2..91169fb 100644 --- a/stim/envi/agilent_binary.h +++ b/stim/envi/agilent_binary.h @@ -44,6 +44,10 @@ public: alloc(); } + char* data() { + return (char*)ptr; + } + size_t dim(size_t i){ return R[i]; } @@ -84,6 +88,11 @@ public: return *this; //return the result } + operator bool() { + if (R[0] == 0 || R[1] == 0 || R[2] == 0) return false; + else return true; + } + ~agilent_binary(){ free(ptr); } @@ -189,6 +198,17 @@ public: ptr[i] = -log10(ptr[i] / background->ptr[i]); } + //crops the image down to a set number of samples + void crop(size_t n) { + if (n < R[2]) { //if the requested size is smaller than the image + R[2] = n; //update the number of bands + T* old_ptr = ptr; //store the old pointer + alloc(); //allocate space for the new image + memcpy(ptr, old_ptr, bytes()); //copy the old data to the new image + free(old_ptr); //free the old data + } + } + //#ifdef CUDA_FOUND /// Perform an FFT and return a binary file with bands in the specified range agilent_binary fft(double band_min, double band_max, double ELWN = 15798, int UDR = 2){ @@ -242,18 +262,19 @@ public: HANDLE_ERROR(cudaMemcpy(cpu_fft, gpu_fft, R[0] * R[1] * (R[2]/2+1) * sizeof(cufftComplex), cudaMemcpyDeviceToHost)); //copy data from the host to the device //double int_delta = 0.00012656; //interferogram sample spacing in centimeters - double int_delta = (1.0 / ELWN) * ((double)UDR / 2.0); //calculate the interferogram spacing - double int_length = int_delta * R[2]; //interferogram length in centimeters - double fft_delta = 1/int_length; //spectrum spacing (in inverse centimeters, wavenumber) - double fft_max = fft_delta * R[2]/2; //get the maximum wavenumber value supported by the specified number of interferogram samples + double int_delta = (1.0 / ELWN) * ((double)UDR / 2.0); //calculate the interferogram spacing + double int_length = int_delta * R[2]; //interferogram length in centimeters + double fft_delta = 1/int_length; //spectrum spacing (in inverse centimeters, wavenumber) + double fft_max = fft_delta * R[2]/2; //get the maximum wavenumber value supported by the specified number of interferogram samples - if(band_max > fft_max) band_max = fft_max; //the user gave a band outside of the FFT range, reset the band to the maximum available + if(band_max > fft_max) band_max = fft_max; //the user gave a band outside of the FFT range, reset the band to the maximum available + if (band_min < 0) band_min = 0; size_t start_i = (size_t)std::ceil(band_min / fft_delta); //calculate the first band to store size_t size_i = (size_t)std::floor(band_max / fft_delta) - start_i; //calculate the number of bands to store - size_t end_i = start_i + size_i; //last band number + size_t end_i = start_i + size_i; //last band number agilent_binary result(R[0], R[1], size_i); - result.Z[0] = start_i * fft_delta; //set the range for the FFT result + result.Z[0] = start_i * fft_delta; //set the range for the FFT result result.Z[1] = end_i * fft_delta; for(size_t b = start_i; b < end_i; b++){ -- libgit2 0.21.4