This is WAY easier to do in a macro. Here is a copy of our total petroleum hydrocarbon macro, which breaks the data into hydrocarbon ranges defined by the user from standards. Note that it subtracts a blank chromatogram (we run the solvent as a blank).
AME InitializeVariables
GasStart = 1.13
GasEnd = 3.18
DieselEnd = 7.17
TPHEnd = 8.80
Surr1RT = 2.79
Surr2RT = 5.56
C6Start = 1.15
C8Start = 1.76
C10Start = 2.58
C12Start = 3.25
C16Start = 4.36
C21Start = 5.62
C6 = 0
C6toC8 = 0
C8toC10 = 0
C10toC12 = 0
C12toC16 = 0
C16toC21 = 0
C21toC36 = 0
Pentane = 0
TPHgas = 0
TPHdiesel = 0
TPHOil = 0
RETURN
NAME tpgc
loadmeth "C:\HPCHEM\1\methods\tphgc.m"
open "C:\HPChem\msexe\loadlist.txt" for input as #30
resfile$ = _datapath$+"TPHCalc.txt"
OPEN resfile$ for output as #100
OPEN _datapath$+"TPHspec.txt" for output as #50
SELECTFILE 2,"Select Blank File","*.D",_BlankPath$,_BlankFile$,Fstat
blankfile$ = _BlankPath$+_BlankFile$
While (EOF(30) <> 1)
input #30, newfile$
InitializeVariables
file newfile$
tic
namelength = len(_datafile$)
filename$ = _datafile$[1:namelength-2]
daterun$ = _dateacquired$[1:10]
timerun$ = _dateacquired$[11:20]
sampledil = multiplier
operator$ = _operator$
processfile$ = _datafile$
file blankfile$
tic
sub
integrate
peakvars 0
looper = 1
!Find surrogates
Surr1WindowLow = Surr1RT - 0.15
Surr1WindowHigh = Surr1RT + 0.15
Surr2WindowLow = Surr2RT - 0.15
Surr2WindowHigh = Surr2RT + 0.15
Surr1Area = 0
Surr2Area = 0
while looper <= npeaks
peakvars looper
if ret_time >= Surr1WindowLow and ret_time <= Surr1WindowHigh then
if peak_area > Surr1Area then
Surr1Area = peak_area
endif
endif
if ret_time >= Surr2WindowLow and ret_time <= Surr2WindowHigh then
if peak_area > Surr2Area then
Surr2Area = peak_area
endif
endif
if ret_time > Surr2WindowHigh then
looper = npeaks
endif
looper = looper + 1
endwhile
looper = 1
peakvars 0
while looper <= npeaks
peakvars looper
! Discard peaks that are too early or too late
if ret_time < GasStart then
Pentane = Pentane + peak_area
endif
if ret_time > TPHEnd then
looper = npeaks
endif
! Discard peaks that are too wide
if ret_time >= GasStart and ret_time < GasEnd then
if (end_time - start_time) > 0.075 then
TPHgas = TPHgas
else
TPHgas = TPHgas + peak_area
endif
endif
if ret_time >= GasEnd and ret_time < DieselEnd then
TPHdiesel = TPHdiesel + Peak_area
endif
if ret_time >= DieselEnd and ret_time < TPHEnd then
TPHOil = TPHOil + Peak_area
endif
if ret_time > C6Start and ret_time <=GasStart then
C6 = C6 + peak_area
endif
if ret_time >= GasStart and ret_time <=C8Start then
C6toC8 = C6toC8 + peak_area
endif
if ret_time > C8Start and ret_time <=C10Start then
C8toC10 = C8toC10 + peak_area
endif
if ret_time > C10Start and ret_time <=C12Start then
C10toC12 = C10toC12 + peak_area
endif
if ret_time > C12Start and ret_time <=C16Start then
C12toC16 = C12toC16 + peak_area
endif
if ret_time > C16Start and ret_time <=C21Start then
C16toC21 = C16toC21 + peak_area
endif
if ret_time > C21Start and ret_time <=TPHEnd then
C21toC36 = C21toC36 + peak_area
endif
looper = looper + 1
endwhile
sprint output1$,processfile$,chr$(9),Pentane,chr$(9),TPHgas,chr$(9),TPHdiesel,chr$(9),TPHOil,chr$(9)
sprint output2$,daterun$,chr$(9),timerun$,chr$(9),sampledil,chr$(9),operator$,chr$(9),Surr1Area,chr$(9),Surr2Area
sprint output3$,processfile$,chr$(9),C6,chr$(9),C6toC8,chr$(9),C8toC10,chr$(9)
sprint output4$,C10toC12,chr$(9),C12toC16,chr$(9),C16toC21,chr$(9),C21toC36
print #100,output1$,output2$
print #50,output3$,output4$
endwhile
close #100
close #50
close #30
RETURN