#! /bin/csh -f

##################################################################
#
# uw 24-Jun-2003
# Script to generate SUN/BMP rasterfile from point data such as heights and deformation rates
#
##################################################################

if ($#argv < 8)then
  echo " " 
  echo "usage: prasdt_pwr24 <plist> <pmask> <SLC_par> <pdata> <rec_num> <par_out> <mli> <cycle> [radius]" 
  echo " " 
  echo "       plist      (input) point list (int)"  
  echo "       pmask      (input) point data stack of mask values (uchar, pmask[i]=0 excludes point i, enter - if not available)"  
  echo "       SLC_par    (input) SLC parameter file of point list coordinates"  
  echo "       pdata      (input) point data stack (float)"  
  echo "       rec_num    record number to process (default -: all records)"  
  echo "       par_out    (input) SLC/MLI parameter file of 2-D output image data file"  
  echo "       mli        (input) 2-D image data file used as output image intensity"  
  echo "       cycle      data value per color cycle"  
  echo "       radius     interpolation window radius used default:   4.00)"  
  echo " " 
  exit
endif

set plist   = $1
set pmask   = $2
set SLC_par = $3
set pdata   = $4
set rec_num = $5
set par_out = $6
set mli     = $7
set cycle   = $8
set radius = "4"
if ($#argv >= 9)then
  set radius = $9
endif

set width = `awk '$1 == "range_samples:" {printf("%s",$2)}' $par_out `

set tmp = tmp.prasdt_pwr24
if (-e $tmp)then
  /bin/rm $tmp
endif

set npt    = `npt $plist | awk '$1 == "total_number_of_points:" {printf("%d",$2)}'`
set nbytes = `ls -l $pdata | awk '{printf("%d",$5)}'`
set nrec   = `echo $nbytes $npt 4|awk '{print ($1/$2/$3)}'`

if ("$rec_num" == "-") then
  set rec = 0
  while ($rec != $nrec)
    set rec = `echo $rec 1|awk '{print $1+$2}'`
    if ($rec < 10) then
      set fras = $pdata".0"$rec".ras"
    else
      set fras = $pdata"."$rec".ras"
    endif
    pt2data $plist $pmask $SLC_par $pdata $rec $tmp $par_out 2 3 $radius 1
    echo "data record: $rec"
    rasdt_pwr24 $tmp $mli $width 1 1 0 1 1 $cycle 1. .4 1 $fras
  end
else
  echo "data record: $rec_num"
  set fras = $pdata".ras"
  pt2data $plist $pmask $SLC_par $pdata $rec_num $tmp $par_out 2 3 $radius 1
  rasdt_pwr24 $tmp $mli $width 1 1 0 1 1 $cycle 1. .4 1 $fras
endif

if (1) then
  if (-e $tmp)then
    /bin/rm $tmp
  endif
  if ("$rec_num" == "-") then
    eog $pdata.*.ras &
  else
    echo "data record: $rec_num"
    eog $pdata.ras &
  endif
endif
