| 1 |
#!/bin/csh -f |
| 2 |
### ascii2grdAutoMinMaxHDR -- transform 3 col ascii in GMT grd (float) format |
| 3 |
### with pixel size forced to 0,0009 degrees, that is about 25m |
| 4 |
### and remove the header, then create an ENVI header |
| 5 |
### It execute first minmax to get the min/max coord. |
| 6 |
### It requires the GMT fct 'nearneighbor' that may pose prblms on some systems |
| 7 |
### ARG = ascii file to transform |
| 8 |
### Adjust script for UTM or Lon/Lat and output as Small or Big Endian |
| 9 |
### $Id: ascii2grd,v 1.1 2007/04/19 NdOreye $ |
| 10 |
################################################################ |
| 11 |
set PRG = `basename "$0"` |
| 12 |
set VER = "v1.0 doris script utilities" |
| 13 |
set AUT = "nicolas doreye, (c)2006" |
| 14 |
echo "$PRG $VER, $AUT" |
| 15 |
echo " " |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
### Handle wrong input |
| 20 |
set WRONG = "0" |
| 21 |
set ASCII = "$1" |
| 22 |
if ( $#argv < 1 ) set WRONG = "1" |
| 23 |
#--------------------------- |
| 24 |
if ( $WRONG == "1" ) then |
| 25 |
cat << __EOFHD |
| 26 |
|
| 27 |
USAGE: |
| 28 |
$PRG ascii3column |
| 29 |
This program transforms the 3 column ascii file of Doris |
| 30 |
(created with LonLat???2ascii) to GMT grd file then remove the header |
| 31 |
in order to be opened by ENVI for instance, then create the appropriate header |
| 32 |
|
| 33 |
First run the program lonlat???2ascii to create the 3 column ascii input file |
| 34 |
|
| 35 |
|
| 36 |
EXAMPLE: |
| 37 |
$PRG lonlatSomething.dat |
| 38 |
|
| 39 |
See also: http://www.remotesensing.org/proj |
| 40 |
|
| 41 |
__EOFHD |
| 42 |
exit 1 |
| 43 |
endif |
| 44 |
echo "-----------------------------" |
| 45 |
echo " compute Min Max Lon and Lat" |
| 46 |
echo "-----------------------------" |
| 47 |
### this part is taken from B Kampes script asci2ps |
| 48 |
### Get min/max and increment from data itselves. |
| 49 |
### Assume lat/lon is formatted as %7.4f? |
| 50 |
### Not robust yet? |
| 51 |
echo "finding out minmax in ascii column data - may take some time !" |
| 52 |
set minmax = `minmax $ASCII` |
| 53 |
echo $minmax |
| 54 |
set WEST = `echo $minmax | cut -d '<' -f2 | cut -d'/' -f1` |
| 55 |
set EAST = `echo $minmax | cut -d '<' -f2 | cut -d'/' -f2 | cut -d'>' -f1` |
| 56 |
set SOUTH = `echo $minmax | cut -d '<' -f3 | cut -d'/' -f1` |
| 57 |
set NORTH = `echo $minmax | cut -d '<' -f3 | cut -d'/' -f2 | cut -d'>' -f1` |
| 58 |
set MINHEI = `echo $minmax | cut -d '<' -f4 | cut -d'/' -f1` |
| 59 |
set MAXHEI = `echo $minmax | cut -d '<' -f4 | cut -d'/' -f2 | cut -d'>' -f1` |
| 60 |
echo " " |
| 61 |
### handle 1e+06 format gracefully? |
| 62 |
#set EAST = `echo $EAST | awk '{printf "%.20f", $1}'` |
| 63 |
#set WEST = `echo $WEST | awk '{printf "%.20f", $1}'` |
| 64 |
#set SOUTH = `echo $SOUTH | awk '{printf "%.20f", $1}'` |
| 65 |
#set NORTH = `echo $NORTH | awk '{printf "%.20f", $1}'` |
| 66 |
echo "Using the following parameters:" |
| 67 |
echo "-------------------------------" |
| 68 |
echo "WEST: $WEST" |
| 69 |
echo "EAST: $EAST" |
| 70 |
echo "SOUTH: $SOUTH" |
| 71 |
echo "NORTH: $NORTH" |
| 72 |
echo "MINHEI: $MINHEI" |
| 73 |
echo "MAXHEI: $MAXHEI" |
| 74 |
|
| 75 |
|
| 76 |
echo " " |
| 77 |
echo "convert ascii to grd with GMT command nearneighbor using $WEST/$EAST/$SOUTH/$NORTH" |
| 78 |
|
| 79 |
# nearneighbor $ASCII -G$ASCII.grd -R$WEST/$EAST/$SOUTH/$NORTH -I25e=/25e= -S0.0009 -V |
| 80 |
# nearneighbor $ASCII -G$ASCII.grd -R$WEST/$EAST/$SOUTH/$NORTH -I0.006n=/0.006n= -S0.012m -V |
| 81 |
nearneighbor $ASCII -G$ASCII.grd -R$WEST/$EAST/$SOUTH/$NORTH -I0.001=/0.001= -S0.001 -V #AO |
| 82 |
# nearneighbor $ASCII -G$ASCII.grd -R$WEST/$EAST/$SOUTH/$NORTH -I0.000224804 -S0.0009 -V |
| 83 |
# xyz2grd $ASCII -G$ASCII.grd -I0.000224804= -R$WEST/$EAST/$SOUTH/$NORTH |
| 84 |
|
| 85 |
set OUTFILE = $ASCII.grd |
| 86 |
|
| 87 |
echo "-----------------------------" |
| 88 |
echo "removing header from $OUTFILE" |
| 89 |
echo "-----------------------------" |
| 90 |
set OUTFILE_NoHdr = $ASCII.nvi |
| 91 |
grdreformat $OUTFILE $ASCII.nvi=bf -N -V |
| 92 |
|
| 93 |
|
| 94 |
echo "-----------------------------" |
| 95 |
echo "Created: $OUTFILE.nvi without hdr (GMT grid @ 0,0009 degrees i.e. about 25m)" |
| 96 |
echo "-----------------------------" |
| 97 |
|
| 98 |
echo "-----------------------------" |
| 99 |
echo "Create ENVI header" |
| 100 |
echo "-----------------------------" |
| 101 |
|
| 102 |
echo "attention: if wants UTM in cm, first run Mathematica notebook and watch out for the alphabumeric characters" |
| 103 |
|
| 104 |
set DATE = `date` |
| 105 |
#set grdinfo = `grdinfo $ASCII.grd` |
| 106 |
#echo $grdinfo |
| 107 |
#set x_inc = `echo $grdinfo | cut -d ':' -f14 | cut -d ' ' -f2` |
| 108 |
#set nX = `echo $grdinfo | cut -d ':' -f16 | cut -d ' ' -f2` |
| 109 |
#set y_inc = `echo $grdinfo | cut -d ':' -f20 | cut -d ' ' -f2` |
| 110 |
#set nY = `echo $grdinfo | cut -d ':' -f22 | cut -d ' ' -f2` |
| 111 |
grdinfo $ASCII.grd > temp |
| 112 |
set x_inc = `grep x_inc temp | gawk '{print $7}'` |
| 113 |
set nX = `grep nx temp | gawk '{print $11}'` |
| 114 |
set y_inc = `grep y_inc temp | gawk '{print $7}'` |
| 115 |
set nY = `grep y_inc temp | gawk '{print $11}'` |
| 116 |
rm temp |
| 117 |
echo |
| 118 |
echo 'nx= ' $nX |
| 119 |
echo 'x_inc= ' $x_inc |
| 120 |
echo 'ny= ' $nY |
| 121 |
echo 'y_inc= '$y_inc |
| 122 |
echo |
| 123 |
# Header: |
| 124 |
echo 'ENVI' >> $ASCII.hdr |
| 125 |
echo 'description = { ' >> $ASCII.hdr |
| 126 |
echo ' Header created auto from gridinfo (gmt) and ' $OUTFILE.NoHdr ' on [' $DATE ']}' >> $ASCII.hdr |
| 127 |
echo 'samples = ' $nX >> $ASCII.hdr |
| 128 |
echo 'lines = ' $nY >> $ASCII.hdr |
| 129 |
echo 'bands = 1' >> $ASCII.hdr |
| 130 |
echo 'header offset = 0' >> $ASCII.hdr |
| 131 |
echo 'file type = ENVI Standard' >> $ASCII.hdr |
| 132 |
echo 'data type = 4' >> $ASCII.hdr |
| 133 |
echo 'interleave = bsq' >> $ASCII.hdr |
| 134 |
echo 'sensor type = Unknown' >> $ASCII.hdr |
| 135 |
# select the output format: small or big Endian? |
| 136 |
echo 'byte order = 0' >> $ASCII.hdr |
| 137 |
echo ' computed on a Little Endian machine' |
| 138 |
echo |
| 139 |
|
| 140 |
# echo "-----------------------------" |
| 141 |
# echo 'UTM FORMAT' |
| 142 |
# echo "-----------------------------" |
| 143 |
# echo 'map info = {UTM, 1.000, 1.000, 715175.972, 9883485.359, 3.0940000000e+001, 3.0740000000e+001, 35, South, WGS-84, units=Meters}' >> $ASCII.hdr |
| 144 |
|
| 145 |
echo "-----------------------------" |
| 146 |
echo 'LON/LAT FORMAT' |
| 147 |
echo "-----------------------------" |
| 148 |
echo 'map info = {Geographic Lat/Lon, 1.0000, 1.0000, ' $WEST ', ' $NORTH ', ' $x_inc ', ' $y_inc ', WGS-84, units=Degrees}' >> $ASCII.hdr |
| 149 |
|
| 150 |
echo 'wavelength units = Unknown' >> $ASCII.hdr |
| 151 |
echo '' >> $ASCII.hdr |
| 152 |
|
| 153 |
### EOF. |