#pragma rtGlobals=1 // Use modern global access method. Menu "KinSim" "Display_help" "Mechanism_Setup" "Mechanism_compile" "Run_Model" "repeated_run" "calc_sensitivities" End Menu Macro Display_help() String nb = "Help_notes" String nbText DoWindow/K $nb NewNotebook/N=$nb/F=1/V=1/K=1/OPTS=15/W=(300,100,800,500) Notebook $nb defaultTab=20, statusWidth=252, pageMargins={72,72,72,72} Notebook $nb font="Arial", fSize=10, fStyle=0, textRGB=(0,0,0), showRuler = 0 nbText = "General usage:\r\r" nbText += "First SAVE THIS AS A NEW EXPERIMENT. If you don’t, multiple errors will occur!!\r\r" nbText += "If this is your first use, try running A + B --> C and plot the results. Once you get that to work, you can move on to more complex mechanisms.\r\r" nbText += "Only uni- or bimolecular reactions can be used in this version.\r" nbText += "Note that reaction rate coefficients and concentrations have to be in same units (e.g. cm-3 molec s-1 and molec cm-3)\r\r" nbText += "First run \"Mechanism_Setup\" in the KinSim menu. This will make a table with all needed columns.\r\r" nbText += "Enter reactants, products, and rate coefficients to set up the chemical model.\r\r" nbText += "Compile model with \"Mechanism_Compile\", in the KinSim menu. This may take a while for more complex mechanisms.\r\r" nbText += "After compilation, the waves \"KK\", \"Names\", \"InitialConcentrations\" should be populated.\r\r" nbText += "Adjust the calculation time by modifying the CalTime wave as desired (e.g. CalTime = 100*p or \rCalTime = p / 100). Long times can lead " nbText += "to long calculation times for stiff ODE's, so we suggest starting with a short integration time. Note that the time step used in the " nbText += "numerical solution is determined internally and not affected by CalTime. CalTime contains the times when YOU want to see the results.\r\r" nbText += "Enter initial concentrations.\r\r" nbText += "\"Run_Model\" in the KinSim meny will calculate time series for all compounds. Plot your data and make sure that the results make sense.\r\r" nbText += "If you use consecutive runs, they will produce waves for previous time series (\"_prev\")\r\r" Notebook $nb text= nbText // Notebook $nb text="First run \"Mechanism_Setup\". This will Make a table with all needed columns.\r" // Notebook $nb text="Enter reactants, products, and rate coefficients to setup the chemical model.\r" // Notebook $nb text="Compile model with \"Mechanism_ODE\", it may take a while for more complex mechanisms.\r" // Notebook $nb text="After compilation, the waves \"KK\", \"Names\", \"InitialConcentrations\" should be populated.\r" // Notebook $nb text="Adjust CalTime as desired (e.g. CalTime = 100*p) with care, long times can lead to long calculation time" // Notebook $nb text="s for stiff ODE's.\r" // Notebook $nb text="Enter initial concentrations.\r" // Notebook $nb text="\"Run_Model\" will calculate time series for all compounds, consecutive runs will produce waves for previo" // Notebook $nb text="us time series (\"_prev\")\r" End Macro Macro Mechanism_Setup_Jim() // // This macro will setup the input waves needed to generate the reaction mechanism // After running this macro, enter the reaction mechanism // Reactant and Product names need to be less than 11 characters in length // Do not use Reactant and Product as species names. // // Enter the Rate coefficients for the reactions in the RateCoefficients wave // // The time base is set for equally spaced points (100) over a period of 0.005 s. // This can be changed in the command window as desired later: i.e. caltime = 1e-3*exp(x/5) (unequally spaced points) // Make/O/T/N=100 Reactant1, Reactant2, Product1, Product2, Names Reactant1 = "" Reactant2 = "" Product1 = "" Product2 = "" Names = "" Make/O/N=100 RateCoefficients RateCoefficients=0 Make/O/N=100 CalTime=x*1e-5 Edit reactant1,reactant2,product1,product2, RateCoefficients DoWindow/C/T ReactionMechanism,"Reaction Mechanism" ModifyTable size=14,width=100 ModifyTable width(ratecoefficients)=150 end Macro Mechanism_ODE_Jim() Variable Rnumber, SpeciesNumber, SpeciesDiff Variable flag,n,m, nn, position, position2 Variable na,nb,nc,nd String temp, temp1, temp2, temp3, temp4 String TotalTemp, totaltemp1, totaltemp2, totaltemp3, totaltemp4 String sa,sb,sc,sd String s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10 String Plus, Equal String MyList, tempNote, tempNote2 Plus = "+" Equal = "=" s0 = "" s1 = " " s2 = S1 + " " s3 = s2 + " " s4 = s3 + " " s5 = s4 + " " s6 = s5 + " " s7 = s6 + " " s8 = s7 + " " s9 = s8 + " " s10 = s9 + " " n=0 printf "\r\t\t\t\tReaction Mechanism \t\t\t\t\t\t\t\t\t\t Rate Coefficient\r" Do temp = Reactant1[n] + Reactant2[n] + Product1[n] + Product2[n] if (stringmatch(temp,"")) //Empty line in rxn. mechanism means jump to the end of the loop Rnumber = n n += 500 else //There is at least one reactant or product na = 10 - strlen(Reactant1[n]) temp = "s" + num2str(na) sa =($temp) + Reactant1[n] + plus if(strlen(Reactant2[n]) == 0) sa =($temp) + Reactant1[n] endif if (strlen(Reactant1[n]) == 0) sa = " " endif nb = 10 - strlen(Reactant2[n]) temp = "s" + num2str(nb) sb =($temp) + Reactant2[n] + equal if (strlen(Reactant2[n]) == 0) sb = " " + equal endif nc = 10 - strlen(Product1[n]) temp = "s" + num2str(nc) sc =($temp) + Product1[n] if (strlen(Product1[n]) == 0) sc = " " endif nd = 10 - strlen(Product2[n]) temp = "s" + num2str(nd) sd = plus + ($temp) + Product2[n] if (strlen(Product2[n]) == 0) sd = " " endif print "\t\t\t\t" + sa + sb + sc + sd+"\t\t\t\t\t" + num2str(ratecoefficients[n]) endif n += 1 while (n < 100) print "\r\r" Print " ODEs in Compound Format" // Transfer Rate Coefficient Data to KK wave Make/O/N=(Rnumber) KK // n = 0 // Do // kk[n] = RateCoefficients[n] // n +=1 // while(n < Rnumber) KK = RateCoefficients[p] // Capture species names and write to Names[n] wave n = 0 Make/O/N=100/T Names = "" Do nn = n*4 Names[nn] = Reactant1[n] Names[nn+1] = Reactant2[n] Names[nn+2] = Product1[n] Names[nn+3] = Product2[n] n += 1 while (n < rnumber) // Remove Blanks from Names List n=0 Do if(strlen(Names[n]) == 0) DeletePoints n,1,Names endif n +=1 while(n < rnumber*4) // Remove Duplicate Names from Names List Silent 1 Do flag=0 n=0 Do m=n+1 Do If((stringmatch(Names[m], Names[n])) &! (stringmatch(Names[n],""))) DeletePoints m,1,Names flag=1 endif m += 1 while(m < rnumber*4) n += 1 while(n< rnumber*4) while (flag==1) // Determine number of Species in Reaction Names List n=0 Do if(stringmatch(Names[n],"")) SpeciesNumber = n n = 500 endif n += 1 while (n <100) Make/O/N=(SpeciesNumber) InitialConcentrations // Make Output waves for Species with wave Names from Names[n] n =0 Do Make/O/D/N=100 $Names[n] = 0 n +=1 while (n < SpeciesNumber) DoWindow ReactionMechanism AppendToTable KK AppendToTable Names AppendToTable InitialConcentrations AppendToTable CalTime ModifyTable size(Names)=14, width(Names)=100 ModifyTable size(KK)=14,rgb(KK)=(65535,0,0), width(KK) = 100 ModifyTable size(initialconcentrations)=14, rgb(InitialConcentrations)=(65535,0,0), width(initialconcentrations)=150 ModifyTable size(CalTime)=14, rgb(CalTime)=(65535,0,0) // Print ODEs for Reaction Mechanism in Chemical Format n = 0 Do m=0 Totaltemp = "" Totaltemp1 = "" Totaltemp2 = "" Totaltemp3 = "" Totaltemp4 = "" Do temp1 = "" If(stringmatch(Names[n], Reactant1[m])) temp1 = "-" + num2str(ratecoefficients[m]) + " * [" + Reactant1[m] + "] * ["+Reactant2[m] + "]" if(strlen(Reactant1[m]) == 0) temp1 = "-" + num2str(ratecoefficients[m]) + " * " + "["+Reactant2[m] + "]" endif if(strlen(Reactant2[m]) == 0) temp1 = "-" + num2str(ratecoefficients[m]) + " * [" + Reactant1[m] + "]" endif else endif Totaltemp1 = Totaltemp1 + temp1 m += 1 While(m 0) if (StrLen(totaltemp)>300) Variable breakpos = StrSearch(Totaltemp, "+", 300) // find first "+" past 300 chars breakpos = min(breakpos, StrSearch(Totaltemp, "-", 300)) // Check if there's a "-" earlier than a "+" if (breakpos>-1) Print "dydt["+ num2str(n) + "] = " + Totaltemp[0,breakpos-1] Print "dydt["+ num2str(n) + "] = " + Totaltemp[breakpos, StrLen(Totaltemp)-1] else if (StrLen(totaltemp)>400) abort "something is strange with this string"+Totaltemp else Print "dydt["+ num2str(n) + "] = " + Totaltemp endif else Print "dydt["+ num2str(n) + "] = " + Totaltemp endif //**************************** // Write to Notebook // tempNote = "dydt["+ num2str(n) + "] = " + Totaltemp // tempNote2 = "Notebook ReactionCopy ruler=Normal, text=" + "\"" + tempnote + "\"" // Execute tempNote2 // Notebook ReactionCopy ruler=Normal, text= "\r" // // DoWindow/F ReactionCopy //**************************** endif n +=1 while (n < speciesnumber) end // These macros (Mechanism_Setup and Mechanism_ODE) are modified from J. Burkholders Kinetics Mechanism macros // The main change is to accomodate a third reaction product Macro Mechanism_Setup() // // This macro will setup the input waves needed to generate the reaction mechanism // After running this macro, enter the reaction mechanism // Reactant and Product names need to be less than 11 characters in length // Do not use Reactant and Product as species names. // // Enter the Rate coefficients for the reactions in the RateCoefficients wave // // The time base is set for equally spaced points (100) over a period of 0.005 s. // This can be changed in the command window as desired later: i.e. caltime = 1e-3*exp(x/5) (unequally spaced points) // Make/O/T/N=100 Reactant1, Reactant2, Product1, Product2, Product3, Names Reactant1 = "" Reactant2 = "" Product1 = "" Product2 = "" Product3 = "" Names = "" Make/O/N=100 RateCoefficients RateCoefficients=0 Make/O/N=100 CalTime=x*1e-5 Edit/W=(5.25,42.5,1122,236) reactant1,reactant2,product1,product2, product3, RateCoefficients DoWindow/K ReactionMechanism DoWindow/C/T ReactionMechanism,"Reaction Mechanism" ModifyTable size=11,width=90 ModifyTable width(ratecoefficients)=100 Variable /G dilution = 0 IncludeChemKineticFuncs() // load subroutines for reaction mechanism from experiment folder end Macro Mechanism_compile(fctname) String fctname = "ChemKinetic" Prompt fctname, "Select Kinetic Function", popup FunctionList("ChemKinetic*",";","KIND:2") String/G CurrChemKineticFct = fctname Variable Rnumber, SpeciesNumber, SpeciesDiff Variable flag,n,m, nn, position, position2 Variable na,nb,nc,nd, ne Variable TotalLen, breakpos String temp, temp1, temp2, temp3, temp4, temp5 String TotalTemp, totaltemp1, totaltemp2, totaltemp3, totaltemp4, totaltemp5 String dilutiontemp String sa,sb,sc,sd, se String s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10 String Plus, Equal String MyList, tempNote, tempNote2 String/G dydtstr = "" // string to be passed to ChemKineticsFuncs Silent 1 PauseUpdate Plus = "+" Equal = "=" s0 = "" s1 = " " s2 = S1 + " " s3 = s2 + " " s4 = s3 + " " s5 = s4 + " " s6 = s5 + " " s7 = s6 + " " s8 = s7 + " " s9 = s8 + " " s10 = s9 + " " n=0 printf "\r\t\t\t\tReaction Mechanism \t\t\t\t\t\t\t\t\t\t Rate Coefficient\r" Do temp = Reactant1[n] + Reactant2[n] + Product1[n] + Product2[n] + Product3[n] if (stringmatch(temp,"")) //Empty line in rxn. mechanism means jump to the end of the loop Rnumber = n // This is the number of reactions n += 500 else //There is at least one reactant or product na = 10 - strlen(Reactant1[n]) temp = "s" + num2str(na) sa =($temp) + Reactant1[n] + plus if(strlen(Reactant2[n]) == 0) sa =($temp) + Reactant1[n] endif if (strlen(Reactant1[n]) == 0) sa = " " endif nb = 10 - strlen(Reactant2[n]) temp = "s" + num2str(nb) sb =($temp) + Reactant2[n] + equal if (strlen(Reactant2[n]) == 0) sb = " " + equal endif nc = 10 - strlen(Product1[n]) temp = "s" + num2str(nc) sc =($temp) + Product1[n] if (strlen(Product1[n]) == 0) sc = " " endif nd = 10 - strlen(Product2[n]) temp = "s" + num2str(nd) sd = plus + ($temp) + Product2[n] if (strlen(Product2[n]) == 0) sd = " " endif ne = 10 - strlen(Product3[n]) temp = "s" + num2str(ne) se = plus + ($temp) + Product3[n] if (strlen(Product3[n]) == 0) sd = " " endif print "\t\t\t\t" + sa + sb + sc + sd+ se + "\t\t\t\t\t" + num2str(ratecoefficients[n]) endif n += 1 while (n < 100) print "\r\r" Print " ODEs in Compound Format" // Transfer Rate Coefficient Data to KK wave Make/O/N=(Rnumber) KK // n = 0 // Do // kk[n] = RateCoefficients[n] // n +=1 // while(n < Rnumber) KK = RateCoefficients[p] // Capture species names and write to Names[n] wave n = 0 Make/O/N=600/T Names = "" Do nn = n*5 Names[nn] = Reactant1[n] Names[nn+1] = Reactant2[n] Names[nn+2] = Product1[n] Names[nn+3] = Product2[n] Names[nn+4] = Product3[n] n += 1 while (n < rnumber) // Remove Blanks from Names List, changed to start at the end, since double empty names were not properly removed before n=numpnts(Names)-1 // last point in Names Do if(strlen(Names[n]) == 0) DeletePoints n,1,Names endif n -=1 while(n > -1) // Remove Duplicate Names from Names List Silent 1 Do flag=0 n=0 Do m=n+1 Do If(stringmatch(Names[m], Names[n])) DeletePoints m,1,Names flag=1 else m += 1 endif while(m < numpnts(Names)) n += 1 while(n< numpnts(Names) - 1) while (flag==1) // Determine number of Species in Reaction Names List n=0 Do if(stringmatch(Names[n],"")) SpeciesNumber = n n = 500 endif n += 1 while (n <100) SpeciesNumber = numpnts(Names) Make/O/N=(SpeciesNumber) InitialConcentrations // Make Output waves for Species with wave Names from Names[n] n =0 Do Make/O/D/N=100 $Names[n] = 0 n +=1 while (n < SpeciesNumber) DoWindow ReactionMechanism AppendToTable KK AppendToTable Names AppendToTable InitialConcentrations AppendToTable CalTime ModifyTable size(Names)=14, width(Names)=100 ModifyTable size(KK)=14,rgb(KK)=(65535,0,0), width(KK) = 100 ModifyTable size(initialconcentrations)=14, rgb(InitialConcentrations)=(65535,0,0), width(initialconcentrations)=150 ModifyTable size(CalTime)=14, rgb(CalTime)=(65535,0,0) // Print ODEs for Reaction Mechanism in Chemical Format n = 0 Do m=0 Totaltemp = "" Totaltemp1 = "" Totaltemp2 = "" Totaltemp3 = "" Totaltemp4 = "" Totaltemp5 = "" Do // Find Reactant 1 in Names temp1 = "" If(stringmatch(Names[n], Reactant1[m])) temp1 = "-" + num2str(ratecoefficients[m]) + " * [" + Reactant1[m] + "] * ["+Reactant2[m] + "]" if(strlen(Reactant1[m]) == 0) temp1 = "-" + num2str(ratecoefficients[m]) + " * " + "["+Reactant2[m] + "]" endif if(strlen(Reactant2[m]) == 0) temp1 = "-" + num2str(ratecoefficients[m]) + " * [" + Reactant1[m] + "]" endif endif Totaltemp1 += temp1 m += 1 While(m 0) if (TotalLen>390) // string too long for one line in function breakpos = StrSearch(Totaltemp, "+", 300) // find first "+" past 300 chars if (breakpos<0 || breakpos> 390) breakpos = StrSearch(Totaltemp, "-", 300)) // Check if there's maybe a "-" endif if (breakpos>300) //Print "dydt["+ num2str(n) + "]=" + Totaltemp[0,breakpos-1] //Print "dydt["+ num2str(n) + "]+=" + Totaltemp[breakpos, StrLen(Totaltemp)-1] dydtstr += "dydt["+ num2str(n) + "]="+Totaltemp[0,breakpos-1] + "\r" dydtstr += "dydt["+ num2str(n) + "]+="+ Totaltemp[breakpos, StrLen(Totaltemp)-1] + "\r" else print Totaltemp abort "something is strange with this string" endif else //Print "dydt["+ num2str(n) + "]=" + Totaltemp dydtstr += "dydt["+ num2str(n) + "]=" + Totaltemp+ "\r" endif endif n +=1 while (n < speciesnumber) RemoveChemKineticFuncs() Execute/Q /P "EditChemKineticFuncs()" IncludeChemKineticFuncs() end Macro Run_Model(Cont, printhist) String Cont = "restart" String PrintHist = "print" Prompt Cont, "Restart or continue?", popup "restart;continue" Prompt PrintHist, "Print stuff in history?", popup "print;noprint" If (!exists("CurrChemKineticFct")) Abort "Must compile ODE first!" Endif String cmd, SpeciesList, CurrSpecies Variable n, speciesnumber Variable npnts SetDataFolder root: Silent 1 PauseUpdate Variable starttime = DateTime n=0 SpeciesList = "" SpeciesNumber = numpnts(Names) Do if(n == 0) SpeciesList += Names[n] else SpeciesList = SpeciesList + "," + Names[n] endif n += 1 while (n < numpnts(Names)) n=0 Do CurrSpecies = Names[n] if (exists(CurrSpecies+"_1prev")) Duplicate/O $(CurrSpecies+"_1prev"), $(CurrSpecies+"_2prev") endif Duplicate/O $CurrSpecies, $(CurrSpecies+"_1prev") if (cmpstr(Cont, "restart")==0) $CurrSpecies[0] = InitialConcentrations[n] // restart: initialize to original values else $CurrSpecies[0] = $CurrSpecies[numpnts($CurrSpecies)-1] // continue: initialize to final previous values endif n += 1 while(n < SpeciesNumber) if (!exists("CurrChemKineticFct")) abort "can't find mechanism name, try running Mechanism_ODE" endif cmd= "IntegrateODE/U=1000/X=CalTime "+CurrChemKineticFct+" KK, {"+ SpeciesList + "}" if (cmpstr(PrintHist, "print")==0) Print cmd endif Execute cmd if (cmpstr(Cont, "restart")==0) // restart case Variable/G LastTime = CalTime[numpnts(CalTime)-1] if (exists("CalTime_cont_1prev")) Duplicate/O CalTime_cont_1prev, CalTime_cont_2prev Duplicate/O CalTime_cont_1prev, CalTime_min_cont_2prev CalTime_min_cont_2prev /= 60 endif if (exists("CalTime_cont")) Duplicate/O CalTime_cont, CalTime_cont_1prev Duplicate/O CalTime_cont, CalTime_min_cont_1prev CalTime_min_cont_1prev /= 60 endif Duplicate/O CalTime, CalTime_cont if (exists("CalTime_min")) Duplicate/O CalTime, CalTime_min_cont CalTime_min_cont /= 60 endif n=0 Do // overwrite cont waves CurrSpecies = Names[n] if (exists(CurrSpecies+"_Cont_1prev")) Duplicate/O $(CurrSpecies+"_Cont_1prev"), $(CurrSpecies+"_Cont_2prev") endif if (exists(CurrSpecies+"_Cont")) Duplicate/O $(CurrSpecies+"_Cont"), $(CurrSpecies+"_Cont_1prev") endif Duplicate/O $(CurrSpecies), $(CurrSpecies+"_Cont") n+=1 While(n < SpeciesNumber) else // continue case Duplicate/O CalTime, TempContTime // expand continuation time wave with any new arbitrary time wave TempContTime += LastTime if (exists("CalTime_cont")) Concatenate/O/NP {CalTime_cont, TempContTime}, TempTempContTime else if (exists("CalTime_1prev") Concatenate/O/NP {CalTime_1prev, TempContTime}, TempTempContTime else Concatenate/O/NP {CalTime, TempContTime}, TempTempContTime endif endif Duplicate/O TempTempContTime, CalTime_cont KillWaves TempTempContTime, TempContTime LastTime = CalTime_cont[numpnts(CalTime_cont)-1] if (exists("CalTime_min")) Duplicate/O CalTime_cont, CalTime_min_cont CalTime_min_cont /= 60 endif n=0 Do // expand concentrations CurrSpecies = Names[n] if (exists(CurrSpecies+"_Cont")) Concatenate/O/NP {$(CurrSpecies+"_Cont"), $(CurrSpecies)}, tempconcwav1 // Continuation wave exists else Concatenate/O/NP {$(CurrSpecies+"_1prev"), $(CurrSpecies)} tempconcwav1 endif Duplicate/O tempconcwav1, $(CurrSpecies+"_Cont") n+=1 While(n < SpeciesNumber) KillWaves tempconcwav1 endif Duplicate/O CalTime, CalTime_1prev if (cmpstr(PrintHist, "print")==0) print "Calculation time", DateTime - starttime,"seconds" endif end Function IncludeChemKineticFuncs() // adds include statement to procedure window // note that ChemKineticsFuncs.ipf must be present in experiment folder // if not present, a blank one will be generated // check if experiment was saved Pathinfo home if (StrLen(S_Path)<1) abort "Save experiment first!" endif String SelectStr=S_Path + "ChemKineticFuncs.ipf" String homepath = S_Path // check if ChemKineticFuncs.ipf exists in same folder GetFileFolderInfo/Z/Q SelectStr if (( V_Flag != 0) || (V_isFile==0)) // ChemKineticFuncs.ipf doesn't exist DoAlert 1, "ChemKineticFuncs.ipf does not exist, should I generate a blank one?" if (V_flag==1) // Yes clicked MakeChemKineticFuncs() else abort "could not include ChemKineticFuncs.ipf" endif endif String cmd = "INSERTINCLUDE "+"\""+homepath+"ChemKineticFuncs\"" Execute /P cmd Execute /P "COMPILEPROCEDURES " End Function Function RemoveChemKineticFuncs() // removes include statement from procedure window // also removes ChemKineticsFuncs.ipf from experiment Pathinfo home String cmd = "DELETEINCLUDE "+"\""+S_path+"ChemKineticFuncs\"" Execute /P cmd Execute /P "COMPILEPROCEDURES " End Function Function EditChemKineticFuncs() if (!exists("dydtstr")) abort "could not find dydtstr, try running Mechanism_ODE" endif SVAR newcode = dydtstr // dynamic code stored in global variable if (!exists("CurrChemKineticFct")) abort "can't find mechanism name, try running Mechanism_ODE" endif SVAR mechname = CurrChemKineticFct // mechanism name stored in global variable Pathinfo home // load ChemKineticFuncs as text into notebook String noteBookName = "ChemKineticsFuncsText" OpenNotebook /P=home /N=$noteBookName "ChemKineticFuncs.ipf" // edit the notebook // find dynamic code start Notebook $notebookName selection = {startOfFile, startOfFile}, findText={mechname, 0} Notebook $notebookName selection={endOfParagraph,endOfParagraph}, findText={"begin dynamic code", 0} if (V_Flag ==1) NoteBook $notebookName selection={endOfParagraph,endOfParagraph} //position at return after text found GetSelection notebook, $notebookName, 1 endif Variable begin_dyn = V_startParagraph // find dynamic code end Notebook $notebookName selection = {startOfFile, startOfFile}, findText={mechname, 0} Notebook $notebookName selection={endOfParagraph,endOfParagraph}, findText={"end dynamic code", 0} if (V_Flag ==1) NoteBook $notebookName selection={endOfParagraph,endOfParagraph} //position at return after text found GetSelection notebook, $notebookName, 1 endif Variable end_dyn = V_startParagraph-1 if (V_Flag ==1) NoteBook $notebookName selection={(begin_dyn,0),(end_dyn,0)} //select dynamic code NoteBook $notebookName text = newcode+"\r" // replace dynamic code with new code // Save the notebook SaveNotebook/O /P=home $noteBookName as "ChemKineticFuncs.ipf" else print "text not found, nothing replaced" endif // Kill the notebook doWindow/K $noteBookName End Function Function MakeChemKineticFuncs() // makes new ChemKineticFuncs.ipf in experiment folder String noteBookName = "ChemKineticsFuncsText" // make notebook NewNotebook /F=0 /N=$noteBookName as "ChemKineticFuncs.ipf" // add hard-coded text into notebook NoteBook $notebookName text = "Function ChemKinetic(pw, tt, yw, dydt)"+"\r" NoteBook $notebookName text = "\tWave pw // rate coefficients"+"\r" NoteBook $notebookName text = "\tVariable tt // time value at which to calculate derivatives"+"\r" NoteBook $notebookName text = "\tWave yw // containing concentrations of species"+"\r" NoteBook $notebookName text = "\tWave dydt // wave to receive dA/dt, dB/dt etc. (output)"+"\r" NoteBook $notebookName text = ""+"\r" NoteBook $notebookName text = ""+"\tif (exists(\"dilution\"))\r" NoteBook $notebookName text = ""+"\t\tNVAR d = dilution\r" NoteBook $notebookName text = ""+"\tendif\r" NoteBook $notebookName text = "// begin dynamic code, don't modify this line!"+"\r" NoteBook $notebookName text = ""+"\r" NoteBook $notebookName text = "// end dynamic code, don't modify this line!"+"\r" NoteBook $notebookName text = ""+"\r" NoteBook $notebookName text = "End"+"\r" // Save the notebook SaveNotebook/O /P=home $noteBookName as "ChemKineticFuncs.ipf" // Kill the notebook doWindow/K $noteBookName End Function