#!/usr/local/bin/tops -s /usr/local/tops/sys -u /opt/mytops/usr/

# File eod1bch, October 2004

# End of day collection of pit data

#-----------------------------------------------------------------------

   usrpath "mget.v" + source
   keys? not IF LOG-FILE set_sysout THEN

   ontheweb
   IF " eod1bch: skipping electronic end of day collection" . nl
      exit
   THEN
 
   usrpath "eod_params" + "host" param_find "HOST" book

   host HOST <>
   IF " eod1bch: only on " . HOST . nl 
      host "plunger" = \ ring the bell if plunger:
      IF no catmsg "snd.v" source 2 TING (qFile)
         (qFile) dup remote_wavPlayq 
         " eod1bch: playing sound file " . dup . sp date . nl
         (qFile) deleteif
      THEN
      exit 
   THEN
 
   "/tmp" chdir

   inline: bcSAVE ( --- ) \ save bc data at end of day
      [ mpath time GMT>LA ctime 1st quote strchop
        sysdate drop intstr ".dat" cat cat "FILE" book
      ]
      " bcSAVE: begin " date + . nl
      bcEOD any? not
      IF 10 idle
         bcEOD any? not
         IF " bcSAVE: two attempts failed" ersys "" THEN
      THEN

      any?
      IF FILE file? IF FILE FILE ".old" + fcopy THEN
         (hT) FILE save " bcSAVE: file saved " date + . nl
      ELSE
         " bcSAVE: failed " date + . nl
      THEN
   end
   bcSAVE
  
   ontheweb not
   drop 
   no
   IF tcCOLLECT "bcSAVE" "FILE" yank -ext "_tch.dat" + save
      " tcCOLLECT: file saved " date + . nl
   THEN
  
   ontheweb not
   IF no catmsg "snd.v" source 2 TING (qFile)
      (qFile) dup remote_wavPlayq 
      " eod1bch: playing sound file " . dup . sp date . nl
      (qFile) deleteif
   THEN

   " eod1bch: ending" . nl

   exit
