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

Last change on this file since 420 was 404, checked in by ajj, 15 years ago

Refactoring USANS functions to use root:Packages:NIST:USANS as their base to comply with canSAS proposal.

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