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

  1. /*****************************************************************************
  2. **                                                                          **
  3. **                       GBRoute Plus ARexx Script                          **
  4. **                                                                          **
  5. **                       (c) 1991 Complex Computers                         **
  6. **                                                                          **
  7. **  Name : gbrarrive.rexx                                                   **
  8. **                                                                          **
  9. **  Description : Given an arrival time, calculates the departure time      **
  10. **                                                                          **
  11. *****************************************************************************/
  12.  
  13.  
  14. TEMPFILE = 'ram:$$temp'                /* This can be any valid filename    */
  15.  
  16. say 'GBRoute Plus ARexx Demonstration'
  17.  
  18. options prompt 'Enter Start: '; 
  19.                                        /* get starting place                */
  20. pull start
  21.  
  22. options prompt 'Enter Destination: '; 
  23.                                        /* get destination place             */
  24. pull dest
  25.  
  26.                                        /* and the proposed arrival time     */
  27. options prompt 'Arrival Time (format 00:00 - 24hr clock): ';
  28.  
  29. pull arrive
  30.  
  31. options results                        /* neeed this if we are to get       */
  32.                                        /* returned values                   */
  33. address 'GBR'
  34.  
  35. 'from' start                           /* give GBR start and destination    */
  36. p1 = result
  37. 'to' dest
  38. p2 = result
  39.  
  40. 'go'                                   /* calculate the time for the route  */
  41.  
  42. 'time'
  43. t = result
  44.  
  45. start = calc_start(arrive,t)           /* calc_start determines the         */
  46.                                        /* departure time, given the arrival */
  47.                                        /* time and the time for the journey */
  48.  
  49.                                        /* tell the user the departure time  */                                          
  50. say 'If you want to arrive at 'p2' for 'arrive','
  51. say 'then you should leave 'p1' at 'start
  52.  
  53.                                        /* ask to see the route ?            */
  54. options prompt 'Do you want to see the route? (Y/N): '
  55. pull ans
  56.                                        /* if N then exit                    */
  57. if compare(left(ans,1),'N') == 0 then exit
  58.  
  59. 'dtime' start                          /* give GBR our calculated departure */
  60.                                        /* time                              */
  61. 'go'                                   /* and calculate the route...        */
  62.  
  63. say 'Calculating journey from: 'p1' to: 'p2 
  64. 'file' TEMPFILE
  65.                                        /* open file                         */
  66. open(file, TEMPFILE, read)
  67.                                        /* loop until the end of the file    */
  68. do while eof(file)=0
  69.                                        /* read a line from file             */
  70.    st = readln(file)
  71.                                        /* and print each line               */
  72.    say st
  73. end
  74.                                        /* close the file                    */
  75. close(file)
  76.  
  77. address command                        /* call dos 'delete' to remove the   */
  78.                                        /* temporary file                    */
  79. delete TEMPFILE
  80.  
  81. address 'GBR'                          /* back to GBR                       */
  82.  
  83. 'dist'                                 /* get the distance, time and cost   */
  84. d = result
  85. 'time'
  86. t = result
  87. 'cost'
  88. c = trunc(result/100,2)                /* fix to pounds.pence               */
  89.  
  90. say 'This journey costs £'c' and takes 't' minutes covering 'd' miles'
  91.  
  92. exit
  93.  
  94.  
  95.                                        /* calc_start                        */
  96. calc_start:
  97. arg arrv,time                          /* arrv, is the arrival time         */
  98.                                        /* time, is the journey time         */
  99.  
  100.                                        /* ignore > 24 hours                 */
  101.    if time > (24*60) then time = time // (24*60)
  102.  
  103.    hrstrt = substr(arrv,1,2)           /* get hours and mins from xx:xx     */
  104.    minstrt = substr(arrv,4,2)
  105.  
  106.    rt = hrstrt*60 + minstrt            /* convert to minutes                */
  107.  
  108.    nt = rt - time                      /* subtract journey time from        */
  109.                                        /* arrival time                      */
  110.    if nt < 0 then nt = nt + 24*60
  111.       
  112.    hrs = nt % 60                       /* convert back to hours and mins    */
  113.                                        /* checking for 0's                  */
  114.    if hrs < 10  then hrs = '0'hrs
  115.    if hrs == 0 then hrs = '00'
  116.    mins = nt // 60
  117.    if mins < 10 then mins = '0'mins
  118.    if mins == 0 then mins = '00'
  119.  
  120. return hrs':'mins                      /* return the departure time         */
  121.  
  122.