#! /bin/csh -f

set VERS = $1
set CT = /home/phil/apps/heat.sao
set MIN=0
set MAX=500
set MIN=1.7
set MAX=4.7
# set MAX=40000

show_info ds=@hg_patch.log -pAq  n=1000 > pt
cat pt >> $VERS'_fits'

cd images
set ibase = `/bin/ls | grep $VERS'_' | wc -l`

set n = `wc -l <../pt`

set i=1
while ($i <= $n)
  @ ilab = $i + $ibase
  set I = `printf "%0.4d" $ilab`
  set this = `head --lines $i ../pt | tail -1`
  set rec = `head --lines $i ../hg_patch.log | tail -1`
  imcopy $this'[1]' this.fits
  set tim = `show_info "$rec" -q key=T_OBS `
  fits_to_ppm +l in=this.fits table=$CT MIN=$MIN MAX=$MAX | \
# fits_to_ppm  in=this.fits table=$CT MIN=$MIN MAX=$MAX | \
    ppmlabel -color white -background black -size 9 -x 10 -y 390 -text "SDO/HMI $tim" |\
    pnmtojpeg -quality=95 >$VERS'_'$I.jpg
  rm this.fits
  @ i = $i + 1
end


