# Read(1,"(\<n\>i10)") problem

**URL:** <https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791>\
**Category:** Uncategorized\
**Created:** [April 8, 2024, 5:27am UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791 "2024-04-08T05:27:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cean](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@Cean](https://fortran-lang.discourse.group/u/Cean)\
**Post date:** [April 8, 2024, 5:27am UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/1 "2024-04-08T05:27:40Z")

</div>

Hi,

I have an old code. It has this line. Can’t compile it with gFortran. How do I change it?

`Read(1,"(<n>i10)") (a(J),J=1,n)`

N is read in before this line.

Thanks for help.

Regard,

Cean

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [April 8, 2024, 6:54am UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/2 "2024-04-08T06:54:05Z")

</div>

I guess you mean:

```auto
read(1,"(<n>i10)") (a(j), j =1,n)

```

as the line you give is standard Fortran (even as old as FORTRAN 77)… You could try:

```auto
read(1,"(*(i10))") (a(j), j =1,n)

```

The asterisk indicates an unlimited repetition of the format group that follows (hence the extra parentheses).

---

<div class="post-metadata">

**Author:** ![JohnCampbell](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@JohnCampbell](https://fortran-lang.discourse.group/u/JohnCampbell)\
**Post date:** [April 8, 2024, 11:39am UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/3 "2024-04-08T11:39:16Z")

</div>

The use of `<n>` is a non-standard extension, which only a few Fortran compilers supported, notably Dec/Vax.  
I would suggest you think about the problem and perhaps solve it in a different way to what Dec provided.  
How big can “n” be is one issue, but to me the important issue is how big/long a data line do you want to prepare ?

Perhaps a compromise as 10 numbers to a line (100 characters) might be a better way to start.  
read (1,fmt=‘(10I10)’ ) (a(j),j=1,n)  
This may provide a more manageable data set to prepare, than perhaps when n=100 where the line of data is 1000 characters.

Also, some compilers supported a comma to terminate each 10-character field, so each “I10” field could be terminated with a comma, so reducing the length of the data line. I am not sure which compilers support this non-standard extension, but it was a feature I used extendively when preparing data.

Another alternative is to use list-directed I/O where no fixed field formatting is used. This can be much better when typing the data into a file, however if the data is being generated by another Fortran program, a fixed field length layout is more reliable and less “error-prone” approach.

I am also puzzled by the use of file unit = 1. On some compilers, this is terminal input, so the data interface may be different to what I am suggesting.

---

<div class="post-metadata">

**Author:** ![nja](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@nja](https://fortran-lang.discourse.group/u/nja)\
**Post date:** [April 8, 2024, 4:28pm UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/4 "2024-04-08T16:28:35Z")

</div>

For the record, the gfortran documentation mentions this extension [here](https://gcc.gnu.org/onlinedocs/gfortran/Variable-FORMAT-expressions.html), which it does not support. The workaround suggested is not exactly your case, but you probably also have write statement with variable format expression in your legacy code.

---

<div class="post-metadata">

**Author:** ![IanMartinAjzenszmidt](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ianmartinajzenszmidt/32/1992_2.png) [@IanMartinAjzenszmidt](https://fortran-lang.discourse.group/u/IanMartinAjzenszmidt)\
**Post date:** [April 8, 2024, 5:38pm UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/5 "2024-04-08T17:38:02Z")

</div>

[quote=“Cean, post:1, topic:7791”]  
Read(1,“(i10)”) (a(J),J=1,n)  
[/quote]`

```auto
ian@ian-Latitude-E7440:~$ nano readb.f
ian@ian-Latitude-E7440:~$ gfortran readb.f -ffree-form
ian@ian-Latitude-E7440:~$ ./a.out
6
1
2
3
4
5
6
           1 2 3 4 5 6 0 0 0 0 7 6
ian@ian-Latitude-E7440:~$ cat readb.f
integer :: J,i
integer a(10), n
n = 10
do i = 1, 10, 1
 a(i) = 0
end do
read(5,*)n
Read(5,"(i10)") (a(J),J=1,n)
print *,a, j, n
end program
ian@ian-Latitude-E7440:~$ 

The above code should work. Replace the quotation marks with ", and the 1 with 5, to input from the screen and keyboard.

```

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [April 8, 2024, 6:05pm UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/6 "2024-04-08T18:05:35Z")

</div>

I would try just

```auto
Read(1,*) a

```

which reads the entire array `a` with a list-directed read, but you should temporarily add a debugging line

`print*,a`

to check that the data is being read properly from the file.

Another possibility, which is closer to the original code, is

`Read(1,"(*(i10))") a`

which means to read each element of `a` using the `i10` format. A final possibility is to create a format string such as “(5i10)” (if for example n = 5) at run-time using an internal write.

---

<div class="post-metadata">

**Author:** ![Cean](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@Cean](https://fortran-lang.discourse.group/u/Cean)\
**Post date:** [April 8, 2024, 9:57pm UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/7 "2024-04-08T21:57:25Z")

</div>

Yes. Never see it before. And (1,“(\*(i10))” works.

(1,\*) also works. This is what I familiar with. Don’t know the former can come down to this.

Thanks all.

---

<div class="post-metadata">

**Author:** ![Harper](https://avatars.discourse-cdn.com/v4/letter/h/b5ac83/32.png) [@Harper](https://fortran-lang.discourse.group/u/Harper)\
**Post date:** [April 8, 2024, 11:25pm UTC](https://fortran-lang.discourse.group/t/read-1-n-i10-problem/7791/8 "2024-04-08T23:25:53Z")

</div>

The difference between `(1,“(*(i10))”` and `(1,*)` will hit you if any of the integers are really large. With most compilers `huge(1)` has 10 digits. An input file intended for the former might say `1234567890111111111`, but that won’t do what you want with the latter. On the other hand, `-1234567890` input would be OK with the latter but not the former.  
That is one reason why `iostat` and `iomsg` were invented.
