Ignore:
Timestamp:
Jun 17, 2016 11:43:46 AM (6 years ago)
Author:
srkline
Message:

main changes here are the addition of a first pass at the file catalog, and patch panel. each of these is based on the old SANS file (for now) and has been updated to at least compile.

Much more work needs to be done to get the functionality to be what VSANS needs, both in what is important to report in the file catalog, and how to best present the patch GUI for different situations

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Reduction/VSANS/V_Utilities_General.ipf

    r994 r1002  
    108108        return(err) 
    109109end 
     110 
     111// TODO: 
     112// -- this still does not quite work. If there are no sub folders present in the RawVSANS folder 
     113//    it still thinks there are (1) item there. 
     114// -- if I replace the semicolon with a comma, it thinks there are two folders present and appears 
     115//    to delete the RawVSANS folder itself! seems very dangerous...this is because DataFolderDir returns 
     116//    a comma delimited list, but with a semicolon and \r at the end. need to remove these... 
     117Function V_CleanOutRawVSANS() 
     118 
     119        SetDataFolder root:Packages:NIST:VSANS:RawVSANS: 
     120         
     121        // get a list of the data folders there 
     122        // kill them all if possible 
     123        String list,item 
     124        Variable numFolders,ii,pt 
     125         
     126        list = DataFolderDir(1) 
     127        // this has FOLDERS: at the beginning and is comma-delimited 
     128        list = list[8,strlen(list)] 
     129        pt = strsearch(list,";",inf,1) 
     130        list = list[0,pt-1]                     //remove the ";\r" from the end of the string 
     131//      print list 
     132         
     133        numFolders = ItemsInList(list , ",") 
     134//      Print List 
     135//      print strlen(list) 
     136 
     137        for(ii=0;ii<numFolders;ii+=1) 
     138                item = StringFromList(ii, list ,",") 
     139//              Print item 
     140                KillDataFolder/Z $(item) 
     141        endfor 
     142 
     143        list = DataFolderDir(1) 
     144        list = list[8,strlen(list)] 
     145        pt = strsearch(list,";",inf,1) 
     146        list = list[0,pt-1] 
     147        numFolders = ItemsInList(list, ",") 
     148        Printf "%g RawVSANS folders could not be killed\r",numFolders 
     149                 
     150        SetDataFolder root: 
     151        return(0) 
     152End 
    110153 
    111154//given a filename of a SANS data filename of the form 
     
    313356// -1 => previous file 
    314357// 1 => next file 
     358// 
     359// V_CheckIfRawData(fname) 
     360// 
    315361Function/S V_GetPrevNextRawFile(curfilename, prevnext) 
    316362        String curfilename 
     
    337383//run number "num". The null string is returned if no valid file can be found 
    338384//the path "catPathName" used and is hard-wired, will abort if this path does not exist 
    339 //the file returned will be a RAW SANS data file, other types of files are  
     385//the file returned will be a RAW VSANS data file, other types of files are  
    340386//filtered out. 
    341387// 
     
    399445                                        isRAW = V_CheckIfRawData(fullName) 
    400446                                        if(isRaw) 
     447                                                //print "is raw, ",fullname 
    401448                                                //stop here 
    402449                                                return(fullname) 
     
    411458 
    412459// 
    413 // TODO -- for VSANS Nexus files, how do I quickly identify if a file is 
     460// TODO x- for VSANS Nexus files, how do I quickly identify if a file is 
    414461//   RAW VSANS data? I don't want to generate any errors, but I want to quickly 
    415462//   weed out the reduced data sets, etc. from file catalogs. 
    416 // 
    417 //function to test a binary file to see if it is a RAW binary SANS file 
    418 //first checks the total bytes in the file (which for raw data is 33316 bytes) 
    419 //**note that the "DIV" file will also show up as a raw file by the run field 
    420 //should be listed in CAT/SHORT and in patch windows 
    421 // 
    422 //Function then checks the file fname (full path:file) for "RAW" run.type field 
    423 //if not found, the data is not raw data and zero is returned 
    424 // 
    425 // called by many procedures (both external and local) 
    426 // 
     463//      (check the instrument name...) 
     464 
    427465// TODO -- as was written by SANS, this function is expecting fname to be the path:fileName 
    428466// - but are the V_get() functions OK with getting a full path, and what do they 
     
    436474         
    437475        testStr = V_getInstrumentName(fname) 
    438          
    439         if(cmpstr(testStr,"") != 0) 
     476 
     477        if(cmpstr(testStr,"NG3-VSANS") == 0) 
     478                //testStr exists, ASSUMING it's a raw VSANS data file 
     479                Return(1) 
     480        else 
     481                //some other file 
     482                Return(0) 
     483        Endif 
     484End 
     485 
     486// TODO -- need to fill in correctly by determining this from the INTENT field 
     487// 
     488Function V_isTransFile(fname) 
     489        String fname 
     490         
     491        Variable refnum,totalBytes 
     492        String testStr="" 
     493         
     494//      testStr = V_getInstrumentName(fname) 
     495 
     496        if(cmpstr(testStr,"NG3-VSANS") == 0)            //wrong test 
    440497                //testStr exists, ASSUMING it's a raw VSANS data file 
    441498                Return(1) 
     
    638695                 
    639696End 
     697 
     698// returns a list of raw data files in the catPathName directory on disk 
     699// - list is SEMICOLON-delimited 
     700// 
     701// TODO: decide how to do this... 
     702// (1) 
     703// checks each file in the directory to see if it is a RAW data file by 
     704// call to V_CheckIfRawData() which currently looks for the instrument name in the file. 
     705// -- CON - this is excruciatingly slow, and by checking a field in the file, has to load in the  
     706//  ENTIRE data file, and will load EVERY file in the folder. ugh. 
     707// 
     708// (2) 
     709// as was done for VAX files, look for a specific string in the file name as written by the acquisition 
     710//  (was .saN), now key on ".nxs.ngv"? 
     711// 
     712// called by PatchFiles.ipf, Tile_2D.ipf 
     713// 
     714Function/S V_GetRawDataFileList() 
     715         
     716        //make sure that path exists 
     717        PathInfo catPathName 
     718        if (V_flag == 0) 
     719                Abort "Folder path does not exist - use Pick Path button on Main Panel" 
     720        Endif 
     721        String path = S_Path 
     722         
     723        String list=IndexedFile(catPathName,-1,"????") 
     724        String newList="",item="",validName="",fullName="" 
     725        Variable num=ItemsInList(list,";"),ii 
     726         
     727        for(ii=0;ii<num;ii+=1) 
     728                item = StringFromList(ii, list  ,";") 
     729 
     730                validName = V_FindValidFileName(item) 
     731                if(strlen(validName) != 0)              //non-null return from FindValidFileName() 
     732                        fullName = path + validName              
     733 
     734        //method (1)                     
     735//                      if(V_CheckIfRawData(item)) 
     736//                              newlist += item + ";" 
     737//                      endif 
     738 
     739        //method (2)                     
     740                        if( stringmatch(item,"*.nxs.ngv*") ) 
     741                                newlist += item + ";" 
     742                        endif 
     743 
     744                         
     745                endif 
     746                //print "ii=",ii 
     747        endfor 
     748        newList = SortList(newList,";",0) 
     749        return(newList) 
     750End 
     751 
     752 
     753//the following is a WaveMetrics procedure from <StrMatchList> 
     754// MatchList(matchStr,list,sep) 
     755// Returns the items of the list whose items match matchStr 
     756// The lists are separated by the sep character, usually ";" 
     757// 
     758// matchStr may be something like "abc", in which case it is identical to CmpStr 
     759// matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc", 
     760//      "*abc" to match anything ending with "abc". 
     761// matchStr may also begin with "!" to indicate a match to anything not matching the rest of 
     762//      the pattern. 
     763// At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed. 
     764// 
     765Function/S V_MyMatchList(matchStr,list,sep) 
     766        String matchStr,list,sep 
     767        String item,outList="" 
     768        Variable n=strlen(list) 
     769        Variable en,st=0 
     770        do 
     771                en= strsearch(list,sep,st) 
     772                if( en < 0 ) 
     773                        if( st < n-1 ) 
     774                                en= n   // no trailing separator 
     775                                sep=""  // don't put sep in output, either 
     776                        else 
     777                                break   // no more items in list 
     778                        endif 
     779                endif 
     780                item=list[st,en-1] 
     781                if( V_MyStrMatch(matchStr,item) == 0 ) 
     782                        outlist += item+sep 
     783                Endif 
     784                st=en+1  
     785        while (st < n ) // exit is by break, above 
     786        return outlist 
     787End 
     788 
     789//the following is a WaveMetrics procedure from <StrMatchList> 
     790// StrMatch(matchStr,str) 
     791// Returns 0 if the pattern in matchStr matches str, else it returns 1 
     792// 
     793// matchStr may be something like "abc", in which case it is identical to CmpStr 
     794// matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc", 
     795//      "*abc" to match anything ending with "abc". 
     796// matchStr may also begin with "!" to indicate a match to anything not matching the rest of 
     797//      the pattern. 
     798// At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed. 
     799// 
     800Function V_MyStrMatch(matchStr,str) 
     801        String matchStr,str 
     802        Variable match = 1              // 0 means match 
     803        Variable invert= strsearch(matchStr,"!",0) == 0 
     804        if( invert ) 
     805                matchStr[0,0]=""        // remove the "!" 
     806        endif 
     807        Variable st=0,en=strlen(str)-1 
     808        Variable starPos= strsearch(matchStr,"*",0) 
     809        if( starPos >= 0 )      // have a star 
     810                if( starPos == 0 )      // at start 
     811                        matchStr[0,0]=""                                // remove star at start 
     812                else                                    // at end 
     813                        matchStr[starPos,999999]=""     // remove star and rest of (ignored, illegal) pattern 
     814                endif 
     815                Variable len=strlen(matchStr) 
     816                if( len > 0 ) 
     817                        if(starPos == 0)        // star at start, match must be at end 
     818                                st=en-len+1 
     819                        else 
     820                                en=len-1        // star at end, match at start 
     821                        endif 
     822                else 
     823                        str=""  // so that "*" matches anything 
     824                endif 
     825        endif 
     826        match= !CmpStr(matchStr,str[st,en])==0  // 1 or 0 
     827        if( invert ) 
     828                match= 1-match 
     829        endif 
     830        return match 
     831End 
     832 
     833 
     834//input is a list of run numbers, and output is a list of filenames (not the full path) 
     835//*** input list must be COMMA delimited*** 
     836//output is equivalent to selecting from the CAT table 
     837//if some or all of the list items are valid filenames, keep them... 
     838//if an error is encountered, notify of the offending element and return a null list 
     839// 
     840//output is COMMA delimited 
     841// 
     842// this routine is expecting that the "ask", "none" special cases are handled elsewhere 
     843//and not passed here 
     844// 
     845// called by Marquee.ipf, MultipleReduce.ipf, ProtocolAsPanel.ipf 
     846// 
     847Function/S ParseRunNumberList(list) 
     848        String list 
     849         
     850        String newList="",item="",tempStr="" 
     851        Variable num,ii,runNum 
     852         
     853        //expand number ranges, if any 
     854        list = V_ExpandNumRanges(list) 
     855         
     856        num=itemsinlist(list,",") 
     857         
     858        for(ii=0;ii<num;ii+=1) 
     859                //get the item 
     860                item = StringFromList(ii,list,",") 
     861                //is it already a valid filename? 
     862                tempStr=V_FindValidFilename(item) //returns filename if good, null if error 
     863                if(strlen(tempstr)!=0) 
     864                        //valid name, add to list 
     865                        //Print "it's a file" 
     866                        newList += tempStr + "," 
     867                else 
     868                        //not a valid name 
     869                        //is it a number? 
     870                        runNum=str2num(item) 
     871                        //print runnum 
     872                        if(numtype(runNum) != 0) 
     873                                //not a number -  maybe an error                         
     874                                DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename." 
     875                                return("") 
     876                        else 
     877                                //a run number or an error 
     878                                tempStr = V_GetFileNameFromPathNoSemi( V_FindFileFromRunNumber(runNum) ) 
     879                                if(strlen(tempstr)==0) 
     880                                        //file not found, error 
     881                                        DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number." 
     882                                        return("") 
     883                                else 
     884                                        newList += tempStr + "," 
     885                                endif 
     886                        endif 
     887                endif 
     888        endfor          //loop over all items in list 
     889         
     890        return(newList) 
     891End 
     892 
     893//takes a comma delimited list that MAY contain number range, and 
     894//expands any range of run numbers into a comma-delimited list... 
     895//and returns the new list - if not a range, return unchanged 
     896// 
     897// local function 
     898// 
     899Function/S V_ExpandNumRanges(list) 
     900        String list 
     901         
     902        String newList="",dash="-",item,str 
     903        Variable num,ii,hasDash 
     904         
     905        num=itemsinlist(list,",") 
     906//      print num 
     907        for(ii=0;ii<num;ii+=1) 
     908                //get the item 
     909                item = StringFromList(ii,list,",") 
     910                //does it contain a dash? 
     911                hasDash = strsearch(item,dash,0)                //-1 if no dash found 
     912                if(hasDash == -1) 
     913                        //not a range, keep it in the list 
     914                        newList += item + "," 
     915                else 
     916                        //has a dash (so it's a range), expand (or add null) 
     917                        newList += V_ListFromDash(item)          
     918                endif 
     919        endfor 
     920         
     921        return newList 
     922End 
     923 
     924//be sure to add a trailing comma to the return string... 
     925// 
     926// local function 
     927// 
     928Function/S V_ListFromDash(item) 
     929        String item 
     930         
     931        String numList="",loStr="",hiStr="" 
     932        Variable lo,hi,ii 
     933         
     934        loStr=StringFromList(0,item,"-")        //treat the range as a list 
     935        hiStr=StringFromList(1,item,"-") 
     936        lo=str2num(loStr) 
     937        hi=str2num(hiStr) 
     938        if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) ) 
     939                numList="" 
     940                return numList 
     941        endif 
     942        for(ii=lo;ii<=hi;ii+=1) 
     943                numList += num2str(ii) + "," 
     944        endfor 
     945         
     946        Return numList 
     947End 
     948 
Note: See TracChangeset for help on using the changeset viewer.