# lines associated with same number are treated # as one line. Blank lines have been deleted. 1 #!/usr/bin/perl 3 use FileHandle; 5 $DATADIR="/home/weather/data"; 7 if ($#ARGV < 0) { die "Usage: weatherd tty\n"; } 8 $TTY = $ARGV[0]; 10 system( "stty `cat /home/weather/bin/tty` < $TTY"); 11 print "stty returned $?\n"; 13 # Filename for today's data 14 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday, $isdst) = 15 localtime(time); 16 $TODAY= sprintf "%02d%02d%02d", $mon+1, $mday, $year; 20 $OUTFILE = "$DATADIR/$TODAY"; 21 open(LINE, "< $TTY") or die "Unable to open tty: $TTY"; 22 open(OUT, ">> $OUTFILE") or die "Unable to open output file: $OUTFILE"; 24 LINE->autoflush(1); 25 OUT->autoflush(1); 27 while(<LINE>) 28 { 30 # parse out date, make sure it matches $TODAY 32 ($time, $date, $wdir, $wspeed, $aux, $intemp, 33 $outtemp, $hum, $bp, $raind,<\n> $rainm, $rain_rate) = split; 35 $date =~ s/\///g; 37 if ( $time =~ /Min/ ) { 38 #system(" echo \'$_\' ><\n> $DATADIR/$date.min "); 40 open(MIN, ">> $DATADIR/$date.min") 41 or die "Unable to open output<\n> file: $DATADIR/$date.min"; 42 printf MIN "%s", $_; 43 close MIN; 44 } 45 elsif ( $time =~ /Max/ ) { 46 #system(" echo \'$_\' > $DATADIR/$date.max "); 48 open(MAX, ">> $DATADIR/$date.max") 49 or die "Unable to open output<\n> file: $DATADIR/$date.max"; 50 printf MAX "%s", $_; 51 close MAX; 52 } 53 else 54 { 55 $date =~ s/\///g; 57 if( $TODAY eq $date ) 58 { 59 printf OUT "%s",$_; 60 } 61 else 62 { 63 $TODAY = $date; 65 # if not, close this file<\n> and open the next one 66 close OUT; 67 $OUTFILE =<\n> "$DATADIR/$TODAY"; 68 open(OUT, ">> $OUTFILE") 69 or die "Unable to<\n> open output file: $OUTFILE"; 71 OUT->autoflush(1); 72 printf OUT "%s",$_; 73 } 74 }