#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access #pragma DefaultTab={3,20,4} // Set default tab width in Igor Pro 9 and later #include Function AutoMPFit_ResultsNotebook(DFREF DFRpath) if (!DataFolderRefStatus(DFRpath)) print "Input folder is invalid" return -1 endif String nb = "AutoMPFit_Report_"+CleanupName(GetDataFolder(0, DFRpath),0) if (WinType(nb) == 5) DoWindow/K $nb endif SVAR/Z notes = DFRpath:notes if (!SVAR_Exists(notes)) print "This seems to be no valid AutoMPFit folder" return -1 endif SVAR YWvName = DFRpath:usedYWave SVAR XWvName = DFRpath:usedXWave NVAR npeaks = DFRpath:gNumPeaks NVAR chiSq = DFRpath:MPFChiSquare Wave yw = $YWvName Wave/Z xw = $XWvName Variable XPointRangeBegin, XPointRangeEnd sscanf GetNote("Fit range", notes), "%d to %d", XPointRangeBegin, XPointRangeEnd NewNotebook/F=1/K=1/N=$nb as "AutoMPFit Report for Data Folder "+GetDataFolder(0, DFRpath) Notebook $nb showRuler=0 Notebook $nb newRuler=PeakHeaderRuler, justification=0, margins={0,0,504}, spacing={0,0,0}, tabs={}, rulerDefaults={"Geneva",10,1,(0,0,0)} Notebook $nb newRuler=PeakParamsRuler, justification=0, margins={0,0,504}, spacing={0,0,0}, tabs={36,126+3*8192,205+1*8192,234+3*8192,305,394}, rulerDefaults={"Geneva",10,0,(0,0,0)} Notebook $nb ruler=PeakParamsRuler, text="Fit completed: "+GetNote("Fit completed", notes)+"\r" Notebook $nb ruler=PeakParamsRuler, text="Y data wave: "+GetWavesDataFolder(yw, 2) if ( (XPointRangeBegin != 0) || (XPointRangeEnd != DimSize(yw,0)-1) ) Notebook $nb ruler=PeakParamsRuler, text="["+num2str(XPointRangeBegin)+", "+num2str(XPointRangeEnd)+"]" endif Notebook $nb text="\r" if (WaveExists(xw)) Notebook $nb ruler=PeakParamsRuler, text="X data wave: "+GetWavesDataFolder(xw, 2)+"\r" endif Notebook $nb ruler=PeakParamsRuler, text="Chi square: "+num2str(chiSq)+"\r" Notebook $nb ruler=PeakParamsRuler, text="Total fitted points: "+GetNote("Fitted points", notes)+"\r" Notebook $nb ruler=PeakParamsRuler, text="Multipeak fit version: 3.02\r" // static for now GetSelection notebook, $nb, 1 Variable paragraphNumberforTotalArea = V_startParagraph Notebook $nb text="\r" String BL_typename = GetNote("Baseline type", notes) String PeakTypeList = GetNote("Peak type", notes) int i,j, reportBackground = 0, numBLParams = 0 if (CmpStr(BL_typename, "None") != 0) FUNCREF MPF2_FuncInfoTemplate blinfo = $(BL_typename + BL_INFO_SUFFIX) String ParamNameList = blinfo(BLFuncInfo_ParamNames) numBLParams = ItemsInList(ParamNameList) Notebook $nb ruler=PeakHeaderRuler,fstyle=-1,text="Baseline\tType: "+BL_typename Notebook $nb text="\r\r" Notebook $nb ruler=PeakParamsRuler Notebook $nb fStyle=0 Wave blw = DFRpath:blcoef Wave ble = DFRpath:W_sigma_0 for (i = 0; i < numBLParams; i += 1) Notebook $nb text= "\t"+StringFromList(i, ParamNameList)+" = \t"+WMMultiPeakFit#MPF2_PrintNumberWithPrecision(blw[i], ble[i])+"\t +/- \t"+num2str(ble[i])+"\r" endfor reportBackground = 1 endif Notebook $nb text="\r" Variable totalParams = numBLParams Variable totalArea = 0 Variable totalAreaVariance = 0 int nTypes = ItemsInList(PeakTypeList)-1 for (i = 0; i < npeaks; i += 1) Variable sigmaSequenceNumber = (numBLParams > 0) ? i+1 : i Wave coefs = DFRpath:$("peakcoef_"+num2istr(i)) Wave sigma = DFRpath:$("W_sigma_"+num2istr(sigmaSequenceNumber)) String PeakTypeName = StringFromList(i > nTypes ? 0 : i, PeakTypeList) FUNCREF MPF2_FuncInfoTemplate infoFunc=$(PeakTypeName+PEAK_INFO_SUFFIX) String ParameterNames = infoFunc(PeakFuncInfo_ParamNames) String DerivedParNames = infoFunc(PeakFuncInfo_DerivedParamNames) String ParamFuncName = infoFunc(PeakFuncInfo_ParameterFunc) Variable nParams = ItemsInList(ParameterNames) Variable nDerived = ItemsInList(DerivedParNames) Make/O/D/N=(nParams, nParams)/FREE MPF2_TempCovar Make/O/D/N=(nDerived,2)/FREE MPF2_TempParams=NaN // initialize to blanks so that if the function doesn't exist, we just get blanks back- the template function doesn't do anything. Notebook $nb ruler=PeakHeaderRuler,fstyle=-1,text="Peak "+num2str(i)+"\t" Notebook $nb text="Type: "+PeakTypeName + "\r\r" Notebook $nb fStyle=0 Notebook $nb ruler=PeakParamsRuler if (strlen(ParamFuncName) > 0) FUNCREF MPF2_ParamFuncTemplate paramFunc=$ParamFuncName Wave M_covar = DFRpath:M_covar MPF2_TempCovar[][] = M_covar[totalParams+p][totalParams+q] paramFunc(coefs, MPF2_TempCovar, MPF2_TempParams) for (j = 0; j < nDerived; j += 1) Notebook $nb text="\t" + StringFromList(j, DerivedParNames) + " = \t"+WMMultiPeakFit#MPF2_PrintNumberWithPrecision(MPF2_TempParams[j][0], MPF2_TempParams[j][1]) if (numtype(MPF2_TempParams[j][1]) != 2) Notebook $nb text= "\t +/- \t" + num2str(MPF2_TempParams[j][1]) endif Notebook $nb text="\r" endfor endif totalArea += MPF2_TempParams[2][0] // area is always in row 2 totalAreaVariance += MPF2_TempParams[2][1]^2 Notebook $nb text="\r" Notebook $nb text="\tFit function parameters\r" for (j = 0; j < nParams; j += 1) Notebook $nb text= "\t"+StringFromList(j, ParameterNames)+" =\t"+WMMultiPeakFit#MPF2_PrintNumberWithPrecision(coefs[j], sigma[j]) + "\t+/-\t"+num2str(sigma[j])+"\r" endfor if (reportBackground) Notebook $nb text="\r" Notebook $nb text="\tBackground Info\r" FUNCREF MPF2_FuncInfoTemplate blinfo = $(BL_typename + BL_INFO_SUFFIX) string BL_FuncName = blinfo(BLFuncInfo_BaselineFName) FUNCREF MPF2_BaselineFunctionTemplate blFunc = $BL_FuncName STRUCT MPF2_BLFitStruct BLStruct Wave BLStruct.cWave = DFRpath:blcoef BLStruct.x = MPF2_TempParams[0][0] Wave BLStruct.yWave = yw // ST 2.48: fill in y- and x-data pointers Wave/Z BLStruct.xWave = xw if (WaveExists(xw)) BLStruct.xStart = xw[XPointRangeBegin] BLStruct.xEnd = xw[XPointRangeEnd] else BLStruct.xStart = pnt2x(yw, XPointRangeBegin) BLStruct.xEnd = pnt2x(yw, XPointRangeEnd) endif Variable bgValue = blFunc(BLStruct) Notebook $nb text="\tBackground at peak location =\t"+num2str(bgValue)+"\r" Notebook $nb text="\tRatio peak height to background =\t"+num2str(MPF2_TempParams[1][0]/bgValue)+"\r" endif totalParams += nParams Notebook $nb text="\r" endfor Notebook $nb, selection={(paragraphNumberforTotalArea, 0), (paragraphNumberforTotalArea, 0)} Notebook $nb, text = "Total Peak Area = "+num2str(totalArea)+" +/- "+num2str(sqrt(totalAreaVariance))+"\r" Notebook $nb selection={startOfFile,startOfFile},findText={"", 1} End static function/S GetNote(string which, string infoStr) return StringByKey(which, infoStr, " = ", "\r") end