source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/USANS/WriteUSANSData.ipf @ 540

Last change on this file since 540 was 474, checked in by srkline, 14 years ago

Moved DoFileSaveDialog? and DoFileOpenDialog? to PlotUtilsMacro_v40 since it is common to all packages. Then there is no need to duplicate functions and no new files to include.

  • Property eol-style set to native
  • Property svn:executable set to *
File size: 6.2 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma Version=2.20
3#pragma IgorVersion=6.0
4
5//////////////
6//for writing out data (q-i-s-dum-dum-dum) from the "type" folder
7//if fullpath is a complete HD path:filename, no dialog will be presented
8//if fullpath is just a filename, the save dialog will be presented (forced if dialog =1)
9//lo,hi are an (optional) range of the data[lo,hi] to save (in points)
10//if lo=hi=0, all of the data is written out
11//
12//////// 27 OCT 04
13// now writes 6-column data such that the last three columns are the divergence
14//  = a constant value, set in Init_MainUSANS()
15//
16Function WriteUSANSWaves(type,fullpath,lo,hi,dialog)
17        String type,fullpath
18        Variable lo,hi,dialog           //=1 will present dialog for name
19       
20        SVAR USANSFolder = root:Packages:NIST:USANS:Globals:gUSANSFolder
21
22       
23        String termStr="\r\n"           //VAX uses only <CR> as terminator, but only CRLF seems to FTP correctly to VAX
24        String destStr="",formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr
25        destStr = USANSFolder+":"+type
26       
27        Variable refNum,integer,realval
28       
29        //*****these waves MUST EXIST, or IGOR Pro will crash, with a type 2 error****
30        WAVE qvals =$(destStr + ":Qvals")
31        WAVE inten=$(destStr + ":DetCts")
32        WAVE sig=$(destStr + ":ErrDetCts")
33       
34        //check each wave
35        If(!(WaveExists(qvals)))
36                Abort "qvals DNExist in WriteUSANSWaves()"
37        Endif
38        If(!(WaveExists(inten)))
39                Abort "inten DNExist in WriteUSANSWaves()"
40        Endif
41        If(!(WaveExists(sig)))
42                Abort "sig DNExist in WriteUSANSWaves()"
43        Endif
44       
45        // 27 OCT 04 SRK
46        // make a dummy wave to hold the divergence, and write it as the last 3 columns
47        // and make the value negative as a flag for the analysis software
48        //
49        Duplicate/O qvals,dumWave
50        NVAR DQv=$(USANSFolder+":Globals:MainPanel:gDQv")
51        dumWave = - DQv
52        ///
53        if(dialog)
54                PathInfo/S catPathName
55                fullPath = DoSaveFileDialog("Save data as")
56                If(cmpstr(fullPath,"")==0)
57                        //user cancel, don't write out a file
58                        Close/A
59                        Abort "no data file was written"
60                Endif
61                //Print "dialog fullpath = ",fullpath
62        Endif
63       
64        //write out partial set?
65        Duplicate/O qvals,tq,ti,te
66        ti=inten
67        te=sig
68        if( (lo!=hi) && (lo<hi))
69                redimension/N=(hi-lo+1) tq,ti,te,dumWave                //lo to hi, inclusive
70                tq=qvals[p+lo]
71                ti=inten[p+lo]
72                te=sig[p+lo]
73        endif
74       
75        //tailor the output given the type of data written out...
76        WAVE inten_EMP=$(USANSFolder+":EMP:DetCts")
77        String samStr="",empStr="",dateStr="",samLabelStr="",paramStr="",empLevStr="",bkgLevStr=""
78        String pkStr=""
79        NVAR TransWide = $(USANSFolder+":Globals:MainPanel:gTransWide")
80        NVAR TransRock = $(USANSFolder+":Globals:MainPanel:gTransRock")
81        NVAR empCts = $(USANSFolder+":Globals:MainPanel:gEmpCts")
82        NVAR bkgCts = $(USANSFolder+":Globals:MainPanel:gBkgCts")
83        NVAR thick = $(USANSFolder+":Globals:MainPanel:gThick")
84       
85        strswitch(type)
86                case "SAM":             
87                        samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";")
88                        empStr = "Uncorrected SAM data"
89                        empLevStr = "Uncorrected SAM data"
90                        bkgLevStr = "Uncorrected SAM data"
91                        paramStr = "Uncorrected SAM data"
92                        pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM"))
93                        break                                           
94                case "EMP":     
95                        samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";")
96                        empStr = "Uncorrected EMP data"
97                        empLevStr = "Uncorrected EMP data"
98                        bkgLevStr = "Uncorrected EMP data"
99                        paramStr = "Uncorrected EMP data"
100                        pkStr += "EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP"))
101                        break
102                default:                //"COR" is the default 
103                        samStr = type +" FILES: "+StringByKey("FILE",note(inten),":",";")
104                        empStr = "EMP FILES: "+StringByKey("FILE",note(inten_EMP),":",";")     
105                        empLevStr = "EMP LEVEL: " + num2str(empCts)
106                        bkgLevStr = "BKG LEVEL: " + num2str(bkgCts)
107                        paramStr = "Ds = "+num2str(thick)+" cm ; "
108                        paramStr += "Twide = "+num2Str(TransWide)+" ; "
109                        paramStr += "Trock = "+num2str(TransRock)       
110                        pkStr += "SAM PEAK ANGLE: "+num2str(QpkFromNote("SAM"))
111                        pkStr += " ; EMP PEAK ANGLE: "+num2str(QpkFromNote("EMP"))                             
112        endswitch
113       
114        //these strings are always the same
115        dateStr="CREATED: "+date()+" at  "+time()
116        samLabelStr ="LABEL: "+StringByKey("LABEL",note(inten),":",";")
117       
118        //actually open the file
119        Open refNum as fullpath
120       
121        fprintf refnum,"%s"+termStr,samStr
122        fprintf refnum,"%s"+termStr,dateStr
123        fprintf refnum,"%s"+termStr,samLabelStr
124        fprintf refnum,"%s"+termStr,empStr
125        fprintf refnum,"%s"+termStr,paramStr
126        fprintf refnum,"%s"+termStr,pkStr
127        fprintf refnum,"%s"+termStr,empLevStr + " ; "+bkglevStr
128       
129        //
130        wfprintf refnum, formatStr, tq,ti,te,dumWave,dumWave,dumWave
131       
132        Close refnum
133       
134        Killwaves/Z ti,tq,te,dumWave
135       
136        Return(0)
137End
138
139
140// convert "old" 3-column .cor files to "new" 6-column files
141// Append the suffix="_6col.cor" to the new data files
142//
143// these "old" files will all have dQv = 0.037 (1/A) to match the
144// absolute scaling constant. "New" files written Nov 2004 or later
145// will have the appropriate values of dQv and scaling, as set in
146// the initialization routines.
147//
148// files were written out in the style above, 7 header lines, then the data
149//
150Function Convert3ColTo6Col()
151       
152        String termStr="\r\n"           //VAX uses only <CR> as terminator, but only CRLF seems to FTP correctly to VAX
153        String formatStr = "%15.6g %15.6g %15.6g %15.6g %15.6g %15.6g"+termStr
154        String newFName="",suffix="_6col.cor",fullpath=""
155       
156        Variable refNum_old,refnum_new,integer,realval
157       
158        // 08 NOV 04 SRK
159        Variable ii,dQv = -0.037                //hard-wired value for divergence (pre- NOV 2004 value)
160        ///
161       
162        Open/R/D/M="Select the 3-column data file"/T="????" refnum_old          //won't actually open the file
163        If(cmpstr(S_filename,"")==0)
164                //user cancel, don't write out a file
165                Close/A
166                Abort "no data file was written"
167        Endif
168        fullpath = S_filename
169        newFname = fullpath[0,strlen(fullpath)-5]+suffix
170        Print fullpath
171        Print newFname
172       
173        String tmpStr
174        String extraStr=""
175        sprintf extraStr,"%15.6g %15.6g %15.6g",dQv,dQv,dQv
176        extraStr += termStr
177        //actually open each of the files
178        Open/R refNum_old as fullpath
179        Open refNum_new as newFname
180       
181        //7 header lines
182        for(ii=0;ii<7;ii+=1)
183                FReadLine refNum_old, tmpStr            //returns only CR
184                fprintf refnum_new,tmpStr+"\n"          // add LF so file has CRLF
185        endfor
186       
187        do
188                FReadLine refNum_old, tmpStr
189                if(strlen(tmpStr)==0)
190                        break
191                endif
192                fprintf refnum_new,tmpStr[0,strlen(tmpStr)-2]+extraStr
193        while(1)
194       
195        Close refnum_old
196        Close refnum_new
197               
198        Return(0)
199End
200
Note: See TracBrowser for help on using the repository browser.