source: sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/WriteQIS.ipf @ 76

Last change on this file since 76 was 76, checked in by srkline, 15 years ago

2nd pass of pulling out NCNR calls. Also cleared a lot of deadwood from the code, removing depricated functions that were mostly already commented out.

File size: 19.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma version=5.0
3#pragma IgorVersion=4.0
4
5//************************
6// Vers 1.2 091001
7//
8//************************
9
10//for writing out data (q-i-s) from the "type" folder, and including reduction information
11//if fullpath is a complete HD path:filename, no dialog will be presented
12//if fullpath is just a filename, the save dialog will be presented
13//if dialog = 1, a dialog will always be presented
14//
15// root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol
16//
17Function WriteWaves_W_Protocol(type,fullpath,dialog)
18        String type,fullpath
19        Variable dialog         //=1 will present dialog for name
20       
21        String destStr=""
22        destStr = "root:"+type
23       
24        Variable refNum
25        String formatStr = "%15.4g %15.4g %15.4g %15.4g %15.4g %15.4g\r\n"
26        String fname,ave="C",hdrStr1="",hdrStr2=""
27        Variable step=1
28       
29       
30       
31        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
32        WAVE intw=$(destStr + ":integersRead")
33        WAVE rw=$(destStr + ":realsRead")
34        WAVE/T textw=$(destStr + ":textRead")
35        WAVE qvals =$(destStr + ":qval")
36        WAVE inten=$(destStr + ":aveint")
37        WAVE sig=$(destStr + ":sigave")
38        WAVE qbar = $(destStr + ":QBar")
39        WAVE sigmaq = $(destStr + ":SigmaQ")
40        WAVE fsubs = $(destStr + ":fSubS")
41
42        SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr
43        Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr)
44       
45        //check each wave
46        If(!(WaveExists(intw)))
47                Abort "intw DNExist BinaryWrite_W_Protocol()"
48        Endif
49        If(!(WaveExists(rw)))
50                Abort "rw DNExist BinaryWrite_W_Protocol()"
51        Endif
52        If(!(WaveExists(textw)))
53                Abort "textw DNExist BinaryWrite_W_Protocol()"
54        Endif
55        If(!(WaveExists(qvals)))
56                Abort "qvals DNExist BinaryWrite_W_Protocol()"
57        Endif
58        If(!(WaveExists(inten)))
59                Abort "inten DNExist BinaryWrite_W_Protocol()"
60        Endif
61        If(!(WaveExists(sig)))
62                Abort "sig DNExist BinaryWrite_W_Protocol()"
63        Endif
64        If(!(WaveExists(qbar)))
65                Abort "qbar DNExist BinaryWrite_W_Protocol()"
66        Endif
67        If(!(WaveExists(sigmaq)))
68                Abort "sigmaq DNExist BinaryWrite_W_Protocol()"
69        Endif
70        If(!(WaveExists(fsubs)))
71                Abort "fsubs DNExist BinaryWrite_W_Protocol()"
72        Endif
73        If(!(WaveExists(proto)))
74                Abort "current protocol wave DNExist BinaryWrite_W_Protocol()"
75        Endif
76
77        //strings can be too long to print-- must trim to 255 chars
78        Variable ii,num=8
79        Make/O/T/N=(num) tempShortProto
80        for(ii=0;ii<num;ii+=1)
81                tempShortProto[ii] = (proto[ii])[0,240]
82        endfor
83       
84        if(dialog)
85                PathInfo/S catPathName
86                fullPath = DoSaveFileDialog("Save data as")
87                If(cmpstr(fullPath,"")==0)
88                        //user cancel, don't write out a file
89                        Close/A
90                        Abort "no data file was written"
91                Endif
92                //Print "dialog fullpath = ",fullpath
93        Endif
94       
95        hdrStr1 = num2str(rw[0])+"  "+num2str(rw[26])+"       "+num2str(rw[19])+"     "+num2str(rw[18])
96        hdrStr1 += "     "+num2str(rw[4])+"     "+num2str(rw[5]) + ave +"   "+num2str(step) + "\r\n"
97
98        hdrStr2 = num2str(rw[16])+"  "+num2str(rw[17])+"  "+num2str(rw[23])+"    "+num2str(rw[24])+"    "
99        hdrStr2 += num2str(rw[25])+"    "+num2str(rw[27])+"    "+num2str(rw[21])+"    "+textW[9] + "\r\n"
100       
101        SVAR samFiles = $("root:"+type+":fileList")
102        //actually open the file here
103        Open refNum as fullpath
104       
105        //write out the standard header information
106        fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]
107        fprintf refnum,"LABEL: %s\r\n",textw[6]
108        fprintf refnum,"MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP\r\n"
109        fprintf refnum,hdrStr1
110        fprintf refnum,"BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP \r\n"
111        fprintf refnum,hdrStr2
112//      fprintf refnum,headerFormat,rw[0],rw[26],rw[19],rw[18],rw[4],rw[5],ave,step
113
114        //insert protocol information here
115        //-1 list of sample files
116        //0 - bkg
117        //1 - emp
118        //2 - div
119        //3 - mask
120        //4 - abs params c2-c5
121        //5 - average params
122        fprintf refnum, "SAM: %s\r\n",samFiles
123        fprintf refnum, "BGD: %s\r\n",tempShortProto[0]
124        fprintf refnum, "EMP: %s\r\n",tempShortProto[1]
125        fprintf refnum, "DIV: %s\r\n",tempShortProto[2]
126        fprintf refnum, "MASK: %s\r\n",tempShortProto[3]
127        fprintf refnum, "ABS Parameters (3-6): %s\r\n",tempShortProto[4]
128        fprintf refnum, "Average Choices: %s\r\n",tempShortProto[5]
129       
130        //write out the data columns
131        fprintf refnum,"The 6 columns are | Q (1/A) | I(Q) (1/cm) | std. dev. I(Q) (1/cm) | sigmaQ | meanQ | ShadowFactor|\r\n"
132        wfprintf refnum, formatStr, qvals,inten,sig,sigmaq,qbar,fsubs
133       
134        Close refnum
135       
136        SetDataFolder root:             //(redundant)
137       
138        //write confirmation of write operation to history area
139        Print "Averaged File written: ", GetFileNameFromPathNoSemi(fullPath)
140        KillWaves/Z tempShortProto
141        Return(0)
142End
143
144
145//for writing out data (phi-i-s) from the "type" folder, and including reduction information
146//if fullpath is a complete HD path:filename, no dialog will be presented
147//if fullpath is just a filename, the save dialog will be presented
148//if dialog = 1, a dialog will always be presented
149//
150// root:myGlobals:Protocols:gProtoStr is the name of the currently active protocol
151//
152Function WritePhiave_W_Protocol(type,fullpath,dialog)
153        String type,fullpath
154        Variable dialog         //=1 will present dialog for name
155       
156        String destStr
157        destStr = "root:"+type
158       
159        Variable refNum
160        String formatStr = "%15.4g %15.4g %15.4g\r\n"
161        String fname,ave="C",hdrStr1,hdrStr2
162        Variable step=1
163       
164        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
165        WAVE intw=$(destStr + ":integersRead")
166        WAVE rw=$(destStr + ":realsRead")
167        WAVE/T textw=$(destStr + ":textRead")
168        WAVE phival =$(destStr + ":phival")
169        WAVE inten=$(destStr + ":aveint")
170        WAVE sig=$(destStr + ":sigave")
171        SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr
172        Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr)
173       
174        //check each wave
175        If(!(WaveExists(intw)))
176                Abort "intw DNExist BinaryWrite_W_Protocol()"
177        Endif
178        If(!(WaveExists(rw)))
179                Abort "rw DNExist BinaryWrite_W_Protocol()"
180        Endif
181        If(!(WaveExists(textw)))
182                Abort "textw DNExist BinaryWrite_W_Protocol()"
183        Endif
184        If(!(WaveExists(phival)))
185                Abort "qvals DNExist BinaryWrite_W_Protocol()"
186        Endif
187        If(!(WaveExists(inten)))
188                Abort "inten DNExist BinaryWrite_W_Protocol()"
189        Endif
190        If(!(WaveExists(sig)))
191                Abort "sig DNExist BinaryWrite_W_Protocol()"
192        Endif
193        If(!(WaveExists(proto)))
194                Abort "current protocol wave DNExist BinaryWrite_W_Protocol()"
195        Endif
196        //strings can be too long to print-- must trim to 255 chars
197        Variable ii,num=8
198        Make/O/T/N=(num) tempShortProto
199        for(ii=0;ii<num;ii+=1)
200                tempShortProto[ii] = (proto[ii])[0,240]
201        endfor
202       
203        if(dialog)
204                PathInfo/S catPathName
205                fullPath = DoSaveFileDialog("Save data as")
206                If(cmpstr(fullPath,"")==0)
207                        //user cancel, don't write out a file
208                        Close/A
209                        Abort "no data file was written"
210                Endif
211                //Print "dialog fullpath = ",fullpath
212        Endif
213       
214        hdrStr1 = num2str(rw[0])+"  "+num2str(rw[26])+"       "+num2str(rw[19])+"     "+num2str(rw[18])
215        hdrStr1 += "     "+num2str(rw[4])+"     "+num2str(rw[5]) + ave +"   "+num2str(step) + "\r\n"
216
217        hdrStr2 = num2str(rw[16])+"  "+num2str(rw[17])+"  "+num2str(rw[23])+"    "+num2str(rw[24])+"    "
218        hdrStr2 += num2str(rw[25])+"    "+num2str(rw[27])+"    "+num2str(rw[21])+"    "+textW[9] + "\r\n"
219       
220        SVAR samFiles = $("root:"+type+":fileList")
221        //actually open the file here
222        Open refNum as fullpath
223       
224        //write out the standard header information
225        fprintf refnum,"FILE: %s\t\t CREATED: %s\r\n",textw[0],textw[1]
226        fprintf refnum,"LABEL: %s\r\n",textw[6]
227        fprintf refnum,"MON CNT   LAMBDA   DET ANG   DET DIST   TRANS   THICK   AVE   STEP\r\n"
228        fprintf refnum,hdrStr1
229        fprintf refnum,"BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP \r\n"
230        fprintf refnum,hdrStr2
231       
232        //insert protocol information here
233        //0 - bkg
234        //1 - emp
235        //2 - div
236        //3 - mask
237        //4 - abs params c2-c5
238        //5 - average params
239        fprintf refnum, "SAM: %s\r\n",samFiles
240        fprintf refnum, "BGD: %s\r\n",tempShortProto[0]
241        fprintf refnum, "EMP: %s\r\n",tempShortProto[1]
242        fprintf refnum, "DIV: %s\r\n",tempShortProto[2]
243        fprintf refnum, "MASK: %s\r\n",tempShortProto[3]
244        fprintf refnum, "ABS Parameters (3-6): %s\r\n",tempShortProto[4]
245        fprintf refnum, "Average Choices: %s\r\n",tempShortProto[5]
246       
247        //write out the data columns
248        fprintf refnum,"The 3 columns are | Phi (deg) | I(phi) (1/cm) | std. dev. I(phi) (1/cm) |\r\n"
249        wfprintf refnum, formatStr, phival,inten,sig
250       
251        Close refnum
252       
253        SetDataFolder root:             //(redundant)
254       
255        //write confirmation of write operation to history area
256        Print "Averaged File written: ", GetFileNameFromPathNoSemi(fullPath)
257        KillWaves/Z tempShortProto
258
259        Return(0)
260End
261
262//*****************
263// saves the data after all of the desired reduction steps (average options)
264// as a 2x expanded PNG file (approx 33kb)
265//
266Function SaveAsPNG(type,fullPath,dialog)
267        String type,fullPath
268        Variable dialog
269       
270        Variable refnum
271        if(dialog)
272                PathInfo/S catPathName
273                Open/D refnum as fullpath               //won't actually open the file
274                If(cmpstr(S_filename,"")==0)
275                        //user cancel, don't write out a file
276                        Close/A
277                        Abort "no data file was written"
278                Endif
279                fullpath = S_filename
280                //Print "dialog fullpath = ",fullpath
281        Endif
282       
283        //cleanup the filename passed in from Protocol...
284        String oldStr="",newStr="",pathStr=""
285        oldStr=GetFileNameFromPathNoSemi(fullPath)      //just the filename
286        pathStr=GetPathStrFromfullName(fullPath)        //just the path
287       
288        newStr = CleanupName(oldStr, 0 )                                //filename with _EXT rather than .EXT
289        fullPath=pathStr+newStr+".png"                          //tack on the png extension
290       
291        print "type=",type
292        //graph the current data and save a little graph
293        Wave data =  $("root:"+type+":data")
294        Wave q_x_axis = $"root:myGlobals:q_x_axis"
295        Wave q_y_axis = $"root:myGlobals:q_y_axis"
296        Wave NIHColors = $"root:myGlobals:NIHColors"
297       
298        NewImage/F data
299        DoWindow/C temp_PNG
300        ModifyImage data cindex= NIHColors
301        AppendToGraph/R q_y_axis
302        ModifyGraph tkLblRot(right)=90,lowTrip(right)=0.001
303        AppendToGraph/T q_x_axis
304        ModifyGraph lowTrip(top)=0.001,standoff=0,mode=2
305        ModifyGraph fSize(right)=9,fSize(top)=9,btLen=3
306       
307//      ModifyGraph nticks=0
308       
309//      WaveStats/Q data
310//      ScaleColorsToData(V_min, V_max, NIHColors)
311
312// ***comment out for DEMO_MODIFIED version
313        SavePict/Z/E=-5/B=144 as fullPath                       //PNG at 2x screen resolution
314//***
315
316        Print "Saved graphic as ",newStr+".png"
317        DoWindow/K temp_PNG
318End
319
320//****************
321//Testing only , not called
322Proc Fast_ASCII_2D_Export(type,term)
323        String type,term
324        Prompt type,"2-D data type for Export",popup,"SAM;EMP;BGD;DIV;COR;CAL;RAW;ABS;MSK;"
325        Prompt term,"line termination",popup,"CR;LF;CRLF;"
326       
327        //terminator is currently ignored
328        Fast2dExport(type,"",1)
329       
330End
331
332//the default termination for the platform is used...
333//if RAW export, sets "dummy" protocol to "RAW data export"
334Function Fast2dExport(type,fullpath,dialog)
335        String type,fullpath
336        Variable dialog         //=1 will present dialog for name
337       
338        String destStr="",ave="C",typeStr=""
339        Variable step=1,refnum
340        destStr = "root:"+type
341       
342        //must select the linear_data to export
343        // can't export log data if there are -ve intensities from a subtraction
344        NVAR isLog = $(destStr+":gIsLogScale")
345        if(isLog==1)
346                typeStr = ":linear_data"
347        else
348                typeStr = ":data"
349        endif
350       
351        NVAR pixelsX = root:myGlobals:gNPixelsX
352        NVAR pixelsY = root:myGlobals:gNPixelsY
353       
354        Wave data=$(destStr+typeStr)
355        WAVE intw=$(destStr + ":integersRead")
356        WAVE rw=$(destStr + ":realsRead")
357        WAVE/T textw=$(destStr + ":textRead")
358
359        SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr
360        String rawTag=""
361        if(cmpstr(type,"RAW")==0)
362                Make/O/T/N=8 proto={"none","none","none","none","none","none","none","none"}
363                RawTag = "RAW Data File: "     
364        else
365                Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr)
366        endif
367        SVAR samFiles = $("root:"+type+":fileList")
368        //check each wave - MUST exist, or will cause a crash
369        If(!(WaveExists(data)))
370                Abort "data DNExist AsciiExport()"
371        Endif
372        If(!(WaveExists(intw)))
373                Abort "intw DNExist AsciiExport()"
374        Endif
375        If(!(WaveExists(rw)))
376                Abort "rw DNExist AsciiExport()"
377        Endif
378        If(!(WaveExists(textw)))
379                Abort "textw DNExist AsciiExport()"
380        Endif
381        If(!(WaveExists(proto)))
382                Abort "current protocol wave DNExist AsciiExport()"
383        Endif
384       
385        if(dialog)
386                PathInfo/S catPathName
387                fullPath = DoSaveFileDialog("Save data as")
388                If(cmpstr(fullPath,"")==0)
389                        //user cancel, don't write out a file
390                        Close/A
391                        Abort "no data file was written"
392                Endif
393                //Print "dialog fullpath = ",fullpath
394        Endif
395       
396/////////
397        Variable numTextLines=18
398        Make/O/T/N=(numTextLines) labelWave
399        labelWave[0] = "FILE: "+textw[0]+"   CREATED: "+textw[1]
400        labelWave[1] = "LABEL: "+textw[6]
401        labelWave[2] = "MON CNT   LAMBDA(A)   DET_OFF(cm)   DET_DIST(m)   TRANS   THICK(cm)"
402        labelWave[3] = num2str(rw[0])+"  "+num2str(rw[26])+"       "+num2str(rw[19])+"     "+num2str(rw[18])
403        labelWave[3] += "     "+num2str(rw[4])+"     "+num2str(rw[5])
404        labelWave[4] = "BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP  "
405        labelWave[5] = num2str(rw[16])+"  "+num2str(rw[17])+"  "+num2str(rw[23])+"  "+num2str(rw[24])+"  "
406        labelWave[5] += num2str(rw[25])+"  "+num2str(rw[27])+"  "+num2str(rw[21])+"  "+textW[9]
407        labelWave[6] =  "SAM: "+rawTag+samFiles
408        labelWave[7] =  "BGD: "+proto[0]
409        labelWave[8] =  "EMP: "+proto[1]
410        labelWave[9] =  "DIV: "+proto[2]
411        labelWave[10] =  "MASK: "+proto[3]
412        labelWave[11] =  "ABS Parameters (3-6): "+proto[4]
413        labelWave[12] = "Average Choices: "+proto[5]
414        labelWave[13] = ""
415        labelWave[14] = "*** Data written from "+type+" folder and may not be a fully corrected data file ***"
416        labelWave[15] = "The detector image is a standard X-Y coordinate system"
417        labelWave[16] = "Data is written by row, starting with Y=1 and X=(1->128)"
418        labelWave[17] = "ASCII data created " +date()+" "+time()
419        //strings can be too long to print-- must trim to 255 chars
420        Variable ii
421        for(ii=0;ii<numTextLines;ii+=1)
422                labelWave[ii] = (labelWave[ii])[0,240]
423        endfor
424//      If(cmpstr(term,"CR")==0)
425//              termStr = "\r"
426//      Endif
427//      If(cmpstr(term,"LF")==0)
428//              termStr = "\n"
429//      Endif
430//      If(cmpstr(term,"CRLF")==0)
431//              termStr = "\r\n"
432//      Endif
433       
434        Duplicate/O data,spWave         
435        Redimension/S/N=(pixelsX*pixelsY) spWave                //single precision (/S)
436       
437        //not demo- compatible, but approx 6x faster!!
438//      Save/G/M="\r\n" labelWave,spWave as fullPath            // /M=termStr specifies terminator
439        ///
440       
441        Open refNum as fullpath
442        wfprintf refNum,"%s\r\n",labelWave
443        fprintf refnum,"\r\n"
444        wfprintf refNum,"%g\r\n",spWave
445        Close refNum
446       
447        Killwaves/Z spWave,labelWave            //don't delete proto!
448       
449        Print "2D ASCII File written: ", GetFileNameFromPathNoSemi(fullPath)
450        return(0)
451End
452
453
454//ASCII export of data as 3-columns qx-qy-Intensity
455//limited header information?
456//
457// - creates the qx and qy data here, based on the data and header information
458//
459// Need to ensure that the data being exported is the linear copy of the dataset - check the global
460//
461Function QxQy_Export(type,fullpath,dialog)
462        String type,fullpath
463        Variable dialog         //=1 will present dialog for name
464       
465        String destStr="",typeStr=""
466        Variable step=1,refnum
467        destStr = "root:"+type
468       
469        //must select the linear_data to export
470        NVAR isLog = $(destStr+":gIsLogScale")
471        if(isLog==1)
472                typeStr = ":linear_data"
473        else
474                typeStr = ":data"
475        endif
476       
477        NVAR pixelsX = root:myGlobals:gNPixelsX
478        NVAR pixelsY = root:myGlobals:gNPixelsY
479       
480        Wave data=$(destStr+typeStr)
481        WAVE intw=$(destStr + ":integersRead")
482        WAVE rw=$(destStr + ":realsRead")
483        WAVE/T textw=$(destStr + ":textRead")
484
485        SVAR gProtoStr = root:myGlobals:Protocols:gProtoStr
486        String rawTag=""
487        if(cmpstr(type,"RAW")==0)
488                Make/O/T/N=8 proto={"none","none","none","none","none","none","none","none"}
489                RawTag = "RAW Data File: "     
490        else
491                Wave/T proto=$("root:myGlobals:Protocols:"+gProtoStr)
492        endif
493        SVAR samFiles = $("root:"+type+":fileList")
494        //check each wave - MUST exist, or will cause a crash
495        If(!(WaveExists(data)))
496                Abort "data DNExist QxQy_Export()"
497        Endif
498        If(!(WaveExists(intw)))
499                Abort "intw DNExist QxQy_Export()"
500        Endif
501        If(!(WaveExists(rw)))
502                Abort "rw DNExist QxQy_Export()"
503        Endif
504        If(!(WaveExists(textw)))
505                Abort "textw DNExist QxQy_Export()"
506        Endif
507        If(!(WaveExists(proto)))
508                Abort "current protocol wave DNExist QxQy_Export()"
509        Endif
510       
511        if(dialog)
512                PathInfo/S catPathName
513                fullPath = DoSaveFileDialog("Save data as")
514                If(cmpstr(fullPath,"")==0)
515                        //user cancel, don't write out a file
516                        Close/A
517                        Abort "no data file was written"
518                Endif
519                //Print "dialog fullpath = ",fullpath
520        Endif
521       
522/////////
523        Variable numTextLines=18
524        Make/O/T/N=(numTextLines) labelWave
525        labelWave[0] = "FILE: "+textw[0]+"   CREATED: "+textw[1]
526        labelWave[1] = "LABEL: "+textw[6]
527        labelWave[2] = "MON CNT   LAMBDA (A)  DET_OFF(cm)   DET_DIST(m)   TRANS   THICK(cm)"
528        labelWave[3] = num2str(rw[0])+"  "+num2str(rw[26])+"       "+num2str(rw[19])+"     "+num2str(rw[18])
529        labelWave[3] += "     "+num2str(rw[4])+"     "+num2str(rw[5])
530        labelWave[4] = "BCENT(X,Y)   A1(mm)   A2(mm)   A1A2DIST(m)   DL/L   BSTOP(mm)   DET_TYP  "
531        labelWave[5] = num2str(rw[16])+"  "+num2str(rw[17])+"  "+num2str(rw[23])+"    "+num2str(rw[24])+"    "
532        labelWave[5] += num2str(rw[25])+"    "+num2str(rw[27])+"    "+num2str(rw[21])+"    "+textW[9]
533        labelWave[6] =  "SAM: "+rawTag+samFiles
534        labelWave[7] =  "BGD: "+proto[0]
535        labelWave[8] =  "EMP: "+proto[1]
536        labelWave[9] =  "DIV: "+proto[2]
537        labelWave[10] =  "MASK: "+proto[3]
538        labelWave[11] =  "ABS Parameters (3-6): "+proto[4]
539        labelWave[12] = "Average Choices: "+proto[5]
540        labelWave[13] = ""
541        labelWave[14] = "*** Data written from "+type+" folder and may not be a fully corrected data file ***"
542        labelWave[15] = "Data columns are Qx - Qy - I(Qx,Qy)"
543        labelWave[16] = ""
544        labelWave[17] = "ASCII data created " +date()+" "+time()
545        //strings can be too long to print-- must trim to 255 chars
546        Variable ii,jj
547        for(ii=0;ii<numTextLines;ii+=1)
548                labelWave[ii] = (labelWave[ii])[0,240]
549        endfor
550//      If(cmpstr(term,"CR")==0)
551//              termStr = "\r"
552//      Endif
553//      If(cmpstr(term,"LF")==0)
554//              termStr = "\n"
555//      Endif
556//      If(cmpstr(term,"CRLF")==0)
557//              termStr = "\r\n"
558//      Endif
559       
560        Duplicate/O data,qx_val,qy_val,z_val
561        Redimension/N=(pixelsX*pixelsY) qx_val,qy_val,z_val
562        MyMat2XYZ(data,qx_val,qy_val,z_val)             //x and y are [p][q] indexes, not q-vals yet
563       
564        qx_val = CalcQx(qx_val+1,rw[16],rw[18],rw[26])          //+1 converts to detector coordinate system
565        qy_val = CalcQy(qy_val+1,rw[17],rw[18],rw[26])
566
567        //not demo-compatible, but approx 8x faster!!           
568//      Save/G/M="\r\n" labelWave,qx_val,qy_val,z_val as fullpath       // /M=termStr specifies terminator
569        //
570       
571        Open refNum as fullpath
572        wfprintf refNum,"%s\r\n",labelWave
573        fprintf refnum,"\r\n"
574        wfprintf refNum,"%8g\t%8g\t%8g\r\n",qx_val,qy_val,z_val
575        Close refNum
576       
577        Killwaves/Z spWave,labelWave,qx_val,qy_val,z_val
578       
579        Print "QxQy_Export File written: ", GetFileNameFromPathNoSemi(fullPath)
580        return(0)
581
582End
583
584
585Function MyMat2XYZ(mat,xw,yw,zw)
586        WAVE mat,xw,yw,zw
587
588        NVAR pixelsX = root:myGlobals:gNPixelsX
589        NVAR pixelsY = root:myGlobals:gNPixelsY
590       
591        xw= mod(p,pixelsX)              // X varies quickly
592        yw= floor(p/pixelsY)    // Y varies slowly
593        zw= mat(xw[p])(yw[p])
594
595End
596
597//converts xyz triple to a matrix
598//MAJOR assumption is that the x and y-spacings are LINEAR
599// (ok for small-angle approximation)
600//
601// currently unused
602//
603Function LinXYZToMatrix(xw,yw,zw,matStr)
604        WAVE xw,yw,zw
605        String matStr
606       
607        NVAR pixelsX = root:myGlobals:gNPixelsX
608        NVAR pixelsY = root:myGlobals:gNPixelsY
609        //mat is "zw" redimensioned to a matrix
610        Make/O/N=(pixelsX*pixelsY) $matStr
611        WAVE mat=$matStr
612        mat=zw
613        Redimension/N=(pixelsX,pixelsY) mat
614        WaveStats/Q xw
615        SetScale/I x, V_min, V_max, "",mat
616        WaveStats/Q yw
617        SetScale/I y, V_min, V_max, "",mat
618       
619        Display;Appendimage mat
620        ModifyGraph lowTrip=0.0001
621        ModifyGraph width={Plan,1,bottom,left},height={Plan,1,left,bottom}
622        ModifyImage $matStr ctab={*,*,YellowHot,0}
623       
624        return(0)
625End
626
627
628//returns the path to the file, or null if cancel
629Function/S DoOpenFileDialog(msg)
630        String msg
631       
632        Variable refNum
633//      String message = "Select a file"
634        String outputPath
635       
636        Open/D/R/T="????"/M=msg refNum
637        outputPath = S_fileName
638       
639        return outputPath
640End
641
642// returns the path to the file, or null if the user cancelled
643Function/S DoSaveFileDialog(msg)
644        String msg
645        Variable refNum
646//      String message = "Save the file as"
647        String outputPath
648       
649        Open/D/M=msg refNum
650        outputPath = S_fileName
651       
652        return outputPath
653End
654
Note: See TracBrowser for help on using the repository browser.