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