#!/usr/bin/perl use Config::IniFiles; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($DEBUG); Log::Log4perl->init("./conf/log4perl.conf"); my $logger = get_logger(); $cfg = new Config::IniFiles( -file => "./conf/noaa-modem.ini" ); $buoy_id = $ARGV[0]; $measurement_date = $ARGV[1]; $measurement_date = '20'.substr($measurement_date,6,2)."/".substr($measurement_date,0,5)." ".substr($measurement_date,9,5); my ($wxpak_wind_speed, $wxpak_wind_direction, $wxpak_wind_gust, $wxpak_air_temp, $wxpak_air_pressure, $buoy_visibility); if ($ARGV[2] ne 'NULL') { $wxpak_wind_speed = $ARGV[2]; } if ($ARGV[3] ne 'NULL') { $wxpak_wind_direction = $ARGV[3]; } if ($ARGV[4] ne 'NULL') { $wxpak_wind_gust = $ARGV[4]; } if ($ARGV[5] ne 'NULL') { $wxpak_air_temp = $ARGV[5]; } if ($ARGV[6] ne 'NULL') { $wxpak_air_pressure = $ARGV[6]; } if ($ARGV[7] ne 'NULL') { $buoy_visibility = $ARGV[7]; } $ndbc_ftp_site = $cfg->val('NDBC', 'ftp_site'); $ndbc_ftp_dir = $cfg->val('NDBC', 'ftp_dir'); $ndbc_ftp_user = $cfg->val('NDBC', 'ftp_user'); $ndbc_ftp_passwd = $cfg->val('NDBC', 'ftp_password'); $ndbc_sent_file_name = $cfg->val('NDBC', 'sent_file_name'); $ndbc_build_message_bin_dir = $cfg->val('NDBC', 'build_message_bin_dir'); my $datafile = "../demodata.txt"; # this file used to send data through BuildMessage $wsunits = "meters/second"; $msg_fmt = "FM13"; # Hash of buoys/stations # buoy, station_id, routing_id, latitude, longitude my %buoys_hash = ( buoy2 => ["FRP2", "41033", "SOVD83 KWBC", "32.26N", "80.42W"], buoy4 => ["CAP2", "41029", "SOVD83 KWBC", "32.80N", "79.62W"], buoy6 => ["SUN2", "41024", "SOVD83 KWBC", "33.83N", "78.48W"], buoy5 => ["CAP3", "41030", "SOVD83 KWBC", "32.50N", "79.32W"], buoy7 => ["SUN3", "41027", "SOVD83 KWBC", "33.31N", "78.15W"] ); if(!exists($buoys_hash{$buoy_id})) { $logger->error("$buoy_id not supported or $buoy_id is invalid."); exit 0; } $id = $buoys_hash{$buoy_id}[0]; $station_id = $buoys_hash{$buoy_id}[1]; $routing_id = $buoys_hash{$buoy_id}[2]; $latitude = $buoys_hash{$buoy_id}[3]; $longitude = $buoys_hash{$buoy_id}[4]; my @data = (); push @data, "STATION =$station_id"; push @data, "ROUTING_ID =$routing_id"; # Date & Time should be expressed as UTC (Universal Coordinated Time) or GMT # Please use this format YYYY/MM/DD HH:MI for DATE push @data, "DATE =$measurement_date"; push @data, "MSGFMT =$msg_fmt"; push @data, "WSUNITS =$wsunits"; push @data, "LAT =$latitude"; push @data, "LON =$longitude"; push @data, "VIS =$buoy_visibility"; push @data, "WSPD =$wxpak_wind_speed"; push @data, "SENSHT =3"; push @data, "WDIR =$wxpak_wind_direction"; push @data, "GUST =$wxpak_wind_gust"; push @data, "ATMP =$wxpak_air_temp"; push @data, "BARO =$wxpak_air_pressure"; #date format 2004/09/27 05:00 $year = substr($measurement_date,0,4); $mon = substr($measurement_date,5,2); $mday = substr($measurement_date,8,2); $hour = substr($measurement_date,11,2); my $file_date = "$year\_$mon\_$mday\_$hour".'00'; $ndbc_sent_file_name = $station_id."_CAROCOOPS_".$file_date."_FM13.dat"; $build_message = "cd $ndbc_build_message_bin_dir; ./BuildMessage > ./perl/data/$ndbc_sent_file_name"; open DATAFILE, ">$datafile" or $log->logdie("Can't open output file! $datafile: $!"); foreach (@data) { print DATAFILE "$_\n"; } close DATAFILE; # FORMAT DATA with NDBC program BuildMessage my $res = `$build_message`; print "$build_message returned $res.\n"; if ($res){ print STDERR "BuildMessage returned $res.\n"; } my $ftpcmd = "/usr/local/bin/ncftpput -u $ndbc_ftp_user -p $ndbc_ftp_passwd -r 3 $ndbc_ftp_site $ndbc_ftp_dir"; $logger->debug("Executing command:"."$ftpcmd ./data/$ndbc_sent_file_name"); # FTP my @res = `$ftpcmd ./data/$ndbc_sent_file_name`; $logger->error(@res."\n");