#pragma TextEncoding = "MacRoman" #pragma rtGlobals=3 // Use modern global access method and strict wave access. //At first read a single file and then concatenate the data from each file //Use the following command in the commmand window to read all the files //LoadAndConcatAllFiles("") //************************** //READING A SINGLE FILE// //************************* Menu "Load Waves" "Load One File.....", LoadOneNeutronDatFile("","") "Load and Concatenate All Files in Folder.....", LoadAndConcatAllFiles("") "Make Histogram for Proton Energy and Proton Time...", MakeHist() "Make Two Dim Hisotgram....", MakeTwoDimHist() End static strConstant FileNameExtension=".dat" //LoadOneNeutronDatFile(pathName, fileName) //Creates the following wave: TimeStampForSpecAmp, TimeStampForPreAmp, ProtonEnergyFor_SpecAmp, ProtonTime_Spec, ProtonEnergyFor_PreAmp, ProtonTime_PreAmp Function LoadOneNeutronDatFile(pathName, fileName) String pathName //Name of an Igor symbolic path or "" String fileName //Name of file or full path to file //First we have to get a valid reference to a file if (strlen(pathName) == 0 ||strlen(fileName) == 0) //Display dialog looking for file variable refNum Open/D=2/R/F=FileNameExtension/P=$pathName refNum as fileName filename=S_fileName //S_filename is set by Open/D If (strlen(fileName)==0) //User Cancelled? Print "LoadOneNeutronDatFile was Cancelled" return -1 endif endif //String fullpath = S_filename Variable i=0, j=0, k Variable Vnam1, Vnam2, NumEvent, SpecMax, PreAmpMax, SpecTiMax, PreAmpTiMax, SpecAmpAvg, PreAmpAvg, Numerator, Denominator, ProtonEnergy //String fullpath = S_filename Open/P=$pathName/R refNum as fileName // fullpath Printf "Reading from file \"%s\". Number of Event is: ", fileName//fullpath // full path is basically the s_filename FStatus refNum // Used to read the file size NumEvent = V_logEOF/8208 // Gives the total Number of Events where 8208 is the total byte of a single event Print NumEvent //Making Waves Make/O/N=(NumEvent) TimeStampForSpecAmp Make/O/N=(NumEvent) TimeStampForPreAmp Make/O/N=(NumEvent) ProtonEnergyFor_SpecAmp Make/O/N=(Numevent) ProtonTime_SpecAmp Make/O/N=(NumEvent) ProtonEnergyFor_PreAmp Make/O/N=(NumEvent) ProtonTime_PreAmp for (k=0; k Specmax) Specmax = Vnam2 SpecTiMax = j*10^-7 endif Numerator = Numerator + Vnam2 endfor //SpecAmpAvg = Numerator / Denominator SpecAmpAvg = Numerator / 2048 ProtonEnergy = Specmax - SpecAmpAvg ProtonEnergyFor_SpecAmp[k] = ProtonEnergy ProtonTime_SpecAmp[k] = SpecTimax //Reading 8 byte time stamp for PreAmp start Fbinread/B=3/F=5 refNum, Vnam1 TimeStampForPreAmp[k] = Vnam1 //Reading 2 byte for PreAmp for (j = 0; j < 2048; j+=1) Fbinread/B=3/F=2 refNum, Vnam2 if (Vnam2 > PreAmpmax) PreAmpmax = Vnam2 PreAmpTimax = j*10^-7 endif Numerator = Numerator + Vnam2 endfor PreAmpAvg = Numerator / 2048 ProtonEnergy = PreAmpmax - PreAmpAvg ProtonenergyFor_PreAmp[k] = ProtonEnergy ProtonTime_PreAmp[k] = PreAmpTiMax //*********End OF ONE EVENT********** endfor Close refNum return 0 //Signifies Success End //*************************************// //READING ALL FILES IN SERIES 340// //************************************// Function LoadAndConcatAllFiles(pathName) String pathName //Name of symbolic path or " " to get dialog String fileName Variable index=0 Wave/D/Z ProtonEnergyFor_SpecAmp, ProtonTime_SpecAmp, ProtonEnergyFor_PreAmp, ProtonTime_PreAmp if (!WaveExists(ProtonEnergyFor_SpecAmp)) //Create the output waves because the code below concatenates Make/O/N=0/D ProtonEnergyFor_SpecAmp, ProtonTime_SpecAmp, ProtonEnergyFor_PreAmp, ProtonTime_PreAmp endif if (strlen(pathName) == 0) //If no path specified, create one NewPath/O temporaryPath //This will put up a dialog if (V_flag !=0) //User cancelled return -1 endif pathName = "temporaryPath" endif Variable result do //Loop through each file in folder filename = IndexedFile($pathName, index, FileNameExtension) if (strlen(fileName) == 0) //No more files? break //Break out of loop endif //Load the new data into a temporary data folder String TempDFName = "TempDataForLoadAndConcat" NewDataFolder/O/S $TempDFName String dfName = ParseFilePath(0, fileName, ":", 1, 0) //Print ParseFilePath(0, fileName, ":, 1, 0) dfName = RemoveEnding(dfName, ".dat") Variable LengthOfString = strlen(dfName) // Determining the length of the .. String FirstPart = dfName[3, 5] // To read only 340 Series String LastPart = dfName[LengthOfString - 1, LengthOfString - 1] if (Stringmatch(FirstPart, "*340*") && stringmatch(LastPart, "1")) result = LoadOneNeutronDatFile(pathName, fileName) endif if (result != 0) string message sprintf message, "Ann error occured while loading the file \"%s\". Aborting the load.\r", fileName Print message DoAlert 0, message KillDataFolder $TempDFName break endif // Create wave references for the waves loaded into the temporary data folder Wave ProtonEnergyFor_SpecAmpNew = :ProtonEnergyFor_SpecAmp Wave ProtonTime_SpecAmpNew = :ProtonTime_SpecAmp Wave ProtonEnergyFor_PreAmpNew = :ProtonEnergyFor_PreAmp Wave ProtonTime_PreAmpNew = :ProtonTime_PreAmp SetDataFolder :: // Back to parent data folder Wave ProtonEnergyFor_SpecAmp, ProtonTime_SpecAmp, ProtonEnergyFor_PreAmp, ProtonTime_PreAmp Concatenate /NP {ProtonEnergyFor_SpecAmpNew}, ProtonEnergyFor_SpecAmp Concatenate /NP {ProtonTime_SpecAmpNew}, ProtonTime_SpecAmp Concatenate /NP {ProtonEnergyFor_PreAmpNew}, ProtonEnergyFor_PreAmp Concatenate /NP {ProtonTime_PreAmpNew}, ProtonTime_PreAmp KillDataFolder $TempDFName Printf "Loaded file %d: \"%s\"\r", index, filename index += 1 while (1) if (Exists("temporaryPath")) // Kill temp path if exists killPath temporaryPath endif Wave ProtonEnergyFor_SpecAmp, ProtonTime_SpecAmp, ProtonEnergyFor_PreAmp, ProtonTime_PreAmp Sort ProtonEnergyFor_SpecAmp, ProtonTime_SpecAmp, ProtonEnergyFor_PreAmp, ProtonTime_PreAmp return 0 End //***********************************************// //MAKING HISTOGRAM //****************************************** //Function MakeHist() //HISTOGRAM FOR PROTON ENERGY FOR SPECAMP Make/N=100/O ProtonEnergyFor_SpecAmpNew_Hist; DelayUpdate Histogram/C/B={0,300,100} ProtonEnergyFor_SpecAmpNew, ProtonEnergyFor_SpecAmpNew_Hist;DelayUpdate //binstatr, binwidth, num of bins //Histogram/B=1 NogueiraWave1,NogueiraWave1_Hist;DelayUpdate Display ProtonEnergyFor_SpecAmpNew_Hist Modifygraph mode=5 ModifyGraph standoff=0 Label bottom "proton energy (a.u.)" Label left "frequency of proton energ" TextBox/C/N=text0/A=MC "proton energy histogram" //HISTOGRAM FOR PROTON TIME Make/N=100/O ProtonTime_SpecAmpNew_Hist;DelayUpdate Histogram/C/B={0,1.2e-6,100} ProtonTimeNew_SpecAmp, ProtonTime_SpecAmpNew_Hist; DelayUpdate //Histogram/B=1 NogueiraWave1,NogueiraWave1_Hist;DelayUpdate Display ProtonTime_SpecAmpNew_Hist Modifygraph mode=5 ModifyGraph standoff=0 Label left "frequency of proton time" Label bottom "proton time (s)" TextBox/C/N=text0/A=MC "histogram for proton time" End //******************************** //MAKING GOINT HISTOGRAM //******************************** //Function TWODIMHIST() Wave ProtonEnergyFor_SpecAmpNew, ProtonTime_SpecAmpNew //make /o/n=(25,25) myHist //setscale x, 0,3000,NogueiraWave1 //setscale y,0,10e-6,NogueiraWave2 JointHistogram/BINS={100,100 } ProtonEnergyFor_SpecAmpNew, ProtonTime_SpecAmpNew //JointHistogram/BINS={100,100} NogueiraWave1, NogueiraWave2 NewImage M_JointHistogram end