#!/usr/bin/perl # put your perl path on the first line use strict; ############################### # # multi.pl 0.01c # # multiple monthly reports with Analog # by Marco Bernardini - webmaster@taggiasca.com # # You can use this utility freely, and you can # modify and improve it (let me know, if you do # this!): it is under Perl Artistic License. # It may be used for commercial use only by # prior arrangement with the author # (Marco Bernardini, webmaster of taggiasca.com). # # This program is free, but if you buy some # excellent extravirgin olive oil on my site # http://www.taggiasca.com # this make me a lot happy. # # Analog is (c) by Stephen Turner - see # http://www.analog.cx for more infos # ##### # # USAGE: # 1) download Analog at http://www.analog.cx # 2) RTFM # 3) put this perl script into Analog directory # 4) create an Analog config file good for multiple # monthly reports as you like (see my sample) # 5) assign to $configfile the name of the config # file created at 4) # 6) assign your choosen start year and month to # $yrstart and $mtstart # 7) assign your choosen end year and month to # $yrend and $mtend # 8) assign a string to $prefix: the name of every # file generated with this script start with it # (you can leave it blank) # 9) assign a string to $extension: if you create # HTML files use .htm or .html, if you create # ASCII or PLAIN files you can use what you want # A) assign an EXISTING directory name with trailing # slash / to $outdir (or leave it blank to have # output into Analog directory) # B) launch this script and wait for a "beep" or # whatever sound is doing your machine # C) Have fun with your multiple monthly reports # # If you need to re-run this program and you don't # want to regenerate all reports set $makerep # variable to something different than "yes" # # ADVANCED USAGE: # If you love frames, you can have a right vertical # menu with link to generated reports. # Variables and default values are: # $useframes = "yes"; # set to something different than "yes" if # you don't need frames # $moreframes = "yes"; # set to "yes" if you need to see # side-by-side reports # $mainframe = "index.html"; # the main frame file (not your Cray) # $menuframe = "nav.htm"; # the file containing the menu # $menubgcolor = "#FFFFFF"; # $menutext = "#000000"; # $menulink = "#000080"; # $menuvlink = "#800080"; # $menualink = "#FF0000"; # $menufontface = "Arial,Helvetica"; # $menufontsize = "2"; # usual HTML values for BODY and FONT # of $menuframe file # # NOTE: # a) if you need side-by-side reports # it's better to set your monitor to # 1024 x 768 or more. # b) you must use a JavaScript/frame enabled # browser # # ############################################## ######### VARIABLES YOU MUST CHANGE ############ my $configfile = "multi.cfg"; # start year and month my $yrstart = 1999; my $mtstart = 11; # end year and month my $yrend = 2000; my $mtend = 3; my $prefix ="r"; my $extension = ".htm"; my $outdir = "multi/"; my $makerep = "yes"; ####### ADVANCED USAGE ################ my $useframes = "yes"; my $moreframes = "yes"; my $mainframe = "index.html"; my $menuframe = "nav.htm"; my $menubgcolor = "#FFFFFF"; my $menutext = "#000000"; my $menulink = "#000080"; my $menuvlink = "#800080"; my $menualink = "#FF0000"; my $menufontface = "Arial,Helvetica"; my $menufontsize = "2"; ############################### ###### internal variables reminder - don't modify! ######### my $adesso = time ; # to show astounding elaboration time my $i; # loops my $j; # loops my $xyr; # 2 digit year (prefixed with 0) my $fyr; # 4 digit year - because 00 is smaller than 99 my $xmt; # 2 digit month (prefixed with 0) my $excmd; # the command line my $elem = 0; # the n-th element of the array my $filename; # file name my $nryrs; # number of years my $idxyr; # index my %yrarr; # hash containing years in 2 and 4 digits my @repfiles; # list of reports for the menu my $menu; # the menu my $lngfile; # your language file extracted from $configfile my @lngmnth; # array - month name in your language my $dum; # trash can my @tmp; # other trash can my @tmp2; # ditto my $title; # menu title my $hostname; # host name (what else?) my $hosturl; # host url my @titfiles; # titles for multiple frames ############################### if ($useframes ne "yes") { $moreframes = "no"; # You moron! How can you make # multiple frames if frames # are disabled? } ######################## # grab month names from # LANGFILE in $configfile ######################## if ($useframes eq "yes") { open (CONF , $configfile) || die $!; push (@tmp,); close CONF; chomp @tmp; @tmp2 = grep (/LANGFILE/,@tmp); $lngfile = $tmp2[0]; $lngfile =~ s/LANGFILE\b//i; $lngfile =~ s/ //; $lngfile = "lang/uk.lng" if (($lngfile eq "")||($lngfile =~ /^#/)); @tmp2 = grep (/HOSTNAME/,@tmp); $hostname = $tmp2[0]; $hostname =~ s/HOSTNAME\b//i; $hostname =~ s/ //; $hostname =~ s/\"//g; $hostname = "Web server" if ($hostname eq ""); @tmp2 = grep (/HOSTURL/,@tmp); $hosturl = $tmp2[0]; $hosturl =~ s/HOSTURL\b//i; $hosturl =~ s/ //; $hosturl =~ s/\"//g; print "Language file in use: $lngfile\n"; @tmp = ""; pop @tmp; open (LNG , $lngfile) || die $!; push (@tmp,); close LNG; chomp @tmp; @tmp = grep !/^##/ , @tmp; @lngmnth[1..12] = @tmp[8..19]; $title = $tmp[68]; } ######################## # create year hash ######################## for $i ($yrstart..$yrend) { if ($i >= 2000) { $xyr = sprintf "%02.0f",$i - 2000; } else { $xyr = sprintf "%02.0f",$i - 1900; } $yrarr{$i} = $xyr; } $nryrs = scalar(keys %yrarr); ######################## # create reports ######################## print "Creating reports for $nryrs years\n\n" if ($makerep eq "yes"); if ($nryrs == 1) { # we are into the same year ($fyr,$xyr)= %yrarr; $menu .= "
$fyr
\n"; for $j ($mtstart .. $mtend) { # while (($fyr,$xyr)=each %yrarr) { $xmt = sprintf "%02.0f",$j; &MakeCommand ($xyr,$fyr); # } } } else { foreach (sort keys %yrarr) { $fyr = $_; $xyr = $yrarr{$_}; $menu .= "
$fyr
\n"; print "******** Scanning year $fyr ($xyr) ********\n\n" if ($makerep eq "yes"); if ($elem == 0) { for $j ($mtstart .. 12) { $xmt = sprintf "%02.0f",$j; &MakeCommand ($xyr,$fyr); } } if (($elem > 0) && ($elem < ($nryrs - 1))) { for $j (1 .. 12) { $xmt = sprintf "%02.0f",$j; &MakeCommand ($xyr,$fyr); } } if ($elem == ($nryrs-1)) { for $j (1 .. $mtend) { $xmt = sprintf "%02.0f",$j; &MakeCommand ($xyr,$fyr); } } $elem++; } } &MakeFrame if ($useframes eq "yes"); my $dopo=time; my $tempo=$dopo-$adesso; print "\aDone - Job time: $tempo seconds "; print "skipping reports generation" if ($makerep ne "yes"); print "\n\n"; ############################### sub MakeCommand { my $dum; my $tit; my ($xyr,$fyr) = @_; my $filename = $prefix . $fyr . $xmt . $extension; $excmd = "analog -G +g" . $configfile . " +C\"FROM " . $xyr . $xmt . "01\" +C\"TO " .$xyr . $xmt . "31\" +C\"OUTFILE " . $outdir . $filename . "\""; print "Command line:\n$excmd\n" if ($makerep eq "yes"); print "$filename report saved into $outdir\n\n" if ($makerep eq "yes"); my $dum = `$excmd` if ($makerep eq "yes"); push (@repfiles, $filename); if ($moreframes ne "yes") { $menu .= "$lngmnth[$xmt]
\n" ; } else { $tit = "tit" . $filename; $menu .= "$lngmnth[$xmt] <---> $lngmnth[$xmt]
\n" ; push (@titfiles, $tit); $dum = $outdir . $tit; open (TITOUT , "> $dum") || die $!; print TITOUT qq~Monthly reports - title

$lngmnth[$xmt] $fyr

~; close TITOUT; } } ############################### sub MakeFrame { my $i; if ($moreframes ne "yes") { open (MAINFRAMEOUT , "> $outdir$mainframe") || die $!; print MAINFRAMEOUT qq~$title ~; close MAINFRAMEOUT; } else { open (MAINFRAMEOUT , "> $outdir$mainframe") || die $!; print MAINFRAMEOUT qq~$title $hostname Sorry, this page use frames<BR><BR> $menu ~; close MAINFRAMEOUT; } open (NAVFRAMEOUT , "> $outdir$menuframe") || die $!; print NAVFRAMEOUT qq~ $title $hostname - menu $title
$hostname


$menu


This page
was made
with multi
© 2000 by
Marco Bernardini
~; close NAVFRAMEOUT; }