#pragma rtGlobals=1 // Use modern global access method. #include #include // Winspec.ipf // Sjors Wurpel 2005 // This procedure file contains the LoadPrincetonSPE() function to import binary winspec (.spe) files // The macro LoadPrincetonSPEdir() is provided to import all files from a directory // The procedures may be used freely. If you find any bugs, please notify me by e-mail: // wurpel at amolf.nl // Enjoy! // General load routine for Princeton binary files as written by e.g. Winspec // Code based on http://www.sccs.swarthmore.edu/users/03/roban/temperature/conversion/read_princeton.pro // Reads both graphs and images // Should work with all datatypes, but only type 3 (int) has been tested // Info from the 4100 byte header is processed and stored in wave notes // If there is calibration info available, a scaling wave is created // Optionally, a visible wavelength (nm) can be provided to convert scaling to raman shift (cm-1) // E.g. call this function as LoadPrincetonSPE("", "", vis=800.8) // CHANGED June 2005, Sjors // Allows for 3D image stacks (e.g. time series) // // Modified May 2011, Doru Constantin // Corrected runtime error due to non-existent $wname (the KillWaves command seems to have been the problem) // Simplified the function by only preserving the functionality related to CCD images Function LoadPrincetonSPE(pathname, filename) string pathname, filename variable refnum, tmp, i variable exp_sec variable nx, ny, nframes, datatype string wname string wnameX, wnameY string datestr, timestr, comment1, comment2, comment3, comment4, comment5 string notestr, wavenote="" variable avg string wnamels open/r/p=$pathname/Z=2/M="Press cancel if you're finished"/t=".spe" refnum as filename if (V_flag!=0) abort endif //Build wavename FStatus refnum wname=S_fileName[0,((strlen(S_fileName)-1)-4)] // remove last 4 chars from filename wname = Cleanupname(wname,0) //Header info FSetPos refnum, 10; FBinRead/B=3/F=4 refnum,exp_sec //exposure in seconds FSetPos refnum, 42; FbinRead/B=3/F=2 refnum, nx //number of x pixels FSetPos refnum, 656; FbinRead/B=3/F=2 refnum, ny //number of y pixels (=1 for graph) FSetPos refnum, 1446; FbinRead/B=3/F=3 refnum, nframes //number of frames FSetPos refnum, 108; FbinRead/B=3/F=2 refnum, datatype //data type float, long, uint, int //Date-time FSetPos refnum, 20; FReadLine/N=10 refnum, datestr //format DDMMMYYYY (20Apr2005) FSetPos refnum, 172; FReadLine/N=6 refnum, timestr //format HHMMSS (161959) //User Comments FsetPos refnum, 200; Freadline refnum, comment1 FsetPos refnum, 280; Freadline refnum, comment2 FsetPos refnum, 360; Freadline refnum, comment3 FsetPos refnum, 440; Freadline refnum, comment4 FsetPos refnum, 520; Freadline refnum, comment5 Close refnum switch(datatype) case 0: // float ? GBLoadWave/O/Q/B=3/S=4100/T={2,4}/U=(nx*ny*nframes)/W=(1)/N=WStemp (S_path+S_filename) break case 1: // long ? GBLoadWave/O/Q/B=3/S=4100/T={32,4}/U=(nx*ny*nframes)/W=(1)/N=WStemp (S_path+S_filename) break case 2: //uint ? GBLoadWave/O/Q/B=3/S=4100/T={16+64,4}/U=(nx*ny*nframes)/W=(1)/N=WStemp (S_path+S_filename) break case 3: //originally int, changed to unsigned integer GBLoadWave/O/Q/B=3/S=4100/T={16+64,4}/U=(nx*ny*nframes)/W=(1)/N=WStemp (S_path+S_filename) break default: abort "Unknown datatype" endswitch //Rename loaded wave to cleaned-up filename Duplicate/O WStemp0, $wname WAVE w = $wname KillWaves/Z WStemp0 // redimension and create scaling waves if (ny>1) // image(stack) file if (nframes == 1) // image redimension/N=(nx,ny) w else // 3D image stack redimension/N=(nx,ny, nframes) w endif endif //Store all parameters in wavenote sprintf notestr, "File: %s\r", S_Filename ;wavenote+=notestr sprintf notestr, "Path: %s\r", S_Path ;wavenote+=notestr sprintf notestr, "Exposure: %g\r", exp_sec ;wavenote+=notestr sprintf notestr, "Frames: %g\r", nframes ;wavenote+=notestr sprintf notestr, "Captured: %s %s\r", DateStr , TimeColon(Timestr) ;wavenote+=notestr sprintf notestr, "Comment: %s -- %s -- %s -- %s -- %s\r", Comment1,Comment2,Comment3,Comment4,Comment5 wavenote+=notestr Note w, wavenote print wname End Function/S TimeColon(timestr) string timestr string hh, mm, ss hh=timestr[0,1] mm=timestr[2,3] ss=timestr[4,5] return hh+":"+mm+":"+ss End