#! /bin/csh -f

set echo

set ID = $1
set SERIES = aia.lev1_nrt2
set SERIES_HG = $SERIES"_hgpatch"
# set PARMS = ( -t locunits=pixels boxunits=pixels t_ref=2011.12.15_TAI x=2248 y=2448 width=2000 height=1000 requestid=$ID)
set PARMS = ( -t locunits=pixels boxunits=pixels t_ref=2011.12.15_TAI x=3096 y=3496 width=1000 height=1000 requestid=$ID)

set prev_count = `show_info -cq $SERIES_HG'[][]['$ID']'`
set new_sn = `show_info -q $SERIES'[2011.12.15/2d][? FSN < 400000000 ?][? WAVELNTH=171 ?]' n=-1 key=FSN `
if ($prev_count > 0) then
  set prev_sn = `show_info -q $SERIES_HG'[][$]['$ID']' key=FSN`
  @ prev_sn = $prev_sn + 1
else
  @ prev_sn = $new_sn - 2
  set prev_sn = 38160319
endif

  set prev_sn = 38162711
set new_sn = 38163750
im_patch $PARMS in=$SERIES'[]['$prev_sn'-'$new_sn'][? WAVELNTH=171 ?]' log=hg_patch.log 
