#!/usr/bin/perl use Date::Calc qw(Day_of_Year check_date Days_in_Year); ################################################################# # # program: dates.pl date: 05/22/2003 # Author Mike Raley # Purpose: currently, to take a date : yyyy mm dd # and convert it to the number day of the year. # ################################################################# if ( scalar(@ARGV) == 0 ) { usage(); exit; } elsif ( scalar(@ARGV) == 3 ) { ( $year, $month, $day ) = @ARGV; } elsif ( scalar(@ARGV) == 2 ) { ( $year, $month ) = @ARGV; $day = 1; } else { usage(); exit; } $year = sprintf "%04d", $year; $month = sprintf "%02d", $month; $day = sprintf "%02d", $day; if ( !check_date($year, $month, $day) ) { # Now check the date is correct warning(); exit; } $doy = Day_of_Year($year,$month,$day); $percentage = $doy/Days_in_Year($year,12); print "\nEntered date is: $month/$day/$year\n"; print "Day of year $year is: $doy\n"; $doy = sprintf "%03d", $doy; print "Check observation list for: $year:$doy\n"; exit; ################################################################# # # subroutines follow # ################################################################# sub warning { print "\nDate is incorrect, check entered values\n"; } sub usage { print "\nInput date in following form: dates.pl yyyy mm dd\n"; print "If no day is entered, assumes dd = 1\n"; }