#pragma rtGlobals=1 // Use modern global access method. Menu "MPC Plots" submenu "Load Data" "Load Data Set From File/1", LoadDataSetFromFile("", "") "Load Data Sets From Folder/2", LoadDataSetsFromFolder("") End submenu "Plots" "Plot Exp. ReducedDOS From Selected Sets/3", PloExpReducedDOS("", "") "Plot Sim. ReducedDOS From Selected Sets/4", PloSimReducedDOS("", "") End End // GetQuantityNameDialog(quantityName) // This is used by PlotDataFromSelectedSets to get the name of the quantity // to be plotted. It returns its result in a global string variable, root:tempQuantityName, // which is assumed to already exist. Function/S GetQuantityNameDialog() String quantityName Prompt quantityName, "Name of quantity to be plotted", popup "RDOS" DoPrompt "Choose Quantity To Plot", quantityName return quantityName End // GetQuantityNameDialog(quantityName) // This is used by PlotDataFromSelectedSets to get the name of the quantity // to be plotted. It returns its result in a global string variable, root:tempQuantityName, // which is assumed to already exist. Function/S GetSimQuantityNameDialog() String quantityName Prompt quantityName, "Name of quantity to be plotted", popup "SimRDOS" DoPrompt "Choose Quantity To Plot", quantityName return quantityName End // GetLeafName(pathStr) // Utility routine that returns the "leaf" of a path. // For example, if the path is "hd:Folder A:Folder B:File A", this returns "File A". // The path separator is assumed to be colon. // If no leaf name is found, returns "". // It is assumed that the input path does NOT end with a colon. Function/S GetLeafName(pathStr) String pathStr String leafName Variable pos leafName = "" pos = strlen(pathStr) - 1 // Search from the end do if (CmpStr(pathStr[pos], "_") == 0) // Found the colon? //if (CmpStr(pathStr[pos], "_") == 0) leafName = pathStr[pos+1, strlen(pathStr)] break //endif // Break out of loop. endif pos -= 1 while(pos > 0) return leafName End // LoadDataSetFromFile(pathName, fileName) // This function loads the waves from a sample data file into a new IGOR data folder. // It creates the data folder, giving it the name of the file. // It then loads the data from the file into the new data folder. // // If pathName is "" or fileName is "", it will put up a dialog from which you can // choose the file to be loaded. // If both pathName and fileName are not "", then it will load the file without // putting up a dialog. In this case, pathName must contain the name of an IGOR // symbolic path that you have created which points to the folder containing the // sample data. fileName must be the name of a file within that folder. Function LoadDataSetFromFile(pathName, fileName) String pathName // Name of an existing IGOR symbolic path or "" String fileName // Name of file within folder pointed to by symbolic path or "" // If either of the input parameters is "", put up a dialog to get file. if ((strlen(pathName)==0) %| (strlen(pathName)==0)) Variable dummyRefNum String pathToFolder Open/R/D/M="Choose data file" dummyRefNum // This sets an automatically created local variable named S_fileName. if (strlen(S_fileName) == 0) // User cancelled? return -1 endif // Now break the full path to file down into path to folder plus file name. // This is done by searching for the last colon in the full path. fileName = GetLeafName(S_fileName) if (strlen(fileName) == 0) Print "LoadDataSetFromFile bug" return -1 endif pathToFolder = S_fileName[0, strlen(S_fileName) - strlen(fileName) - 1] // Make sure there is an IGOR symbolic path pointing to the folder NewPath/O/Q CurrentDataFilePath pathToFolder pathName = "CurrentDataFilePath" endif String extension = "." + ParseFilePath(4, fileName, ":", 0, 0) // e.g., ".dat" // Save the current data folder so we can restore it below. String savedDataFolder = GetDataFolder(1) // If it does not already exist, make a data folder to contain the waves from the file. // The new data folder is created in the current data folder with the name the // same as the name of the file we are about to load. // The /S flag sets new data folder as the current data folder. String dfName = RemoveEnding(fileName, extension) NewDataFolder/O/S :$dfName // This loads data set from the file into the current IGOR data folder // which is the data folder we just created above. The wave names come // from the first line of the data in the file because of the /W flag. LoadWave/J/O/A/W/Q/P=$pathName fileName // Restore the original data folder. SetDataFolder savedDataFolder return 0 End // LoadDataSetsFromFolder(pathName) // Loads data from all of the files in the folder associated with the specified symbolic path. // pathName is the name of an IGOR symbolic path which you can create with the New Path // dialog in the Misc menu. // If pathName is "", it puts up a dialog from which you can choose the folder. // // NOTE: This function assumes that ALL of the files in the specified folder are data // files and thus loads them all. Function LoadDataSetsFromFolder(pathName) String pathName // Name of an existing IGOR symbolic path or "" // If pathName is "", allow user to create a new symbolic path to the folder containing the runs of data. if (strlen(pathName) == 0) NewPath/O/Q/M="Choose folder containing data files" CurrentDataFilePath PathInfo CurrentDataFilePath // Check to see if user created the path. if (V_flag == 0) return -1 // User cancelled. endif pathName = "CurrentDataFilePath" endif Variable i, numFilesLoaded String fileName String extension = ".txt" // You need to change this for your data. numFilesLoaded = 0 i = 0 do fileName = IndexedFile($pathName, i, extension) if (strlen(fileName) == 0) break endif LoadDataSetFromFile(pathName, fileName) i += 1 numFilesLoaded += 1 while(1) return numFilesLoaded End // PlotDataFromSelectedSets(dataFolderList, quantityName) // This function plots a particular quantity from one or more data sets which // you have previously loaded into IGOR data folders. // // dataFolderList can be something like: // "root:Run 0;root:Run 1" // If dataFolderList is "", it uses the Data Browser selection. // In this case, you must select the data folders of interest in the Data Browser // before running the function and only those data folders may be selected. // // quantityName is the quantity that you want to plot, for example "quantity0", // "quantity1", or "quantity2". If quantityName is "", the function will display a dialog // from which you can choose the quantity of interest. // // Returns the number of waves plotted or -1 if there is an error. Function PloExpReducedDOS(dataFolderList, quantityName) String dataFolderList String quantityName Variable wantTags = 0 // Change to 1 to tag each trace Variable wantLegend = 1 String tempStr, legendStr if (strlen(dataFolderList) == 0) Variable i = 0 String nextFolder do nextFolder = GetBrowserSelection (i) if (strlen(nextFolder) == 0) break endif dataFolderList += nextFolder + ";" i += 1 while(1) endif if (strlen(quantityName) == 0) quantityName = GetQuantityNameDialog() endif // Create a graph and display the data Variable numPlotted = 0 i = 0 String dataFolderPathStr // Full path to data folder (e.g., "root:Run 1") String dataSetNameStr // Leaf data folder name (e.g., "Run 1") String YwaveNameStr // Full wave path (e.g., "root:Run 1:quantity0") String XwaveNameStr String traceNameStr // Name of trace in graph (e.g, quantity0, quantity0#1, quantity0#2) String titleStr Make/O Markercoefs = {1, 2, 3, 4, 5, 6, 61, 25, 8, 11, 39, 28, 12, 13} do dataFolderPathStr = StringFromList(i, dataFolderList, ";") if (strlen(dataFolderPathStr) == 0) break // No more data folders. endif dataSetNameStr = GetLeafName(dataFolderPathStr) if (strlen(dataSetNameStr) == 0) Print "PlotDataFromSelectedSets bug" return -1 endif YwaveNameStr = dataFolderPathStr + ":" + quantityName XwaveNameStr = dataFolderPathStr + ":" + "Energy" if (i == 0) titleStr = quantityName Display/W=(5,42,595,366) $YwaveNameStr vs $XwaveNameStr as titleStr ModifyGraph log(left)=1 else AppendToGraph $YwaveNameStr vs $XwaveNameStr endif sprintf traceNameStr, "%s#%d", quantityName, i // e.g., quantity0#0, quantity0#1 //ModifyGraph rgb($traceNameStr) = (TraceColor(0, i), TraceColor(1, i), TraceColor(2, i)) ModifyGraph mode = 3, marker($traceNameStr) = Markercoefs [i] // The legend is created if (wantLegend) sprintf tempStr, "\r\\s(%s)%s K", traceNameStr, dataSetNameStr if (i == 0) legendStr = tempStr else legendStr = legendStr + " " + tempStr endif endif if (wantTags) Tag $traceNameStr, 0, dataSetNameStr endif numPlotted += 1 i += 1 while(1) if (numPlotted > 0) if (wantLegend) Legend/N=theLegend/X=-4.5/Y=-4.0 legendStr endif endif return numPlotted End // PlotDataFromSelectedSets(dataFolderList, quantityName) // This function plots a particular quantity from one or more data sets which // you have previously loaded into IGOR data folders. // // dataFolderList can be something like: // "root:Run 0;root:Run 1" // If dataFolderList is "", it uses the Data Browser selection. // In this case, you must select the data folders of interest in the Data Browser // before running the function and only those data folders may be selected. // // quantityName is the quantity that you want to plot, for example "quantity0", // "quantity1", or "quantity2". If quantityName is "", the function will display a dialog // from which you can choose the quantity of interest. // // Returns the number of waves plotted or -1 if there is an error. Function PloSimReducedDOS(dataFolderList, quantityName) String dataFolderList String quantityName Variable wantTags = 0 // Change to 1 to tag each trace Variable wantLegend = 1 String tempStr, legendStr if (strlen(dataFolderList) == 0) Variable i = 0 String nextFolder do nextFolder = GetBrowserSelection (i) if (strlen(nextFolder) == 0) break endif dataFolderList += nextFolder + ";" i += 1 while(1) endif if (strlen(quantityName) == 0) quantityName = GetSimQuantityNameDialog() endif // Create a graph and display the data Variable numPlotted = 0 i = 0 String dataFolderPathStr // Full path to data folder (e.g., "root:Run 1") String dataSetNameStr // Leaf data folder name (e.g., "Run 1") String YwaveNameStr // Full wave path (e.g., "root:Run 1:quantity0") String XwaveNameStr String traceNameStr // Name of trace in graph (e.g, quantity0, quantity0#1, quantity0#2) String titleStr //Make/O Colorcoefs1 = {65280, 0, 0, 19456, 65280, 65280, 61, 25, 8, 11, 39, 28, 12, 13} //Make/O Colorcoefs2 = {0, 12800, 0, 39168, 65280, 49152, 61, 25, 8, 11, 39, 28, 12, 13} //Make/O Colorcoefs3 = {0, 52224, 0, 0, 0, 16384, 61, 25, 8, 11, 39, 28, 12, 13} do dataFolderPathStr = StringFromList(i, dataFolderList, ";") if (strlen(dataFolderPathStr) == 0) break // No more data folders. endif dataSetNameStr = GetLeafName(dataFolderPathStr) if (strlen(dataSetNameStr) == 0) Print "PlotDataFromSelectedSets bug" return -1 endif YwaveNameStr = dataFolderPathStr + ":" + quantityName XwaveNameStr = dataFolderPathStr + ":" + "Energy" //if (i == 0) //titleStr = quantityName //Display/W=(5,42,595,366) $YwaveNameStr vs $XwaveNameStr as titleStr //ModifyGraph log(left)=1 //else AppendToGraph $YwaveNameStr vs $XwaveNameStr //endif sprintf traceNameStr, "%s#%d", quantityName, i // e.g., quantity0#0, quantity0#1 //ModifyGraph rgb($traceNameStr) = (TraceColor(0, i), TraceColor(1, i), TraceColor(2, i)) //ModifyGraph mode = 0, rgb($traceNameStr) = (0,0,0) // The legend is created if (wantLegend) sprintf tempStr, "\r\\s(%s)%s K", traceNameStr, dataSetNameStr if (i == 0) legendStr = tempStr else legendStr = legendStr + " " + tempStr endif endif if (wantTags) Tag $traceNameStr, 0, dataSetNameStr endif numPlotted += 1 i += 1 while(1) if (numPlotted > 0) if (wantLegend) Legend/N=theLegend/X=-4.5/Y=-4.0 legendStr endif endif return numPlotted End