home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Database / GBROUTE1,03PLUS.DMS / in.adf / ARexx / GBRMETRIC.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1991-09-12  |  4.2 KB  |  97 lines

  1. /*****************************************************************************
  2. **                                                                          **
  3. **                       GBRoute Plus ARexx Script                          **
  4. **                                                                          **
  5. **                       (c) 1991 Complex Computers                         **
  6. **                                                                          **
  7. **  Name : gbrmetric.rexx                                                   **
  8. **                                                                          **
  9. **  Description : Calculates a route with distances in Kilometres           **
  10. **                and prompts for cost in pence/litre                       **
  11. **                                                                          **
  12. *****************************************************************************/
  13.  
  14. TEMPFILE = 'ram:$$temp'                /* This can be any valid filename    */
  15. blank = ''
  16.  
  17. say 'GBRoute Plus ARexx Metric Demonstration'
  18.  
  19. options prompt 'Enter Start: '; 
  20.                                        /* get starting place                */
  21. pull start
  22.  
  23. options prompt 'Enter Destination: '; 
  24.                                        /* get destination place             */
  25. pull dest
  26.  
  27.                                        /* and cost in pence/litre           */
  28. options prompt 'Cost/Litre (pence): '; 
  29.  
  30. pull cost
  31.                                        /* send commands to GBRoute          */
  32. options results                        /* neeed this if we are to get       */
  33.                                        /* returned values                   */
  34. address 'GBR'                          /* address host                      */
  35.  
  36. 'from' start                           /* give GBR start and destination    */
  37. p1 = result
  38. 'to' dest
  39. p2 = result
  40.  
  41. cost = cost * 4.5461                   /* convert cost from pence/litre to  */
  42.                                        /* pence/gallon
  43.  
  44. 'pcost' cost                           /* send GBR converted cost           */
  45.  
  46. say 'Calculating journey from: 'p1' to: 'p2 
  47.  
  48. 'go'                                   /* calculate route                   */
  49.                                        /* Check for no route                */
  50. if result == 'RESULT' then do
  51.                                        /* output journey to file            */
  52.    'file' TEMPFILE
  53.                                        /* open file                         */
  54.    open(file, TEMPFILE, read)
  55.                                        /* loop until the end of the file    */
  56.    do while eof(file)=0
  57.                                        /* read a line from file             */
  58.       st = readln(file)
  59.  
  60.                                        /* here we cut each line into 3 parts*/
  61.                                        /* the middle part contatining the   */
  62.                                        /* distances is converted to         */
  63.                                        /* kilometres                        */
  64.       part1 = substr(st,1,64)
  65.  
  66.       dist = strip( substr(st, 65, 5)) /* extract distance and strip spaces */
  67.                                        /* convert and round up to nearest km*/
  68.       dist = ( dist * 1.60934 + 0.5) % 1
  69.  
  70.       part2 = substr(st, 70, 7)
  71.                                        /* justify right into a 5 char string*/
  72.       dist = insert(dist, blank, 5 - length(dist))
  73.  
  74.       say part1''dist''part2           /* print with all 3 parts joined     */
  75.  
  76.    end
  77.                                        /* close the file                    */
  78.    close(file)
  79.  
  80.    address command                     /* call dos 'delete' to remove       */
  81.    delete TEMPFILE                     /* temporary file                    */
  82.  
  83.    address 'GBR'                       /* back to GBR                       */
  84.  
  85.    'dist'
  86.    d = (result * 1.60934 + 0.5) % 1    /* convert total distance to km      */
  87.    'time'
  88.    t = result
  89.    'cost'
  90.    c = trunc(result/100,2)             /* pounds and pence                  */
  91.  
  92.    say 'This journey costs £'c' and takes 't'mins covering 'd' Km'
  93. end
  94.                                        /* Route not possible                */
  95. else say result
  96. exit
  97.