From: JuanPablo-Chile on
Hi Fellas:

If somebody has a few minutes I would appreciate it. I got the
following error when compyling my code:

Error--------------------------------------------------
forrtl: severe (24): end of file during read unit 1, file:C\.......


What I want to read is this: (file: apartado1.dat)__________________
(10: size of the matrix, the rest, the values of my matrix)
10
.7582 -.6919 .6802 -1.0725 .8998 -2.1231 .2847 -.
7333 -.7734 .1518
-.3368 .9708 -.1072 1.0135 -.4753 .0689 .3986
1.1163 .6205 -.2877
-1.3718 -.6859 .3317 -.9977 .2914 1.1071 .2450 .
1650 .4062 1.2160
1.4484 -1.0251 .2054 .5889 -.2640 2.4953 .8559 -.
8510 .8119 .7002
.7599 -1.7129 1.5370 -1.6098 1.1095 -1.1097 .3855 .
9652 .8183 .0370
-.9260 -.1119 -.8030 -1.6650 -.9014 .5883 .5542 -.
4152 .0618 .4574
.1990 .2576 2.0807 -2.2772 .3390 .2899 .6623 -.
5809 .8878 .1719
.8488 .9638 1.3219 -.0643 1.3171 .2280 -1.4296 -.
1497 -.5050 -1.7291
-.4175 -.6150 .7208 .3394 .8828 .2842 -.1455 -.
0896 .2892 1.1648
.8057 -1.3556 .1209 -.2222 .5717 -.3001 1.1343 -.
1794 -1.4671 1.3953

My code (if somebody hast the time to try it):
----------------------------------------------------------------------------------------------------------------------
implicit real*8 (a-h,o-z)
parameter (na_max= 100)
dimension a(na_max,na_max),v(na_max),w(na_max)

open (unit=1,file='apartado1.dat',status='old')
read (1,1020) ndim
write (6,*) ndim

do 69 i=1,ndim
read (1,1041) (a(i,j), j=1,ndim)
69 continue
write (6,*) a(1,1)

c----- writing the results
call write_result(ndim,a,v,w,x)

close(1)
stop

1020 format(2I8)
1041 format(1F8.4)
c stop
end

c-------------------------------------------------------
c----- Writing the results
subroutine write_result(n,a_mat,b,c,x)
implicit real*8 (a-h,o-z)
dimension a_mat(n,n),b(n),c(n)

open (unit=10,file='results.dat',status='old')

write (10,10)
do 20 i=1,n
write (10,30) (a_mat(i,j),j=1,n)
20 continue

close(10)

10 format ('The Matrix input is: '/)
30 format (5(1x,1pe14.6))

return
end

---------------------------------------------------------------------------------------
Last comments:

The thing is that I am leraning how to read files in fortran. After a
few headaches I have done this code. I can read the value 10, as you
can see after running the code. Now I want to read the values of the
matrix, I got many mistakes because of the format how to read the
numbers and save them in a file (results.dat). after a few
modifications the problem seems to solved but a new kind of error
appears, the end-of-file stuff.

Well, thanks to all for all this time reading this forum.

Thanks to the Fortran community

From: Gordon Sande on
On 2010-04-15 13:38:21 -0300, JuanPablo-Chile <jpsegura(a)gmail.com> said:

> Hi Fellas:
>
> If somebody has a few minutes I would appreciate it. I got the
> following error when compyling my code:
>
> Error--------------------------------------------------
> forrtl: severe (24): end of file during read unit 1, file:C\.......
>
>
> What I want to read is this: (file: apartado1.dat)__________________
> (10: size of the matrix, the rest, the values of my matrix)
> 10
> .7582 -.6919 .6802 -1.0725 .8998 -2.1231 .2847 -.
> 7333 -.7734 .1518
> -.3368 .9708 -.1072 1.0135 -.4753 .0689 .3986
> 1.1163 .6205 -.2877
> -1.3718 -.6859 .3317 -.9977 .2914 1.1071 .2450 .
> 1650 .4062 1.2160
> 1.4484 -1.0251 .2054 .5889 -.2640 2.4953 .8559 -.
> 8510 .8119 .7002
> .7599 -1.7129 1.5370 -1.6098 1.1095 -1.1097 .3855 .
> 9652 .8183 .0370
> -.9260 -.1119 -.8030 -1.6650 -.9014 .5883 .5542 -.
> 4152 .0618 .4574
> .1990 .2576 2.0807 -2.2772 .3390 .2899 .6623 -.
> 5809 .8878 .1719
> .8488 .9638 1.3219 -.0643 1.3171 .2280 -1.4296 -.
> 1497 -.5050 -1.7291
> -.4175 -.6150 .7208 .3394 .8828 .2842 -.1455 -.
> 0896 .2892 1.1648
> .8057 -1.3556 .1209 -.2222 .5717 -.3001 1.1343 -.
> 1794 -1.4671 1.3953
>
> My code (if somebody hast the time to try it):
> ----------------------------------------------------------------------------------------------------------------------

>
> implicit real*8 (a-h,o-z)
> parameter (na_max= 100)
> dimension a(na_max,na_max),v(na_max),w(na_max)
>
> open (unit=1,file='apartado1.dat',status='old')
> read (1,1020) ndim
> write (6,*) ndim
>
> do 69 i=1,ndim
> read (1,1041) (a(i,j), j=1,ndim)
> 69 continue
> write (6,*) a(1,1)
>
> c----- writing the results
> call write_result(ndim,a,v,w,x)
>
> close(1)
> stop
>
> 1020 format(2I8)
> 1041 format(1F8.4)
> c stop
> end
>
> c-------------------------------------------------------
> c----- Writing the results
> subroutine write_result(n,a_mat,b,c,x)
> implicit real*8 (a-h,o-z)
> dimension a_mat(n,n),b(n),c(n)
>
> open (unit=10,file='results.dat',status='old')
>
> write (10,10)
> do 20 i=1,n
> write (10,30) (a_mat(i,j),j=1,n)
> 20 continue
>
> close(10)
>
> 10 format ('The Matrix input is: '/)
> 30 format (5(1x,1pe14.6))
>
> return
> end
>
> ---------------------------------------------------------------------------------------
Last
>
> comments:
>
> The thing is that I am leraning how to read files in fortran. After a
> few headaches I have done this code. I can read the value 10, as you
> can see after running the code. Now I want to read the values of the
> matrix, I got many mistakes because of the format how to read the
> numbers and save them in a file (results.dat). after a few
> modifications the problem seems to solved but a new kind of error
> appears, the end-of-file stuff.
>
> Well, thanks to all for all this time reading this forum.
>
> Thanks to the Fortran community

Hint 1: Write what was read immediately while debugging. Was it the
first or the last read that failed? You don't know from what was shown.

Hint 2: End-of-file is sometimes a problem with the last record being
incomplete due to a missing end-of-line because of text processing
problems. Add an extra blank line for a quick check. Read all the options
for you text editor to have it force an end-of-line at end (or get a
better text editor which will).

These hints are based on common problems of this sort as I did not read
your code becasuse you failed to say which version of which compiler on
which computer. But you get credit for showing the exact error and all
the code.




From: Richard Maine on
JuanPablo-Chile <jpsegura(a)gmail.com> wrote:

> I got the following error when compyling my code:
> forrtl: severe (24): end of file during read unit 1, file:C\.......

I seriously doubt you got that error while compiling. That would be an
error from running it. But anyway...

> 10
> .7582 -.6919 .6802 -1.0725 .8998 -2.1231 .2847 -.
> 7333 -.7734 .1518
....
[mostly elided]
> do 69 i=1,ndim
> read (1,1041) (a(i,j), j=1,ndim)
> 69 continue
....
> 1041 format(1F8.4)

Note the "1" in the 1F8.4 in your format. This format defines 1 field on
a line - that's all. When your read statement tries to read 10 values,
this means that it reads 1 of them from the first line, since that's all
your format said to read from a line. Since there are still more values
to read, goes to the next line and reuses the format, reading 1 value
from that line. (This is called "format reversion" and in some cases
reuses only part of the format, but in your simple case, it reuses the
whole thing).

The important part is that when when the format is used up, the reading
then goes to the next line as part of reusing the format. It does not
multiply the effect of the format on the same line.

Thus the read statement for what you intend to be the first row ends up
reading 1 value from each of 10 lines instead of 10 values from 1 line.
When you try to tead the second row, you are at the end of the file.

Your format statement needs to be at least 10F8.4 to read 10 values from
a single line. It is harmless for the repeat factor (the 10) to be
larger than the number of values to be read, but if it it too small, you
will get the kind of behavior you are seeing. I recomend using a value
sufficiently large that it will always be large enough. For example, you
could use something like 999F8.4.

There are more sophisticated ways to handle such things, including ways
that don't require you to come up with a value guaranteed to be large
enough, but I would guess that this simple version is adequate for your
current purposes.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: Tobias Burnus on
On 04/15/2010 07:23 PM, Richard Maine wrote:
> For example, you
> could use something like 999F8.4.
>
> There are more sophisticated ways to handle such things, including ways
> that don't require you to come up with a value guaranteed to be large
> enough,

For instance in Fortran 2008; instead of 999F8.4 one can then write
*F8.4. Thus, if you have one of the very few compilers which already
implement it ...

Tobias
From: JuanPablo-Chile on
Hi:

I changed the code as you recommended and now I am geeting the next
error:

forrtl: severe (64): input conversion error, unit 1, fil C:\.....

--------------------------------------------------
the new line in the code:
....
1020 format(2I8)
1041 format(999F8.4)
....
-----------------------------------------------------
just in case I am using Visual Fortran 5.0 (Microsoft Developer Studio
97)

Jp
 |  Next  |  Last
Pages: 1 2 3 4 5 6 7
Prev: GCC/gfortran 4.5.0 release
Next: linking not done