" intav macro by Alex Eletski 04/01/2005         "
" integrates the region from 10.5 ppm to 8.5 ppm "
" or between points specified by user            "
" stores integrals in 'fp.out' file,             " 
" mimicking the action of the 'fp' command       "

" Usage: intav(left, right)                      "

$solvent=''
$left=$1
$right=$2
$npoints=0
$integral=0



exists('arraydim','parameter'):$e
if $e then
   getvalue('arraydim', 1, 'processed'):$npoints
endif

if ($npoints=0) then
   write('line3', 'intav: Error - No arrayed spectra found!')
   return
endif 


exists('solvent','parameter'):$e
if ($e) then
   getvalue('solvent', 1, 'processed'):$solvent
endif

if not($solvent = 'D2O') then
   write('line3', 'intav: Warning - Solvent is not D2O, calibration may be wrong!')
endif

setref
	"reference the spectrum according to H2O line"

cz
	"Clear resets for integration"

"dc"
isadj
	"Adjust the integration scale"


exists(curexp+'/fp.out','file'):$e
if ($e) then
   write('reset', curexp+'/fp.out')
endif
write('file', curexp+'/fp.out', 'List of 1 lines in spectrum 1 to spectrum %d', $npoints)
write('file', curexp+'/fp.out', 'line         frequency (Hz)')
write('file', curexp+'/fp.out', '1              %d', $left)
write('file', curexp+'/fp.out', 'line    spectrum    amplitude (mm)')

$i=1

while ($i<=$npoints) do
   select($i)
   dc
   integ($left,$right):$integral
   write('file', curexp+'/fp.out', '   1           %d         %f', $i, $integral)
   $i=$i+1
endwhile

return

