Subject: | No support for reading D and E formats |
Just as in #47484, there is no sub to read D and E formats:
perl -MFortran::Format -le 'print
Fortran::Format->new("E5.1")->read("1.1E1", 1)'
Can't locate object method "read_once" via package
"Fortran::Format::Edit::E" at
/usr/local/share/perl/5.12.3/Fortran/Format.pm line 769, <$fh> line 1.
Expected output:
11
The fix:
diff --git a/Format.pm b/Format.pm
index 06e2efa..82e0c65 100644
--- a/Format.pm
+++ b/Format.pm
@@ -1001,6 +1001,39 @@ sub write_once {
$s || "*" x $width;
}
+sub read_once {
+ my ($self) = @_;
+ return undef unless $self->writer->want_more;
+ my $s = $self->writer->read($self->{width});
+ my $f;
+
+ my ($num, $exp) = $s =~ /^ *([+-]?[\d ]*\.?[\d
]*)((?:[ed][+-]?|[+-])[\d ]+)?$/i;
+ if (defined $num and $num =~ /\d/) {
+ unless ($num =~ /\./) {
+ substr $num, length($num) - $self->{precision}, 0, '.';
+ }
+ if (!defined $exp) {
+ $s = $num;
+ } elsif ($exp =~ /[ed]/i) {
+ $s = $num . $exp;
+ } else {
+ $s = $num . $self->exp_char . $exp;
+ }
+ if ($self->writer->bz) {
+ $s =~ s/ /0/g;
+ } else {
+ $s =~ s/ //g;
+ }
+ $f = $s / 10**($self->writer->scale);
+ } elsif ($s =~ /^[ .]*$/) {
+ $f = 0;
+ } else {
+ die 'invalid ', $self->exp_char, " number'$s'\n";
+ }
+ $self->writer->put($f);
+ 1;
+};
+
sub exp_char { "D" }