It depends upon what is in the table or how a set of nested
if-then-else statements were written.

Such code is easy to replace.  Consider

mdlfind: procedure(MDLTABp, cyls)
  returns(character(6) varying)
  reorder ;

  /*  uses lub-seeking binary search to find the subscript i of the
      element MDLTAB.tab.ncyl(i) for which MDLTAB.tab.ncyl >= cyls
      is a minimum, i.e.,

     min(i | MDLTAB.tab.ncyl >= cyls)

     If such a lub is found the return code is set  to 0 and the nickname
     of the corresponding pseudo-3390 model is returned as the value
     of this function.  If instead no lub  is found the return code is set to
    1 and a null string is returned as the value of this function.
  */


  /* parameters */

  declare (MDLTABp       /* -> MDLTAB */
    pointer,
    cyls                       /* cylinders */
    binary fixed(31,0))
    nonassignable ;


  /* table template */

  declare 1 MDLTAB based(MDLTABp),
    2 eye character(8)     /* eyecatcher: 'MDLTAB  ' */
    2 nmd                        /* number of models */
      signed binary fixed(31,0),
    2 tab(1 refer(MDLTAB.nmd),
      3 ncyl                       /* number of cylinders */
        signed binary fixed(31,0),
      3 nick                      /* nickname */
        character(6) varying ;


  /* LIFO scratch storage */

  declare (lo, mi, hi, retcode)
    signed binary fixed(31,0) ;
  declare (again, bounded, search_higher)
    aligned bit ;
  declare nickout character(6) varying ;

  /* named constants, BIF used */

  declare (F0 initial(0b), F1 initial(1b), F2 initial(10b))
     signed binary fixed(31,0) ;
  declare pliretc builtin ;


  lo = F1 ;
  hi = MDLTAB.nmd ;
  do again = (lo <= hi) repeat(lo <= hi) while(again) ;
    mi = lo + (hi - lo)/F2 ;
    search_higher = (cyls < MDLTAB.tab.ncyl) ;
    if search_higher then lo = mi + F1 ;
    else hi = mi - F1 ;
  end ;
  bounded = (hi <= MDLTAB.nmd) ;
  if bounded then
    do ;
      retcode = F0 ;
      nickout = MDLTAB.tab.nick(hi) ;
    end ;
  else
    do ;
      retcode = F1 ;
      nickout = '' ;
    end ;
  call pliretc(retcode) ;
  return ;

end mdlfind ;

This is PL/I, but it could serve as a template for another
implementation.  One in assembly language would be easy; one in C
would be possible.

The merits of such an approach are that it consistently produces a
least upper bound on a cylinders value and is easily changed/extended
by changing only the external table it uses.

John Gilmore, Ashland, MA 01721 - USA

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to