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

Last change on this file since 491 was 328, checked in by ajj, 15 years ago

Rearranging files

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