
#!/usr/bin/perl -w
use strict;
# Command line variables
my $pref = $ARGV[0];
my $grid = $ARGV[1];
my $range;
$pref =~ s/poly\.xy//;
my $infofile = $pref . "info.info";
print $infofile . "\n";
system("grdinfo $grid > $infofile");
open(INFO,"<$infofile");
while (<INFO>) {
if (/Command/) {
s/.*-R(.*) -I.*//;
$range = $1;
}
}
close(INFO);
print $range . "\n";
#!/usr/bin/perl -w
use strict;
my $v1 = 157.34;
my $v2 = 34.9;
$v1 = int($v1 / 10 + .5) * 10;
$v2 = int($v2 / 10 + .5) * 10;
print "v1: $v1 - v2: $v2\n";

print /-R(.+?)\s+/ while <>;
print /(-R.+?)\s+/ while <>;
print int($int + .5);($whole, $rem) = split(/\./, $int+.5);
print $whole;
print int($int + .5 * ($int <=> 0));
#!/bin/bash
# This version finalized August 4, 2005
# Written by Leigh Holcombe, Texas A&M University, Oceanography Department
# Special thanks to VoidMain for regexp assistance
#
# Creates a GMT histogram for an underwater geographic area, which can be used to
# analyze historic trends in sealevel and other such things. The histogram is produced
# automatically, using base values extracted from the dataset.
#
# Usage: histogrammar [polygon file] [gridfile]
# requires a bash shell, awk, sed, and a local installation of GMT
#
# Arguments: this script expects only 2 arguments, a gridfile, and a polygon file.
#
# The polygon file should be a 2 column ASCII list of floating point values, with the first
# column being decimal longitude, and the second column being decimal latitude. The values
# should describe an enclosed geographic area. Note that the polygon must be completely
# above sealevel or below sealevel - ie, it must not cross zero meters, or the zero data will
# be lost. The polygon's name should be a string designating its location, followed by
# "poly.xy". As an example, featurenamepoly.xy. Any other naming convention will fault the
# program.
#
# The gridfile should be a NetCDF gridfile of the elevations or depths of the area of
# interest. Currently, the program is setup to only accept grids of 1/4 second cellsize,
# but that may change as needed.
#
# Output: an Encapsulated PostScript (EPS) file which will produce a 12-inch plot of the
# polygon, with the form featurenamepoly.ps, and an EPS file of a 24-inch bar histogram,
# with the bars colored darkish gray.
#
# command line variables
POLY=$1
GRID=$2
# get prefix
PREF="`echo $POLY | sed \"s/\(.*\)poly.xy/\1/\"`"
infofile=$PREF.info
# get range
grdinfo $GRID > infofile
RANGE="`grep Command infofile | sed \"s/.*-R\(.*\) -I.*/\1/\"`"
# make and apply the mask
maskfile=$PREF.mask
grdmask -G$maskfile -I0.25c -R$RANGE -V -N0/0/NaN $POLY
postmath=$PREF.postmath
grdmath -V $maskfile $GRID AND = $postmath
# transform grid to histogram format
basexyz=$PREF.basexyz
grd2xyz -V $postmath > $basexyz
ready=$PREF.ready
ready=wfnums.xy
awk '{if ($3!=0) print $3}' $basexyz > $ready
# print the line file
linefile=${PREF}poly.ps
psxy -R$RANGE $POLY -P -JQ-93/12i > $linefile
# build the histogram
histfile=${PREF}hist.ps
outfile=${PREF}hist.info
minmax $ready > $infofile
topval="`grep $ready $infofile | sed \"s/.*<\(.*\)\/.*/\1/\"`"
botval="`grep $ready $infofile | sed \"s/.*\/\(.*\)>.*/\1/\"`"
pshistogram $ready -JX24i -W1 -Z1 -Io > $outfile
valfile=${PREF}hist.val
scratch=${PREF}hist.scr
awk '{print $2}' $outfile > $valfile
minmax $valfile > $scratch
maxval="`grep $valfile $scratch | sed \"s/.*\/\(.*\)>.*/\1/\"`"
minval=0
values=$topval/$botval/$minval/$maxval
pshistogram $ready -JX24i -W1 -P -C -V -Z1 -R$values -Ba10f1/a1f0.5 -G125/125/125 > $histfile
echo "Process completed"
echo "Files created:"
echo $linefile
echo $histfile
echo $outfile
# end of program

Users browsing this forum: No registered users and 1 guest