#!/bin/bash # program: lfilesearch # version 1.1 # by Andrew Newman modified by Grant Farmer # last modified: Wed Sep 20 12:10:04 EDT 2006 # program will search default or input lfile for # stations that are either within a certain distance of a point # or within a rectangular range # it will also, optionally search on date LFILE=~/gg/tables/lfile.spherical SINFO=~/gg/tables/station.info USAGE=~/$$.usage # create a usage display that will be shown if command is run with no arguements printf "Usage: `basename $0` [-CLON/LAT/RAD] [-RLONMIN/LONMAX/LATMIN/LATMAX] [-T YYYY/DOY] [-L lfile] [-S station.info] [-I sittbl.] Program will search default or input lfile for stations that are either within a certain distance of a point or within a rectangular area. One of the two options is required: -C will search the LFILE for stations within the circular radius [km] from CLON, CLAT -R will search the LFILE for stations within rectangular region between LONMIN/LONMAX and LATMIN/LATMAX. distance output will be from center of rectangle. Option: -T will search if stations are good for a specific day -L will use the input LFILE rather than default -S will use the input station.info rather than default -I will check supplied sittbl. file for stations Caveat: + This program _will_ give erroneous results if search is across the international dateline or poles. + search assumes a useful range between -180/180 and -90/90. For example: `basename $0` -C-107/35/1000 -Llocal.lfile -Slocal.station.info or: `basename $0` -R-120/-100/10/40 -T2002/311 \n " >$USAGE if [ ${#} -lt "1" ] ; then cat $USAGE # display usage rm $USAGE exit 1 # exit with error after removing temp file fi while getopts ":C:R:L:S:T:I:" OPT do case ${OPT} in C) CLON=`echo $OPTARG | awk -F"/" '{print $1}'` CLAT=`echo $OPTARG | awk -F"/" '{print $2}'` CRAD=`echo $OPTARG | awk -F"/" '{print $3}'` CSEARCH=1; # flag for radial search, else do a rectangular search ;; R) LONMIN=`echo $OPTARG | awk -F"/" '{print $1}'` LONMAX=`echo $OPTARG | awk -F"/" '{print $2}'` LATMIN=`echo $OPTARG | awk -F"/" '{print $3}'` LATMAX=`echo $OPTARG | awk -F"/" '{print $4}'` CLON=`echo $OPTARG | awk -F"/" '{print ($1+$2)/2}'` # Get central point CLAT=`echo $OPTARG | awk -F"/" '{print ($3+$4)/2}'` # of rectangle ;; L) LFILE=$OPTARG ;; S) SINFO=$OPTARG ;; T) YYYY=`echo $OPTARG | awk -F"/" '{print $1}'` DOY=`echo $OPTARG | awk -F"/" '{print $2}'` TSEARCH=1; # flag for temporal search, else print out all information ;; I) SITTBL=$OPTARG ;; *) echo "ERROR: unknown modifier flag used (${OPT}), exiting." # if a bad modifier is used rm $USAGE exit 1 ;; # exit with error after removing temp file esac done # check to see if LFILE exists if [ ! -e $LFILE ] ; then # does $LFILE exist? echo "ERROR: $LFILE doesn't exist. Exiting." rm $USAGE exit 1 # exit with error after removing temp file fi # check to see if SINFO exists if [ ! -e $SINFO ] ; then # does $SINFO exist? echo "ERROR: $SINFO doesn't exist. Exiting." rm $USAGE exit 1 # exit with error after removing temp file fi # 1 2 3 4 5 6 7 8 91011 12 awk 'BEGIN{FIELDWIDTHS="4 13 1 2 3 9 1 1 3 3 9 43" } BEGIN{print "# STAT LON LAT RAD"} (NR>1){ {LAT=$4+$5/60+$6/3600; LON=$9+$10/60+$11/3600} # convert deg min and sec to deg.decimal {if ($3=="S") LAT=0-LAT}{if ($8=="W") LON=0-LON} # correct for S and W as negatives {RAD=(((LAT-CLAT)**2+(LON-CLON)**2)**.5)*111.15} # calculate distance if (CSEARCH==1) { # if using circular search if (CRAD>RAD) printf " %4s %13.8f %13.8f %13.6f\n", $1, LON, LAT, RAD} # only stations closer than CRAD else { # otherwise, a rectangular search if (LAT>LATMIN && LATLONMIN && LON $$.tmp echo "#STAT Station_Name BYER BDY BYER BDY LONGITUDE LATITUDE DISTANCE " >$$.tmp2 for STAT in ` awk '$1!~"#"{print $1}' $$.tmp ` do awk 'BEGIN{FIELDWIDTHS="1 4 20 4 1 3 11 4 1 3" } $2==STAT && $1!~"*" { if (TSEARCH==1) { if ($4+$6/366<=YYYY+DOY/366 && $8+$10/366>=YYYY+DOY/366){ printf "%4s %20s %4d %3d %4d %3d", $2,$3, $4,$6, $8,$10} } else {printf "%4s %20s %4d %3d %4d %3d", $2,$3, $4,$6, $8,$10} }' STAT=$STAT TSEARCH=$TSEARCH YYYY=$YYYY DOY=$DOY $SINFO | head -n 1 >>$$.tmp2 printf " ` egrep $STAT $$.tmp | head -n 1 | cut -c 6- `\n " >>$$.tmp2 done # output if [ $SITTBL ] ; then for STAT in `awk '{print $1}' $$.tmp` do if egrep $STAT $SITTBL >/dev/null ; then echo " IGS_CORE" >> $$.tmp3 else echo " " >> $$.tmp3 fi done paste $$.tmp2 $$.tmp3 else cat $$.tmp2 fi # remove temporary usage file rm $USAGE $$.tmp $$.tmp2 $$.tmp3 # exit cleanly exit 0