#! /bin/csh -f

##################################################################
#
# uw 5-Apr-2004
# Script to generate SUN/BMP rasterfile from point data such as heights and deformation rates in map geometry
#
##################################################################

if ($#argv < 7)then
  echo " " 
  echo "usage: prasdt_pwr24 <plist_map> <pmask> <DEM_par> <pdata> <rec_num> <mli> <cycle> [radius]" 
  echo " " 
  echo "       plist_map  (input) point list containing map coordinates (int)"  
  echo "       pmask      (input) point data stack of mask values (uchar, pmask[i]=0 excludes point i, enter - if not available)"  
  echo "       DEM_par    (input) DIFF/GEO DEM parameter file"  
  echo "       pdata      (input) point data stack (float)"  
  echo "       rec_num    record number to process (default -: all records)"  
  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 DEM_par = $3
set pdata   = $4
set rec_num = $5
set mli     = $6
set cycle   = $7
set radius = "4"
if ($#argv >= 8)then
  set radius = $8
endif

set width = `awk '$1 == "width:" {printf("%s",$2)}' $DEM_par `
set nlines = `awk '$1 == "nlines:" {printf("%s",$2)}' $DEM_par `
set post_north = `awk '$1 == "post_north:" {printf("%s",$2)}' $DEM_par `
set post_east = `awk '$1 == "post_east:" {printf("%s",$2)}' $DEM_par `

set tmp = tmp.prasdt_pwr24_map
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
    pt2d $plist $pmask $pdata $rec $tmp $width $nlines $post_east $post_north 1 1 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"
  pt2d $plist $pmask $pdata $rec_num $tmp $width $nlines $post_east $post_north 1 1 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
