; Write SECCHI FSW schedule file
; $Revision: 1.3 $
; $Date: 2007/07/26 15:13:35 $
; $Modtime:$
; $Author: wang $
; $Log: scc_schedule.pro,v $
; Revision 1.3  2007/07/26 15:13:35  wang
; Added ability to handle multiple passes and comments in schedule file
;
;
; Called by blocksched.pro
;
PRO scc_schedule,blockname,blockcomments,writefile=writefile

beginline='---00000000B16B0'
endline='---00000000T16C2'

ymmdd=' '
print,'Enter Schedule YMMDD :'
tryagain:
read,ymmdd
if strlen(ymmdd) ne 5 then begin
 print,'ymmdd must be exactly 5 characters!'
 goto,tryagain
endif

print,beginline
if keyword_set(writefile) then BEGIN 
 openw,lun,'schedule.sch',/GET_LUN
 printf,lun,"# Generated by scc_schedule $Revision: 1.3 $"
 printf,lun,beginline
endif

for icount=0,11 do begin
 hh=icount * 2
 hour=strtrim(string(hh),2)
 if(hh lt 10) then hour='0'+hour

 mm=0
 if(icount eq 0) then  mm = 5
 minute=strtrim(string(mm),2)
 if(minute lt 10) then minute='0'+minute

 print,format='(1H#,1x,A50)',blockcomments(icount)
 print,format='(A5,I02,I02,7H00F2800,A12)', $
  strtrim(string(ymmdd),2),hh,mm,blockname(icount)

 if keyword_set(writefile) then  $
  printf,lun,format='(1H#,1x,A50)',strtrim(blockcomments(icount),2)
  printf,lun,format='(A5,I02,I02,7H00F2800,A12)', $
   strtrim(string(ymmdd),2),hh,mm,blockname(icount)
endfor

print,endline
if keyword_set(writefile) then BEGIN 
 printf,lun,endline
 close,lun
endif

spawn,'uname',os

if( strcmp(os,'Linux') eq 1 ) then print,'Run Solaris command: fix_schedule schedule.sch 0'+strtrim(string(ymmdd),2)+'00.sch'

if( strcmp(os,'SunOS') eq 1 ) then spawn,'fix_schedule schedule.sch 0'+strtrim(string(ymmdd),2)+'00.sch'
end
