#!/bin/tcsh

set DUMP = "./dump2dbin"
set XNUM = 361
set YNUM = 289
set TMP  = temporally_file
set BOPT1 = '-Ba50f10:I:/a50f10:J::.TITLE:WeSn'


if( $# < 1 ) then
	echo $0 filename
	exit
endif

set PSOUT = $1:t:r.ps
set BOPT = `echo $BOPT1 | sed "s/TITLE/$1:t:r/"`

cc -o $DUMP ${DUMP}.c

echo "Checking " $1 

$DUMP $XNUM $YNUM $1 > $TMP
xyz2grd  ${TMP} -G${TMP}.grd -I1 -R1/${XNUM}/1/${YNUM}
# surface   ${TMP} -G${TMP}.grd -I1 -R1/${XNUM}/1/${YNUM}

set ZMIN = `grdinfo ${TMP}.grd | awk '/z_min/ {print $3}'`
set ZMAX = `grdinfo ${TMP}.grd | awk '/z_min/ {print $5}'`
set DZ = `grdinfo ${TMP}.grd | awk '/z_min/ {print ($5-$3)/20}'`

echo "Max:" $ZMAX "Min: " $ZMIN, "DZ: " $DZ

grd2cpt ${TMP}.grd -Cpolar > $TMP.cpt
#  makecpt -Cpolar -T${ZMIN}/${ZMAX}/${DZ} > ${TMP}.cpt

grdimage  ${TMP}.grd  -C${TMP}.cpt -JX10 ${BOPT} -R1/$XNUM/1/$YNUM -K > ${PSOUT}
psscale -D0/0/10/1 -C${TMP}.cpt -X12 -Y5 -O >> ${PSOUT}

rm $TMP $TMP.cpt
