;+
; NAME:
;     TPCALCHEK
; PURPOSE:
;     Main routine to analyze total power calibration data (just a
;     date-sensitive shell to call TPCALCHEK1, TPCALCHEK2, etc.).
; CATEGORY:
;     OVRO APC DATA CALIBRATION
; CALLING SEQUENCE:
;     tpcalchek[,filename][,hrec | ,after=after][,debug][,/cmdfile]
; INPUTS:
;     filename   the name of the file containing TPCAL data.  If
;                  omitted, the file DAILY.ARC in directory
;                  !DEFAULTS.WORKDIR is assumed.
;     hrec       the record number of the TPCAL scan header.  Data
;                  will be processed up to the next EOS segment.
;                  If this argument is given, then AFTER keyword
;                  is ignored.
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;     after      an optional time string of the standard form
;                  [yyyy.ddd ]hh:mm[:ss]m after which to start
;                  looking for a valid TPCAL scan.
;     cmdfile    a switch that indicates that the routine was called
;                  from a command file, so issue no modal messages, and
;                  print any error messages to <WORKDIR>\TPCAL.MSG.
;     debug      a switch that activates some debugging statements
;                  for getting an indication of intermediate steps.
;                  This switch is not compatible with /CMDFILE switch.
; ROUTINES CALLED:
;     break_file, tpcalchek1, tpcalchek2
; OUTPUTS:
; COMMENTS:
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     Written 28-Aug-2000 by Dale E. Gary
;-

pro tpcalchek,filename,hrec,after=after,debug=debug,cmdfile=cmdfile

   ; Update this to the date that the latest version goes into effect
   yrday_latest = 2000.100
   ; Determine the date from the filename
   break_file,filename,disk,dir,stem,ext

   ; If the filename is DAILY.ARC, set to use the latest version
   if (strupcase(stem) eq 'DAILY') then begin
      yrday = yrday_latest
   endif else begin
      year = (byte(strmid(strupcase(stem),0,1))+1929)(0)
      doy = strmid(stem,1,3)
      yrday = year+(doy/1000.)
   endelse

   ; Call routines according to date of data
   case 1 of
      yrday lt 2000.100: begin
            tpcalchek1,filename,hrec,after=after,debug=debug,cmdfile=cmdfile
         end
      yrday ge yrday_latest: begin
            tpcalchek2,filename,hrec,after=after,debug=debug,cmdfile=cmdfile
         end
   endcase

return
END