source: sans/USANSReduction/trunk/Put in User Procedures Folder/USANS Procedures v2.20/WriteUSANSData.ipf @ 51

Last change on this file since 51 was 35, checked in by ajj, 16 years ago

Set pragma = 2.20 and required version >= 2.20 for includes in USANS_Includes.ipf

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