#!/bin/bash

for file in *bath.grd *geo.grd
do
    echo
    echo processing $file
    echo
    #mbm_arc2grd -I$file -O${file%%.asc}.grd
    X=`grdinfo ${file}|grep x_min`
    Y=`grdinfo ${file}|grep y_min`

    XMIN=`echo $X | awk '{print $3}'`
    XMAX=`echo $X | awk '{print $5}'`
    YMIN=`echo $Y | awk '{print $3}'`
    YMAX=`echo $Y | awk '{print $5}'`

    echo $XMIN $XMAX
    echo $YMIN $YMAX

    XAVE=`echo $XMIN $XMAX | awk '{print ($1+$2)/2.}'`
    YAVE=`echo $YMIN $YMAX | awk '{print ($1+$2)/2.}'`

    echo $XAVE $YAVE

    out=${file%%.grd}-bbox.iv
cat <<EOF > $out
#Inventor V2.1 ascii
Separator {
        Coordinate3 { point [
                             $XMIN $YMIN 0.,
                             $XMAX $YMIN 0.,
                             $XMAX $YMAX 0.,
                             $XMIN $YMAX 0.
			    ] }
        #IndexedFaceSet { coordIndex [ 0, 1, 2, 3, -1, ]}
        BaseColor { rgb [ 1 0 0] }
        IndexedLineSet { coordIndex [ 0, 1, 2, 3, 0 ] }

	Translation { translation $XAVE $YAVE 0.05 }
	Scale { scaleFactor .002 .002 .002 }
	BaseColor { rgb [ 1 1 1] }
	Text3 { string "${file%%.grd}" }
}

EOF

    #echo "$XMIN $YMIN 0.," >> $out

done