! 
! Alma_preliminary: some useful procedures...
!
!
begin procedure sayold
!
! @ SAYOLD Variable 
!       will display the command
! Let Variable 'Variable_value'
!
! Works for all variables, of any kind and dimensions, provided
! the dimensions are small enough. Parameter MXY sets the maximum dimension
! allowed
!
define integer dims[5] types ixy mxy
let mxy 8   ! Maximum size of array
let types typeof(old_&1)
if (types.eq.0) then
   SAY "E-SAYALL,  Variable &1 does not exist"
   return error
endif
compute dims dimof old_&1
!
if (types.gt.0) then  
!
! Character Strings & Arrays
  if (dims[5].eq.0) then 
     say "let old_&1 " """" 'old_&1' """" /format a a a a 
  else if (dims[5].eq.1) then
     if (dims[1].lt.mxy) then
        for i 1 to dims[1]
        say "let old_&1["'i'"] " """" 'old_&1[i]' """" /format a a a a 
        next
     else
        say "E-SAYALL,  Character array &1 too large "'dims[1]'
        return error
     endif
  else
     SAY "E-SAYALL,  Does not handle that yet ..."
     return error
  endif
else 
!
! Arithmetics...        
  if (dims[5].eq.0) then ! Scalar
     say "let old_&1 "'old_&1'
  else if (dims[5].eq.1) then
     if (dims[1].lt.mxy) then
        for i 1 to dims[1]
           say "Let old_&1["'i'"] "'old_&1[i]'
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]'
        return error
     endif
  else if (dims[5].eq.2) then
     let ixy dims[1]*dims[2]
     if (ixy.lt.mxy) then
        for j 1 to dims[2]
           for i 1 to dims[1]
             say "Let old_&1["'i'","'j'"] "'old_&1[i,j]'
             next
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]' 'dims[2]'
        return error
     endif
  else if (dims[5].eq.3) then
     let ixy dims[1]*dims[2]*dims[3]
     if (ixy.lt.mxy) then
        for k 1 to dims[3]
        for j 1 to dims[2]
        for i 1 to dims[1]
             say "Let old_&1["'i'","'j'","'k'"] "'old_&1[i,j,k]'
        next
        next
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]' 'dims[2]' 'dims[3]'
        return error
     endif
  else if (dims[5].eq.4) then
     let ixy dims[1]*dims[2]*dims[3]*dims[4]
     if (ixy.lt.mxy) then
        for l 1 to dims[4]
        for k 1 to dims[3]
        for j 1 to dims[2]
        for i 1 to dims[1]
             say "Let old_&1["'i'","'j'","'k'","'l'"] "'old_&1[i,j,k,l]'
        next
        next
        next
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]' 'dims[2]' 'dims[3]' 'dims[4]'
        return error
     endif
   endif
endif
!
end procedure sayold
!
!-------------------------------------------------------------------------
!
begin procedure createold
!
! @ CREATEOLD Variable 
!       will display the command
! Let Variable 'Variable_value'
!
! Works for all variables, of any kind and dimensions, provided
! the dimensions are small enough. Parameter MXY sets the maximum dimension
! allowed
!
define integer dims[5] types ixy mxy
let mxy 8   ! Maximum size of array
let types typeof(&1)
if (types.eq.0) then
   SAY "E-SAYALL,  Variable &1 does not exist"
   return error
endif
compute dims dimof &1
!
if (types.gt.0) then  
!
! Character Strings & Arrays
  if (dims[5].eq.0) then 
     say "define character old_&1*"'types'" /global"
     say "let old_&1 " """" '&1' """" /format a a a a 
  else if (dims[5].eq.1) then
     say "define character old_&1*"'types'"["'dims[1]'"] /global" 
     if (dims[1].lt.mxy) then
        for i 1 to dims[1]
        say "let old_&1["'i'"] " """" '&1[i]' """" /format a a a a 
        next
     else
        say "E-SAYALL,  Character array &1 too large "'dims[1]'
        return error
     endif
  else
     SAY "E-SAYALL,  Does not handle that yet ..."
     return error
  endif
else 
  if (types.eq.type_real) then
     say "define real old_&1 /like &1 /global"
  else if (types.eq.type_inte) then
     say "define inte old_&1 /like &1 /global"
  else if (types.eq.type_dble) then
     say "define double old_&1 /like &1 /global"
  else if (types.eq.type_logi) then
     say "define logi old_&1 /like &1 /global"
  else
     say "DO NOT KNOW"
  endif
!
! Arithmetics...        
  if (dims[5].eq.0) then ! Scalar
     say "let old_&1 "'&1'
  else if (dims[5].eq.1) then
     if (dims[1].lt.mxy) then
        for i 1 to dims[1]
           say "Let old_&1["'i'"] "'&1[i]'
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]'
        return error
     endif
  else if (dims[5].eq.2) then
     let ixy dims[1]*dims[2]
     if (ixy.lt.mxy) then
        for j 1 to dims[2]
           for i 1 to dims[1]
             say "Let old_&1["'i'","'j'"] "'&1[i,j]'
             next
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]' 'dims[2]'
        return error
     endif
  else if (dims[5].eq.3) then
     let ixy dims[1]*dims[2]*dims[3]
     if (ixy.lt.mxy) then
        for k 1 to dims[3]
        for j 1 to dims[2]
        for i 1 to dims[1]
             say "Let old_&1["'i'","'j'","'k'"] "'&1[i,j,k]'
        next
        next
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]' 'dims[2]' 'dims[3]'
        return error
     endif
  else if (dims[5].eq.4) then
     let ixy dims[1]*dims[2]*dims[3]*dims[4]
     if (ixy.lt.mxy) then
        for l 1 to dims[4]
        for k 1 to dims[3]
        for j 1 to dims[2]
        for i 1 to dims[1]
             say "Let old_&1["'i'","'j'","'k'","'l'"] "'&1[i,j,k,l]'
        next
        next
        next
        next
     else
        SAY "E-SAYALL,  Array too large "'dims[1]' 'dims[2]' 'dims[3]' 'dims[4]'
        return error
     endif
   endif
endif
!
end procedure createold
!
! End procedure alma_preliminary
!
