source: sans/Dev/trunk/NCNR_User_Procedures/Analysis/WriteModelData_v40.ipf @ 473

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

Changes to DoSaveFileDialog? are now package specific (U_ and A_) since including WriteQIS made a big mess, starting a long chain of dependencies... So now the function is in three places. There's got to be a common place.

File size: 3.7 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma IgorVersion = 6.0
3
4Proc WriteModelData(xwave,ywave,delim,term)
5        String xwave,ywave,delim,term
6        Prompt xwave,"X data",popup,PossibleModelWaves("x*")
7        Prompt ywave,"Y data",popup,PossibleModelWaves("y*")
8        Prompt delim,"delimeter",popup,"tab;space;"
9        Prompt term,"line termination",popup,"CR;LF;CRLF;"
10       
11        //Print xwave, ywave, delim, term
12       
13        fWriteModelData($xwave,$ywave,delim,term)
14       
15End
16
17Function/S PossibleModelWaves(filterStr)
18        String filterStr
19       
20        String list,tmplist,DF,newList=""
21        Variable ii,num
22       
23        //waves in root
24        list = WaveList(filterStr,";","")
25       
26        //add possble smeared models that are housed in data folders
27        ControlInfo/W=WrapperPanel popup_0
28        if(V_flag==0 || cmpstr(S_Value,"No data loaded")==0)
29                return(list)
30        else
31                DF="root:"+S_Value
32                SetDataFolder $DF
33                if(cmpstr(filterStr,"x*")==0)
34                        tmplist = WaveList("*_q",";","")
35                        tmpList += WaveList("GFitX_*",";","")
36                else
37                        tmplist = WaveList("smea*",";","")
38                        tmpList += WaveList("GFit_*",";","")
39                endif
40                //prepend these list items with the folder
41                num=itemsinlist(tmplist)
42                if(num > 0)
43                        ii=0
44                        do
45                                newList += DF+":"+StringFromList(ii, tmpList, ";") + ";"
46                                ii+=1
47                        while(ii<num)
48                       
49                        //then add to the list
50                        list += newList
51                endif
52        endif
53       
54        SetDataFolder root:
55        return(list)
56end
57
58// always asks for a file name
59Function fWriteModelData(xwave,ywave,delim,term)
60        Wave xwave,ywave
61        String delim,term
62       
63        String formatStr="",fullpath=""
64        Variable refnum,dialog=1
65       
66        //setup delimeter and terminator choices
67        If(cmpstr(delim,"tab")==0)
68                //tab-delimeted
69                formatStr="%15.4g\t%15.4g"
70        else
71                //use 3 spaces
72                formatStr="%15.4g   %15.4g"
73        Endif
74        If(cmpstr(term,"CR")==0)
75                formatStr += "\r"
76        Endif
77        If(cmpstr(term,"LF")==0)
78                formatStr += "\n"
79        Endif
80        If(cmpstr(term,"CRLF")==0)
81                formatStr += "\r\n"
82        Endif
83       
84        if(dialog)
85                PathInfo/S catPathName
86                fullPath = A_DoSaveFileDialog("Save data as",fname=NameofWave(ywave)+".txt")
87                If(cmpstr(fullPath,"")==0)
88                        //user cancel, don't write out a file
89                        Close/A
90                        Abort "no data file was written"
91                Endif
92                //Print "dialog fullpath = ",fullpath
93        Endif
94       
95        Open refnum as fullpath
96       
97        fprintf refnum,"Model data created %s\r\n",(date()+" "+time())
98        wfprintf refnum,formatStr,xwave,ywave
99        Close refnum
100        return(0)
101End
102
103// returns the path to the file, or null if the user cancelled
104// fancy use of optional parameters
105//
106// enforce short file names (26 characters)
107// DUPLICATE of similar-named function in WriteQIS (including starts a bad dependency chain)
108Function/S A_DoSaveFileDialog(msg,[fname,suffix])
109        String msg,fname,suffix
110        Variable refNum
111//      String message = "Save the file as"
112
113        if(ParamIsDefault(fname))
114//              Print "fname not supplied"
115                fname = ""
116        endif
117        if(ParamIsDefault(suffix))
118//              Print "suffix not supplied"
119                suffix = ""
120        endif
121       
122        String outputPath,tmpName,testStr
123        Variable badLength=0,maxLength=26,l1,l2
124       
125       
126        tmpName = fname + suffix
127       
128        do
129                badLength=0
130                Open/D/M=msg/T="????" refNum as tmpName
131                outputPath = S_fileName
132               
133                testStr = ParseFilePath(0, outputPath, ":", 1, 0)               //just the filename
134                if(strlen(testStr)==0)
135                        break           //cancel, allow exit
136                endif
137                if(strlen(testStr) > maxLength)
138                        badlength = 1
139                        DoAlert 2,"File name is too long. Is\r"+testStr[0,25]+"\rOK?"
140                        if(V_flag==3)
141                                outputPath = ""
142                                break
143                        endif
144                        if(V_flag==1)                   //my suggested name is OK, so trim the output
145                                badlength=0
146                                l1 = strlen(testStr)            //too long length
147                                l1 = l1-maxLength               //number to trim
148                                //Print outputPath
149                                l2=strlen(outputPath)
150                                outputPath = outputPath[0,l2-1-l1]
151                                //Print "modified  ",outputPath
152                        endif
153                        //if(V_flag==2)  do nothing, let it go around again
154                endif
155               
156        while(badLength)
157       
158        return outputPath
159End
Note: See TracBrowser for help on using the repository browser.