#! /bin/csh -f

source /mdisw/setup/setup_mdisoi
setenv SSW /ssw
setenv SSWDB /ssw/sswdb
setenv SSW_INSTR "mdi eit trace lasco sxt"
source $SSW/gen/setup/setup.ssw
unsetenv LM_LICENSE_FILE
setenv IDL_PATH "+~/idl:<IDL_DEFAULT>"


#### MAGNETOGRAMS ####  

/home/jsoc/cvs/JSOC/bin/linux_x86_64/jsoc_info op=rs_list ds=hmi.M_720s\[2011.02.14_12:00:00_TAI] key=T_REC,CROTA2,RSUN_OBS,CRPIX1,CRPIX2,CDELT1,CDELT2 seg=magnetogram  | grep keywords > latestHMImag.info
fixInfo.pl mag
sleep 5;
set TREC = `grep TREC latestHMImag.info2 | awk -F\= '{print $2}'`
set CROTA2 = `grep CROTA2 latestHMImag.info2 | awk -F\= '{print $2}'`
set RSUNOBS = `grep RSUNOBS latestHMImag.info2 | awk -F\= '{print $2}'`
set CRPIX1 = `grep CRPIX1 latestHMImag.info2 | awk -F\= '{print $2}'`
set CRPIX2 = `grep CRPIX2 latestHMImag.info2 | awk -F\= '{print $2}'`
set CDELT1 = `grep CDELT1 latestHMImag.info2 | awk -F\= '{print $2}'`
set CDELT2 = `grep CDELT2 latestHMImag.info2 | awk -F\= '{print $2}'`
set FILE = `grep FILE latestHMImag.info2 | awk -F\= '{print $2}'`


if ( $FILE == "NoDataDirectory" ) then 
  echo "Latest magnetogram missing: $TREC"
else
/ssw/gen/setup/ssw_idl <<BAR
.run fitsio_read_image.pro
.run HMIlatestMag.pro
HMIlatestMag, trec=$TREC, crota2=$CROTA2, rsunobs=$RSUNOBS, crpix1=$CRPIX1, crpix2=$CRPIX2, cdelt1=$CDELT1, cdelt2=$CDELT2, file=$FILE
BAR
endif

sleep 5;

#### Continuum ####

/home/jsoc/cvs/JSOC/bin/linux_x86_64/jsoc_info op=rs_list ds=hmi.Ic_720s\[2011.02.14_12:00:00_TAI] key=T_REC,CROTA2,RSUN_OBS,CRPIX1,CRPIX2,CDELT1,CDELT2 seg=continuum | grep keywords > latestHMIint.info

fixInfo.pl int
sleep 5;
set TREC = `grep TREC latestHMIint.info2 | awk -F\= '{print $2}'`
set CROTA2 = `grep CROTA2 latestHMIint.info2 | awk -F\= '{print $2}'`
set RSUNOBS = `grep RSUNOBS latestHMIint.info2 | awk -F\= '{print $2}'`
set CRPIX1 = `grep CRPIX1 latestHMIint.info2 | awk -F\= '{print $2}'`
set CRPIX2 = `grep CRPIX2 latestHMIint.info2 | awk -F\= '{print $2}'`
set CDELT1 = `grep CDELT1 latestHMIint.info2 | awk -F\= '{print $2}'`
set CDELT2 = `grep CDELT2 latestHMIint.info2 | awk -F\= '{print $2}'`
set FILE = `grep FILE latestHMIint.info2 | awk -F\= '{print $2}'`

if ( $FILE == "NoDataDirectory" ) then
  echo "Latest continuum file missing: $TREC"
else
/ssw/gen/setup/ssw_idl <<BAR
.run fitsio_read_image.pro
.run HMIlatestInt.pro
HMIlatestInt, trec=$TREC, crota2=$CROTA2, rsunobs=$RSUNOBS, crpix1=$CRPIX1, crpix2=$CRPIX2, cdelt1=$CDELT1, cdelt2=$CDELT2, file=$FILE
BAR
endif

sleep 5;

### Doppler ####

/home/jsoc/cvs/JSOC/bin/linux_x86_64/jsoc_info op=rs_list ds=hmi.V_720s\[2011.02.14_12:00:00_TAI] key=T_REC,CROTA2,RSUN_OBS,CRPIX1,CRPIX2,CDELT1,CDELT2,OBS_VR seg=Dopplergram | grep keywords > latestHMIdop.info

fixInfo.pl dop
sleep 5;
set TREC = `grep TREC latestHMIdop.info2 | awk -F\= '{print $2}'`
set CROTA2 = `grep CROTA2 latestHMIdop.info2 | awk -F\= '{print $2}'`
set RSUNOBS = `grep RSUNOBS latestHMIdop.info2 | awk -F\= '{print $2}'`
set CRPIX1 = `grep CRPIX1 latestHMIdop.info2 | awk -F\= '{print $2}'`
set CRPIX2 = `grep CRPIX2 latestHMIdop.info2 | awk -F\= '{print $2}'`
set CDELT1 = `grep CDELT1 latestHMIdop.info2 | awk -F\= '{print $2}'`
set CDELT2 = `grep CDELT2 latestHMIdop.info2 | awk -F\= '{print $2}'`
set OBSVR = `grep OBSVR latestHMIdop.info2 | awk -F\= '{print $2}'`
set FILE = `grep FILE latestHMIdop.info2 | awk -F\= '{print $2}'`

if ( $FILE == "NoDataDirectory" ) then
  echo "Latest dopplergram missing: $TREC"
else
  echo "Latest dopplergram: $TREC"
/ssw/gen/setup/ssw_idl <<BAR
.run fitsio_read_image.pro
.run HMIlatestDop.pro
HMIlatestDop, trec=$TREC, crota2=$CROTA2, rsunobs=$RSUNOBS, crpix1=$CRPIX1, crpix2=$CRPIX2, cdelt1=$CDELT1, cdelt2=$CDELT2, obsvr=$OBSVR, file=$FILE
BAR
endif


sleep 5;

### Line Depth ####

/home/jsoc/cvs/JSOC/bin/linux_x86_64/jsoc_info op=rs_list ds=hmi.Ld_720s\[2011.02.14_12:00:00_TAI] key=T_REC,CROTA2,RSUN_OBS,CRPIX1,CRPIX2,CDELT1,CDELT2,OBS_VR seg=linedepth | grep keywords > latestHMILd.info

fixInfo.pl ld
sleep 5;
set TREC = `grep TREC latestHMILd.info2 | awk -F\= '{print $2}'`
set CROTA2 = `grep CROTA2 latestHMILd.info2 | awk -F\= '{print $2}'`
set RSUNOBS = `grep RSUNOBS latestHMILd.info2 | awk -F\= '{print $2}'`
set CRPIX1 = `grep CRPIX1 latestHMILd.info2 | awk -F\= '{print $2}'`
set CRPIX2 = `grep CRPIX2 latestHMILd.info2 | awk -F\= '{print $2}'`
set CDELT1 = `grep CDELT1 latestHMILd.info2 | awk -F\= '{print $2}'`
set CDELT2 = `grep CDELT2 latestHMILd.info2 | awk -F\= '{print $2}'`
set OBSVR = `grep OBSVR latestHMILd.info2 | awk -F\= '{print $2}'`
set FILE = `grep FILE latestHMILd.info2 | awk -F\= '{print $2}'`

if ( $FILE == "NoDataDirectory" ) then
  echo "Latest Ldplergram missing: $TREC"
else
  echo "Latest Ldplergram: $TREC"
/ssw/gen/setup/ssw_idl <<BAR
.run fitsio_read_image.pro
.run HMIlatestLd.pro
HMIlatestLd, trec=$TREC, crota2=$CROTA2, rsunobs=$RSUNOBS, crpix1=$CRPIX1, crpix2=$CRPIX2, cdelt1=$CDELT1, cdelt2=$CDELT2, obsvr=$OBSVR, file=$FILE
BAR
endif


sleep 5;

### Line Width ####

/home/jsoc/cvs/JSOC/bin/linux_x86_64/jsoc_info op=rs_list ds=hmi.Lw_720s\[2011.02.14_12:00:00_TAI] key=T_REC,CROTA2,RSUN_OBS,CRPIX1,CRPIX2,CDELT1,CDELT2,OBS_VR seg=linewidth | grep keywords > latestHMILw.info

fixInfo.pl lw
sleep 5;
set TREC = `grep TREC latestHMILw.info2 | awk -F\= '{print $2}'`
set CROTA2 = `grep CROTA2 latestHMILw.info2 | awk -F\= '{print $2}'`
set RSUNOBS = `grep RSUNOBS latestHMILw.info2 | awk -F\= '{print $2}'`
set CRPIX1 = `grep CRPIX1 latestHMILw.info2 | awk -F\= '{print $2}'`
set CRPIX2 = `grep CRPIX2 latestHMILw.info2 | awk -F\= '{print $2}'`
set CDELT1 = `grep CDELT1 latestHMILw.info2 | awk -F\= '{print $2}'`
set CDELT2 = `grep CDELT2 latestHMILw.info2 | awk -F\= '{print $2}'`
set OBSVR = `grep OBSVR latestHMILw.info2 | awk -F\= '{print $2}'`
set FILE = `grep FILE latestHMILw.info2 | awk -F\= '{print $2}'`

if ( $FILE == "NoDataDirectory" ) then
  echo "Latest Lwplergram missing: $TREC"
else
  echo "Latest Lwplergram: $TREC"
/ssw/gen/setup/ssw_idl <<BAR
.run fitsio_read_image.pro
.run HMIlatestLw.pro
HMIlatestLw, trec=$TREC, crota2=$CROTA2, rsunobs=$RSUNOBS, crpix1=$CRPIX1, crpix2=$CRPIX2, cdelt1=$CDELT1, cdelt2=$CDELT2, obsvr=$OBSVR, file=$FILE
BAR
endif

