-# this section deals with files that are julian date based
-
-# open a data file with prefix $fn/$year/$day.dat and return an object to it
-sub open
-{
- my ($pkg, $fn, $year, $day, $mode) = @_;
-
- # if we are writing, check that the directory exists
- if (defined $mode) {
- my $dir = "$fn/$year";
- mkdir($dir, 0777) if ! -e $dir;
- }
- my $self = {};
- $self->{fn} = sprintf "$fn/$year/%03d.dat", $day;
- $mode = 'r' if !$mode;
- my $fh = new FileHandle $self->{fn}, $mode;
- return undef if !$fh;
- $fh->autoflush(1) if $mode ne 'r'; # make it autoflushing if writable
- $self->{fh} = $fh;
- $self->{year} = $year;
- $self->{day} = $day;
- dbg("julian", "opening $self->{fn}\n");
-
- return bless $self, $pkg;
-}
-
-# close the data file
-sub close
-{
- my $self = shift;
- undef $self->{fh}; # close the filehandle
- delete $self->{fh};
-}
-
-sub DESTROY # catch undefs and do what is required further do the tree
-{
- my $self = shift;
- dbg("julian", "closing $self->{fn}\n");
- undef $self->{fh} if defined $self->{fh};
-}