source: sans/USANSReduction/trunk/Put in User Procedures Folder/USANS Procedures v2.20/USANSCatNotebook.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
File size: 4.9 KB
Line 
1#pragma rtGlobals=1             // Use modern global access method.
2#pragma Version=2.20
3#pragma IgorVersion=4.0
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        //Igor 4 - need a loop, work backwards to preserve the index
60        ii=itemsinlist(list,";")
61        do
62                partialName = StringFromList(ii, list, ";")
63                if(stringmatch(partialName, matchStr )!=1)
64                        list = RemoveFromList(partialName, list  ,";")
65                endif
66                ii -= 1
67        while(ii>=0)
68       
69        //loop through all of the files in the list, reading header information
70        String str,fullName
71        numitems = ItemsInList(list,";")
72        ii=0
73        if(numItems == 0)
74                Notebook CatWin,textRGB=(65000,0,0),fStyle=1,fsize=14,text="No files found matching \""+matchStr+"\"\r\r"
75//              Notebook CatWin,fStyle=0,text=fileStr+"\r"
76                return          //exit from macro
77        endif
78
79        do
80                //get current item in the list
81                partialName = StringFromList(ii, list, ";")
82
83                //prepend path to tempName for read routine
84                PathInfo bt5PathName
85                FullName = S_path + partialName
86                //go write the header information to the Notebook
87                WriteUCatToNotebook(fullName,partialName)
88                ii+=1
89        while(ii<numitems)
90End
91
92//writes out the CATalog information to the notebook named CatWin (which must exist)
93//fname is the full path for opening (and reading) information from the file
94//which alreay was found to exist
95// sname is the file;vers to be written out,
96//avoiding the need to re-extract it from fname.
97Function WriteUCatToNotebook(fname,sname)
98        String fname,sname
99               
100        String fileStr,dateStr,timePt,titleStr,angRange,temp
101        Variable refnum
102       
103        Open/R refNum as fname          //READ-ONLY.......if fname is "", a dialog will be presented
104        if(refnum==0)
105                return(1)               //user cancelled
106        endif
107        //read in the ASCII data line-by-line
108        Variable numLinesLoaded = 0,firstchar
109        Variable v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,ii,valuesRead
110        String buffer ="",s1,s2,s3,s4,s5,s6,s7,s8,s9,s10
111       
112        //parse the first line
113        FReadLine refnum,buffer
114        sscanf buffer, "%s%s%s%s%s%s%g%g%s%g%s",s1,s2,s3,s4,s5,s6,v1,v2,s7,v3,s8
115        fileStr = s1
116        dateStr = s2+" "+s3+" "+s4+" "+s5
117       
118        //v1 is the time per point (sec)
119        timePt = num2istr(v1)+" sec"
120       
121        //skip the next line
122        FReadLine refnum,buffer
123        //the next line is the title, use it all
124        FReadLine refnum,buffer
125        titleStr = buffer
126       
127        //skip the next 3 lines
128        For(ii=0;ii<3;ii+=1)
129                FReadLine refnum,buffer
130        EndFor
131       
132        //parse the angular range from the next line
133        FReadLine refnum,buffer
134        sscanf buffer,"%g%g%g%g",v1,v2,v3,v4
135        angRange = num2str(v2)+" to "+num2str(v4)+" step "+num2str(v3)
136       
137        Close refNum            // Close the file, read-only, so don't need to move to EOF first
138       
139        Notebook CatWin,textRGB=(0,0,0),fStyle=1,fsize=10,text="FILE: "
140        Notebook CatWin,fStyle=0,text=fileStr+"\r"
141       
142        Notebook CatWin,fStyle=1,text="TITLE: "
143        Notebook CatWin,textRGB=(65000,0,0),fStyle=1,text=titleStr              //?? needs no CR here
144       
145        Notebook CatWin,textRGB=(0,0,0),fStyle=1,text="TIME/PT: "
146        Notebook CatWin,fStyle=0,text=timePt+"\r"
147       
148        Notebook CatWin,fStyle=1,text="DATE: "
149        Notebook CatWin,fStyle=0,text=dateStr+"\r"
150       
151        Notebook CatWin,fStyle=1,text="ANGLE RANGE: "
152        Notebook CatWin,fStyle=0,text=angRange+"\r\r"
153
154//      Notebook CatWin,textRGB=(50000,0,0),fStyle = 1,text=temp
155
156End
157
Note: See TracBrowser for help on using the repository browser.