# Time-stamp: </wrf/c/hydrog/fns, Sun, 24 Apr 2011, 13:53:21 EDT, http://wrfranklin.org/>

# Process n x n terrain.
# Usage:  don DATA N
# DATA is expanded to data/DATA.elevb
# E.g. don ps_height_4k 4097 

function don() {
   local m
   echo -n '*****DON START*****'
   date
   time hydrog $2 < data/$1.elevb
   echo -n '*****DON END*****'
   date
#   composite $1-edges.pbm data/$1.jpg -compose darken $1-edgesover.png
    convert  flow.pgm  out/$1-flow.png
    convert  flow.pgm -gamma 5 -normalize out/$1-flow2.png
    mergeflow $1
    rm -f flow.pgm
}


function doall() {
don mtn1 400
don mtn2 400
don mtn3 400
don hill1 400
don hill2 400
don hill3 400
don ps1k 1025
don ps4k 4097
}

# e.g. doflow2 ps1k
function doflow2() {
    convert  $1-flow.png -gamma 5 -normalize $1-flow2.png
}

function domtn2() {
don mtn2 400
}

function do1k() {
don ps1k 1025
}

function inpe() {
gdal_translate -ot UInt16 -of PNM -srcwin 1 1 3000 3000  23_48_ZN.tif e3000.pgm
tail -n +4 e3000.pgm >! e3000.elevb
}

function mountdata() {
fusecompress dataraw data
}

function umountdata() {
fusermount -u data
}

function dohist() {
tr ' ' '
' < $1.txt | tr -d ' 
' | tr ',' '.' | sort | uniq -c > $1.hist
}

function doscale() {
   sed 's/,/./g ' $1.txt  | ./scale $2 $3 > /dev/shm/$1.elevb
}

function doelevb() {
tail -n +7 $1.asc |  sed 's/,/./g ' | scale >! $1.elevb
}




function mergeflow() {
    convert out/$1-flow.png  -gamma 5 -normalize -negate data/$1.jpg -compose darken -composite out/$1-m.jpg
    xv out/$1-m.jpg&
}
