#!/usr/bin/perl $units = @ARGV[0]; # to produce default contours in MB, no units should be passed # otherwise pass _inches_mercury $txt_dest_dir = '/usr2/seacoos_model_scratch'; $grd_dest_dir = '/usr2/maps/seacoos/data/model_gmt_grids'; $grd_commands = '/tmp/mk_model_grd.bash'; $psql_prefix = '/usr/local/pgsql/bin/psql' .' -d sea_coos_model -h nemo.baruch.sc.edu -U postgres' .' --no-align -F " "'; $psql_suffix = "egrep -v 'lon lat prmsl$units|rows'"; $grd_surface_bounds = '-100/-60/20/50'; # $grd_surface_sample_incr = '0.0625'; # was 0.125 before UNC changed res to 0.125 $grd_surface_sample_incr = '0.125'; # $grd_surface_sample_incr = '1.0'; # $grd_filter = 'm3'; $grd_filter = 'g4'; `rm -f $txt_dest_dir/*`; `echo '#!/bin/bash' > $grd_commands`; `echo 'export PATH="/usr2/local/gmt/GMT3.4.3/bin:/usr/kerberos/bin:/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/pgsql/bin:/usr2/home/scmodel/bin"' >> $grd_commands`; `echo 'export GMTHOME="/usr2/local/gmt/GMT3.4.3"' >> $grd_commands`; use DBI; #establish database connection $dbh = DBI->connect ( "dbi:Pg:dbname=sea_coos_model;host=nemo.baruch.sc.edu", "postgres", "postgres"); if ( !defined $dbh ) { die "Cannot connect to database!\n"; } # make .txt dumps of the prml by hour my $sql = "select distinct time_stamp, to_char(time_stamp,'YYYY_MM_DD_HH24_MI_SS') from met_sea_level_pressure_unc_stage order by time_stamp"; my $sth = $dbh->prepare( $sql ); $sth->execute(); $sth->bind_columns(undef,\$time_stamp,\$formatted_time_stamp); while ($sth->fetch()) { $out_file = "$txt_dest_dir/prmsl$units_$formatted_time_stamp.txt"; $psql_command = $psql_prefix .' -c "select lon, lat, prmsl'.$units.' from met_sea_level_pressure_unc_stage' .' where prmsl'.$units.' > -1 and time_stamp = timestamp without time zone' ." '$time_stamp';\""; $cmd = $psql_command .' | '.$psql_suffix .' > '."$txt_dest_dir/met_sea_level_pressure".$units."_unc_prod_$formatted_time_stamp.txt"; print "SQL met_sea_level_pressure".$units."_unc_prod $time_stamp\n"; `$cmd`; # now do the GMT stuff `echo "echo 'GMT met_sea_level_pressure".$units."_unc_prod $time_stamp'" >> $grd_commands`; $surface_cmd = 'surface' ." $txt_dest_dir/met_sea_level_pressure".$units."_unc_prod_$formatted_time_stamp.txt" ." -R$grd_surface_bounds" ." -I$grd_surface_sample_incr" ." -G$txt_dest_dir/met_sea_level_pressure".$units."_unc_prod_$formatted_time_stamp.grd"; `echo "$surface_cmd" >> $grd_commands`; $grdfilter_cmd = 'grdfilter' ." $txt_dest_dir/met_sea_level_pressure".$units."_unc_prod_$formatted_time_stamp.grd" ." -D0 -F$grd_filter -G$grd_dest_dir/met_sea_level_pressure".$units."_unc_prod_$formatted_time_stamp.grd\n"; `echo "$grdfilter_cmd" >> $grd_commands`; } $sth->finish; $dbh->disconnect(); `echo "rm -f .gmtcommands" >> $grd_commands`; `chmod 755 $grd_commands`; print "$grd_commands\n";