Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Perl script error

by sellinios (Initiate)
on Apr 22, 2016 at 15:16 UTC ( [id://1161231]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl script error
in thread Perl script error

Ok I got your point, so bellow is the file I think it has the issue :
#!/usr/bin/perl -w use Class::Date qw(date now); use File::Path; use File::Copy; use List::Util qw(min max); chomp( $region = $ARGV[0] ); chomp( $lrun = $ARGV[1] ); chomp( $flag = $ARGV[2] ); if ( $flag =~ m/^(00|06|12|18)$/ ) { $hh = $flag; chomp( $yyyymmdd = `date +%Y%m%d` ); $yymmdd = substr( $yyyymmdd, 2, 6 ); $real_time = 1; } elsif ( $flag =~ m!^(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])(00|06|12|18) +$! ) { $yyyymmdd = substr( $flag, 0, 8 ); $yymmdd = substr( $yyyymmdd, 2, 6 ); $hh = substr( $flag, 8, 2 ); $real_time = 1; } $yyyymmddhh = $yyyymmdd . $hh; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $data_inici = date $yyyymmddhh. "0000"; $copyright = $data_inici->year; $data_final = $data_inici + "$lrun h"; $root = '/home/meteo/Build_WRF'; $regdir = "$root/SCRIPTS$region"; $wpsdir = "$root/WPS"; $wrfdir = "$root/WRFV3"; $wrfdmdir = "$root/WRFV3"; $postdir = "$root/ARWpost"; $rundir = "$root/DATA/WRF/$region/$yyyymmddhh"; $gfsdir = '/home/meteo/Build_WRF/DATA/GFS'; $mapsdir = "/home/meteo/Build_WRF/DATA/MAPS/$region/$ +yyyymmddhh"; $grads = '/home/meteo/Build_WRF/LIBRARIES/grads/bin/grads'; if ( !-d $mapsdir ) { mkpath($mapsdir) or die $!; } else { rmtree($mapsdir) or die $!; mkpath($mapsdir) or die $!; } chdir("$rundir/arwpost") or die $!; %var_list = ( 'prec' => 'Total precipitation (mm)', 't2m' => 'Temperature at 2m (Celsius)', 't850' => 'Temperature at 850hPa (Celsius)', 't500' => 'Temperature at 500hPa (Celsius)', 't700' => 'Temperature at 700hPa (Celsius)', 'slp' => 'Sea level pressure (hPa)', 'clfr' => 'Total cloud clover (%)', 'prec_slp' => 'Precipitation (mm) and SLP (hPa)', 'prec_type' => 'Precipitation type', 'frozen_lvl' => 'Frozen level (m)', 'wind10_slp' => 'Wind 10m (m/s) and SLP (hPa)', 'prec24' => '24h Precipitation (mm)', 'acsnow' => 'Accumulated snow and ice (mm) + snow cover', # 'cape' => 'CAPE (J/kg)' ); @doms = ( 'd01', 'd02' ); foreach (@doms) { $domain = $_; if ( $domain eq 'd01' ) { $xsize = '850'; $ysize = '650'; $img_size = '850x650'; $latmin = '34.0'; $latmax = '72.5'; $lonmin = '-12.3333'; $lonmax = '39.0'; $logo_size = '+130+540'; $region_plot = 'europe-27km'; $gradsdir = "$root/Build_WRF/SCRIPTS/grads_europe"; } elsif ( $domain eq 'd02' ) { $xsize = '850'; $ysize = '650'; $img_size = '850x650'; $latmin = '34.6875'; $latmax = '41.8125'; $lonmin = '19.0'; $lonmax = '28.5'; $logo_size = '+130+540'; $region_plot = 'greece-9km'; $gradsdir = "$root/Build_WRF/SCRIPTS/grads_greece"; } elsif ( $domain eq 'd03' ) { $xsize = '850'; $ysize = '650'; $img_size = '850x650'; $latmin = '37.3875'; $latmax = '39.1125'; $lonmin = '23.0'; $lonmax = '25.3'; $logo_size = '+130+540'; $region_plot = 'attica-3km'; $gradsdir = "$root/Build_WRF/SCRIPTS/grads_attica"; } $mapsdir = "/home/meteo/Build_WRF/DATA/MAPS/$region_plot/$yyyymmdd +hh"; if ( !-d $mapsdir ) { mkpath($mapsdir) or die $!; } else { rmtree($mapsdir) or die $!; mkpath($mapsdir) or die $!; } chdir("$rundir/arwpost") or die $!; while ( ( $var, $name ) = each(%var_list) ) { print("$var, $fname\n"); if ( $var eq 'prec' || $var eq 'prec_type' || $var eq 'prec_sl +p' ) { $data = $data_inici; while ( $data <= $data_final ) { print "$region_plot $gradsdir $var \"$name\" $data\n"; $Class::Date::DATE_FORMAT = "%Y-%m-%d %H"; $title = "$name $data UTC"; $Class::Date::DATE_FORMAT = "%Y%m%d%H"; $pngfile = "$data\_$var.png"; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $ctlfile = "wrfout_$domain\_$data.ctl +"; $data2 = $data - '1h'; $ctlfile2 = "wrfout_$domain\_$data2.ct +l"; if ( $data != $data_inici ) { open( GS1, ">$rundir/arwpost/commands.gs" ) or die + $!; print GS1 "'open $ctlfile'\n"; print GS1 "'open $ctlfile2'\n"; print GS1 "'clear'\n"; print GS1 "'set lat $latmin $latmax'\n"; print GS1 "'set lon $lonmin $lonmax'\n"; print GS1 "'run $gradsdir/$var\_in.gs'\n"; print GS1 "'run $gradsdir/xcbar.gs -fs 3 -edge cir +cle'\n"; print GS1 "'set font 0'\n"; print GS1 "'set rgb 100 100 0 100'\n"; print GS1 "'set map 1 1 6'\n"; print GS1 "'set string 1 tc 5'\n"; print GS1 "'draw string 5.5 0.4 kairos.gr copyrigh +t $copyright'\n"; print GS1 "'set strsiz 0.18'\n"; print GS1 "'set string 1 tc 9'\n"; print GS1 "'draw string 5.5 8.2 $title'\n"; print GS1 "'set mpdraw off'\n"; print GS1 "'printim $mapsdir/$pngfile png white x$ +xsize y$ysize -b /home/meteo/Build_WRF/SCRIPTS/background.png'\n"; print GS1 "'quit'\n"; close(GS1); } else { open( GS2, ">$rundir/arwpost/commands.gs" ) or die + $!; print GS2 "'open $ctlfile'\n"; print GS2 "'clear'\n"; print GS2 "'set lat $latmin $latmax'\n"; print GS2 "'set lon $lonmin $lonmax'\n"; print GS2 "'run $gradsdir/$var.gs'\n"; print GS2 "'run $gradsdir/xcbar.gs -fs 3 -edge cir +cle'\n"; print GS2 "'set font 0'\n"; print GS2 "'set rgb 100 100 0 100'\n"; print GS2 "'set map 1 1 6'\n"; print GS2 "'set string 1 tc 5'\n"; print GS2 "'draw string 5.5 0.4 kairos.gr copyrigh +t $copyright'\n"; print GS2 "'set strsiz 0.18'\n"; print GS2 "'set string 1 tc 9'\n"; print GS2 "'draw string 5.5 8.2 $title'\n"; print GS2 "'set mpdraw off'\n"; print GS2 "'printim $mapsdir/$pngfile png white x$ +xsize y$ysize'\n"; print GS2 "'quit'\n"; close(GS2); } @args = ("$grads -blc $rundir/arwpost/commands.gs > /d +ev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; open( LG, ">$rundir/arwpost/composite.sh" ) or die $!; print LG "#!/bin/bash\n"; print LG "convert -size $img_size xc:white $mapsdir/co +mposite.png\n"; print LG "composite -geometry +0+0 $mapsdir/$pngfile $ +mapsdir/composite.png $mapsdir/composite.png\n"; print LG "mv $mapsdir/composite.png $mapsdir/$pngfile" +; close(LG); my $file = "$rundir/arwpost/composite.sh"; chmod 0755, $file or die "Couldn't chmod $file: $!"; @args = ("$file > /dev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; $data = $data + '1h'; } } elsif ($var eq 't2m' || $var eq 't850' || $var eq 't500' || $v +ar eq 'slp' || $var eq 'clfr' || $var eq 'frozen_lvl' || $var eq 'wind1 +0_slp' || $var eq 'acsnow' || $var eq 'cape' ) { $data = $data_inici; while ( $data <= $data_final ) { print "$region_plot $gradsdir $var \"$name\" $data\n"; $Class::Date::DATE_FORMAT = "%Y-%m-%d %H"; $title = "$name $data UTC"; $Class::Date::DATE_FORMAT = "%Y%m%d%H"; $pngfile = "$data\_$var.png"; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $ctlfile = "wrfout_$domain\_$data.ctl +"; open( GS3, ">$rundir/arwpost/commands.gs" ) or die $!; print GS3 "'open $ctlfile'\n"; print GS3 "'clear'\n"; print GS3 "'set lat $latmin $latmax'\n"; print GS3 "'set lon $lonmin $lonmax'\n"; print GS3 "'run $gradsdir/$var.gs'\n"; print GS3 "'run $gradsdir/xcbar.gs -fs 3 -edge circle' +\n"; print GS3 "'set font 0'\n"; print GS3 "'set rgb 100 100 0 100'\n"; print GS3 "'set map 1 1 6'\n"; print GS3 "'set string 1 tc 5'\n"; print GS3 "'draw string 5.5 0.4 kairos.gr copyright $c +opyright'\n"; print GS3 "'set strsiz 0.18'\n"; print GS3 "'set string 1 tc 9'\n"; print GS3 "'draw string 5.5 8.2 $title'\n"; print GS3 "'set mpdraw off'\n"; print GS3 "'printim $mapsdir/$pngfile png white x$xsiz +e y$ysize'\n"; print GS3 "'quit'\n"; close(GS3); @args = ("$grads -blc $rundir/arwpost/commands.gs > /d +ev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; open( LG, ">$rundir/arwpost/composite.sh" ) or die $!; print LG "#!/bin/bash\n"; print LG "convert -size $img_size xc:white $mapsdir/co +mposite.png\n"; print LG "composite -geometry +0+0 $mapsdir/$pngfile $ +mapsdir/composite.png $mapsdir/composite.png\n"; print LG "mv $mapsdir/composite.png $mapsdir/$pngfile" +; close(LG); my $file = "$rundir/arwpost/composite.sh"; chmod 0755, $file or die "Couldn't chmod $file: $!"; @args = ("$file > /dev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; $data = $data + '1h'; } } elsif ( $var eq 'prec24' ) { $data = $data_inici; while ( $data < $data_final ) { print "$region_plot $gradsdir $var \"$name\" $data\n"; $Class::Date::DATE_FORMAT = "%Y-%m-%d %H"; $title = "$name $data UTC"; $Class::Date::DATE_FORMAT = "%Y%m%d%H"; $pngfile = "$data\_$var.png"; $data = $data + '24h'; $Class::Date::DATE_FORMAT = "%Y-%m-%d_%H:%M:%S"; $ctlfile = "wrfout_$domain\_$data.ctl +"; $data2 = $data - '24h'; $ctlfile2 = "wrfout_$domain\_$data2.ct +l"; open( GS4, ">$rundir/arwpost/commands.gs" ) or die $!; print GS4 "'open $ctlfile'\n"; print GS4 "'open $ctlfile2'\n"; print GS4 "'clear'\n"; print GS4 "'set lat $latmin $latmax'\n"; print GS4 "'set lon $lonmin $lonmax'\n"; print GS4 "'run $gradsdir/$var\_in.gs'\n"; print GS4 "'run $gradsdir/xcbar.gs -fs 3 -edge circle' +\n"; print GS4 "'set font 0'\n"; print GS4 "'set rgb 100 100 0 100'\n"; print GS4 "'set map 1 1 6'\n"; print GS4 "'set strsiz 0.18'\n"; print GS4 "'set string 1 tc 5'\n"; print GS4 "'draw string 5.5 0.4 kairos.gr copyright $c +opyright'\n"; print GS4 "'set string 1 tc 9'\n"; print GS4 "'draw string 5.5 8.2 $title'\n"; print GS4 "'set mpdraw off'\n"; print GS4 "'printim $mapsdir/$pngfile png white x$xsiz +e y$ysize -b /home/meteo/Build_WRF/SCRIPTS/background.png'\n"; print GS4 "'quit'\n"; close(GS4); @args = ("$grads -blc $rundir/arwpost/commands.gs > /d +ev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; open( LG, ">$rundir/arwpost/composite.sh" ) or die $!; print LG "#!/bin/bash\n"; print LG "convert -size $img_size xc:white $mapsdir/co +mposite.png\n"; print LG "composite -geometry +0+0 $mapsdir/$pngfile $ +mapsdir/composite.png $mapsdir/composite.png\n"; print LG "mv $mapsdir/composite.png $mapsdir/$pngfile" +; close(LG); my $file = "$rundir/arwpost/composite.sh"; chmod 0755, $file or die "Couldn't chmod $file: $!"; @args = ("$file > /dev/null 2>&1"); print("@args\n"); system(@args) == 0 or die $!; } } } } exit;

Replies are listed 'Best First'.
Re^5: Perl script error
by talexb (Chancellor) on Apr 22, 2016 at 15:20 UTC

    Where are lines 52 and 54? Where are you outputting "Something's wrong"?

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      #!/usr/bin/perl -w use Class::Date qw(date now); use File::Path; use File::Copy; use List::Util qw(min max); use DateTime; $start_time = DateTime->now(); $region = 'greece-9km'; $lrun = '32'; chomp( $flag = $ARGV[0] ); if ( $flag =~ m/^(00|06|12|18)$/ ) { $hh = $flag; chomp( $yyyymmdd = `date +%Y%m%d` ); $yymmdd = substr( $yyyymmdd, 2, 6 ); $real_time = 1; } elsif ( $flag =~ m!^(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])(00|06|12|18) +$! ) { $yyyymmdd = substr( $flag, 0, 8 ); $yymmdd = substr( $yyyymmdd, 2, 6 ); $hh = substr( $flag, 8, 2 ); $real_time = 1; } $yyyymmddhh = $yyyymmdd . $hh; $Class::Date::DATE_FORMAT = "%Y%m%d%H"; $data_inici = date $yyyymmddhh. "0000"; $data_gfs = $data_inici - '6 h'; $rm_wrf_maps = $data_inici - '192 h'; $root = '/home/meteo/Build_WRF'; $gfsdir = "$root/SCRIPTS"; $wrfdir = "$root/SCRIPTS"; $gfsdat = "$root/DATA/GFS"; $wrfdat = "$root/DATA/WRF/$region"; @args = ("rm -rf $gfsdat/*"); system(@args) == 0 or warn; @args = ("rm -rf $wrfdat/*"); system(@args) == 0 or warn; @doms = ( 'europe-27km', 'greece-9km' ); foreach (@doms) { $domain = $_; $wrfmap = "$root/DATA/MAPS/$domain"; @args = ("rm -r $wrfmap/$rm_wrf_maps"); system(@args) == 0 or warn; } @args = ("$gfsdir/get_gfs_30min.pl $data_gfs"); system(@args) == 0 or warn; @args = ("$wrfdir/autorun.WRF.v3.pl $region $lrun $data_inici"); system(@args) == 0 or warn; @args = ("$wrfdir/plot.maps.v2.pl $region $lrun $data_inici"); system(@args) == 0 or warn; @args = ("touch $wrfmap/$data_inici/ready"); system(@args) == 0 or warn; #@args = ("rm -r $gfsdat/*"); #system(@args) == 0 or warn; #@args = ("rm -r $wrfdat/*"); #system(@args) == 0 or warn; print("STOP"); $end_time = DateTime->now; $elapse = $end_time - $start_time; print "Elapsed time : ".$elapse->in_units('minutes')."m\n"; exit;
        Try printing each string first before calling system on it. The strings on lines 51 and 53 don't finish successfully. You should also change
        system(@args) == 0 or warn;

        to

        system(@args) == 0 or warn $?;

        as system doesn't populate $@ which is the default argument of warn.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        Thanks for posting more code. I still have no idea where the problem lines are, or where your error code is coming from. Good luck! :)

        Alex / talexb / Toronto

        Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1161231]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-19 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found