#! /bin/csh -f

##################################################################
#
# uw 5-Apr-2004
# Script to generate SUN/BMP rasterfile from point data such as differential interferograms in map geometry
#
##################################################################

if ($#argv < 6)then
  echo " " 
  echo "usage: prasmph_pwr24_map <plist_map> <pmask> <DEM_par> <pdiff> <rec_num> <mli> [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 "       pdiff      (input) point data stack (fcomplex)"  
  echo "       rec_num    record number to process (default -: all records)"  
  echo "       mli        (input) 2-D image data file used as output image intensity"  
  echo "       radius     interpolation window radius used default:   4.00)"  
  echo " " 
  exit
endif

set plist   = $1
set pmask   = $2
set DEM_par = $3
set pdiff   = $4
set rec_num = $5
set mli     = $6
set radius = "4"
if ($#argv >= 7)then
  set radius = $7
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.prasmph_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 $pdiff | awk '{printf("%d",$5)}'`
set nrec   = `echo $nbytes $npt 8|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 = $pdiff".0"$rec".ras"
    else
      set fras = $pdiff"."$rec".ras"
    endif
    pt2d $plist $pmask $pdiff $rec $tmp $width $nlines $post_east $post_north 1 1 0 3 $radius 1
    echo "data record: $rec"
    rasmph_pwr24 $tmp $mli $width 1 1 0 1 1 1. .4 1 $fras
  end
else
  echo "data record: $rec_num"
  set fras = $pdiff".ras"
  pt2d $plist $pmask $pdiff $rec_num $tmp $width $nlines $post_east $post_north 1 1 0 3 $radius 1
  rasmph_pwr24 $tmp $mli $width 1 1 0 1 1 1. .4 1 $fras
endif

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