1 | #pragma rtGlobals=1 // Use modern global access method. |
---|
2 | #pragma Version=2.20 |
---|
3 | #pragma IgorVersion=6.1 |
---|
4 | |
---|
5 | //************** |
---|
6 | // Vers 1. 18JAN06 |
---|
7 | // |
---|
8 | // Procedures for creating a catalog listing of USANS datafiles in the folder |
---|
9 | // specified by catPathName. |
---|
10 | // |
---|
11 | // selects only files with a named prefix, since all data from a given cycle |
---|
12 | // is in the data folder. |
---|
13 | // Header information from each of the daafles is organized in a notebook for |
---|
14 | // easy identification of each file. |
---|
15 | |
---|
16 | |
---|
17 | //this main procedure does all the work for making the cat notebook, |
---|
18 | // obtaining the folder path, parsing the filenames in the list, |
---|
19 | // and (dispatching) to write out the appropriate information to the notebook window |
---|
20 | Proc BuildUSANSNotebook(matchStr) |
---|
21 | String matchStr="*" |
---|
22 | |
---|
23 | DoWindow/F CatWin |
---|
24 | If(V_Flag ==0) |
---|
25 | String nb = "CatWin" |
---|
26 | NewNotebook/F=1/N=$nb/W=(5.25,40.25,581.25,380.75) as "USANS Catalog" |
---|
27 | Notebook $nb defaultTab=36, statusWidth=238, pageMargins={72,72,72,72} |
---|
28 | Notebook $nb showRuler=1, rulerUnits=1, updating={1, 60} |
---|
29 | Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={} |
---|
30 | Notebook $nb ruler=Normal; Notebook $nb margins={0,0,544} |
---|
31 | Endif |
---|
32 | |
---|
33 | Variable err |
---|
34 | PathInfo bt5PathName |
---|
35 | if(v_flag==0) |
---|
36 | err = PickBT5Path() //sets the local path to the data (bt5PathName) |
---|
37 | if(err) |
---|
38 | Abort "no path to data was selected, no catalog can be made - use PickPath button" |
---|
39 | Endif |
---|
40 | Endif |
---|
41 | |
---|
42 | String temp="" |
---|
43 | //clear old window contents, reset the path |
---|
44 | Notebook CatWin,selection={startOfFile,EndOfFile} |
---|
45 | Notebook CatWin,text="\r" |
---|
46 | Notebook CatWin,font="Geneva",fsize=14,textRGB=(0,0,0),fStyle=1,text = "FOLDER: " |
---|
47 | |
---|
48 | PathInfo bt5PathName |
---|
49 | temp = S_path+"\r\r" |
---|
50 | Notebook CatWin,fStyle=0,text = temp |
---|
51 | |
---|
52 | //get a list of all files in the folder |
---|
53 | String list,partialName,tempName |
---|
54 | list = IndexedFile(bt5PathName,-1,"????") //get all files in folder |
---|
55 | Variable numitems,ii,ok |
---|
56 | |
---|
57 | //Igor 5 only - trim the list to the selected matching prefix (a one-liner) |
---|
58 | list = ListMatch(list, matchStr , ";" ) |
---|
59 | |
---|
60 | // Igor 4 - need a loop, work backwards to preserve the index |
---|
61 | // ii=itemsinlist(list,";") |
---|
62 | // do |
---|
63 | // partialName = StringFromList(ii, list, ";") |
---|
64 | // if(stringmatch(partialName, matchStr )!=1) |
---|
65 | // list = RemoveFromList(partialName, list ,";") |
---|
66 | // endif |
---|
67 | // ii -= 1 |
---|
68 | // while(ii>=0) |
---|
69 | |
---|
70 | // remove the "fpx*" files, they are not real data |
---|
71 | String tmp = ListMatch(list,"fpx*",";") |
---|
72 | list = RemoveFromList(tmp, list ,";") |
---|
73 | print tmp |
---|
74 | |
---|
75 | // remove the ".DS_Store" |
---|
76 | list = RemoveFromList(".DS_Store",list,";") |
---|
77 | |
---|
78 | // remove .cor, .dsm reduced data files |
---|
79 | tmp = ListMatch(list,"*.cor",";") |
---|
80 | list = RemoveFromList(tmp, list ,";") |
---|
81 | tmp = ListMatch(list,"*.dsm",";") |
---|
82 | list = RemoveFromList(tmp, list ,";") |
---|
83 | tmp = ListMatch(list,"*.pxp",";") |
---|
84 | list = RemoveFromList(tmp, list ,";") |
---|
85 | |
---|
86 | |
---|
87 | //loop through all of the files in the list, reading header information |
---|
88 | String str,fullName |
---|
89 | numitems = ItemsInList(list,";") |
---|
90 | ii=0 |
---|
91 | if(numItems == 0) |
---|
92 | Notebook CatWin,textRGB=(65000,0,0),fStyle=1,fsize=14,text="No files found matching \""+matchStr+"\"\r\r" |
---|
93 | // Notebook CatWin,fStyle=0,text=fileStr+"\r" |
---|
94 | return //exit from macro |
---|
95 | endif |
---|
96 | list = SortList(list ,";",0) //default sort |
---|
97 | do |
---|
98 | //get current item in the list |
---|
99 | partialName = StringFromList(ii, list, ";") |
---|
100 | |
---|
101 | //prepend path to tempName for read routine |
---|
102 | PathInfo bt5PathName |
---|
103 | FullName = S_path + partialName |
---|
104 | //go write the header information to the Notebook |
---|
105 | WriteUCatToNotebook(fullName,partialName) |
---|
106 | ii+=1 |
---|
107 | while(ii<numitems) |
---|
108 | End |
---|
109 | |
---|
110 | //writes out the CATalog information to the notebook named CatWin (which must exist) |
---|
111 | //fname is the full path for opening (and reading) information from the file |
---|
112 | //which alreay was found to exist |
---|
113 | // sname is the file;vers to be written out, |
---|
114 | //avoiding the need to re-extract it from fname. |
---|
115 | Function WriteUCatToNotebook(fname,sname) |
---|
116 | String fname,sname |
---|
117 | |
---|
118 | String fileStr,dateStr,timePt,titleStr,angRange,temp |
---|
119 | Variable refnum |
---|
120 | |
---|
121 | Open/R refNum as fname //READ-ONLY.......if fname is "", a dialog will be presented |
---|
122 | if(refnum==0) |
---|
123 | return(1) //user cancelled |
---|
124 | endif |
---|
125 | //read in the ASCII data line-by-line |
---|
126 | Variable numLinesLoaded = 0,firstchar |
---|
127 | Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead |
---|
128 | String buffer ="",s1,s2,s3,s4,s5,s6,s7,s8,s9,s10 |
---|
129 | |
---|
130 | //parse the first line |
---|
131 | FReadLine refnum,buffer |
---|
132 | sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8 |
---|
133 | fileStr = s1 |
---|
134 | dateStr = s2+" "+s3+" "+s4+" "+s5 |
---|
135 | |
---|
136 | //v1 is the time per point (sec) |
---|
137 | timePt = num2istr(v1)+" sec" |
---|
138 | |
---|
139 | //skip the next line |
---|
140 | FReadLine refnum,buffer |
---|
141 | //the next line is the title, use it all |
---|
142 | FReadLine refnum,buffer |
---|
143 | titleStr = buffer |
---|
144 | |
---|
145 | //skip the next 3 lines |
---|
146 | For(ii=0;ii<3;ii+=1) |
---|
147 | FReadLine refnum,buffer |
---|
148 | EndFor |
---|
149 | |
---|
150 | //parse the angular range from the next line |
---|
151 | FReadLine refnum,buffer |
---|
152 | sscanf buffer,"%g%g%g%g",v1,v2,v3,v4 |
---|
153 | angRange = num2str(v2)+" to "+num2str(v4)+" step "+num2str(v3) |
---|
154 | |
---|
155 | Close refNum // Close the file, read-only, so don't need to move to EOF first |
---|
156 | |
---|
157 | Notebook CatWin,textRGB=(0,0,0),fStyle=1,fsize=10,text="FILE: " |
---|
158 | Notebook CatWin,fStyle=0,text=fileStr+"\r" |
---|
159 | |
---|
160 | Notebook CatWin,fStyle=1,text="TITLE: " |
---|
161 | Notebook CatWin,textRGB=(65000,0,0),fStyle=1,text=titleStr //?? needs no CR here |
---|
162 | |
---|
163 | Notebook CatWin,textRGB=(0,0,0),fStyle=1,text="TIME/PT: " |
---|
164 | Notebook CatWin,fStyle=0,text=timePt+"\r" |
---|
165 | |
---|
166 | Notebook CatWin,fStyle=1,text="DATE: " |
---|
167 | Notebook CatWin,fStyle=0,text=dateStr+"\r" |
---|
168 | |
---|
169 | Notebook CatWin,fStyle=1,text="ANGLE RANGE: " |
---|
170 | Notebook CatWin,fStyle=0,text=angRange+"\r\r" |
---|
171 | |
---|
172 | // Notebook CatWin,textRGB=(50000,0,0),fStyle = 1,text=temp |
---|
173 | |
---|
174 | End |
---|