Changeset 69 for sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/VAXFileUtils.ipf
- Timestamp:
- Mar 29, 2007 1:45:45 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sans/SANSReduction/branches/kline_29MAR07/Put in User Procedures/SANS_Reduction_v5.00/VAXFileUtils.ipf
r47 r69 3 3 #pragma IgorVersion=4.0 4 4 5 //**************************6 // Vers. 1.2 0921017 //8 //this file is a collection of uilities for processing vax filenames9 //and processing lists (especially for display in popup menus)10 //11 //required to correctly account for VAX supplied version numbers, which12 //may or may not be removed by the ftp utility13 //14 // - parses lists of run numbers into real filenames15 // - selects proper detector constants16 //17 //**************************18 19 20 //given a filename of a SANS data filename of the form21 //TTTTTnnn.SAn_TTT_Txxx22 //returns the run number "nnn" as a number23 //returns -1 as an invalid file number24 Function GetRunNumFromFile(item)25 String item26 Variable invalid = -1 //negative numbers are invalid27 Variable num=-128 29 //find the "dot"30 String runStr=""31 Variable pos = strsearch(item,".",0)32 if(pos == -1)33 //"dot" not found34 return (invalid)35 else36 //found, get the three characters preceeding it37 if (pos <=2)38 //not enough characters39 return (invalid)40 else41 runStr = item[pos-3,pos-1]42 //convert to a number43 num = str2num(runStr)44 //if valid, return it45 if (num == NaN)46 //3 characters were not a number47 return (invalid)48 else49 //run was OK50 return (num)51 Endif52 Endif53 Endif54 End55 56 //given a filename of a SANS data filename of the form57 //TTTTTnnn.SAn_TTT_Txxx58 //returns the run number "nnn" as a STRING of THREE characters59 //returns "ABC" as an invalid file number60 Function/S GetRunNumStrFromFile(item)61 String item62 String invalid = "ABC" //"ABC" is not a valid run number, since it's text63 Variable num=-164 65 //find the "dot"66 String runStr=""67 Variable pos = strsearch(item,".",0)68 if(pos == -1)69 //"dot" not found70 return (invalid)71 else72 //found, get the three characters preceeding it73 if (pos <=2)74 //not enough characters75 return (invalid)76 else77 runStr = item[pos-3,pos-1]78 return (runStr)79 Endif80 Endif81 End82 83 //returns a string containing the full path and file to the file containing the84 //run number "num". The null string is returned if no valid file can be found85 //the path "catPathName" used and is hard-wired, will abort if this path does not exist86 //the file returned will be a RAW SANS data file, other types of files are87 //filtered out.88 Function/S FindFileFromRunNumber(num)89 Variable num90 91 String fullName="",partialName="",item=""92 //get list of raw data files in folder that match "num" (add leading zeros)93 if( (num>999) || (num<=0) )94 //Print "error in FindFileFromRunNumber(num), file number too large or too small"95 Return ("")96 Endif97 //make a three character string of the run number98 String numStr=""99 if(num<10)100 numStr = "00"+num2str(num)101 else102 if(num<100)103 numStr = "0"+num2str(num)104 else105 numStr = num2str(num)106 Endif107 Endif108 //Print "numstr = ",numstr109 110 //make sure that path exists111 PathInfo catPathName112 String path = S_path113 if (V_flag == 0)114 Abort "folder path does not exist - use Pick Path button"115 Endif116 String list="",newList="",testStr=""117 118 list = IndexedFile(catPathName,-1,"????") //get all files in folder119 //find (the) one with the number in the run # location in the name120 Variable numItems,ii,runFound,isRAW121 numItems = ItemsInList(list,";") //get the new number of items in the list122 ii=0123 do124 //parse through the list in this order:125 // 1 - does item contain run number (as a string) "TTTTTnnn.SAn_XXX_Tyyy"126 // 2 - exclude by isRaw? (to minimize disk access)127 item = StringFromList(ii, list ,";" )128 if(strlen(item) != 0)129 //find the run number, if it exists as a three character string130 testStr = GetRunNumStrFromFile(item)131 runFound= cmpstr(numStr,testStr) //compare the three character strings, 0 if equal132 if(runFound == 0)133 //the run Number was found134 //build valid filename135 partialName = FindValidFileName(item)136 if(strlen(partialName) != 0) //non-null return from FindValidFileName()137 fullName = path + partialName138 //check if RAW, if so,this must be the file!139 isRAW = CheckIfRawData(fullName)140 if(isRaw)141 //stop here142 return(fullname)143 Endif144 Endif145 Endif146 Endif147 ii+=1148 while(ii<numItems) //process all items in list149 Return ("") //null return if file not found in list150 End151 152 //function to test a binary file to see if it is a RAW binary SANS file153 //first checks the total bytes in the file (which for raw data is 33316 bytes)154 //**note that the "DIV" file will also show up as a raw file by the run field155 //should be listed in CAT/SHORT and in patch windows156 //157 //Function then checks the file fname (full path:file) for "RAW" run.type field158 //if not found, the data is not raw data and zero is returned159 Function CheckIfRawData(fname)160 String fname161 162 Variable refnum,totalBytes163 String testStr=""164 165 Open/R/T="????TEXT" refNum as fname166 //get the total number of bytes in the file, to avoid moving past EOF167 FStatus refNum168 totalBytes = V_logEOF169 //Print totalBytes170 if(totalBytes!=33316)171 //can't possibly be a raw data file172 Close refnum173 return(0) //not a raw SANS file174 Endif175 FSetPos refNum,75176 FReadLine/N=3 refNum,testStr177 Close refNum178 179 if(cmpstr(testStr,"RAW")==0)180 //true, is raw data file181 Return(1)182 else183 //some other file184 Return(0)185 Endif186 End187 188 //function to remove all spaces from names when searching for filenames189 //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn)190 //but the text field in the header WILL, if less than 3 characters were used for the191 //user's initials, and can have leading spaces if prefix was less than 5 characters192 //193 //returns a string identical to the original string, except with the interior spaces removed194 //195 Function/S RemoveAllSpaces(str)196 String str197 198 String tempstr = str199 Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename200 ii=0201 do202 len = strlen(tempStr)203 spc = strsearch(tempStr," ",0) //is the last character a space?204 if (spc == -1)205 break //no more spaces found, get out206 endif207 str = tempstr208 tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string209 While(1) //should never be more than 2 or 3210 211 If(strlen(tempStr) < 1)212 tempStr = "" //be sure to return a null string if problem found213 Endif214 215 //Print strlen(tempstr)216 217 Return(tempStr)218 219 End220 221 222 //Function attempts to find valid filename from partial name that has been stripped of223 //the VAX version number. The partial name is tried first224 //*** the PATH is hard-wired to catPathName (which is assumed to exist)225 //version numers up to ;10 are tried226 //only the "name;vers" is returned. the path is not prepended, hence the return string227 //is not a complete specification of the file228 //229 // added 11/99 - uppercase and lowercase versions of the file are tried, if necessary230 // since from marquee, the filename field (textread[0]) must be used, and can be a mix of231 // upper/lowercase letters, while the filename on the server (should) be all caps232 // now makes repeated calls to ValidFileString()233 //234 Function/S FindValidFilename(partialName)235 String PartialName236 237 String retStr=""238 239 //try name with no changes - to allow for ABS files that have spaces in the names 12APR04240 retStr = ValidFileString(partialName)241 if(cmpstr(retStr,"") !=0)242 //non-null return243 return(retStr)244 Endif245 246 //if the partial name is derived from the file header, there can be spaces at the beginning247 //or in the middle of the filename - depending on the prefix and initials used248 //249 //remove any leading spaces from the name before starting250 partialName = RemoveAllSpaces(partialName)251 252 //try name with no spaces253 retStr = ValidFileString(partialName)254 if(cmpstr(retStr,"") !=0)255 //non-null return256 return(retStr)257 Endif258 259 //try all UPPERCASE260 partialName = UpperStr(partialName)261 retStr = ValidFileString(partialName)262 if(cmpstr(retStr,"") !=0)263 //non-null return264 return(retStr)265 Endif266 267 //try all lowercase (ret null if failure)268 partialName = LowerStr(partialName)269 retStr = ValidFileString(partialName)270 if(cmpstr(retStr,"") !=0)271 //non-null return272 return(retStr)273 else274 return(retStr)275 Endif276 End277 278 //Function attempts to find valid filename from partial name that has been stripped of279 //the VAX version number. The partial name is tried first280 //*** the PATH is hard-wired to catPathName (which is assumed to exist)281 //version numers up to ;10 are tried282 //only the "name;vers" is returned. the path is not prepended, hence the return string283 //is not a complete specification of the file284 //285 Function/S ValidFileString(partialName)286 String partialName287 288 String tempName = "",msg=""289 Variable ii,refnum290 291 ii=0292 do293 if(ii==0)294 //first pass, try the partialName295 tempName = partialName296 Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag)297 if(V_flag == 0)298 //file exists299 Close refnum //YES needed,300 break301 endif302 else303 tempName = partialName + ";" + num2str(ii)304 Open/Z/R/T="????TEXT"/P=catPathName refnum tempName305 if(V_flag == 0)306 //file exists307 Close refnum308 break309 endif310 Endif311 ii+=1312 //print "ii=",ii313 while(ii<11)314 //go get the selected bits of information, using tempName, which exists315 if(ii>=11)316 //msg = partialName + " not found. is version number > 11?"317 //DoAlert 0, msg318 //PathInfo catPathName319 //Print S_Path320 Return ("") //use null string as error condition321 Endif322 323 Return (tempName)324 End325 5 326 6 327 7 328 //the following is a WaveMetrics procedure from <StrMatchList>329 // MatchList(matchStr,list,sep)330 // Returns the items of the list whose items match matchStr331 // The lists are separated by the sep character, usually ";"332 //333 // matchStr may be something like "abc", in which case it is identical to CmpStr334 // matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc",335 // "*abc" to match anything ending with "abc".336 // matchStr may also begin with "!" to indicate a match to anything not matching the rest of337 // the pattern.338 // At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed.339 //340 Function/S MyMatchList(matchStr,list,sep)341 String matchStr,list,sep342 String item,outList=""343 Variable n=strlen(list)344 Variable en,st=0345 do346 en= strsearch(list,sep,st)347 if( en < 0 )348 if( st < n-1 )349 en= n // no trailing separator350 sep="" // don't put sep in output, either351 else352 break // no more items in list353 endif354 endif355 item=list[st,en-1]356 if( MyStrMatch(matchStr,item) == 0 )357 outlist += item+sep358 Endif359 st=en+1360 while (st < n ) // exit is by break, above361 return outlist362 End363 364 //the following is a WaveMetrics procedure from <StrMatchList>365 // StrMatch(matchStr,str)366 // Returns 0 if the pattern in matchStr matches str, else it returns 1367 //368 // matchStr may be something like "abc", in which case it is identical to CmpStr369 // matchStr may also be "*" to match anything, "abc*" to match anything starting with "abc",370 // "*abc" to match anything ending with "abc".371 // matchStr may also begin with "!" to indicate a match to anything not matching the rest of372 // the pattern.373 // At most one "*" and one "!" are allowed in matchStr, otherwise the results are not guaranteed.374 //375 Function MyStrMatch(matchStr,str)376 String matchStr,str377 Variable match = 1 // 0 means match378 Variable invert= strsearch(matchStr,"!",0) == 0379 if( invert )380 matchStr[0,0]="" // remove the "!"381 endif382 Variable st=0,en=strlen(str)-1383 Variable starPos= strsearch(matchStr,"*",0)384 if( starPos >= 0 ) // have a star385 if( starPos == 0 ) // at start386 matchStr[0,0]="" // remove star at start387 else // at end388 matchStr[starPos,999999]="" // remove star and rest of (ignored, illegal) pattern389 endif390 Variable len=strlen(matchStr)391 if( len > 0 )392 if(starPos == 0) // star at start, match must be at end393 st=en-len+1394 else395 en=len-1 // star at end, match at start396 endif397 else398 str="" // so that "*" matches anything399 endif400 endif401 match= !CmpStr(matchStr,str[st,en])==0 // 1 or 0402 if( invert )403 match= 1-match404 endif405 return match406 End407 408 409 //returns a string containing filename (WITHOUT the ;vers)410 //the input string is a full path to the file (Mac-style, still works on Win in IGOR)411 //with the folders separated by colons412 Function/S GetFileNameFromPathNoSemi(fullPath)413 String fullPath414 415 Variable offset1,offset2416 String filename=""417 //String PartialPath418 offset1 = 0419 do420 offset2 = StrSearch(fullPath, ":", offset1)421 if (offset2 == -1) // no more colons ?422 fileName = FullPath[offset1,strlen(FullPath) ]423 //PartialPath = FullPath[0, offset1-1]424 break425 endif426 offset1 = offset2+1427 while (1)428 429 //remove version number from name, if it's there - format should be: filename;N430 filename = StringFromList(0,filename,";") //returns null if error431 432 Return filename433 End434 435 //returns a string containing filename (INCLUDING the ;vers)436 //the input string is a full path to the file (Mac-style, still works on Win in IGOR)437 //with the folders separated by colons438 Function/S GetFileNameFromPathKeepSemi(fullPath)439 String fullPath440 441 Variable offset1,offset2442 String filename443 //String PartialPath444 offset1 = 0445 do446 offset2 = StrSearch(fullPath, ":", offset1)447 if (offset2 == -1) // no more colons ?448 fileName = FullPath[offset1,strlen(FullPath) ]449 //PartialPath = FullPath[0, offset1-1]450 break451 endif452 offset1 = offset2+1453 while (1)454 455 //keep version number from name, if it's there - format should be: filename;N456 457 Return filename458 End459 460 //given the full path and filename (fullPath), strips the data path461 //(Mac-style, separated by colons) and returns this path462 //this partial path is the same string that would be returned from PathInfo, for example463 Function/S GetPathStrFromfullName(fullPath)464 String fullPath465 466 Variable offset1,offset2467 //String filename468 String PartialPath469 offset1 = 0470 do471 offset2 = StrSearch(fullPath, ":", offset1)472 if (offset2 == -1) // no more colons ?473 //fileName = FullPath[offset1,strlen(FullPath) ]474 PartialPath = FullPath[0, offset1-1]475 break476 endif477 offset1 = offset2+1478 while (1)479 480 Return PartialPath481 End482 483 //given the VAX filename, pull off the first 8 characters to make a valid484 //file string that can be used for naming averaged 1-d files485 Function/S GetNameFromHeader(fullName)486 String fullName487 String temp, newName = ""488 Variable spc,ii=0489 490 //filename is 20 characters NNNNNxxx.SAn_NNN_NNN491 //want the first 8 characters, NNNNNxxx, then strip off any spaces at the beginning492 //NNNNN was entered as less than 5 characters493 //returns a null string if no name can be found494 do495 temp = fullname[ii,7] //characters ii,7 of the name496 spc = strsearch(temp," ",0)497 if (spc == -1)498 break //no more spaces found499 endif500 ii+=1501 While(ii<8)502 503 If(strlen(temp) < 1)504 newName = "" //be sure to return a null string if problem found505 else506 newName = temp507 Endif508 509 Return(newName)510 End511 512 //list (input) is a list, typically returned from IndexedFile()513 //which is semicolon-delimited, and may contain filesnames from the VAX514 //that contain version numbers, where the version number appears as a separate list item515 //(and also as a non-existent file)516 //these numbers must be purged from the list, especially for display in a popup517 //or list processing of filenames518 //the function returns the list, cleaned of version numbers (up to 11)519 //raw data files will typically never have a version number other than 1.520 Function/S RemoveVersNumsFromList(list)521 String list522 523 //get rid of version numbers first (up to 11)524 Variable ii,num525 String item526 num = ItemsInList(list,";")527 ii=1528 do529 item = num2str(ii)530 list = RemoveFromList(item, list ,";" )531 ii+=1532 while(ii<12)533 534 return (list)535 End536 537 //input is a list of run numbers, and output is a list of filenames (not the full path)538 //*** input list must be COMMA delimited***539 //output is equivalent to selecting from the CAT table540 //if some or all of the list items are valid filenames, keep them...541 //if an error is encountered, notify of the offending element and return the null list542 //543 //output is COMMA delimited544 //545 // this routine is expecting that the "ask", "none" special cases are handled elsewhere546 //and not passed here547 Function/S ParseRunNumberList(list)548 String list549 550 String newList="",item="",tempStr=""551 Variable num,ii,runNum552 553 //expand number ranges, if any554 list = ExpandNumRanges(list)555 556 num=itemsinlist(list,",")557 558 for(ii=0;ii<num;ii+=1)559 //get the item560 item = StringFromList(ii,list,",")561 //is it already a valid filename?562 tempStr=FindValidFilename(item) //returns filename if good, null if error563 if(strlen(tempstr)!=0)564 //valid name, add to list565 //Print "it's a file"566 newList += tempStr + ","567 else568 //not a valid name569 //is it a number?570 runNum=str2num(item)571 //print runnum572 if(numtype(runNum) != 0)573 //not a number - maybe an error574 DoAlert 0,"List item "+item+" is not a valid run number or filename. Please enter a valid number or filename."575 return("")576 else577 //a run number or an error578 tempStr = GetFileNameFromPathNoSemi( FindFileFromRunNumber(runNum) )579 if(strlen(tempstr)==0)580 //file not found, error581 DoAlert 0,"List item "+item+" is not a valid run number. Please enter a valid number."582 return("")583 else584 newList += tempStr + ","585 endif586 endif587 endif588 endfor //loop over all items in list589 590 return(newList)591 End592 593 //takes a comma delimited list that MAY contain number range, and594 //expands any range of run numbers into a comma-delimited list...595 //and returns the new list - if not a range, return unchanged596 Function/S ExpandNumRanges(list)597 String list598 599 String newList="",dash="-",item,str600 Variable num,ii,hasDash601 602 num=itemsinlist(list,",")603 // print num604 for(ii=0;ii<num;ii+=1)605 //get the item606 item = StringFromList(ii,list,",")607 //does it contain a dash?608 hasDash = strsearch(item,dash,0) //-1 if no dash found609 if(hasDash == -1)610 //not a range, keep it in the list611 newList += item + ","612 else613 //has a dash (so it's a range), expand (or add null)614 newList += ListFromDash(item)615 endif616 endfor617 618 return newList619 End620 621 //be sure to add a trailing comma to the return string...622 Function/S ListFromDash(item)623 String item624 625 String numList="",loStr="",hiStr=""626 Variable lo,hi,ii627 628 loStr=StringFromList(0,item,"-") //treat the range as a list629 hiStr=StringFromList(1,item,"-")630 lo=str2num(loStr)631 hi=str2num(hiStr)632 if( (numtype(lo) != 0) || (numtype(hi) !=0 ) || (lo > hi) )633 numList=""634 return numList635 endif636 for(ii=lo;ii<=hi;ii+=1)637 numList += num2str(ii) + ","638 endfor639 640 Return numList641 End642 643 644 //****************645 //utilities for handling binary data - prompting for files or paths,646 //moving data from one folder to another (within IGOR)647 //and converting data to log or linear scale648 649 650 //prompts user to choose the local folder that contains the SANS Data651 //only one folder can be used, and its path is catPathName (and is a NAME, not a string)652 //this will overwrite the path selection653 //returns 1 if no path selected as error condition, or if user cancelled654 Function PickPath()655 656 //set the global string to the selected pathname657 NewPath/O/M="pick the SANS data folder" catPathName658 if(V_Flag != 0)659 return(1) //user cancelled660 endif661 662 PathInfo/S catPathName663 String dum = S_path664 String alertStr = ""665 alertStr = "You must set the path to Charlotte through a Mapped Network Drive, not through the Network Neighborhood"666 //alertStr += " Please see the manual for details."667 if (V_flag == 0)668 //path does not exist - no folder selected669 String/G root:myGlobals:gCatPathStr = "no folder selected"670 return(1)671 else672 //set the global to the path (as a string)673 // need 4 \ since it is the escape character674 if(cmpstr("\\\\",dum[0,1])==0) //Windoze user going through network neighborhood675 DoAlert 0,alertStr676 KillPath catPathName677 return(1)678 endif679 String/G root:myGlobals:gCatPathStr = dum680 // these are now set in theire respective procedures, since the folders don't exist yet!681 // String/G root:myGlobals:Patch:gCatPathStr = dum //and the global used by Patch and Trans682 // String/G root:myGlobals:TransHeaderInfo:gCatPathStr = dum //and the global used by Patch and Trans683 return(0) //no error684 endif685 End686 687 //a utility function that prompts the user for a file (of any type)688 //and returns the full path:name;vers string required to open the file689 //the file is NOT opened by this routine (/D flag)690 //a null string is returned if no file is selected691 //"msgStr" is the message displayed in the dialog, informing the user what692 //file is desired693 //694 Function/S PromptForPath(msgStr)695 String msgStr696 String fullPath697 Variable refnum698 699 //this just asks for the filename, doesn't open the file700 Open/D/R/T="????"/M=(msgStr) refNum701 fullPath = S_FileName //fname is the full path702 // Print refnum,fullPath703 704 //null string is returned in S_FileName if user cancelled, and is passed back to calling function705 Return(fullPath)706 End707 708 709 //returns a string containg the transmision stored in the file that is710 //currently in the "type" folder (not from the binary header)711 //returns "none" if the value (in RealsRead) cannot be found712 //713 Function/S GetTrans(type)714 String type715 716 String name="root:"+type+":realsread"717 WAVE reals = $name718 if(waveExists(reals))719 return(num2str(reals[4]))720 else721 return("none")722 endif723 End724 725 //returns a string containg the sample thickness stored in the file that is726 //currently in the "type" folder (not from the binary header)727 //returns "none" if the value (in RealsRead) cannot be found728 //729 Function/S GetThick(type)730 String type731 732 String name="root:"+type+":realsread"733 WAVE reals = $name734 if(waveExists(reals))735 return(num2str(reals[5]))736 else737 return("none")738 endif739 End740 741 //procedure is not called from anywhere, for debugging purposes only742 //not for gerneral users, since it Kills data folders, requiring743 //re-initialization of the experiment744 //745 Proc ClearWorkFolders()746 747 //not foolproof - will generage an error if any wavs, etc.. are in use.748 KillDataFolder root:RAW749 KillDataFolder root:SAM750 KillDataFolder root:EMP751 KillDataFolder root:BGD752 KillDataFolder root:COR753 KillDataFolder root:DIV754 KillDataFolder root:MSK755 KillDataFolder root:ABS756 KillDataFolder root:CAL757 SetDataFolder root:758 759 End760 761 //not used - but potentially very useful for ensuring that old762 // data in work folders is not accidentally being used763 //764 Function ClearWorkFolder(type)765 String type766 767 SetDataFolder $("root:"+type)768 KillWaves/A/Z769 KillStrings/A/Z770 KillVariables/A/Z771 772 SetDataFolder root:773 End774 775 776 //procedure is not called from anywhere, for debugging purposes only777 //not for gerneral users, but could be useful in reducon clutter778 //779 Proc ClearRootFolder()780 781 DoAlert 1,"Are you sure you want to delete everything from the root level?"782 SetDataFolder root:783 KillWaves/A/Z784 KillStrings/A/Z785 KillVariables/A/Z786 787 End788 789 ///*****************790 //unused testing procedure for writing a 4 byte floating point value in VAX format791 Proc TestReWriteReal()792 String Path793 Variable value,start794 795 GetFileAndPath()796 Path = S_Path + S_filename797 798 value = 0.2222799 start = 158 //trans starts at byte 159800 ReWriteReal(path,value,start)801 802 SetDataFolder root:803 End804 805 //function will re-write a real value (4bytes) to the header of a RAW data file806 //to ensure re-readability, the real value must be written mimicking VAX binary format807 //which is done in this function808 //path is the full path:file;vers to the file809 //value is the real value to write810 //start is the position to move the file marker to, to begin writing811 //--so start is actually the "end byte" of the previous value812 //813 //this procedure takes care of all file open/close pairs needed814 //815 Function ReWriteReal(path,value,start)816 String path817 Variable value,start818 819 //Print " in F(), path = " + path820 Variable refnum,int1,int2, value4821 822 //////823 value4 = 4*value824 825 Open/A/T="????TEXT" refnum as path826 //write IEEE FP, 4*desired value827 FSetPos refnum,start828 FBinWrite/B=3/F=4 refnum,value4 //write out as little endian829 830 //move to the end of the file831 FStatus refnum832 FSetPos refnum,V_logEOF833 //Print "Wrote end of header to " + num2str(V_filePOS)834 835 Close refnum836 837 ///////838 Open/R refnum as path839 //read back as two 16-bit integers840 FSetPos refnum,start841 FBinRead/B=2/F=2 refnum,int1 //read as big-endian842 FBinRead/B=2/F=2 refnum,int2843 844 //file was opened read-only845 //no need to move to the end of the file, just close it846 847 Close refnum848 ///////849 Open/A/T="????TEXT" refnum as path850 //write the two 16-bit integers, reversed851 FSetPos refnum,start852 FBinWrite/B=2/F=2 refnum,int2 //re-write as big endian853 FBinWrite/B=2/F=2 refnum,int1854 855 //move to the end of the file856 FStatus refnum857 FSetPos refnum,V_logEOF858 //Print "Wrote end of header to " + num2str(V_filePOS)859 860 Close refnum //at this point, it is as the VAX would have written it.861 862 Return(0)863 End864 865 //Utility function that returns the detector resolution (in cm) given information866 //from the file header867 //Global values are set in the Initialize procedure868 Function DetectorPixelResolution(fileStr,detStr)869 String fileStr,detStr870 871 Variable DDet872 String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total)873 874 NVAR PixelResNG3_ILL = root:myGlobals:PixelResNG3_ILL //pixel resolution in cm875 NVAR PixelResNG5_ILL = root:myGlobals:PixelResNG5_ILL876 NVAR PixelResNG7_ILL = root:myGlobals:PixelResNG7_ILL877 NVAR PixelResNG3_ORNL = root:myGlobals:PixelResNG3_ORNL878 NVAR PixelResNG5_ORNL = root:myGlobals:PixelResNG5_ORNL879 NVAR PixelResNG7_ORNL = root:myGlobals:PixelResNG7_ORNL880 NVAR PixelResDefault = root:myGlobals:PixelResDefault881 882 strswitch(instr)883 case "NG3":884 if(cmpstr(detStr, "ILL ") == 0 )885 DDet= PixelResNG3_ILL886 else887 DDet = PixelResNG3_ORNL //detector is ordella-type888 endif889 break890 case "NG5":891 if(cmpstr(detStr, "ILL ") == 0 )892 DDet= PixelResNG5_ILL893 else894 DDet = PixelResNG5_ORNL //detector is ordella-type895 endif896 break897 case "NG7":898 if(cmpstr(detStr, "ILL ") == 0 )899 DDet= PixelResNG7_ILL900 else901 DDet = PixelResNG7_ORNL //detector is ordella-type902 endif903 break904 default:905 //return error?906 DDet = PixelResDefault //5mm, typical for new ORNL detectors907 endswitch908 909 return(DDet)910 End911 912 //Utility function that returns the detector deadtime (in seconds) given information913 //from the file header914 //Global values are set in the Initialize procedure915 Function DetectorDeadtime(fileStr,detStr)916 String fileStr,detStr917 918 Variable deadtime919 String instr=fileStr[1,3] //filestr is "[NGnSANSn] " or "[NGnSANSnn]" (11 characters total)920 921 NVAR DeadtimeNG3_ILL = root:myGlobals:DeadtimeNG3_ILL //pixel resolution in cm922 NVAR DeadtimeNG5_ILL = root:myGlobals:DeadtimeNG5_ILL923 NVAR DeadtimeNG7_ILL = root:myGlobals:DeadtimeNG7_ILL924 NVAR DeadtimeNG3_ORNL = root:myGlobals:DeadtimeNG3_ORNL925 NVAR DeadtimeNG5_ORNL = root:myGlobals:DeadtimeNG5_ORNL926 NVAR DeadtimeNG7_ORNL = root:myGlobals:DeadtimeNG7_ORNL927 NVAR DeadtimeDefault = root:myGlobals:DeadtimeDefault928 929 strswitch(instr)930 case "NG3":931 if(cmpstr(detStr, "ILL ") == 0 )932 deadtime= DeadtimeNG3_ILL933 else934 deadtime = DeadtimeNG3_ORNL //detector is ordella-type935 endif936 break937 case "NG5":938 if(cmpstr(detStr, "ILL ") == 0 )939 deadtime= DeadtimeNG5_ILL940 else941 deadtime = DeadtimeNG5_ORNL //detector is ordella-type942 endif943 break944 case "NG7":945 if(cmpstr(detStr, "ILL ") == 0 )946 deadtime= DeadtimeNG7_ILL947 else948 deadtime = DeadtimeNG7_ORNL //detector is ordella-type949 endif950 break951 default:952 //return error?953 deadtime = DeadtimeDefault //1e-6 seconds, typical for new ORNL detectors954 endswitch955 956 return(deadtime)957 End958 959 //////////////////////960 // "intelligent" differentiation of the data files based on information gathered while961 // getting the FIle Catalog. Uses some waves that are generated there, but not displayed in the table962 //963 // See CatVSTable.ipf for where these files are created (and sorted to keep them together)964 ////////////965 966 //testing - unused967 //968 Function/S TextWave2SemiList(textW)969 Wave/T textW970 971 String list=""972 Variable num=numpnts(textW),ii=0973 do974 list += textw[ii] + ";"975 ii+=1976 while(ii<num)977 return(list)978 End979 980 Function/S NumWave2CommaList(numW)981 Wave numW982 983 String list=""984 Variable num=numpnts(numW),ii=0985 do986 list += num2Str(numW[ii]) + ","987 ii+=1988 while(ii<num)989 return(list)990 End991 992 // utility function to convert a list (string) of semicolon-delimited993 //items to a text wave994 Function List2TextWave(str,tw)995 String str996 wave/T tw997 998 Variable num=ItemsinList(str,";"),ii=0999 Redimension/N=(num) tw1000 do1001 tw[ii] = StringFromList(ii, str ,";")1002 ii+=11003 while(ii<num)1004 return(0)1005 1006 End1007 1008 // generates a list of the procedure files in the experiment1009 // putting the results in a wave named "tw", editing and sorting the wave1010 //1011 Proc ListIncludedFiles()1012 Make/O/T/N=2 tw1013 String str=""1014 //str = WinList("*", ";","INCLUDE:6")1015 str = WinList("*", ";","WIN:128")1016 List2TextWave(str,tw)1017 Edit tw1018 Sort tw tw1019 End1020 1021 // returns a comma delimited list of run numbers based on the run numbers collected1022 // during the building of the File Catalog (why do it twice)1023 Function/S RunNumberList()1024 1025 Wave w= $"root:myGlobals:CatVSHeaderInfo:RunNumber"1026 String list=""1027 if(WaveExists(w) == 0)1028 list = ""1029 else1030 list=NumWave2CommaList(w)1031 endif1032 return(list)1033 End1034 1035 // list is a comma delimited list of run numbers, from the File Catalog1036 // - scan through the list and remove numbers that are not transmission files1037 //1038 Function/S isTransList(list)1039 String list1040 1041 //scan through the list, find the corresponding point number, and see what isTrans says1042 Variable ii,num,temp1043 String newList=""1044 num=ItemsInList(list ,",")1045 for(ii=0;ii<num;ii+=1)1046 temp = str2num( StringFromList(ii, list ,",") )1047 if(RunNumIsTransFile(temp))1048 newList += num2str(temp) + ","1049 endif1050 endfor1051 1052 return(newList)1053 End1054 1055 //truth if run number is a transmission file1056 // based on whatever is currently in the File Catalog1057 //1058 // Can't use findlevel - it assumes a monotonic RunNumber wave1059 Function RunNumIsTransFile(num)1060 Variable num1061 1062 Wave isTrans = $"root:myGlobals:CatVSHeaderInfo:IsTrans"1063 Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber"1064 1065 if( (WaveExists(isTrans) == 0 ) || (WaveExists(RunNumber) == 0 ) )1066 return(0)1067 endif1068 1069 Variable pts=numpnts(RunNumber),ii1070 for(ii=0;ii<pts;ii+=1)1071 if(RunNumber[ii] == num)1072 return(isTrans[ii])1073 endif1074 endfor1075 // FindLevel/P/Q RunNumber,num1076 //1077 // if(isTrans[V_LevelX]==1)1078 // return(1)1079 // else1080 // return(0)1081 // endif1082 End1083 1084 //truth if run number is at the given sample to detector distance1085 // based on whatever is currently in the File Catalog1086 //1087 // need fuzzy comparison, since SDD = 1.33 may actually be represented in FP as 1.33000004 !!!1088 Function RunNumIsAtSDD(num,sdd)1089 Variable num,sdd1090 1091 Wave w = $"root:myGlobals:CatVSHeaderInfo:SDD"1092 Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber"1093 1094 if( (WaveExists(w) == 0 ) || (WaveExists(RunNumber) == 0 ) )1095 return(0)1096 endif1097 Variable pts=numpnts(RunNumber),ii1098 for(ii=0;ii<pts;ii+=1)1099 if(RunNumber[ii] == num)1100 if(abs(w[ii] - sdd) < 0.001 ) //if numerically within 0.001 meter, they're the same1101 return(1)1102 else1103 return(0)1104 endif1105 endif1106 endfor1107 End1108 1109 1110 // list is a comma delimited list of run numbers, from the File Catalog1111 // - scan through the list and remove numbers that are not at the specified SDD1112 //1113 Function/S atSDDList(list,sdd)1114 String list1115 Variable sdd1116 1117 //scan through the list, find the corresponding point number, and see what SDD the run is at1118 Variable ii,num,temp1119 String newList=""1120 num=ItemsInList(list ,",")1121 for(ii=0;ii<num;ii+=1)1122 temp = str2num( StringFromList(ii, list ,",") )1123 if(RunNumIsAtSDD(temp,sdd))1124 newList += num2str(temp) + ","1125 endif1126 endfor1127 1128 return(newList)1129 End1130 1131 //given a comma-delimited list, remove those that are trans files1132 //1133 Function/S removeTrans(list)1134 String list1135 1136 //scan through the list, and remove those that are trans files1137 Variable ii,num,temp1138 // String newList=""1139 num=ItemsInList(list ,",")1140 for(ii=0;ii<num;ii+=1)1141 temp = str2num( StringFromList(ii, list ,",") )1142 if(RunNumIsTransFile(temp))1143 list = RemoveFromList(num2str(temp),list,",")1144 ii -= 1 //item ii was just deleted (everything moves to fill in)1145 num -= 1 // and the list is shorter now1146 endif1147 endfor1148 1149 return(list)1150 End1151 1152 Function setMREDFileList(str)1153 String str1154 1155 SVAR/Z list = root:myGlobals:MRED:gFileNumList1156 if(SVAR_Exists(list)==0) //check for myself1157 DoAlert 0,"The Multiple Reduce Panel must be open for you to use this function"1158 Return(1)1159 endif1160 1161 list = str1162 1163 //force an update If the SVAR exists, then the panel does too - MRED cleans up after itself when done1164 DoWindow/F Multiple_Reduce_Panel //bring to front1165 MRedPopMenuProc("MRFilesPopup",0,"") //parse the list, pop the menu1166 1167 return(0)1168 End1169 1170 Proc FillEMPUsingSelection()1171 FillEMPFilenameWSelection()1172 End1173 1174 Proc GuessEveryTransFiles(num)1175 Variable num=61176 GuessAllTransFiles(num)1177 End1178 1179 Proc GuessSelectedTransFiles(num)1180 Variable num=61181 fGuessSelectedTransFiles(num)1182 End1183 1184 Proc ClearSelectedTransAssignments()1185 ClearSelectedAssignments()1186 End1187 1188 Proc CreateRunNumList()1189 String/G rStr=""1190 rStr=RunNumberList()1191 Print "The list is stored in root:rStr"1192 print rStr1193 End1194 1195 Proc TransList()1196 String/G rStr=""1197 rStr=RunNumberList()1198 rStr=isTransList(rStr)1199 print rStr1200 End1201 1202 Proc ScatteringAtSDDList(sdd)1203 Variable sdd=131204 1205 String/G rStr=""1206 rStr=RunNumberList()1207 rStr=removeTrans(rStr)1208 rStr=atSDDList(rStr,sdd)1209 1210 //for Igor 4, the search is case-sensitive, so use all permutations1211 // in Igor 5, use the proper flag in strsearch() inside FindStringInLabel()1212 rStr = RemoveEmptyBlocked(rStr,"EMPTY")1213 rStr = RemoveEmptyBlocked(rStr,"Empty")1214 rStr = RemoveEmptyBlocked(rStr,"empty")1215 rStr = RemoveEmptyBlocked(rStr,"MT Cell")1216 rStr = RemoveEmptyBlocked(rStr,"MT CELL")1217 rStr = RemoveEmptyBlocked(rStr,"mt cell")1218 rStr = RemoveEmptyBlocked(rStr,"BLOCKED")1219 rStr = RemoveEmptyBlocked(rStr,"Blocked")1220 rStr = RemoveEmptyBlocked(rStr,"blocked")1221 1222 print rStr1223 End1224 1225 Proc FillMREDList()1226 setMREDFileList(rStr)1227 DoUpdate1228 End1229 1230 //num passed in is the run number, as in the list1231 // ii is the index of all of the files from the catalog1232 //return will be -1 if string not found, >=0 if found1233 //1234 Function FindStringInLabel(num,findThisStr)1235 Variable num1236 String findThisStr1237 1238 Wave/T w = $"root:myGlobals:CatVSHeaderInfo:Labels"1239 Wave RunNumber = $"root:myGlobals:CatVSHeaderInfo:RunNumber"1240 1241 if( (WaveExists(w) == 0 ) || (WaveExists(RunNumber) == 0 ) )1242 return(0)1243 endif1244 1245 Variable pts=numpnts(RunNumber),ii,loc1246 for(ii=0;ii<pts;ii+=1)1247 if(RunNumber[ii] == num)1248 loc = strsearch(w[ii], findThisStr, 0) //Igor 4 version is case-sensitive1249 // loc = strsearch(w[ii], findThisStr, 0 ,2) //2==case insensitive, but Igor 5 specific1250 if(loc != -1)1251 Print "Remove w[ii] = ",num," ",w[ii]1252 endif1253 endif1254 endfor1255 1256 return(loc) //return will be -1 if string not found, >=0 if found1257 end1258 1259 //rStr is the global string, already atSDD (so there should be only one instance of1260 // empty and one instance of blocked1261 //1262 //scan through the list, and remove those that are have "empty" or "blocked" in the label1263 // or anything that is listed in StrToFind1264 //1265 Function/S RemoveEmptyBlocked(list,StrToFind)1266 String list,StrToFind1267 1268 Variable ii,num,temp1269 num=ItemsInList(list ,",")1270 for(ii=0;ii<num;ii+=1)1271 temp = str2num( StringFromList(ii, list ,",") )1272 if(FindStringInLabel(temp,StrToFind) != -1)1273 list = RemoveFromList(num2str(temp),list,",")1274 ii -= 1 //item ii was just deleted (everything moves to fill in)1275 num -= 1 // and the list is shorter now1276 endif1277 endfor1278 //print list1279 return(list)1280 end1281 1282 // input is a single run number to remove from the list1283 // - typically EC and BN - before sending to MRED1284 Proc RemoveRunFromList(remList)1285 String remList=""1286 1287 rStr = RemoveFromList(remList, rStr ,",")1288 end
Note: See TracChangeset
for help on using the changeset viewer.