#pragma rtGlobals=1 // Use modern global access method. #pragma version=5.0 #pragma IgorVersion=6.1 //************************* // Vers. 1.2 092101 // // - procedures for (easier) caluclation of transmissions along with // simultaneous patching of the calculated transmission in designated // raw sans files. // - transmission and empty beam files are linked to the dataset by their "Annn" suffix // only (and their residence in the same data folder) // - unused (analysis) integer values are used to store these run numbers in the sample // file headers so that transmissions can be automatically calculated, once the xy box is set // in the empty beam file. // //*************************** //main entry procedure for displaying the Trans input panel //also initializes the globals as needed // Proc CalcTrans() DoWindow/F Trans_Panel If(V_flag == 0) InitializeTransPanel() //draw panel Trans_Panel() AutoPositionWindow/M=1/R=Main_Panel Trans_Panel Endif End // The BuildFileTables routine will build two tables: one containing the // data from the headers of transmission files in the folder and one // containing the header data from all other SANS data files. They will // each have the first column empty for, in the case of transmission files, // the empty beam file and, in the case of scattering files, the scattering // run file name. Proc BuildFileTables() Variable err PathInfo catPathName if(v_flag==0) err = PickPath()//sets the local path to the data (catPathName) if(err) Abort "no path to data was selected, no catalog can be made - use PickPath button" Endif Endif DoWindow/F TransFileTable Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Suffices" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Filenames" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Suffix" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:T_Labels" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_SDD" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Lambda" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Transmission" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:T_Whole" If(V_Flag==0) BuildTransTableWindow() ModifyTable width(:myGlobals:TransHeaderInfo:T_SDD)=40 ModifyTable width(:myGlobals:TransHeaderInfo:T_Lambda)=40 ModifyTable rgb(:myGlobals:TransHeaderInfo:T_Filenames)=(0,0,65535) ModifyTable width(:myGlobals:TransHeaderInfo:T_Transmission)=60 ModifyTable width(:myGlobals:TransHeaderInfo:T_Whole)=60 ModifyTable width(Point)=0 //ModifyTable width(:myGlobals:TransHeaderInfo:T_Transmission)=40 Endif DoWindow/F ScatterFileTable Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Suffices" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Filenames" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Suffix" Make/O/T/N=0 $"root:myGlobals:TransHeaderInfo:S_Labels" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_SDD" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Lambda" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Transmission" Make/O/D/N=0 $"root:myGlobals:TransHeaderInfo:S_Whole" If(V_Flag==0) BuildScatTableWindow() ModifyTable width(:myGlobals:TransHeaderInfo:S_SDD)=40 ModifyTable width(:myGlobals:TransHeaderInfo:S_Lambda)=40 ModifyTable width(:myGlobals:TransHeaderInfo:S_Transmission)=60 ModifyTable rgb(:myGlobals:TransHeaderInfo:S_Filenames)=(0,0,65535) ModifyTable width(Point)=0 Endif String temp="" //get a list of all files in the folder, some will be junk version numbers that don't exist String list,partialName,tempName list = IndexedFile(catPathName,-1,"????") //get all files in folder Variable numitems,ii,ok //remove version numbers from semicolon-delimited list list = RemoveVersNumsFromList(list) numitems = ItemsInList(list,";") //loop through all of the files in the list, reading CAT/SHORT information if the file is RAW SANS //***version numbers have been removed*** String str,fullName Variable lastPoint ii=0 do //get current item in the list partialName = StringFromList(ii, list, ";") //get a valid file based on this partialName and catPathName tempName = FindValidFilename(partialName) If(cmpstr(tempName,"")==0) //a null string was returned //write to notebook that file was not found //if string is not a number, report the error if(str2num(partialName) == NaN) str = "this file was not found: "+partialName+"\r\r" //Notebook CatWin,font="Times",fsize=12,text=str Endif else //prepend path to tempName for read routine PathInfo catPathName FullName = S_path + tempName //make sure the file is really a RAW data file ok = CheckIfRawData(fullName) if (ok) GetTransHeaderInfoToWave(fullName,tempName) Endif Endif ii+=1 while(ii "A001" rollover // Function SortTransByDate() Wave/T T_GEMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices" Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix" Wave/T T_GLabels = $"root:myGlobals:TransHeaderInfo:T_Labels" Wave T_GSDD = $"root:myGlobals:TransHeaderInfo:T_SDD" Wave T_GLambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" Wave/T S_GTRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices" Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix" Wave/T S_GLabels = $"root:myGlobals:TransHeaderInfo:S_Labels" Wave S_GSDD = $"root:myGlobals:TransHeaderInfo:S_SDD" Wave S_GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" Sort T_GSuffix, T_GEMP_Filenames, T_GSuffix, T_GSuffices, T_GFilenames, T_GLabels, T_GSDD, T_GLambda, T_GTransmission, T_Whole Sort S_GSuffix, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole End // sorts files alphabetically byt the sample label // - consistent and descriptive sample labels really pay off here // Function SortTransByLabel() Wave/T T_GEMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices" Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix" Wave/T T_GLabels = $"root:myGlobals:TransHeaderInfo:T_Labels" Wave T_GSDD = $"root:myGlobals:TransHeaderInfo:T_SDD" Wave T_GLambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" Wave T_Whole= $"root:myGlobals:TransHeaderInfo:T_Whole" Wave/T S_GTRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices" Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix" Wave/T S_GLabels = $"root:myGlobals:TransHeaderInfo:S_Labels" Wave S_GSDD = $"root:myGlobals:TransHeaderInfo:S_SDD" Wave S_GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" Wave S_Whole= $"root:myGlobals:TransHeaderInfo:S_Whole" Sort T_GLabels, T_GEMP_Filenames, T_GSuffix, T_GSuffices, T_GFilenames, T_GLabels, T_GSDD, T_GLambda, T_GTransmission, T_Whole Sort S_GLabels, S_GTRANS_Filenames, S_GSuffix, S_GSuffices, S_GFilenames, S_GLabels, S_GSDD, S_GLambda, S_GTransmission, S_Whole End //reads the file and assigns header information to the proper table // //fname - is the full path:name of the datafile (used by Open) //sname - is the name only, used as the filename field // // takes care of all necessary open/close of file // Function GetTransHeaderInfoToWave(fname,sname) String fname,sname Variable isTrans Variable lastPoint isTrans = isTransFile(fname) // decalre the correct set of waves // S_Whole is only a place holder so the waves are of equal length if (isTrans) Wave/T GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices" Wave/T G_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" Wave/T GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" Wave/T GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix" Wave/T GLabels = $"root:myGlobals:TransHeaderInfo:T_Labels" Wave GSDD = $"root:myGlobals:TransHeaderInfo:T_SDD" Wave GLambda = $"root:myGlobals:TransHeaderInfo:T_Lambda" Wave GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" Wave GWhole = $"root:myGlobals:TransHeaderInfo:T_Whole" Else Wave/T GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices" Wave/T G_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" Wave/T GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" Wave/T GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix" Wave/T GLabels = $"root:myGlobals:TransHeaderInfo:S_Labels" Wave GSDD = $"root:myGlobals:TransHeaderInfo:S_SDD" Wave GLambda = $"root:myGlobals:TransHeaderInfo:S_Lambda" Wave GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" Wave GWhole = $"root:myGlobals:TransHeaderInfo:S_Whole" Endif lastPoint = numpnts(GLambda) InsertPoints lastPoint,1,G_TRANS_Filenames G_TRANS_Filenames[lastPoint]="" InsertPoints lastPoint,1,GFilenames GFilenames[lastPoint]=sname //read the file suffix InsertPoints lastPoint,1,GSuffix GSuffix[lastPoint]=getSuffix(fname) //read any suffix that this file is associated with InsertPoints lastPoint,1,GSuffices GSuffices[lastPoint]=getAssociatedFileSuffix(fname) // read the sample.label text field InsertPoints lastPoint,1,GLabels GLabels[lastPoint]=getSampleLabel(fname) //Transmission InsertPoints lastPoint,1,GTransmission GTransmission[lastPoint]=getSampleTrans(fname) //Whole detector Transmission InsertPoints lastPoint,1,GWhole GWhole[lastPoint]=getSampleTransWholeDetector(fname) //SDD InsertPoints lastPoint,1,GSDD GSDD[lastPoint]=getSDD(fname) //wavelength InsertPoints lastPoint,1,GLambda GLambda[lastPoint]=getWavelength(fname) return(0) End //fills in the file relations that have already been set // // Function GetFilenamesFromSuffices() Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" Wave/T T_GSuffices = $"root:myGlobals:TransHeaderInfo:T_Suffices" Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix" Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices" Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix" Variable num_s_files, num_t_files, ii, jj num_t_files = numpnts(T_GFilenames) num_s_files = numpnts(S_GFilenames) //print num_t_files, num_s_files // Get transmission file relations ii= 0 do if (cmpstr(T_GSuffices[ii],"")!=0) jj=0 do if (cmpstr(T_GSuffices[ii],T_GSuffix[jj])==0) T_EMP_Filenames[ii]=T_GFilenames[jj] endif jj+=1 while(jj sample scattering //also writes a trans=1 value back to the sample file // // DEC 2006 - now also writes blank suffix to clear trans->empty assignment, and Twhole=1 // // target = 1 = ScatterFileTable // target = 2 = TransFileTable Function fClearSelectedAssignments(startRow,endRow,target) Variable startRow,endRow,target Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" Wave/T S_GSuffices = $"root:myGlobals:TransHeaderInfo:S_Suffices" Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" Wave/T S_GSuffix = $"root:myGlobals:TransHeaderInfo:S_Suffix" Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" Wave/T T_GSuffix = $"root:myGlobals:TransHeaderInfo:T_Suffix" Wave T_GTransmission = $"root:myGlobals:TransHeaderInfo:T_Transmission" Wave T_GTWhole = $"root:myGlobals:TransHeaderInfo:T_Whole" Variable num_s_files, num_t_files, ii, jj Variable refnum,zero=0 num_t_files = numpnts(T_GFilenames) String suffix = " " //4 blank spaces PathInfo catPathName String pathname = S_path String filename // If the selection is from the TransFileTable // - wipe out the box coordinates // - wipe out the suffix // - wipe out the transmission // - wipe out T_whole // - update the waves in the table if(target == 2) ii= startRow do filename = pathname + T_GFilenames[ii] // write in zeros for the box coordinates WriteXYBoxToHeader(filename,0,0,0,0) // write in a null suffix WriteAssocFileSuffixToHeader(filename,suffix) //write a trans==1 to the file header of the raw data WriteTransmissionToHeader(filename,1) //sample trans WriteWholeTransToHeader(filename,1) //WholeTrans start byte is 392 //then update the table that is displayed T_EMP_Filenames[ii] = "" T_GTransmission[ii] = 1 T_GTWhole[ii] = 1 ii+=1 while(ii<=endRow) endif if(target == 1) // Write null suffix of transmission files into scattering files ii= startRow do filename = pathname + S_GFilenames[ii] // write in a null suffix WriteAssocFileSuffixToHeader(filename,suffix) //write a trans==1 to the file header of the raw data (open/close done in function) WriteTransmissionToHeader(filename,1) //sample trans //then update the table that is displayed S_TRANS_Filenames[ii] = "" S_GTransmission[ii] = 1 ii+=1 while(ii<=endRow) endif return(0) End //given a selection of scattering files, calculates the transmission //and writes the new transmission to the file header // //given the full path;name;vers (= filenmame), of a raw binary SANS file, //the transmission of the sample is calculated (if possible) from information //in the file header. empty beam and sample transmision run numbers are extracted //and the files are located from the run number (if possible) //from the header of the empty beam file, the XY box coordinates and "empty" //counts are determined //once all information is located, the transmission is calculated and the //transmission field of the sample file is automatically "Patched" // - updates the global variable that is displayed in the panel //can be run in batch mode, sequentially passing each item from a list of filenames //this is the single step of the batch mode // //in batch mode: execution will proceed through all of the files, reporting //results to the history window. If no trans could be successfully calculated //(for a blocked beam, for example), then that is displayed as well, and the //raw data is not modified // // now takes the attenuation of the sample trans and empty beam trans into account, (normally this == 1) // and rescales the transmission as appropriate // 3/31/04 SRK // Function CalcSelTransFromHeader(startRow,endRow) Variable startRow,endRow // GetSelection table,ScatterFileTable,1 String filename Wave/T T_EMP_Filenames = $"root:myGlobals:TransHeaderInfo:T_EMP_Filenames" Wave/T T_GFilenames = $"root:myGlobals:TransHeaderInfo:T_Filenames" Wave/T S_TRANS_Filenames = $"root:myGlobals:TransHeaderInfo:S_TRANS_Filenames" Wave/T S_GFilenames = $"root:myGlobals:TransHeaderInfo:S_Filenames" Wave S_GTransmission = $"root:myGlobals:TransHeaderInfo:S_Transmission" Variable num_s_files, num_t_files, ii, jj Variable refnum, transCts, emptyCts,attenRatio,lambda,trans Variable x1,x2,y1,y2,err,attenEmp,attenSam String suffix = "",pathName,textStr,abortStr,emptyFile,transFile,samFileStr String GBLoadStr="GBLoadWave/O/N=tempGBwave/T={2,2}/J=2/W=1/Q" String strToExecute num_t_files = numpnts(T_GFilenames) PathInfo catPathName pathname = S_path ii= startRow do if (cmpstr(S_TRANS_Filenames[ii],"")!=0) //if there is a sample trans file assigned jj=0 do if (cmpstr(S_TRANS_Filenames[ii],T_GFilenames[jj])==0) //find it in the trans file table if (cmpstr(T_EMP_Filenames[jj],"")!=0) //if empty beam file assigned, proceed with the calculation //full path+name to access all 3 files filename=pathname+S_GFilenames[ii] emptyFile = pathname+T_EMP_Filenames[jj] transFile = pathname+T_GFilenames[jj] ////////// // check the empty beam file for previously selected coordinates //if they exist, set the xy string , save the normalized counts somewhere //the value was written to an unused r*4 header analysis.factor (@b494) GetXYBoxFromFile(emptyFile,x1,x2,y1,y2) //read the real count value emptyCts = getBoxCounts(emptyFile) // read the attenuator number of the empty beam file attenEmp = getAttenNumber(emptyFile) // if( ((x1-x2)==0) || ((y1-y2)==0) ) //zero width marquee in either direction //no region selected -- prompt user to select box w/marquee DoWindow/F TransFileTable Abort "Use \"Set BCENT File\", then \"SetXYBox\" to select XY range in empty beam file "+T_EMP_Filenames[jj] //from here the Marquee menu selection must handle the task of setting the box and updating the information in the file header Endif //read in trans file then add to SAM ReadHeaderAndData(transFile) //adds to SAM err = Raw_to_work("SAM") //sum region in SAM transCts = SumCountsInBox(x1,x2,y1,y2,"SAM") // get the attenuator, lambda, and sample string (to get the instrument) WAVE/T samText = $"root:Packages:NIST:SAM:textRead" WAVE samReals = $"root:Packages:NIST:SAM:realsRead" samfileStr = samText[3] lambda = samReals[26] attenSam = samReals[3] //calculate the ratio of attenuation factors - assumes that same instrument used for each, AND same lambda AttenRatio = AttenuationFactor(samFileStr,lambda,attenEmp)/AttenuationFactor(samFileStr,lambda,attenSam) //calculate trans based on empty beam value and rescale by attenuation ratio trans= transCts/emptyCts * AttenRatio //write out counts and transmission to history window, showing the attenuator ratio, if it is not unity If(attenRatio==1) Printf "%s\t\tTrans Counts = %g\tTrans = %g\r",S_GFilenames[ii], transCts,trans else Printf "%s\t\tTrans Counts = %g\tTrans = %g\tAttenuatorRatio = %g\r",S_GFilenames[ii], transCts,trans,attenRatio endif //write the trans to the file header of the raw data (open/close done in function) WriteTransmissionToHeader(filename,trans) //then update the global that is displayed S_GTransmission[ii] = trans else // There is no empty assigned abortStr = "Empty beam file not assigned properly for " + T_GFilenames[jj] Print abortStr //Abort abortStr return(1) endif endif jj+=1 while(jj 0.95) //95%, from conversation w/Lionel printf " Tbox/Twhole = %g\r",T_GTransmission[ii]/trans else printf " !!! Tbox/Twhole is low !!! = %g\r",T_GTransmission[ii]/trans endif //write the trans to the file header of the raw data (open/close done in function) WriteWholeTransToHeader(filename,trans) //then update the global that is displayed GWhole[ii] = trans else // There is no empty assigned abortStr = "Empty beam file not assigned properly for " + T_GFilenames[jj] Print abortStr //Abort abortStr return(1) endif endif jj+=1 while(jjScattering File table is not open" return (1) endif Wave/T sw = root:myGlobals:TransHeaderInfo:S_Labels //Sample file labels Wave/T tw = root:myGlobals:TransHeaderInfo:T_Labels //trans file labels Wave/T tnam = root:myGlobals:TransHeaderInfo:T_FileNames //trans file names Wave/T snam = root:myGlobals:TransHeaderInfo:S_TRANS_FileNames //Scattering - trans correspondence Wave/T samfile = root:myGlobals:TransHeaderInfo:S_FileNames //Scattering file name // can do fancy formatted string with ... //"asdf* matches file: \\f01filen\\f00 \\K(52428,1,1)\\f01afdsfdd\\f00\\K(0,0,0)asdfasdfs" Variable num=numpnts(matchRows) String result="",tmpStr for(ii=0;iiScattering File table is not open" endif return(0) End Function ClearSelectedAssignments() String winStr = WinList("*", ";", "WIN:" ) //returns the target window Variable scatterTableExists, transTableExists Print winStr scatterTableExists = cmpstr(winStr,"ScatterFileTable;") if (scatterTableExists == 0) GetSelection table,ScatterFileTable,1 fClearSelectedAssignments(V_startRow,V_endRow,1) endif transTableExists = cmpstr(winStr,"TransFileTable;") if (transTableExists == 0) GetSelection table,TransFileTable,1 fClearSelectedAssignments(V_startRow,V_endRow,2) endif return(0) End