#pragma rtGlobals=3 // Use modern global access method. #pragma version=5.0 #pragma IgorVersion=6.1 #include //************************ // Vers 1.15 20171003 // //************************ /////////////////////////////////////////////////////////////////////////// // - WriteNxCanSAS1D - Method for writing 1D NXcanSAS data // Creates an HDF5 file, with reduced 1D data and stores all meta data // If dialog and fullpath are left blank (0 and ""), fake data will be used Function WriteNxCanSAS1D(type,fullpath,dialog) // Define input variables String type // data location, in memory, relative to root:Packages:NIST: String fullpath // file path and name where data will be saved Variable dialog // if 1, prompt user for file path, otherwise, use fullpath // Define local function variables Variable fileID String destStr="" String parentBase = "/sasentry/" // HDF5 base path for all String/G base = "root:NXcanSAS_file" KillDataFolder/Z $base // Define local waves Wave/T vals,attr,attrVals // Define folder for data heirarchy NewDataFolder/O/S root:NXcanSAS_file // Check fullpath and dialog if(dialog || stringmatch(fullpath, "")) fileID = NxCansas_DoSaveFileDialog() else fileID = NxCansas_CreateFile(fullpath) Endif if(!fileID) Print "Unable to create file at " + fullpath + "." else destStr = "root:Packages:NIST:"+type //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error**** WAVE intw = $(destStr + ":integersRead") WAVE rw = $(destStr + ":realsRead") WAVE/T textw=$(destStr + ":textRead") WAVE qvals =$(destStr + ":qval") WAVE inten=$(destStr + ":aveint") WAVE sig=$(destStr + ":sigave") WAVE qbar = $(destStr + ":QBar") WAVE sigmaq = $(destStr + ":SigmaQ") WAVE fsubs = $(destStr + ":fSubS") endif /////////////////////////////////////////////////////////////////////////// // Write all data // Define common attribute waves Make/T/N=1 empty = {""} Make/T/N=1 units = {"units"} Make/T/N=1 inv_cm = {"1/cm"} Make/T/N=1 inv_angstrom = {"1/A"} // Run Name and title NewDataFolder/O/S $(base + ":entry1") Make/T/N=1 $(base + ":entry1:title") = {textw[6]} CreateStrNxCansas(fileID,parentBase,"","title",$(base + ":entry1:title"),empty,empty) Make/T/N=1 $(base + ":entry1:run") = {textw[0]} CreateStrNxCansas(fileID,parentBase,"","run",$(base + ":entry1:run"),empty,empty) // SASData String dataParent = parentBase + "sasdata/" // Create SASdata entry String dataBase = base + ":entry1:sasdata" NewDataFolder/O/S $(dataBase) Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"} Make/O/T/N=5 $(dataBase + ":attrVals") = {"SASdata","I","Q","NXdata","0",textw[1]} CreateStrNxCansas(fileID,dataParent,"","",empty,$(dataBase + ":attr"),$(dataBase + ":attrVals")) // Create q entry NewDataFolder/O/S $(dataBase + ":q") Make/T/N=2 $(dataBase + ":q:attr") = {"units","resolutions"} Make/T/N=2 $(dataBase + ":q:attrVals") = {"1/angstrom","Qdev"} CreateVarNxCansas(fileID,dataParent,"sasdata","Q",qvals,$(dataBase + ":q:attr"),$(dataBase + ":q:attrVals")) // Create i entry NewDataFolder/O/S $(dataBase + ":i") Make/T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"} Make/T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"} CreateVarNxCansas(fileID,dataParent,"sasdata","I",inten,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals")) // Create idev entry CreateVarNxCansas(fileID,dataParent,"sasdata","Idev",sig,units,inv_cm) // Create qdev entry CreateVarNxCansas(fileID,dataParent,"sasdata","Qdev",sigmaq,units,inv_angstrom) CreateVarNxCansas(fileID,dataParent,"sasdata","Qmean",qbar,units,inv_angstrom) // Write all meta data WriteMetaData(fileID,base,parentBase,rw,textw) // /////////////////////////////////////////////////////////////////////////// // Close the file if(fileID) HDF5CloseFile /Z fileID endif KillDataFolder/Z $base End // /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // - WriteNxCanSAS2D - Method for writing 2D NXcanSAS data // Creates an HDF5 file, generates reduced 2D data and stores all meta data // If dialog and fullpath are left blank (0 and ""), fake data will be used Function WriteNxCanSAS2D(type,fullpath,dialog) // Define input variables String type // data location, in memory, relative to root:Packages:NIST: String fullpath // file path and name where data will be saved Variable dialog // if 1, prompt user for file path, otherwise, use fullpath // Define local function variables Variable fileID String destStr="",typeStr="" String parentBase = "/sasentry/" // HDF5 base path for all String/G base = "root:NXcanSAS_file" KillDataFolder/Z $base // Define local waves Wave/T vals,attr,attrVals // Define folder for data heirarchy NewDataFolder/O/S root:NXcanSAS_file // Check fullpath and dialog if(dialog || stringmatch(fullpath, "")) fileID = NxCansas_DoSaveFileDialog() else fileID = NxCansas_CreateFile(fullpath) Endif if(!fileID) Print "Unable to create file at " + fullpath + "." else destStr = "root:Packages:NIST:"+type //must select the linear_data to export NVAR isLog = $(destStr+":gIsLogScale") if(isLog==1) typeStr = ":linear_data" else typeStr = ":data" endif NVAR pixelsX = root:myGlobals:gNPixelsX NVAR pixelsY = root:myGlobals:gNPixelsY Wave data=$(destStr+typeStr) Wave data_err=$(destStr+":linear_data_error") WAVE intw=$(destStr + ":integersRead") WAVE rw=$(destStr + ":realsRead") WAVE/T textw=$(destStr + ":textRead") endif /////////////////////////////////////////////////////////////////////////// // Compute Qx, Qy data from pixel space Duplicate/O data,qx_val,qy_val,z_val,qval,qz_val,phi,r_dist Variable xctr,yctr,sdd,lambda,pixSize xctr = rw[16] yctr = rw[17] sdd = rw[18] lambda = rw[26] pixSize = rw[13]/10 //convert mm to cm (x and y are the same size pixels) qx_val = CalcQx(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) //+1 converts to detector coordinate system qy_val = CalcQy(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) Redimension/N=(pixelsX*pixelsY) qx_val,qy_val,z_val Variable L2 = rw[18] Variable BS = rw[21] Variable S1 = rw[23] Variable S2 = rw[24] Variable L1 = rw[25] Variable lambdaWidth = rw[27] Variable usingLenses = rw[28] //new 2007 Variable vz_1 = 3.956e5 //velocity [cm/s] of 1 A neutron Variable g = 981.0 //gravity acceleration [cm/s^2] Variable m_h = 252.8 // m/h [=] s/cm^2 Variable acc,ssd,lambda0,yg_d,qstar G = 981. //! ACCELERATION OF GRAVITY, CM/SEC^2 acc = vz_1 // 3.956E5 //! CONVERT WAVELENGTH TO VELOCITY CM/SEC SDD = L2 *100 //1317 SSD = L1 *100 //1627 //cm lambda0 = lambda // 15 YG_d = -0.5*G*SDD*(SSD+SDD)*(LAMBDA0/acc)^2 qstar = -2*pi/lambda0*2*yg_d/sdd // the gravity center is not the resolution center // gravity center = beam center // resolution center = offset y = dy + (2)*yg_d ///************ // do everything to write out the resolution too // un-comment these if you want to write out qz_val and qval too, then use the proper save command qval = CalcQval(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) qz_val = CalcQz(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10) // phi = FindPhi( pixSize*((p+1)-xctr) , pixSize*((q+1)-yctr)) //(dx,dy) // r_dist = sqrt( (pixSize*((p+1)-xctr))^2 + (pixSize*((q+1)-yctr))^2 ) //radial distance from ctr to pt phi = FindPhi( pixSize*((p+1)-xctr) , pixSize*((q+1)-yctr)+(2)*yg_d) //(dx,dy+yg_d) r_dist = sqrt( (pixSize*((p+1)-xctr))^2 + (pixSize*((q+1)-yctr)+(2)*yg_d)^2 ) //radial distance from ctr to pt Redimension/N=(pixelsX*pixelsY) qz_val,qval,phi,r_dist Make/O/N=(2,pixelsX,pixelsY) qxy_vals //everything in 1D now Duplicate/O qval SigmaQX,SigmaQY Make/O/N=(pixelsX,pixelsY) shadow Make/O/N=(2,pixelsX,pixelsY) SigmaQ_combined //Two parameters DDET and APOFF are instrument dependent. Determine //these from the instrument name in the header. //From conversation with JB on 01.06.99 these are the current good values Variable DDet NVAR apOff = root:myGlobals:apOff //in cm DDet = rw[10]/10 // header value (X) is in mm, want cm here Variable ret1,ret2,ret3,jj Variable nq = 0 Variable ii = 0 do jj = 0 do nq = ii * pixelsX + jj get2DResolution(qval[nq],phi[nq],lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,pixSize,usingLenses,r_dist[nq],ret1,ret2,ret3) qxy_vals[0][ii][jj] = qx_val[nq] qxy_vals[1][ii][jj] = qy_val[nq] SigmaQ_combined[0][ii][jj] = ret1 SigmaQ_combined[1][ii][jj] = ret2 shadow[ii][jj] = ret3 jj+=1 while(jj