;+ ; NAME: ; smei_www_skymaps ; PURPOSE: ; Creates the html tables showing available skymaps ; on SMEI website. ; CALLING SEQUENCE: PRO smei_www_skymaps, mode, $ supercat = supercat , $ update = update , $ lastmonths = lastmonths, $ remote = remote , $ silent = silent ; OPTIONAL INPUTS: ; mode array or scaler; type: integer; default: 'sky' ; modes to be processed ; INCLUDE: @compile_opt.pro ; CALLS: ; InitVar, TimeUnit, CheckDir, TimeUnit, boost, txt_read ; TimeSet, TimeSystem, FindAllFiles, smei_coriolis ; GetFileSpec, hide_env ; PROCEDURE: ; MODIFICATION HISTORY: ; OCT-2006, Paul Hick (UCSD/CASS) ; JAN-2010, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Bug fix in construction of index.html with /update set when ; crossing from one year to the next. ;- InitVar, supercat , /key InitVar, update , /key InitVar, lastmonths , 1 InitVar, silent , 0 is_remote = IsType(remote,/defined) IF IsType(mode, /undefined) THEN BEGIN smei_www_skymaps, 'sky', supercat=supercat, update=update, remote=remote IF supercat THEN BEGIN smei_www_skymaps, 'equ', supercat=supercat, update=update, remote=remote, lastmonths=lastmonths smei_www_skymaps, 'pnt', supercat=supercat, update=update, remote=remote, lastmonths=lastmonths smei_www_skymaps, 'ecl', supercat=supercat, update=update, remote=remote, lastmonths=lastmonths ENDIF RETURN ENDIF CASE supercat OF 1: BEGIN destination = filepath(root=getenv('HOME'),subdir=['public_html','smei'],mode) bkg_white = '../../images/bkg_white.gif' logo = '../../images/logo_poncho_small.png' button_vmark_sci= '../../images/button_checkmark_blue.gif' button_vmark_eng= '../../images/button_checkmark_green.gif' button_xmark = '../../images/button_xmark_red.gif' acknowledgement = '../../acknowledgements.html' home_page = '../../index.html' smei_page = '../../smei/index.html' arrow_up = '../../images/arrow_up.png' arrow_left = '../../images/arrow_left.png' arrow_right = '../../images/arrow_right.png' question_mark = '../images/question_mark.gif' anon_ftp = 'ftp://supercat.ucsd.edu' banner_tag = 'poncho' END 0: BEGIN destination = filepath(root='/var',subdir=['www','html'],mode) bkg_white = 'bkg_white.gif' logo = 'logo_poncho_small.png' button_vmark_sci= 'button_checkmark_blue.gif' button_vmark_eng= 'button_checkmark_green.gif' button_xmark = 'button_xmark_red.gif' acknowledgement = 'acknowledgements.html' home_page = 'http://cass.ucsd.edu/solar/index.html' smei_page = '/index.html' arrow_up = 'arrow_up.png' arrow_left = 'arrow_left.png' arrow_right = 'arrow_right.png' question_mark = 'question_mark.gif' anon_ftp = 'ftp://smei.ucsd.edu' banner_tag = 'smei' END ENDCASE question_mark = '' arrow_up = '' arrow_left = '' arrow_right = '' button_vmark_sci = '' button_vmark_eng = '' button_xmark = '' root = getenv('SMEISKY0') source = filepath(root=root,mode) camera = [1,2,3] CASE is_remote OF 0: BEGIN IF NOT CheckDir(destination,/silent) THEN BEGIN message, /info, 'destination does not exist, '+hide_env(destination) RETURN ENDIF remote_destination = destination END 1: BEGIN remote_destination = remote+(['',':'])[strpos(remote,':') EQ -1]+destination destination = getenv('TUB') END ENDCASE ncam = n_elements(camera) camskyname = ptrarr(ncam,/allocate) ; File names of skymaps camskymode = ptrarr(ncam,/allocate) camskyftp = ptrarr(ncam,/allocate) FOR icam=0,ncam-1 DO BEGIN cam_id = camera[icam] ; Attach subdirectory c to each entry of source camsource = filepath(root=source,'c'+strcompress(cam_id,/rem)) ; Locate all the skymaps ; The directories may contain lots of files so we pick up all files, ; then sort things out later. tmp = FindAllFiles(paths=camsource+['','m0'], /nodir, count=count) ; Now sort out the skymaps for the proper camera prefix = 'c'+strcompress(cam_id,/rem)+mode+'_' i = where(strpos(GetFileSpec(tmp,part='name'),prefix) EQ 0, count) CASE count EQ 0 OF 0: tmp = tmp[i] 1: tmp = '' ENDCASE SetFileSpec, tmp, /strict *camskyname[icam] = GetFileSpec(part='name') *camskymode[icam] = GetFileSpec(GetFileSpec(upto='directory',/asfile),part='name') EQ 'c'+strcompress(cam_id,/rem)+'m0' *camskyftp [icam] = strmid(tmp,strlen(root)) ENDFOR uyr = TimeUnit(/year) usec = TimeUnit(/sec ) ;======================================================= ; The time format must match the format used by smei_orbits.pro format = 'YEAR/MN/DD (DOY) hh:mm:ss.mss' nformat = strlen(format) tt_end = TimeSystem(/silent) CASE update OF 0: tt_beg = TimeSet( yr=2003, doy=33 ) 1: tt_beg = TimeSet( yr=TimeGet(tt_end,/year), mon=TimeGet(tt_end,/month)-lastmonths, day=1 ) ENDCASE orbit_beg = smei_coriolis(tt_beg, /number)+1 orbit_end = smei_coriolis(tt_end, /number)+1 iyr_last = -1 mon_last = '' diff_last = 0 xysize = [800,400] xyplus = 'width='+strcompress(xysize[0]+10,/rem)+',height='+strcompress(xysize[1]+10,/rem) xysize = '[' +strcompress(xysize[0] ,/rem)+',' +strcompress(xysize[1] ,/rem)+']' ;http = "http://supercat.ucsd.edu/smei/sky/" http = "" content_lead_1 = [ $ '' , $ '' , $ ' SMEI Skymaps' , $ ' ' , $ ' ' , $ '' , $ '' , $ ' ";' , $ '' , $ ' } else {' , $ '' , $ ' $b = strtok($orbit,"[,]");', $ ' $name = "'+mode+'_$oname$b";', $ ' $pngname = "$name.png";' , $ ' $pngfile = "/tmp/$pngname";' , $ '' , $ ' if ( is_file("$pngfile") ) {' , $ '' , $ ' touch("$pngfile");' , $ '' , $ ' } else {' , $ '' , $ " if ($oname == 'default') {", $ ' $idlcmd = "smei_sky, $orbit, charsize=1.5, xysize='+xysize+', silent=2, breakval=5*lindgen\(200\), sn_position=[0.0,-2.0,0.0,1.0],/fixgain,/exact,/legend";',$ ' } else {' , $ ' $idlcmd = "smei_sky, $orbit, charsize=1.5, xysize='+xysize+', silent=2, sn_position=[0.0,-2.0,0.0,1.0],/fixgain,/exact,/legend,/flip_ct,timeavgcam=3";', $ ' }' , $ '' , $ ' echo `source /zshare/smei/com/linux/login nobody /zshare/smei /zshare/dat /zshare/ssw /zshare/sswdb notemp;', $ ' IDL_DEV=Z,none;' , $ ' export IDL_DEV;' , $ ' echo $idlcmd, mode=\"'+mode+'\", imgfile=\"$pngfile\", logo=\"lr:'+logo+'\" | /zshare/rsi/idl/bin/idl -quiet`;', $ '' , $ ' }' , $ '' , $ ' echo "' , $ '', $ ' ";' , $ '' , $ ' }' , $ '' , $ '?>' , $ '' ] content_lead_3 = [ $ '' , $ '
' , $ '' , $ '' ] content_trail = [ $ '
OrbitDateDOYTimeC1C2C3
' , $ '
' , $ '' , $ '' ] count = 0 month_count = 0 FOR orbit=orbit_beg,orbit_end DO BEGIN torbit = TimeSet(smei=orbit) iyr = TimeGet(torbit, uyr, /scalar) imon = TimeGet(torbit, /month, /scalar) mon = TimeMonth(imon) ; If a new month starts, then write the php file for the previous month IF (iyr_last NE -1 AND (iyr NE iyr_last OR mon NE mon_last)) OR orbit EQ orbit_end THEN BEGIN iyrmon_id = mode+'_'+strcompress(iyr_last,/rem)+'_'+strlowcase(mon_last) bracket = Timeset(yr=iyr_last,mon=TimeMonth(mon_last)+[-1,1]) bracket = mode+'_'+strcompress(TimeGet(bracket,uyr),/rem)+'_'+strlowcase(TimeMonth(TimeGet(bracket,/month))) bracket += '.php' content_arrow = $ ['' , $ '' , $ '' , $ ' ' , $ ' ' , $ ' ' , $ '' , $ '
'+button_vmark_sci+'= Science Mode'+button_vmark_eng+'= Engineering Mode'+button_xmark +'= No Data
' , $ '' , $ '
' , $ "'+question_mark+'', $ ''+arrow_up+''] CASE month_count EQ 0 OF 0: boost, content_arrow, ''+arrow_left+'' 1: boost, content_arrow, arrow_left ENDCASE CASE orbit EQ orbit_end OF 0: boost, content_arrow, ''+arrow_right+'' 1: boost, content_arrow, arrow_right ENDCASE boost, content_arrow, ['
',''] CASE count GT 0 OF 0: content = [ $ content_lead_1 , $ content_arrow , $ content_lead_3 , $ content_trail ] 1: content = [ $ content_lead_1 , $ content_arrow , $ content_lead_3 , $ content , $ content_trail ] ENDCASE file = filepath(root=([destination,remote_destination])[is_remote], iyrmon_id+'.php') message, /info, hide_env(file) IF is_remote THEN $ file = filepath(root=destination, GetFileSpec(file,from='name')) openw, /get_lun, iu, file FOR i=0,n_elements(content)-1 DO printf, iu, content[i] free_lun, iu IF is_remote THEN $ spawn, 'scp -q '+file+' '+remote_destination+'; rm -f '+file IF orbit EQ orbit_end THEN BEGIN ptr_free, camskyname ptr_free, camskymode ptr_free, camskyftp break ENDIF destroyvar, content count = 0 month_count++ ENDIF torbit_string = TimeGet(torbit,upto=usec,/round,/scalar,/_ydoy) corbit = strcompress(orbit,/rem) line = '' line += ''+string(orbit,format='(I5.5)')+''+ $ ''+TimeGet(torbit,/scalar,format='YYYY/MN/DD')+''+ $ ''+TimeGet(torbit,/scalar,format='DOY' )+''+ $ ''+TimeGet(torbit,upto=usec,/round,/scalar,format='hh:mm:ss')+'' map_found = 0 FOR icam=1,3 DO BEGIN tmp = 'c'+strcompress(icam,/rem)+mode+'_'+torbit_string tmp = (where(tmp EQ *camskyname[icam-1]))[0] CASE tmp NE -1 OF 0: line += ''+button_xmark+'' 1: BEGIN line += '' ;line += '' line += ([button_vmark_sci,button_vmark_eng])[(*camskymode[icam-1])[tmp]] ;line += '' line += '' map_found++ END ENDCASE ENDFOR iyrmon_id = mode+'_'+strcompress(iyr,/rem)+'_'+strlowcase(mon) field1 = 'Full-Sky' IF map_found EQ 0 THEN field1 = '';strjoin(replicate(' ',strlen(field1))) field2 = 'Difference' IF map_found EQ 0 OR NOT diff_last THEN field2 = '';strjoin(replicate(' ',strlen(field2))) field3 = 'Custom' IF map_found EQ 0 THEN field3 = '';strjoin(replicate(' ',strlen(field3))) line += ''+field1+''+field2+''+field3+'' line += '' boost, content, line iyr_last = iyr mon_last = mon diff_last = map_found GT 0 count += map_found ENDFOR destroyvar, content ; Construct index.html file CASE update OF 0: content_lead_1 = [ $ '' , $ '' , $ '' , $ 'SMEI Skymaps' , $ '' , $ '' , $ '' , $ '' , $ '' , $ '' ] 1: BEGIN file = filepath(root=([destination,remote_destination])[is_remote],'index.html') message, /info, hide_env(file) ; Read the index.html file (after retrieving it from the remote machine, ; if necessary (we need to update the old content). IF is_remote THEN BEGIN spawn, 'scp -q '+file+' '+destination file = filepath(root=destination,GetFileSpec(file,from='name')) ENDIF tmp = txt_read(file,content_lead_1) IF is_remote THEN spawn, 'rm -f '+file IF NOT tmp THEN RETURN month_beg = TimeGet(tt_beg,/month,/scalar) month_end = TimeGet(tt_end,/month,/scalar) ; Updates are to start at iyr_beg, month_beg tmp = mode+'_' + $ strcompress(TimeGet(tt_beg,/year),/rem)+'_'+ $ strlowcase(TimeMonth(month_beg))+'.php' ; Keep php file up to (but not including) iyr_beg, month_beg tmp = (where(strpos(content_lead_1,tmp) NE -1))[0] content_lead_1 = content_lead_1[0:tmp-1] END ENDCASE content_trail = [ $ '
' , $ '
' , $ 'Last Updated '+TimeGet(/ymd,TimeSystem(/silent),upto=TimeUnit(/min))+'', $ '' , $ '' , $ '' , $ '' ] iyr_beg = TimeGet(tt_beg, uyr, /scalar) iyr_end = TimeGet(tt_end, uyr, /scalar) FOR iyr=iyr_beg,iyr_end DO BEGIN ; Do not start a new year in the first year of an update ; (we just want to continue adding months). IF NOT update OR iyr NE iyr_beg THEN boost, content, ['',''] FOR mon=1,12 DO BEGIN IF update THEN BEGIN ; In update mode skip in iyr_beg until month_beg is reached ; and brek in iyr_end if month_end is reached IF iyr EQ iyr_beg AND mon LT month_beg THEN continue IF iyr EQ iyr_end AND mon GT month_end THEN break ENDIF cmon = TimeMonth(mon) ciyr = strcompress(iyr,/rem) line = ' ' file = filepath(root=([destination,remote_destination])[is_remote],mode+'_'+ciyr+'_'+strlowcase(cmon)+'.php') message, /info, 'check '+hide_env(file) IF is_remote THEN BEGIN spawn, 'scp -q '+file+' '+destination ;+' 2> /dev/null' file = filepath(root=destination,GetFileSpec(file,from='name')) ENDIF IF (file_search(file))[0] NE '' THEN BEGIN line += ''+ciyr+' '+strmid(cmon,0,1)+strlowcase(strmid(cmon,1,2))+'' IF is_remote THEN spawn, 'rm -f '+file ENDIF line += '' boost, content, line ENDFOR boost, content, '' ENDFOR boost, content, '' content = [ $ content_lead_1 , $ content , $ content_trail ] file = filepath(root=([destination,remote_destination])[is_remote],'index.html') message, /info, hide_env(file) IF is_remote THEN $ file = filepath(root=destination,GetFileSpec(file,from='name')) openw, /get_lun, iu, file FOR i=0,n_elements(content)-1 DO printf, iu, content[i] free_lun, iu IF is_remote THEN $ spawn, 'scp -q '+file+' '+remote_destination+'; rm -f '+file RETURN & END