source: sans/Dev/trunk/NCNR_User_Procedures/Reduction/USANS/USANSCatNotebook.ipf @ 1004

Last change on this file since 1004 was 667, checked in by srkline, 13 years ago

USANS dialogs now prompt with "x" added to the suffix when saving.

These files are also filtered out at the same time as normal .cor and .dsm file extensions

  • Property eol-style set to native
File size: 5.5 KB
Line 
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
20Proc 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        // should also catch .corx, .dsmx if they are generated
80        tmp = ListMatch(list,"*.cor*",";")             
81        list = RemoveFromList(tmp, list  ,";")
82        tmp = ListMatch(list,"*.dsm*",";")             
83        list = RemoveFromList(tmp, list  ,";")
84        tmp = ListMatch(list,"*.pxp",";")               
85        list = RemoveFromList(tmp, list  ,";")
86       
87       
88        //loop through all of the files in the list, reading header information
89        String str,fullName
90        numitems = ItemsInList(list,";")
91        ii=0
92        if(numItems == 0)
93                Notebook CatWin,textRGB=(65000,0,0),fStyle=1,fsize=14,text="No files found matching \""+matchStr+"\"\r\r"
94//              Notebook CatWin,fStyle=0,text=fileStr+"\r"
95                return          //exit from macro
96        endif
97        list = SortList(list  ,";",0)           //default sort
98        do
99                //get current item in the list
100                partialName = StringFromList(ii, list, ";")
101
102                //prepend path to tempName for read routine
103                PathInfo bt5PathName
104                FullName = S_path + partialName
105                //go write the header information to the Notebook
106                WriteUCatToNotebook(fullName,partialName)
107                ii+=1
108        while(ii<numitems)
109End
110
111//writes out the CATalog information to the notebook named CatWin (which must exist)
112//fname is the full path for opening (and reading) information from the file
113//which alreay was found to exist
114// sname is the file;vers to be written out,
115//avoiding the need to re-extract it from fname.
116Function WriteUCatToNotebook(fname,sname)
117        String fname,sname
118               
119        String fileStr,dateStr,timePt,titleStr,angRange,temp
120        Variable refnum
121       
122        Open/R refNum as fname          //READ-ONLY.......if fname is "", a dialog will be presented
123        if(refnum==0)
124                return(1)               //user cancelled
125        endif
126        //read in the ASCII data line-by-line
127        Variable numLinesLoaded = 0,firstchar
128        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead
129        String buffer ="",s1,s2,s3,s4,s5,s6,s7,s8,s9,s10
130       
131        //parse the first line
132        FReadLine refnum,buffer
133        sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8
134        fileStr = s1
135        dateStr = s2+" "+s3+" "+s4+" "+s5
136       
137        //v1 is the time per point (sec)
138        timePt = num2istr(v1)+" sec"
139       
140        //skip the next line
141        FReadLine refnum,buffer
142        //the next line is the title, use it all
143        FReadLine refnum,buffer
144        titleStr = buffer
145       
146        //skip the next 3 lines
147        For(ii=0;ii<3;ii+=1)
148                FReadLine refnum,buffer
149        EndFor
150       
151        //parse the angular range from the next line
152        FReadLine refnum,buffer
153        sscanf buffer,"%g%g%g%g",v1,v2,v3,v4
154        angRange = num2str(v2)+" to "+num2str(v4)+" step "+num2str(v3)
155       
156        Close refNum            // Close the file, read-only, so don't need to move to EOF first
157       
158        Notebook CatWin,textRGB=(0,0,0),fStyle=1,fsize=10,text="FILE: "
159        Notebook CatWin,fStyle=0,text=fileStr+"\r"
160       
161        Notebook CatWin,fStyle=1,text="TITLE: "
162        Notebook CatWin,textRGB=(65000,0,0),fStyle=1,text=titleStr              //?? needs no CR here
163       
164        Notebook CatWin,textRGB=(0,0,0),fStyle=1,text="TIME/PT: "
165        Notebook CatWin,fStyle=0,text=timePt+"\r"
166       
167        Notebook CatWin,fStyle=1,text="DATE: "
168        Notebook CatWin,fStyle=0,text=dateStr+"\r"
169       
170        Notebook CatWin,fStyle=1,text="ANGLE RANGE: "
171        Notebook CatWin,fStyle=0,text=angRange+"\r\r"
172
173//      Notebook CatWin,textRGB=(50000,0,0),fStyle = 1,text=temp
174
175End
Note: See TracBrowser for help on using the repository browser.