#!/usr/local/bin/perl # PERL program to sort tropical storm database # Copyright (C) 1996 Thomas R. Metcalf # # This software is provided "as is" and is subject to change without # notice. No warranty of any kind is made with regard to this software, # including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose. The author shall # not be liable for any errors or for direct, indirect, special, # incidental or consequential damages in connection with the furnishing, # performance, or use of this software: use it at your own risk. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # #setpriority(0,0,getpriority(0,0)+4); # nice the process while (<>) { # Read input file into an array $input[$.-1] = $_; } $oneday = 0.00273225; $oneweek = 0.0191257; # Find the time of the last actual observation which was generated # at least one day before $now. This is a guess at the time sortropical # was last run. # Only observations after one week before this time will be sorted. # For safety, take the minimum of $lasttime and now. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime; if ($year>=94) {$year+=1900;} else {$year+=2000;} $now = $year + ($yday+1 + ($hour/24.0))/366.0; $lasttime = $now; tsearch: for ($i=$#input;$i>=0;--$i) { @sline = split(/[ \n]/,$input[$i]); # split fields if ($#sline >= 23) { if ($sline[20] eq 'ACT' && (($sline[23]+$oneday)<$now)) { $lasttime = $sline[21]; last tsearch; } } } if ($now < $lasttime) {$lasttime = $now;} # Dump the early stuff $tspointer=0; for ($i=0;$i<=$#input;++$i) { @sline = split(/[ ]/,$input[$i]); if (($sline[21]+$oneweek) < $lasttime) {print $input[$i];} else {$tosort[$tspointer++]=$input[$i];} } # Sort the rest of the input by date sub bydate { $na = @aa = split(/[ ]/,$a); $nb = @ab = split(/[ ]/,$b); $aa[21] <=> $ab[21]; } if ($#tosort > 0) { @tosort = sort bydate @tosort; print @tosort; }