// reset_ahXXX: reset functions for the sequence ahYXX.c

//             Create BioPack globals

if ($#=0) then 

   exists('investigator','parameter','global'):$e
   if $e < 0.5 then
      create('investigator','string','global')
      investigator=''
   endif 

   exists('notebook','parameter'):$e
   if $e < 0.5 then
      create('notebook','string','global')
      notebook=''
   endif 

   exists('page','parameter'):$e
   if $e < 0.5 then
      create('page','string','global')
      page=''
   endif 

// Create Local Sample Filename 

   exists('samplefilename','parameter'):$e
   if $e < 0.5 then
      create('samplefilename','string')
      page=''
   endif 

// Create Global Sample Filename 

   exists('SPsamplefilename','parameter','global'):$e
   if $e < 0.5 then
      create('SPsamplefilename','string','global')
      page=''
   endif 

   write('line3','Macro %s is complete\n',$0)
endif

// Define Panel Macros

if ($#>0) then 

// Make or Edit the Sample Module

   if ($1 = 'makemod') then 
      paramgroup('params','',                'C13d1','real',-1,
                                             'N15d1','real',-1,
                                             'C13nt','integer',-1,
                                             'N15nt','integer',-1,
                                             'C13np','integer',-1,
                                             'N15np','integer',-1,
                                             'C13at','real',-1,
                                             'N15at','real',-1,
                                             'C13ni','integer',-1,
                                             'N15ni','integer',-1)

      paramgroup('params','',                'C13ni2','integer',-1,
                                             'N15ni2','integer',-1,
                                             'C13sw','frequency',-1,
                                             'N15sw','frequency',-1,
                                             'C13sw1','frequency',-1,
                                             'N15sw1','frequency',-1,
                                             'C13sw2','frequency',-1,
                                             'N15sw2','frequency',-1)

      $paramlist='C13d1 N15d1 C13nt N15nt C13np N15np C13at N15at C13ni N15ni '
      $paramlist=$paramlist + 'C13ni2 N15ni2 C13sw N15sw C13sw1 N15sw1 C13sw2 N15sw2'

      $sampmodname=userdir+'/modules/'+SPsamplefilename 
      exists($sampmodname,'file'):$e
      if ($e>0.5) then 
         shell('touch '+$sampmodname):$dum
         fread($sampmodname)
         write('line3','Read Module %s\n',SPsamplefilename)
      else
         write('line3','Creating Module %s\n',SPsamplefilename)
      endif
      writeparam($sampmodname,$paramlist)
      $ok = 'reset_ahX(\'savemod\')'
      $cancel='reset_ahX(\'cleanmod\')'
      parampopup($paramlist,'enter','modal',$ok,$cancel)
   endif

// Save the Sample Module in the Modules Directory

   if ($1 = 'savemod') then
      $sampmodname=userdir+'/modules/'+SPsamplefilename
      $paramlist=''
      module('list',SPsamplefilename):$paramlist 
      write('line3','Saving Module %s\n',SPsamplefilename)
      writeparam($sampmodname,$paramlist,'current')
      destroy($paramlist)
   endif

   if ($1 = 'cleanmod') then 
      $sampmodname=userdir+'/modules/'+SPsamplefilename
      $paramlist=''
      module('list',SPsamplefilename):$paramlist
      write('line3','Exit Module %s\n',SPsamplefilename)
      destroy($paramlist)
   endif
endif



