source: sans/Dev/branches/nxcansas_writer/NCNR_User_Procedures/Reduction/SANS/Write_SANS_NXcanSAS.ipf @ 1218

Last change on this file since 1218 was 1218, checked in by srkline, 3 years ago

changes to NXcanSAS branch to allow each reduction package to compile correctly by having the proper files included.

Some checks have been added to the file loaders to catch errors where header fields are not present in the file (sometimes an issue with NSORTed files)

File size: 21.4 KB
Line 
1#pragma rtGlobals=3             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=6.1
4
5#include <HDF5 Browser>
6
7//************************
8// Vers 1.15 20171003
9//
10//************************
11
12
13///////////////////////////////////////////////////////////////////////////
14// - WriteNxCanSAS1D - Method for writing 1D NXcanSAS data
15// Creates an HDF5 file, with reduced 1D data and stores all meta data
16// If dialog and fullpath are left blank (0 and ""), fake data will be used
17
18Function WriteNxCanSAS1D(type,fullpath,dialog)
19        // Define input variables
20        String type // data location, in memory, relative to root:Packages:NIST:
21        String fullpath // file path and name where data will be saved
22        Variable dialog // if 1, prompt user for file path, otherwise, use fullpath
23       
24        // Define local function variables
25        Variable fileID
26        String destStr="", parentBase, nxcansasBase
27        String/G base = "root:NXcanSAS_file"
28       
29        // Define local waves
30//      Wave/T vals,attr,attrVals
31       
32        // Define folder for data heirarchy
33        NewDataFolder/O/S root:NXcanSAS_file
34       
35        // Check fullpath and dialog
36        fileID = NXcanSAS_OpenOrCreate(dialog,fullpath,base)
37       
38        Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1)
39        sPrintf parentBase,"%s:sasentry%d",base,sasentry // Igor memory base path for all
40        sPrintf nxcansasBase,"/sasentry%d/",sasentry // HDF5 base path for all
41
42        destStr = "root:Packages:NIST:"+type
43        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
44//      WAVE intw = $(destStr + ":integersRead")                // SRK_0920
45        WAVE rw = $(destStr + ":realsRead")
46        WAVE/T textw=$(destStr + ":textRead")
47        WAVE qvals =$(destStr + ":qval")
48        WAVE inten=$(destStr + ":aveint")
49        WAVE sig=$(destStr + ":sigave")
50        WAVE qbar = $(destStr + ":QBar")
51        WAVE sigmaq = $(destStr + ":SigmaQ")
52        WAVE fsubs = $(destStr + ":fSubS")
53
54        ///////////////////////////////////////////////////////////////////////////
55        // Write all data
56       
57        // Define common attribute waves
58        Make/T/O/N=1 empty = {""}
59        Make/T/O/N=1 units = {"units"}
60        Make/T/O/N=1 inv_cm = {"1/cm"}
61        Make/T/O/N=1 inv_angstrom = {"1/A"}
62       
63        // Run Name and title
64        NewDataFolder/O/S $(parentBase)
65        Make/O/T/N=1 $(parentBase + ":title") = {textw[6]}
66        CreateStrNxCansas(fileID,nxcansasBase,"","title",$(parentBase + ":title"),empty,empty)
67        Make/O/T/N=1 $(parentBase + ":run") = {textw[0]}
68        CreateStrNxCansas(fileID,nxcansasBase,"","run",$(parentBase + ":run"),empty,empty)
69       
70        // SASData
71        String dataParent = nxcansasBase + "sasdata/"
72        // Create SASdata entry
73        String dataBase = parentBase + ":sasdata"
74        NewDataFolder/O/S $(dataBase)
75        Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"}
76        Make/O/T/N=5 $(dataBase + ":attrVals") = {"SASdata","I","Q","NXdata","0",textw[1]}
77        CreateStrNxCansas(fileID,dataParent,"","",empty,$(dataBase + ":attr"),$(dataBase + ":attrVals"))
78        // Create q entry
79        NewDataFolder/O/S $(dataBase + ":q")
80        Make/O/T/N=2 $(dataBase + ":q:attr") = {"units","resolutions"}
81        Make/O/T/N=2 $(dataBase + ":q:attrVals") = {"1/angstrom","Qdev"}
82        CreateVarNxCansas(fileID,dataParent,"sasdata","Q",qvals,$(dataBase + ":q:attr"),$(dataBase + ":q:attrVals"))
83        // Create i entry
84        NewDataFolder/O/S $(dataBase + ":i")
85        Make/O/T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"}
86        Make/O/T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"}
87        CreateVarNxCansas(fileID,dataParent,"sasdata","I",inten,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals"))
88        // Create idev entry
89        CreateVarNxCansas(fileID,dataParent,"sasdata","Idev",sig,units,inv_cm)
90        // Create qdev entry
91        CreateVarNxCansas(fileID,dataParent,"sasdata","Qdev",sigmaq,units,inv_angstrom)
92        CreateVarNxCansas(fileID,dataParent,"sasdata","Qmean",qbar,units,inv_angstrom)
93       
94        // Write all meta data
95        if (CmpStr(type,"NSORT") == 0)
96                Wave/T process = $(destStr + ":processNote")
97                String processNote = process[0]
98                WriteProcess(fileID,nxcansasBase,parentBase,"NSORTed Data",processNote)
99        Else
100                WriteMetaData(fileID,parentBase,nxcansasBase,rw,textw)
101        EndIf
102       
103        //
104        ///////////////////////////////////////////////////////////////////////////
105       
106        // Close the file
107        if(fileID)
108                HDF5CloseFile /Z fileID
109        endif
110       
111        KillDataFolder/Z $base
112       
113End
114
115//
116///////////////////////////////////////////////////////////////////////////
117
118
119///////////////////////////////////////////////////////////////////////////
120// - WriteNxCanSAS2D - Method for writing 2D NXcanSAS data
121// Creates an HDF5 file, generates reduced 2D data and stores all meta data
122// If dialog and fullpath are left blank (0 and ""), fake data will be used
123
124Function WriteNxCanSAS2D(type,fullpath,dialog)
125        // Define input variables
126        String type // data location, in memory, relative to root:Packages:NIST:
127        String fullpath // file path and name where data will be saved
128        Variable dialog // if 1, prompt user for file path, otherwise, use fullpath
129       
130        // Define local function variables
131        Variable fileID
132        String destStr="",typeStr="", parentBase, nxcansasBase
133        String/G base = "root:NXcanSAS_file"
134       
135        // Define local waves
136//      Wave/T vals,attr,attrVals
137       
138        // Define folder for data heirarchy
139        NewDataFolder/O/S root:NXcanSAS_file
140       
141        // Check fullpath and dialog
142        fileID = NXcanSAS_OpenOrCreate(dialog,fullpath,base)
143
144        Variable sasentry = NumVarOrDefault("root:Packages:NIST:gSASEntryNumber", 1)
145        sPrintf parentBase,"%s:sasentry%d",base,sasentry // Igor memory base path for all
146        sPrintf nxcansasBase,"/sasentry%d/",sasentry // HDF5 base path for all
147       
148        destStr = "root:Packages:NIST:"+type
149
150        //must select the linear_data to export
151        NVAR isLog = $(destStr+":gIsLogScale")
152        if(isLog==1)
153                typeStr = ":linear_data"
154        else
155                typeStr = ":data"
156        endif
157        NVAR pixelsX = root:myGlobals:gNPixelsX
158        NVAR pixelsY = root:myGlobals:gNPixelsY
159        Wave data=$(destStr+typeStr)
160        Wave data_err=$(destStr+":linear_data_error")
161        WAVE intw=$(destStr + ":integersRead")
162        WAVE rw=$(destStr + ":realsRead")
163        WAVE/T textw=$(destStr + ":textRead")
164       
165        ///////////////////////////////////////////////////////////////////////////
166        // Compute Qx, Qy data from pixel space
167       
168        Duplicate/O data,qx_val,qy_val,z_val,qval,qz_val,phi,r_dist
169       
170        Variable xctr,yctr,sdd,lambda,pixSize
171        xctr = rw[16]
172        yctr = rw[17]
173        sdd = rw[18]
174        lambda = rw[26]
175        pixSize = rw[13]/10             //convert mm to cm (x and y are the same size pixels)
176       
177        qx_val = CalcQx(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10)          //+1 converts to detector coordinate system
178        qy_val = CalcQy(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10)
179       
180        Redimension/N=(pixelsX*pixelsY) qx_val,qy_val,z_val
181
182        Variable L2 = rw[18]
183        Variable BS = rw[21]
184        Variable S1 = rw[23]
185        Variable S2 = rw[24]
186        Variable L1 = rw[25]
187        Variable lambdaWidth = rw[27]   
188        Variable usingLenses = rw[28]           //new 2007
189
190        Variable vz_1 = 3.956e5         //velocity [cm/s] of 1 A neutron
191        Variable g = 981.0                              //gravity acceleration [cm/s^2]
192        Variable m_h    = 252.8                 // m/h [=] s/cm^2
193
194        Variable acc,ssd,lambda0,yg_d,qstar
195               
196        G = 981.  //!   ACCELERATION OF GRAVITY, CM/SEC^2
197        acc = vz_1              //      3.956E5 //!     CONVERT WAVELENGTH TO VELOCITY CM/SEC
198        SDD = L2        *100    //1317
199        SSD = L1        *100    //1627          //cm
200        lambda0 = lambda                //              15
201        YG_d = -0.5*G*SDD*(SSD+SDD)*(LAMBDA0/acc)^2
202        qstar = -2*pi/lambda0*2*yg_d/sdd
203
204        // the gravity center is not the resolution center
205        // gravity center = beam center
206        // resolution center = offset y = dy + (2)*yg_d
207        ///************
208        // do everything to write out the resolution too
209        // un-comment these if you want to write out qz_val and qval too, then use the proper save command
210        qval = CalcQval(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10)
211        qz_val = CalcQz(p+1,q+1,rw[16],rw[17],rw[18],rw[26],rw[13]/10)
212        //      phi = FindPhi( pixSize*((p+1)-xctr) , pixSize*((q+1)-yctr))             //(dx,dy)
213        //      r_dist = sqrt(  (pixSize*((p+1)-xctr))^2 +  (pixSize*((q+1)-yctr))^2 )          //radial distance from ctr to pt
214        phi = FindPhi( pixSize*((p+1)-xctr) , pixSize*((q+1)-yctr)+(2)*yg_d)            //(dx,dy+yg_d)
215        r_dist = sqrt(  (pixSize*((p+1)-xctr))^2 +  (pixSize*((q+1)-yctr)+(2)*yg_d)^2 )         //radial distance from ctr to pt
216        Redimension/N=(pixelsX*pixelsY) qz_val,qval,phi,r_dist
217        Make/O/N=(2,pixelsX,pixelsY) qxy_vals
218        //everything in 1D now
219        Duplicate/O qval SigmaQX,SigmaQY
220        Make/O/N=(pixelsX,pixelsY) shadow
221        Make/O/N=(2,pixelsX,pixelsY) SigmaQ_combined
222
223        //Two parameters DDET and APOFF are instrument dependent.  Determine
224        //these from the instrument name in the header.
225        //From conversation with JB on 01.06.99 these are the current good values
226        Variable DDet
227        NVAR apOff = root:myGlobals:apOff               //in cm
228        DDet = rw[10]/10                        // header value (X) is in mm, want cm here
229
230        Variable ret1,ret2,ret3,jj
231        Variable nq = 0
232        Variable ii = 0
233       
234        do
235                jj = 0
236                do
237                        nq = ii * pixelsX + jj
238                        get2DResolution(qval[nq],phi[nq],lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,pixSize,usingLenses,r_dist[nq],ret1,ret2,ret3)
239                        qxy_vals[0][ii][jj] = qx_val[nq]
240                        qxy_vals[1][ii][jj] = qy_val[nq]
241                        SigmaQ_combined[0][ii][jj] = ret1       
242                        SigmaQ_combined[1][ii][jj] = ret2
243                        shadow[ii][jj] = ret3   
244                        jj+=1
245                while(jj<pixelsX)
246                ii+=1
247        while(ii<pixelsY)
248        //
249        ///////////////////////////////////////////////////////////////////////////
250
251       
252        ///////////////////////////////////////////////////////////////////////////
253        // Write all data
254       
255        // Define common attribute waves
256        Make/O/T/N=1 empty = {""}
257        Make/O/T/N=1 units = {"units"}
258        Make/O/T/N=1 inv_cm = {"1/cm"}
259        Make/O/T/N=1 inv_angstrom = {"1/A"}
260       
261        // Run Name and title
262        NewDataFolder/O/S $(parentBase)
263        Make/O/T/N=1 $(parentBase + ":title") = {textw[6]}
264        CreateStrNxCansas(fileID,nxcansasBase,"","title",$(parentBase + ":title"),empty,empty)
265        Make/O/T/N=1 $(parentBase + ":run") = {textw[0]}
266        CreateStrNxCansas(fileID,nxcansasBase,"","run",$(parentBase + ":run"),empty,empty)
267       
268        // SASData
269        String dataParent = nxcansasBase + "sasdata/"
270        // Create SASdata entry
271        String dataBase = parentBase + ":sasdata"
272        NewDataFolder/O/S $(dataBase)
273        Make/O/T/N=5 $(dataBase + ":attr") = {"canSAS_class","signal","I_axes","NX_class","Q_indices", "timestamp"}
274        Make/O/T/N=5 $(dataBase + ":attrVals") = {"SASdata","I","Q,Q","NXdata","0,1",textw[1]}
275        CreateStrNxCansas(fileID,dataParent,"","",empty,$(dataBase + ":attr"),$(dataBase + ":attrVals"))
276        // Create i entry
277        NewDataFolder/O/S $(dataBase + ":i")
278        Make/O/T/N=2 $(dataBase + ":i:attr") = {"units","uncertainties"}
279        Make/O/T/N=2 $(dataBase + ":i:attrVals") = {"1/cm","Idev"}
280        CreateVarNxCansas(fileID,dataParent,"sasdata","I",data,$(dataBase + ":i:attr"),$(dataBase + ":i:attrVals"))
281
282        //
283        // TODO: Reinstate Qdev/resolutions when I can fix the reader issue
284        //
285
286        // Create qx and qy entry
287        NewDataFolder/O/S $(dataBase + ":q")
288        Make/O/T/N=2 $(dataBase + ":q:attr") = {"units"}//,"resolutions"}
289        Make/O/T/N=2 $(dataBase + ":q:attrVals") = {"1/angstrom"}//,"Qdev"}
290        CreateVarNxCansas(fileID,dataParent,"sasdata","Q",qxy_vals,$(dataBase + ":q:attr"),$(dataBase + ":q:attrVals"))
291       
292        // Create idev entry
293        CreateVarNxCansas(fileID,dataParent,"sasdata","Idev",data_err,units,inv_cm)
294        // Create qdev entry
295        CreateVarNxCansas(fileID,dataParent,"sasdata","Qdev",SigmaQ_combined,units,inv_angstrom)
296        // Create shadwfactor entry
297        CreateVarNxCansas(fileID,dataParent,"sasdata","ShadowFactor",shadow,empty,empty)
298       
299        // Write all meta data
300        WriteMetaData(fileID,parentBase,nxcansasBase,rw,textw)
301       
302        // Close the file
303        if(fileID)
304                HDF5CloseFile /Z fileID
305        endif
306       
307        KillDataFolder/Z $base
308       
309End
310
311//
312///////////////////////////////////////////////////////////////////////////
313
314///////////////////////////////////////////////////////////////////////////
315// - WriteMetaData - Method used to write non data elements into NXcanSAS
316// format. This is common between 1D and 2D data sets.
317
318Function WriteMetaData(fileID,base,parentBase,rw,textw)
319        String base,parentBase
320        Variable fileID
321        Wave rw
322        Wave/T textw
323       
324        // Define common attribute waves
325        Make/T/O/N=1 empty = {""}
326        Make/T/O/N=1 units = {"units"}
327        Make/T/O/N=1 m = {"m"}
328        Make/T/O/N=1 mm = {"mm"}
329        Make/T/O/N=1 cm = {"cm"}
330        Make/T/O/N=1 pixel = {"pixel"}
331        Make/T/O/N=1 angstrom = {"A"}
332       
333        // SASinstrument
334        String instrParent = parentBase + "sasinstrument/"
335        // Create SASinstrument entry
336        String instrumentBase = base + ":sasinstrument"
337        NewDataFolder/O/S $(instrumentBase)
338        Make/O/T/N=5 $(instrumentBase + ":attr") = {"canSAS_class","NX_class"}
339        Make/O/T/N=5 $(instrumentBase + ":attrVals") = {"SASinstrument","NXinstrument"}
340        CreateStrNxCansas(fileID,instrParent,"","",empty,$(instrumentBase + ":attr"),$(instrumentBase + ":attrVals"))
341       
342        // SASaperture
343        String apertureParent = instrParent + "sasaperture/"
344        // Create SASaperture entry
345        String apertureBase = instrumentBase + ":sasaperture"
346        NewDataFolder/O/S $(apertureBase)
347        Make/O/T/N=5 $(apertureBase + ":attr") = {"canSAS_class","NX_class"}
348        Make/O/T/N=5 $(apertureBase + ":attrVals") = {"SASaperture","NXaperture"}
349        CreateStrNxCansas(fileID,apertureParent,"","",empty,$(apertureBase + ":attr"),$(apertureBase + ":attrVals"))
350        // Create SASaperture shape entry
351        Make/O/T/N=1 $(apertureBase + ":shape") = {"pinhole"}
352        CreateStrNxCansas(fileID,apertureParent,"sasaperture","shape",$(apertureBase + ":shape"),empty,empty)
353        // Create SASaperture x_gap entry
354        Make/O/N=1 $(apertureBase + ":x_gap") = {rw[24]}
355        CreateVarNxCansas(fileID,apertureParent,"sasaperture","x_gap",$(apertureBase + ":x_gap"),units,mm)
356        // Create SASaperture y_gap entry
357        Make/O/N=1 $(apertureBase + ":y_gap") = {rw[24]}
358        CreateVarNxCansas(fileID,apertureParent,"sasaperture","y_gap",$(apertureBase + ":y_gap"),units,mm)
359       
360        // SAScollimation
361        String collimationParent = instrParent + "sascollimation/"
362        // Create SAScollimation entry
363        String collimationBase = instrumentBase + ":sascollimation"
364        NewDataFolder/O/S $(collimationBase)
365        Make/O/T/N=5 $(collimationBase + ":attr") = {"canSAS_class","NX_class"}
366        Make/O/T/N=5 $(collimationBase + ":attrVals") = {"SAScollimation","NXcollimator"}
367        CreateStrNxCansas(fileID,collimationParent,"","",empty,$(collimationBase + ":attr"),$(collimationBase + ":attrVals"))
368        // Create SAScollimation distance entry
369        Make/O/N=1 $(collimationBase + ":distance") = {rw[25]}
370        CreateVarNxCansas(fileID,collimationParent,"sasaperture","distance",$(collimationBase + ":distance"),units,m)
371       
372        // SASdetector
373        String detectorParent = instrParent + "sasdetector/"
374        // Create SASdetector entry
375        String detectorBase = instrumentBase + ":sasdetector"
376        NewDataFolder/O/S $(detectorBase)
377        Make/O/T/N=5 $(detectorBase + ":attr") = {"canSAS_class","NX_class"}
378        Make/O/T/N=5 $(detectorBase + ":attrVals") = {"SASdetector","NXdetector"}
379        CreateStrNxCansas(fileID,detectorParent,"","",empty,$(detectorBase + ":attr"),$(detectorBase + ":attrVals"))
380        // Create SASdetector name entry
381        Make/O/T/N=1 $(detectorBase + ":name") = {textw[9]}
382        CreateStrNxCansas(fileID,detectorParent,"","name",$(detectorBase + ":name"),empty,empty)
383        // Create SASdetector distance entry
384        Make/O/N=1 $(detectorBase + ":SDD") = {rw[18]}
385        CreateVarNxCansas(fileID,detectorParent,"","SDD",$(detectorBase + ":SDD"),units,m)
386        // Create SASdetector beam_center_x entry
387        Make/O/N=1 $(detectorBase + ":beam_center_x") = {rw[16]}
388        CreateVarNxCansas(fileID,detectorParent,"","beam_center_x",$(detectorBase + ":beam_center_x"),units,pixel)
389        // Create SASdetector beam_center_y entry
390        Make/O/N=1 $(detectorBase + ":beam_center_y") = {rw[17]}
391        CreateVarNxCansas(fileID,detectorParent,"","beam_center_y",$(detectorBase + ":beam_center_y"),units,pixel)
392        // Create SASdetector x_pixel_size entry
393        Make/O/N=1 $(detectorBase + ":x_pixel_size") = {rw[10]}
394        CreateVarNxCansas(fileID,detectorParent,"","x_pixel_size",$(detectorBase + ":x_pixel_size"),units,mm)
395        // Create SASdetector y_pixel_size entry
396        Make/O/N=1 $(detectorBase + ":y_pixel_size") = {rw[13]}
397        CreateVarNxCansas(fileID,detectorParent,"","y_pixel_size",$(detectorBase + ":y_pixel_size"),units,mm)
398       
399        // SASsource
400        String sourceParent = instrParent + "sassource/"
401        // Create SASdetector entry
402        String sourceBase = instrumentBase + ":sassource"
403        NewDataFolder/O/S $(sourceBase)
404        Make/O/T/N=5 $(sourceBase + ":attr") = {"canSAS_class","NX_class"}
405        Make/O/T/N=5 $(sourceBase + ":attrVals") = {"SASsource","NXsource"}
406        CreateStrNxCansas(fileID,sourceParent,"","",empty,$(sourceBase + ":attr"),$(sourceBase + ":attrVals"))
407        // Create SASsource radiation entry
408        Make/O/T/N=1 $(sourceBase + ":radiation") = {"Reactor Neutron Source"}
409        CreateStrNxCansas(fileID,sourceParent,"","radiation",$(sourceBase + ":radiation"),empty,empty)
410        // Create SASsource incident_wavelength entry
411        Make/O/N=1 $(sourceBase + ":incident_wavelength") = {rw[26]}
412        CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength",$(sourceBase + ":incident_wavelength"),units,angstrom)
413        // Create SASsource incident_wavelength_spread entry
414        Make/O/N=1 $(sourceBase + ":incident_wavelength_spread") = {rw[27]}
415        CreateVarNxCansas(fileID,sourceParent,"","incident_wavelength_spread",$(sourceBase + ":incident_wavelength_spread"),units,angstrom)
416       
417        // SASsample
418        String sampleParent = parentBase + "sassample/"
419        // Create SASsample entry
420        String sampleBase = base + ":sassample"
421        NewDataFolder/O/S $(sampleBase)
422        Make/O/T/N=5 $(sampleBase + ":attr") = {"canSAS_class","NX_class"}
423        Make/O/T/N=5 $(sampleBase + ":attrVals") = {"SASsample","NXsample"}
424        CreateStrNxCansas(fileID,sampleParent,"","",empty,$(sampleBase + ":attr"),$(sampleBase + ":attrVals"))
425        // Create SASsample name entry
426        Make/O/T/N=1 $(sampleBase + ":name") = {textw[6]}
427        CreateStrNxCansas(fileID,sampleParent,"","name",$(sampleBase + ":name"),empty,empty)
428        // Create SASsample thickness entry
429        Make/O/N=1 $(sampleBase + ":thickness") = {rw[5]}
430        CreateVarNxCansas(fileID,sampleParent,"","thickness",$(sampleBase + ":thickness"),units,cm)
431        // Create SASsample transmission entry
432        Make/O/N=1 $(sampleBase + ":transmission") = {rw[4]}
433        CreateVarNxCansas(fileID,sampleParent,"","transmission",$(sampleBase + ":transmission"),empty,empty)
434End
435
436Function WriteProcess(fileID,parentBase,base,processName,processNote)
437        Variable fileID
438        String parentBase,base,processName,processNote
439        // Create SASprocess entry
440        Make/T/O/N=1 empty = {""}
441        String processParent = parentBase + "sasprocess/"
442        String processBase = base + ":sasprocess"
443        NewDataFolder/O/S $(processBase)
444        Make/O/T/N=5 $(processBase + ":attr") = {"canSAS_class","NX_class"}
445        Make/O/T/N=5 $(processBase + ":attrVals") = {"SASprocess","NXprocess"}
446        CreateStrNxCansas(fileID,processParent,"","",empty,$(processBase + ":attr"),$(processBase + ":attrVals"))
447        // Create SASprocess name entry
448        Make/O/T/N=1 $(processBase + ":name") = {processName}
449        CreateStrNxCansas(fileID,processParent,"","name",$(processBase + ":name"),empty,empty)
450        // Create SASprocess note entries
451        Make/O/T/N=1 $(processBase + ":note0") = {processNote}
452        CreateStrNxCansas(fileID,processParent,"","note0",$(processBase + ":note0"),empty,empty)
453End
454
455
456///////////////////////////////////////////////////////////////////////////
457//
458// Methods related to NSORT
459
460
461//these canSANs NSORT files are only necessary for SANS reduction, not USANS or VSANS. as such,
462// move them to the SANS-specific NXcanSAS file. Conditional compilation did not work since I can't access
463// user-defined objects through #if
464//
465// SRK 092019
466//
467
468Function WriteNSORTedNXcanSASFile(qw,iw,sw,firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34,[res])
469        Wave qw,iw,sw,res
470        String firstFileName,secondFileName,thirdFileName,fourthFileName,normTo
471        Variable norm12,norm23,norm34
472       
473        Variable err=0,refNum,numCols,dialog=1,useRes=0
474        String fullPath="",formatStr="",process
475       
476        //check each wave - else REALLY FATAL error when writing file
477        If(!(WaveExists(qw)))
478                err = 1
479                return err
480        Endif
481        If(!(WaveExists(iw)))
482                err = 1
483                return err
484        Endif
485        If(!(WaveExists(sw)))
486                err = 1
487                return err
488        Endif
489        if(WaveExists(res))
490                useRes = 1
491        endif
492       
493        NVAR/Z useTable = root:myGlobals:CombineTable:useTable
494        if(NVAR_Exists(useTable) && useTable==1)
495                SVAR str=root:myGlobals:CombineTable:SaveNameStr        //messy, but pass in as a global
496                fullPath = str
497                dialog=0
498        endif
499       
500        NewDataFolder/O/S root:Packages:NIST:NSORT
501        SetDataFolder root:Packages:NIST:NSORT
502       
503        process = CreateNSORTProcess(firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34)
504        Make/O/T/N=1 processNote = process
505       
506        Variable pts = numpnts(qw)
507        Make/O/N=(pts) qval = qw
508        Make/O/N=(pts) aveint = iw
509        Make/O/N=(pts) sigave = sw
510        if (useRes)
511                Make/O/N=(dimsize(res,0)) SigmaQ = res[p][0]
512                Make/O/N=(dimsize(res,0)) QBar = res[p][1]
513                Make/O/N=(dimsize(res,0)) fSubS = res[p][2]
514        Else
515                Make/O/N=(pts) SigmaQ = 0
516                Make/O/N=(pts) QBar = 0
517                Make/O/N=(pts) fSubS = 0
518        EndIf
519       
520        Make/O/T/N=11 textRead
521        textRead[6] = firstfileName
522        textRead[0] = "Combined data"
523       
524        Make/O/N=52 realsRead = 0
525       
526        WriteNxCanSAS1D("NSORT",fullpath,dialog)
527       
528End
529
530
531Function/T CreateNSORTProcess(firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34)
532        String firstFileName,secondFileName,thirdFileName,fourthFileName,normTo
533        Variable norm12,norm23,norm34
534        String process
535        String processFormat = "COMBINED FILE CREATED: %s - NSORT-ed %s\t+ %s\t+ %s\t+%s, normalized to %s, multiplicative factor 1-2 = %12.8g\t multiplicative factor 2-3 = %12.8g\t multiplicative factor 3-4 = %12.8g"
536       
537        sprintf process,processFormat,date(),firstFileName,secondFileName,thirdFileName,fourthFileName,normTo,norm12,norm23,norm34
538        return process
539End
540
541//
542
543
544//
545///////////////////////////////////////////////////////////////////////////
546
Note: See TracBrowser for help on using the repository browser.