From: braver on
Greetings -- I have a sparse matrix in Harwell-Boeing (HB) format,
which saves space by making use of the fact that all values are single-
digit integers. Thus, even though the target array in the program is
defined as

double values(nnzero)

the input format is (40I2) per line (per HB spec) and it's read by a
standard HB input matrix routine into valfmt, and the main reading
loop is then

read ( lunit, valfmt ) ( values (i), i = 1, nnzero )

Each text line to read contains 40 one-digit integers, space
separated, like

1 4 3 2 5 4 3 2 ...

-- conforming to the 40I2 format specifier.

Now this code works with Intel Fortran, but fails to run with
gfortran, with

Fortran runtime error: Expected INTEGER for item 2 in formatted
transfer, got REAL
(40I2)

-- at the read loop line above.

What simplest type-conversion can I add to the read loop to convert
integer inputs into double values on the fly?

Cheers,
Alexy
From: James Van Buskirk on
"braver" <deliverable(a)gmail.com> wrote in message
news:8ed0e754-ac58-4603-bbda-8fb3af2d5727(a)b9g2000prh.googlegroups.com...

> Greetings -- I have a sparse matrix in Harwell-Boeing (HB) format,
> which saves space by making use of the fact that all values are single-
> digit integers. Thus, even though the target array in the program is
> defined as

> double values(nnzero)

Did gfortran really approve?

> the input format is (40I2) per line (per HB spec) and it's read by a
> standard HB input matrix routine into valfmt, and the main reading
> loop is then

> read ( lunit, valfmt ) ( values (i), i = 1, nnzero )

> Each text line to read contains 40 one-digit integers, space
> separated, like

> 1 4 3 2 5 4 3 2 ...

> -- conforming to the 40I2 format specifier.

> Now this code works with Intel Fortran, but fails to run with
> gfortran, with

> Fortran runtime error: Expected INTEGER for item 2 in formatted
> transfer, got REAL
> (40I2)

> -- at the read loop line above.

> What simplest type-conversion can I add to the read loop to convert
> integer inputs into double values on the fly?

C:\gfortran\clf\HB>type HB.in
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
9 0
8 4 2 1 9 1 7 6 5 0 4 6 7 2 5 8 4 1 4 6 5 6 9 8 7 4 2 3 5 1 5 1 5 2 5 3 6 9
8 7
1 2 3 4

C:\gfortran\clf\HB>type HB.f90
program HB
implicit none
integer, parameter :: nnzero = 84
double precision values(nnzero)
integer i
integer iunit
character valfmt*80

iunit = 10
valfmt = '(40f2.0)'
open(iunit, file='HB.in', status='old')
read(iunit, valfmt) (values(i), i = 1, nnzero)
write(*,'(15(f4.1))') values
end program HB

C:\gfortran\clf\HB>c:\gfortran\win64\bin\x86_64-pc-mingw32-gfortran
HB.f90 -oHB

C:\gfortran\clf\HB>HB
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 0.0 1.0 2.0 3.0 4.0 5.0
6.0 7.0 8.0 9.0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 0.0
1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 0.0 8.0 4.0 2.0 1.0 9.0
1.0 7.0 6.0 5.0 0.0 4.0 6.0 7.0 2.0 5.0 8.0 4.0 1.0 4.0 6.0
5.0 6.0 9.0 8.0 7.0 4.0 2.0 3.0 5.0 1.0 5.0 1.0 5.0 2.0 5.0
3.0 6.0 9.0 8.0 7.0 1.0 2.0 3.0 4.0

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


From: Tobias Burnus on
On Apr 6, 9:31 am, braver <delivera...(a)gmail.com> wrote:
> Greetings -- I have a sparse matrix in Harwell-Boeing (HB) format,
> which saves space by making use of the fact that all values are single-
> digit integers.  Thus, even though the target array in the program is
> defined as
>
> double values(nnzero)

I assume you mean "double precision" and not "double".


> the input format is (40I2) per line (per HB spec) and it's read by a
> standard HB input matrix routine into valfmt, and the main reading
> loop is then
>           read ( lunit, valfmt ) ( values (i), i = 1, nnzero )
[...]
> Now this code works with Intel Fortran, but fails to run with
> gfortran, with
>
> Fortran runtime error: Expected INTEGER for item 2 in formatted
> transfer, got REAL
> (40I2)

It does not seem to work with ifort: it does not show an error but one
gets numbers such as 4.940656458412465E-324, which is presumably not
what you want.

Any reason for not using '(40f2.0)' ?

Tobias
From: braver on
On Apr 6, 1:35 am, Tobias Burnus <bur...(a)net-b.de> wrote:

> Any reason for not using '(40f2.0)' ?

Tobias -- danke schön! Exactly what the doctor ordered.

Cheers,
Alexy