source: sans/Release/trunk/NCNR_User_Procedures/USANS Procedures v2.21/WriteUSANSData.ipf @ 284

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

Major structural changes, hopefully correct, to prepare for v2.21 release (not tagged yet)

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