#pragma rtGlobals=1 // Use modern global access method. #pragma version=5.0 #pragma IgorVersion=6.1 // this file contains globals and functions that are specific to a // particular facility or data file format // branched out 29MAR07 - SRK // // functions are either labeled with the procedure file that calls them, // or noted that they are local to this file // initializes globals that are specific to a particular facility // - number of XY pixels // - pixexl resolution [cm] // - detector deadtime constant [s] // // called by Initialize.ipf // Function InitFacilityGlobals() //Detector -specific globals Variable/G root:myGlobals:gNPixelsX=192 // number of detector X and Y pixels Variable/G root:myGlobals:gNPixelsY=192 // pixel dimensions are now read directly from the file header. Variable/G root:myGlobals:PixelResDefault = 0.51 //pixel resolution in cm //No dead time measured for HFIR detector but the count rate is set very low. For now, set the detector perfect. // This should be updated when the condition is changed. JHC 09/02/09 Variable/G root:myGlobals:DeadtimeDefault = 0 //3.4e-6 (NIST value) //deadtime in seconds Variable/G root:myGlobals:apOff = 5.0 // (cm) distance from sample aperture to sample positio End //********************** // Resolution calculation - used by the averaging routines // to calculate the resolution function at each q-value // - the return value is not used // // equivalent to John's routine on the VAX Q_SIGMA_AVE.FOR // Incorporates eqn. 3-15 from J. Appl. Cryst. (1995) v. 28 p105-114 // // - 21 MAR 07 uses projected BS diameter on the detector // - APR 07 still need to add resolution with lenses. currently there is no flag in the // raw data header to indicate the presence of lenses. // // - Aug 07 - added input to switch calculation based on lenses (==1 if in) // // - called by CircSectAvg.ipf and RectAnnulAvg.ipf // // passed values are read from RealsRead // except DDet and apOff, which are set from globals before passing // // Function/S getResolution(inQ,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,SigmaQ,QBar,fSubS) Variable inQ, lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses Variable &fSubS, &QBar, &SigmaQ //these are the output quantities at the input Q value //lots of calculation variables Variable a2, q_small, lp, v_lambda, v_b, v_d, vz, yg, v_g Variable r0, delta, inc_gamma, fr, fv, rmd, v_r1, rm, v_r //Constants Variable vz_1 = 3.956e5 //velocity [cm/s] of 1 A neutron Variable g = 981.0 //gravity acceleration [cm/s^2] String results results ="Failure" S1 *= 0.5*0.1 //convert to radius and [cm] S2 *= 0.5*0.1 L1 *= 100.0 // [cm] L1 -= apOff //correct the distance L2 *= 100.0 L2 += apOff del_r *= 0.1 //width of annulus, convert mm to [cm] BS *= 0.5*0.1 //nominal BS diameter passed in, convert to radius and [cm] // 21 MAR 07 SRK - use the projected BS diameter, based on a point sample aperture Variable LB LB = 20.1 + 1.61*BS //distance in cm from beamstop to anode plane (empirical) BS = bs + bs*lb/(l2-lb) //adjusted diameter of shadow from parallax //Start resolution calculation a2 = S1*L2/L1 + S2*(L1+L2)/L1 q_small = 2.0*Pi*(BS-a2)*(1.0-lambdaWidth)/(lambda*L2) lp = 1.0/( 1.0/L1 + 1.0/L2) v_lambda = lambdaWidth^2/6.0 // if(usingLenses==1) //SRK 2007 if(usingLenses != 0) //SRK 2008 allows for the possibility of different numbers of lenses in header v_b = 0.25*(S1*L2/L1)^2 +0.25*(2/3)*(lambdaWidth/lambda)^2*(S2*L2/lp)^2 //correction to 2nd term else v_b = 0.25*(S1*L2/L1)^2 +0.25*(S2*L2/lp)^2 //original form endif v_d = (DDet/2.3548)^2 + del_r^2/12.0 vz = vz_1 / lambda yg = 0.5*g*L2*(L1+L2)/vz^2 v_g = 2.0*(2.0*yg^2*v_lambda) //factor of 2 correction, B. Hammouda, 2007 r0 = L2*tan(2.0*asin(lambda*inQ/(4.0*Pi) )) delta = 0.5*(BS - r0)^2/v_d if (r0 < BS) inc_gamma=exp(gammln(1.5))*(1-gammp(1.5,delta)) else inc_gamma=exp(gammln(1.5))*(1+gammp(1.5,delta)) endif fSubS = 0.5*(1.0+erf( (r0-BS)/sqrt(2.0*v_d) ) ) if (fSubS <= 0.0) fSubS = 1.e-10 endif fr = 1.0 + sqrt(v_d)*exp(-1.0*delta) /(r0*fSubS*sqrt(2.0*Pi)) fv = inc_gamma/(fSubS*sqrt(Pi)) - r0^2*(fr-1.0)^2/v_d rmd = fr*r0 v_r1 = v_b + fv*v_d +v_g rm = rmd + 0.5*v_r1/rmd v_r = v_r1 - 0.5*(v_r1/rmd)^2 if (v_r < 0.0) v_r = 0.0 endif QBar = (4.0*Pi/lambda)*sin(0.5*atan(rm/L2)) SigmaQ = QBar*sqrt(v_r/rmd^2 +v_lambda) results = "success" Return results End //Utility function that returns the detector resolution (in cm) //Global values are set in the Initialize procedure // // - called by CircSectAvg.ipf, RectAnnulAvg.ipf, and ProtocolAsPanel.ipf // // fileStr is passed as TextRead[3] and is the filename // detStr is passed as TextRead[9] and is an identifier for the detector // // depricated - pixel dimensions are read directly from the file header Function xDetectorPixelResolution(fileStr,detStr) String fileStr,detStr Variable DDet NVAR PixelResDefault = root:myGlobals:PixelResDefault //your code here DDet = PixelResDefault //0.515 cm, typical for new ORNL detectors return(DDet) End //Utility function that returns the detector deadtime (in seconds) //Global values are set in the Initialize procedure // // - called by WorkFileUtils.ipf // // fileStr is passed as TextRead[3] and is the filename // detStr is passed as TextRead[9] and is an identifier for the detector // Function DetectorDeadtime(fileStr,detStr) String fileStr,detStr Variable deadtime NVAR DeadtimeDefault = root:myGlobals:DeadtimeDefault deadtime = DeadtimeDefault //3.4e-6 seconds, typical for new ORNL detectors //??????????????????????????? return(deadtime) End // item is a filename // // this function extracts some sort of number from the file // presumably some sort of automatically incrementing run number set by the // acquisition system // // this run number should be a unique identifier for the file //Because HFIR data format is w/ 2X 4digit number. We add them to get a unique number => This will cause the arrow button not working. Function GetRunNumFromFile(item) String item Variable invalid = -1 //negative numbers are invalid Variable num=-1 //find the "dot" String runStr="" Variable pos = strsearch(item,".",0) if(pos == -1) //"dot" not found return (invalid) else //found, get the nine characters preceeding it if (pos <=8) //not enough characters return (invalid) else Variable pos_bio = strsearch( LowerStr(item),"biosans",0) //if (pos_bio== -1) runStr = item[pos-9,pos-6] //first 4 numbers //else runStr += item[pos-4,pos-1] //add last 4 numbers //endif //convert to a number num = str2num(runStr) //if valid, return it if (num == NaN) //8 characters were not a number return (invalid) else //run was OK return (num) Endif Endif Endif End // item is a filename // // this function extracts some sort of number from the file // presumably some sort of automatically incrementing run number set by the // acquisition system // // this run number should be a unique identifier for the file // // same as GetRunNumFromFile(0), just with a string return // // "ABC" returned as an invalid result // XXXXSANS_expXX._scan1234_5678.xmp ==> "12345678" // -- result is an 8-character string // Function/S GetRunNumStrFromFile(item) //,numposition) String item Variable numposition String invalid = "ABC" //"ABC" is not a valid run number, since it's text String retStr retStr=invalid //find the "dot" Variable pos = strsearch( LowerStr(item),".xml",0) if(pos == -1) //"dotxml" not found return (retStr) else pos = strsearch( LowerStr(item),"_scan",0) if (pos == -1) //not a raw data file return (retStr) else //Variable pos_bio = strsearch( LowerStr(item),"biosans_",0) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //if (numposition == 0) //Take the first four: //HiResSANS retStr = item[pos+5,pos+8] //else //add the last four: //BioSANS retStr += item[pos+10,pos+13] //Endif return (retStr) Endif Endif End //returns a string containing the full path to the file containing the //run number "num". The null string is returned if no valid file can be found. // // // search in the path "catPathName" (hard-wired), will abort if this path does not exist //the file returned will be a RAW SANS data file, other types of files are //filtered out. // // called by Buttons.ipf and Transmission.ipf, and locally by parsing routines // Function/S FindFileFromRunNumber(num) Variable num String fullName="",partialName="",item="" //get list of raw data files in folder that match "num" (add leading zeros) if( (num>99999999) || (num<0) ) //Print "error in FindFileFromRunNumber(num), file number too large or too small" Return ("") Endif //make a four character string of the run number String numStr="" if(num > 9999999 && num < 100000000) numStr = num2istr(num) endif if(num > 999999 && num < 10000000) numStr = "0"+num2istr(num) endif if(num > 99999 && num < 1000000) numStr = "00"+num2istr(num) endif if(num > 9999 && num < 100000) numStr = "000"+num2istr(num) endif if(num > 999 && num < 10000) numStr = "0000"+num2istr(num) endif if(num > 99 && num < 1000) numStr = "00000"+num2istr(num) endif if(num > 9 && num < 100) numStr = "000000"+num2istr(num) endif if(num < 10 && num >0) numStr = "0000000"+num2iStr(num) endif if(num == 0) numStr = "00000000" endif //make sure that path exists PathInfo catPathName String path = S_path if (V_flag == 0) Abort "folder path does not exist - use Pick Path button" Endif String list="",newList="",testStr="" list = IndexedFile(catPathName,-1,"????") //get all files in folder //find (the) one with the number in the run # location in the name Variable numItems,ii,runFound,isRAW numItems = ItemsInList(list,";") //get the new number of items in the list ii=0 do //parse through the list in this order: // 1 - does item contain run number (as a string) "NAMESANS_expNN_scan####_####.xml" : Let's check the 8 nums. // 2 - exclude by isRaw? (to minimize disk access) item = StringFromList(ii, list ,";" ) if(strlen(item) != 0) //find the run number, if it exists as a 8 character string testStr = GetRunNumStrFromFile(item) //0) runFound= cmpstr(numStr,testStr) //compare the three character strings, 0 if equal if(runFound == 0) //the run Number was found //build valid filename partialName = FindValidFileName(item) if(strlen(partialName) != 0) //non-null return from FindValidFileName() fullName = path + partialName //check if RAW, if so,this must be the file! isRAW = CheckIfRawData(fullName) if(isRaw) //stop here return(fullname) Endif Endif Endif Endif ii+=1 while(ii 8) return("") else return(numstr) endif End //given a filename of a SANS data filename of the form //TTTTTnnn.SAn_TTT_Txxx //returns the prefix "TTTTT" as some number of characters //returns "" as an invalid file prefix // // HFIR writes out files with a "prefix" of the following -- since there is really no "prefix" // like in the VAX scheme: // newFileName = ReplaceString(".xml",textPath[0],"") //removes 4 chars // newFileName = ReplaceString("SANS",newFileName,"") //removes 4 more chars = 8 // newFileName = ReplaceString("exp",newFileName,"") //removes 3 more chars = 11 // newFileName = ReplaceString("scan",newFileName,"") //removes 4 more chars = 15, should be enough? // // // -- so the raw data: BioSANS_exp9_scan1828_0001.xml // -- translates to: Bio_9_1828_0001.AVE // // // NCNR-specifc, does not really belong here - it's a beta procedure used for the // Combine Files Panel, and I'm not sure of how I'm really going to get this to work properly // since the .ABS file written is not of the form that NSORT->Set3NSORTFiles(low,med,hi,pref) // is trying to construct // // changed (Oct 2010) the naming for HFIR from ExecuteProtocol to: // newFileName = GetPrefixStrFromFile(textPath[0])+GetRunNumStrFromFile(textPath[0]) // -- translates to: BioSANS18280001.AVE // Function/S GetPrefixStrFromFile(item) String item String invalid = "" //"" is not a valid run prefix, since it's text Variable num=-1 //find the "dash" String runStr="" Variable pos = strsearch(item,"_",0) if(pos == -1) //"dot" not found return (invalid) else //found if (pos <=3) //not enough characters return (invalid) else runStr = item[0,pos-1] return (runStr) Endif Endif End //function to test a binary file to see if it is a RAW binary SANS file //first checks the total bytes in the file (which for raw data is 33316 bytes) //**note that the "DIV" file will also show up as a raw file by the run field //should be listed in CAT/SHORT and in patch windows // //Function then checks the file fname (full path:file) for "RAW" run.type field //if not found, the data is not raw data and zero is returned // // called by many procedures (both external and local) // Function CheckIfRawData(fname) String fname String tempheadhfir Variable ind=0 Variable refNum //If not have .xml extension, return 0. if (stringmatch(fname,"*.xml") <1) print fname+": Failed. Not a *.xml file." return 0 //Not *.xml. Do nothing... endif //actually open the file refNum = XmlOpenFile(fname) if (refNum < 0) print "==> "+ fname+ "\r ==> Failed to load: Not a standard xml file format or broken.. Please check the file if properly written..." return 0 //Not a xml file. Do nothing... endif // Check if it is the SPICE version = 1.1 Variable item,i,ns = 0 String thislocation if (refNum >0) ns = str2num(XMLstrFmXpath(refNum, "//SPICErack/@SPICE_version","","")) endif XmlCloseFile(refNum,0) if (ns <1.1) ns =0 else ns =1 endif return ns End // for HFIR data, both DIV and RAW are determined by looking for "*.xml" Function CheckIfDIVData(fname) String fname return(CheckIfRawData(fname)) End // function returns 1 if file is a transmission file, 0 if not // // called by Transmission.ipf, CatVSTable.ipf, NSORT.ipf // // SRK MAR 2010 - apparently from what I can see in the files, the beam stop "out" // position is 25 mm for all four beam stop Y POSITIONS // - if one is larger, (in the hundreds of mm) then it's in, and the run is not a transmission // - so if all four y positions are less than (tol) 30 mm, call it a trans file // // there is a field for this in the header, write "True", so I don't need to guess again. // -- but this field is often incorrect - for some sample data ALL FILES were "True" // -- better to check the physical location every time // // tol changed to 401 per Gernot's experience 6/24/10 // Function isTransFile(fName) /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! String fname Variable beamtrap_1y=0,beamtrap_2y=0,beamtrap_3y=0,beamtrap_4y=0,tol=401 //Check by key "transsmission" // if (stringmatch( getIsTrans(fName),"True")>0) // return (1) // else //Check from beam stop motor position // if(your test here) beamtrap_1y=getRealValueFromHeader(fname,"//Motor_Positions/trap_y_101mm","mm") beamtrap_2y=getRealValueFromHeader(fname,"//Motor_Positions/trap_y_25mm","mm") beamtrap_3y=getRealValueFromHeader(fname,"//Motor_Positions/trap_y_50mm","mm") beamtrap_4y=getRealValueFromHeader(fname,"//Motor_Positions/trap_y_76mm","mm") if (beamtrap_1y < tol && beamtrap_2y < tol && beamtrap_3y < tol && beamtrap_4y < tol) //Write the flag ON Write_isTransmissionToHeader(fName,"True") return (1) else //some other file Write_isTransmissionToHeader(fName,"False") return (0) endif // endif return (0) End //function to remove all spaces from names when searching for filenames //the filename (as saved) will never have interior spaces (TTTTTnnn_AB _Bnnn) //but the text field in the header WILL, if less than 3 characters were used for the //user's initials, and can have leading spaces if prefix was less than 5 characters // //returns a string identical to the original string, except with the interior spaces removed // // local function for file name manipulation // // NO CHANGE NEEDED // Function/S RemoveAllSpaces(str) String str String tempstr = str Variable ii,spc,len //should never be more than 2 or 3 trailing spaces in a filename ii=0 do len = strlen(tempStr) spc = strsearch(tempStr," ",0) //is the last character a space? if (spc == -1) break //no more spaces found, get out endif str = tempstr tempStr = str[0,(spc-1)] + str[(spc+1),(len-1)] //remove the space from the string While(1) //should never be more than 2 or 3 If(strlen(tempStr) < 1) tempStr = "" //be sure to return a null string if problem found Endif //Print strlen(tempstr) Return(tempStr) End //Function attempts to find valid filename from partial name by checking for // the existence of the file on disk // // returns a valid filename (No path prepended) or a null string // // called by any functions, both external and local // Function/S FindValidFilename(partialName) String PartialName String retStr=partialName //your code here //try name with no changes - to allow for ABS files that have spaces in the names 12APR04 retStr = ValidFileString(partialName) if(cmpstr(retStr,"") !=0) return(retStr) endif //if the partial name is derived from the file header, there can be spaces at the beginning //or in the middle of the filename - depending on the prefix and initials used // //remove any leading spaces from the name before starting partialName = RemoveAllSpaces(partialName) //try name with no spaces retStr = ValidFileString(partialName) if(cmpstr(retStr,"") !=0) //non-null return return(retStr) endif //try all UPPERCASE partialName = UpperStr(partialName) retStr = ValidFileString(partialName) if(cmpstr(retStr,"") !=0) //non-null return return(retStr) endif //try all lowercase (ret null if failure) partialName = LowerStr(partialName) retStr = ValidFileString(partialName) if(cmpstr(retStr,"") !=0) //non-null return return(retStr) else return(retStr) endif End // Function checks for the existence of a file // *** the PATH is hard-wired to catPathName (which is assumed to exist) // version numers up to ;10 are tried // only the "name;vers" is returned if successful. The path is not prepended // // local function // Function/S ValidFileString(partialName) String partialName String tempName = "",msg="" Variable ii,refnum ii=0 do if(ii==0) //first pass, try the partialName tempName = partialName Open/Z/R/T="????TEXT"/P=catPathName refnum tempName //Does open file (/Z flag) if(V_flag == 0) //file exists Close refnum //YES needed, break endif else tempName = partialName + ";" + num2str(ii) Open/Z/R/T="????TEXT"/P=catPathName refnum tempName if(V_flag == 0) //file exists Close refnum break endif Endif ii+=1 while(ii<11) //go get the selected bits of information, using tempName, which exists if(ii>=11) //msg = partialName + " not found. is version number > 11?" //DoAlert 0, msg //PathInfo catPathName //Print S_Path Return ("") //use null string as error condition Endif Return (tempName) End //returns a string containing filename (WITHOUT the ;vers) //the input string is a full path to the file (Mac-style, still works on Win in IGOR) //with the folders separated by colons // // called by MaskUtils.ipf, ProtocolAsPanel.ipf, WriteQIS.ipf // // NO CHANGE NEEDED // Function/S GetFileNameFromPathNoSemi(fullPath) String fullPath Variable offset1,offset2 String filename="" //String PartialPath offset1 = 0 do offset2 = StrSearch(fullPath, ":", offset1) if (offset2 == -1) // no more colons ? fileName = FullPath[offset1,strlen(FullPath) ] //PartialPath = FullPath[0, offset1-1] break endif offset1 = offset2+1 while (1) //remove version number from name, if it's there - format should be: filename;N filename = StringFromList(0,filename,";") //returns null if error Return filename End //returns a string containing filename (INCLUDING the ;vers) //the input string is a full path to the file (Mac-style, still works on Win in IGOR) //with the folders separated by colons // // local, currently unused // // NO CHANGE NEEDED // Function/S GetFileNameFromPathKeepSemi(fullPath) String fullPath Variable offset1,offset2 String filename //String PartialPath offset1 = 0 do offset2 = StrSearch(fullPath, ":", offset1) if (offset2 == -1) // no more colons ? fileName = FullPath[offset1,strlen(FullPath) ] //PartialPath = FullPath[0, offset1-1] break endif offset1 = offset2+1 while (1) //keep version number from name, if it's there - format should be: filename;N Return filename End //given the full path and filename (fullPath), strips the data path //(Mac-style, separated by colons) and returns this path //this partial path is the same string that would be returned from PathInfo, for example // // - allows the user to save to a different path than catPathName // // called by WriteQIS.ipf // // NO CHANGE NEEDED // Function/S GetPathStrFromfullName(fullPath) String fullPath Variable offset1,offset2 //String filename String PartialPath offset1 = 0 do offset2 = StrSearch(fullPath, ":", offset1) if (offset2 == -1) // no more colons ? //fileName = FullPath[offset1,strlen(FullPath) ] PartialPath = FullPath[0, offset1-1] break endif offset1 = offset2+1 while (1) Return PartialPath End //given the filename trim or modify the filename to get a new //file string that can be used for naming averaged 1-d files // // called by ProtocolAsPanel.ipf and Tile_2D.ipf // Function/S GetNameFromHeader(fName) String fName String temp, newName = "" Variable spc,ii=0 //filename is 31-33 characters INSTRNAMESANS_exp##_scan####_####.xml (where # : numbers) //returns a null string if no name can be found Variable iimax = strlen(fName) do temp = fname[ii,iimax-1-4] //characters ii,all of the name spc = strsearch(temp," ",0) if (spc == -1) break //no more spaces found endif ii+=1 While(ii hi) ) numList="" return numList endif for(ii=lo;ii<=hi;ii+=1) numList += num2str(ii) + "," endfor Return numList End //returns the proper attenuation factor based on the instrument // // filestr is passed from TextRead[3] = the default directory, used to identify the instrument // lam is passed from RealsRead[26] // AttenNo is passed from ReaslRead[3] // // Attenuation factor as defined here is <= 1 // // Facilities can pass ("",1,attenuationFactor) and have this function simply // spit back the attenuationFactor (that was read into rw[3]) // // called by Correct.ipf, ProtocolAsPanel.ipf, Transmission.ipf // Function AttenuationFactor(fileStr,lam,attenuation) String fileStr Variable lam,attenuation // 0 =< attenuation <= 100 (%) : where no attenuator stands for 0. Variable attenFactor=1 // your code here attenFactor = 1- attenuation*0.01 //???Attenuate transmission return(attenFactor) End //function called by the popups to get a file list of data that can be sorted // this procedure simply removes the raw data files from the string - there //can be lots of other junk present, but this is very fast... // // could also use the alternate procedure of keeping only file with the proper extension // // another possibility is to get a listing of the text files, but is unreliable on // Windows, where the data file must be .txt (and possibly OSX) // // called by FIT_Ops.ipf, NSORT.ipf, PlotUtils.ipf // Function/S ReducedDataFileList(ctrlName) String ctrlName String list="",newList="",item="" Variable num,ii //check for the path PathInfo catPathName if(V_Flag==0) DoAlert 0, "Data path does not exist - pick the data path from the button on the main panel" Return("") Endif list = IndexedFile(catpathName,-1,"????") num=ItemsInList(list,";") for(ii=(num-1);ii>=0;ii-=1) item = StringFromList(ii, list ,";") //simply remove all that are not raw data files (SA1 SA2 SA3) //if( !stringmatch(item,"*HiResSANS*.xml") && !stringmatch(item,"*BioSANS*.xml")) if( !stringmatch(item,".*") && !stringmatch(item,"*.pxp") && !stringmatch(item,"*.DIV")) //eliminate mac "hidden" files, pxp, and div files newlist += (item) + ";" endif //endif endfor //remove VAX version numbers newList = RemoveVersNumsFromList(newList) //sort newList = SortList(newList,";",0) return newlist End // returns a list of raw data files in the catPathName directory on disk // - list is SEMICOLON-delimited // // does it the "cheap" way, simply finding the ".SAn" in the file name // = does not check for proper byte length. // // called by PatchFiles.ipf, Tile_2D.ipf // Function/S GetRawDataFileList() //make sure that path exists PathInfo catPathName if (V_flag == 0) Abort "Folder path does not exist - use Pick Path button on Main Panel" Endif String list=IndexedFile(catPathName,-1,"????") String newList="",item="" Variable num=ItemsInList(list,";"),ii for(ii=0;ii0) newlist += item + ";" endif endif // if condition is in here twice, not sure why since they are both "*.xml" // if( stringmatch(item,"*.xml") ) // if (CheckIfRawData(S_path+item) >0) // newlist += item + ";" // endif // endif endfor newList = SortList(newList,";",0) return(newList) End //********************** // 2D resolution function calculation - in terms of X and Y // // based on notes from David Mildner, 2008 // // the final NCNR version is located in NCNR_Utils.ipf // Function/S get2DResolution(inQ,phi,lambda,lambdaWidth,DDet,apOff,S1,S2,L1,L2,BS,del_r,usingLenses,r_dist,SigmaQX,SigmaQY,fSubS) Variable inQ, phi,lambda, lambdaWidth, DDet, apOff, S1, S2, L1, L2, BS, del_r,usingLenses,r_dist Variable &SigmaQX,&SigmaQY,&fSubS //these are the output quantities at the input Q value return("Function Empty") End // Return the filename that represents the previous or next file. // Input is current filename and increment. // Increment should be -1 or 1 // -1 => previous file // 1 => next file Function/S GetPrevNextRawFile(curfilename, prevnext) String curfilename Variable prevnext String filename //get the run number Variable num = GetRunNumFromFile(curfilename) //find the next specified file by number fileName = FindPrevNextRawFile(curfilename, prevnext) if(cmpstr(fileName,"")==0) //null return, do nothing fileName = FindFileFromRunNumber(num) Endif //print "in FU "+filename Return filename End // Find next or previous file name w/ current file name given. // Sort the list of files and get the next/previous file name. Function/S FindPrevNextRawFile(curfilename, prevnext) String curfilename Variable prevnext String fullName="",partialName="",item="", list="" Variable numItems,isRAW //make sure that path exists PathInfo catPathName String path = S_path if (V_flag == 0) Abort "folder path does not exist - use Pick Path button" Endif list = SortList(IndexedFile(catPathName,-1,"????"),";") //get all files in folder and make sure it is sorted. //find (the) one with the number in the run # location in the name numItems = ItemsInList(list,";") //get the new number of items in the list //index of curfilename Variable index = WhichListItem(curfilename,list,";",0,0) //get the prenextitem in the list item = StringFromList(index+prevnext, list ,";") partialName = FindValidFileName(item) if(strlen(partialName) != 0) //non-null return from FindValidFileName() fullName = path + partialName //check if RAW, if so,this must be the file! isRAW = CheckIfRawData(fullName) if(isRaw) //stop here return(fullname) Endif Endif print "Please type 'scan number(s)' from your file name..." Return ("") //null return if file not found in list End