// createparam - Create a new parameter using SolidsPack types and
//               define a default value. This macro also creates the
//               proper entry in the "dg" and "ap" string parameters to define
//		 the "dg" screen and the "pap" printout.  Bit 14 is set
//		 for the parameter so that it can be properly loaded by
//		 the "solidsseq1d" apptype. "channel" parameters create an
//		 entry in the "clearparams" string so that the "solidsseq1d"
//		 apptype will clear bit 14. This macro creates the parameters
//		 dgrowindex, dgcharindex, aprowindex and apcharindex if 
//               they do not exist.  dg(ap)rowindex hold current row in 
//               in the "dg" and "ap" displays so that the macros can 
//               intelligently set a new column. dg(ap)charindex keeps
//		 track of the number of characters in "dg" and "ap" so that
//		 macros can provide an error message if the length of these
//		 strings are exceeded.

// EXAMPLE:      createparam('aHhx','amplitude',2000)

//		 SolidsPack types:

// Solidstype:   Type:      Max       Min      Step        Figures   Clear

// 'amplitude'   real       4095.0    0.0     0.0(0.06248) 4          n
// 'delay'       delay      none      none      0.0125e-6  6          n
// 'frequency'   frequency  none      none      0.1        1          n
// 'pulse'       pulse      8192      0.0       0.0125     1          n
// 'string'      string      na        na.       na.        na.       n
// 'integer'     real       32768     -32768    1          0          n
// 'scaler'      real       63        -16       0.5        0          n
// 'phase'       real       none      none    0.0(0.00549) 5         n
// 'real'        real       none      none      none       3          n
// 'channel'     string      na.       na.       na.        na.       y

// Initialize Temporary Parameters

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

exists('aprowindex','parameter'):$e
if $e < 0.5 then
   create('aprowindex','real')
   setlimit('aprowindex',1024,0,1)
   rowindex = 0
endif

exists('apcharindex','parameter'):$e
if $e < 0.5 then
   create('apcharindex','real')
   setlimit('apcharindex',1024,0,1)
   charindex = 0
endif

exists('dgrowindex','parameter'):$e
if $e < 0.5 then
   create('dgrowindex','real')
   setlimit('dgrowindex',1024,0,1)
   rowindex = 0
endif

exists('dgcharindex','parameter'):$e
if $e < 0.5 then
   create('dgcharindex','real')
   setlimit('dgcharindex',1024,0,1)
   charindex = 0
endif

"******** Create Parameter and Assign Default Value********"

$par = ''
$type = ''
$fstring = ''
$cstring = ''

$par = $1
exists($par,'parameter'):$e
$type = $2
if ($type = 'amplitude') then
   if ($e < 0.5) then 
      create($par,'real') 
      setlimit($par,0,4095.0,0.0)
   endif
   $fstring = $par + ':0,'
elseif ($type = 'delay') then
   if ($e < 0.5) then 
      create($par,'delay')
   endif
   $fstring = $par + ':6,'
elseif  ($type = 'frequency') then
   if ($e < 0.5) then 
      create($par,'frequency')
   endif
   $fstring = $par + ':1,'
elseif  ($type = 'pulse') then
   if ($e < 0.5) then 
      create($par,'pulse')
      setlimit($par,8192,8192,0.0125)
   endif
   $fstring = $par + ':1,'
elseif  ($type = 'string') then
   if ($e < 0.5) then
      create($par,'string')
   endif
   $fstring = $par + ','
elseif  ($type = 'integer') then
   if ($e < 0.5) then
      create($par,'real')
      setlimit($par,-32768,32768,1)
   endif
   $fstring = $par + ':0,'
elseif  ($type = 'scaler') then
   if ($e < 0.5) then
      create($par,'real')
      setlimit($par,-16,63,1)
   endif
   $fstring = $par + ':0,'
elseif  ($type = 'phase') then
   if ($e < 0.5) then
      create($par,'real')
   endif
   setlimit($par,180.0,-180.0,0.0)
   $fstring = $par + ':3,'
elseif  ($type = 'real') then
   if ($e < 0.5) then
      create($par,'real')
   endif
   $fstring = $par + ':6,'
elseif ($type = 'channel') then
   if ($e < 0.5) then
      create($par,'string')
   endif      
   $cstring = $cstring + $par + ' '
   $fstring = $par + ','
else
   write('line3','type: %s not found\n',$type)
endif

setvalue($par,$3,'current')
setprotect($par,'on',16384)
length($fstring):$charnumber
apcharindex = apcharindex + $charnumber
dgcharindex = dgcharindex + $charnumber
aprowindex = aprowindex + 1
dgrowindex = dgrowindex + 1
clearparams = clearparams + $cstring

if ((aprowindex < 73) and (apcharindex < 1024)) then 
   setprotect('ap','clear',4)
   ap = ap + $fstring
   setvalue('ap',ap,'processed')
   setprotect('ap','on',4)
else
   if (aprowindex >= 72) then 
      write('error','Maximum Rows exceeded')
   endif
   if (apcharindex >= 1023) then 
      write('error','Maximum Characters exceeded')
   endif
   abort
endif

if ((dgrowindex < 73) and (dgcharindex < 1024)) then 
   setprotect('dg','clear',4)
   dg = dg + $fstring
   setprotect('dg','on',4)
else
   if (dgrowindex >= 72) then 
      write('error','Maximum Rows exceeded')
   endif
   if (dgcharindex >= 1023) then 
      write('error','Maximum Characters exceeded')
   endif
   abort
endif
