Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Issue with Reading multiple characters

109 views
Skip to first unread message

nik@cabana

unread,
Apr 19, 2021, 5:32:04 PM4/19/21
to
Hello,

I have following lines of code to read 9 file names into array "Input_Files".
Do I=1,2
Read(10, *) CaseNum(I), ! 1 case no variable
& Input_files(I,:), ! 9 file names
EndDo

Problem is when I try to read 9 strings (file names) of characters into "Input_files" array nothing happens.
Program complies but I am not getting desired output. Can somebody tell what is going wrong?

Thank you in advance,
Nik

Neil

unread,
Apr 19, 2021, 5:54:09 PM4/19/21
to
Dear Nik,

I'm surprised it compiles, since there is a missing continuation
character ("&") at the end of the line

> Read(10, *) CaseNum(I), ! 1 case no variable

(before the "!" comment character) and there is a spare comma at the
end of the line

> & Input_files(I,:), ! 9 file names

How is the array Input_files declared?

Best wishes,

Neil.

nik@cabana

unread,
Apr 19, 2021, 6:09:32 PM4/19/21
to
Character*250 Input_files(300,11)

I am using Visual studio with Intel fortran compiler, so "&" is highlighted green in below line
& Input_files(I,:), ! 9 file names


nik@cabana

unread,
Apr 19, 2021, 6:11:51 PM4/19/21
to
sry last line
& Input_files(I,:) ! 9 file names
no comma at the end

Neil

unread,
Apr 19, 2021, 6:37:30 PM4/19/21
to
>> Character*250 Input_files(300,11)

Then

Read(10, *) CaseNum(I),& ! 1 case no variable
& Input_files(I,:) ! 9 file names

will attempt to read CaseNum(I), followed by 11 (not 9) character
strings from the file open on unit 10.

If you just want to read 9 strings, you could use

Read(10, *) CaseNum(I),& ! 1 case no variable
& Input_files(I,1:9) ! 9 file names

Best wishes,

Neil.

nik@cabana

unread,
Apr 19, 2021, 6:47:02 PM4/19/21
to
Read(10, *) CaseNum(I), & ! 1 case no variable
& Input_files(I,1:9) !9 file names

is giving me below error message for first line

Error 1 error #5082: Syntax error, found '&' when expecting one of: ( <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ..

File containing these lines is saved as .for if that is the issue.

JCampbell

unread,
Apr 19, 2021, 9:56:22 PM4/19/21
to
My experience for reading character strings, it is better to use a format statement, rather than list directed I/O ",*)" .
While list directed I/O provides more flexibility, the layout structure of "CaseNum" and the 9 file names should not be too restrictive using a format
perhaps (i5/11(a/)) , if I understand your code.
If you want to persist with (10,*), you could have the file names enclosed in apostrophes or quotation marks,
eg 9 "file_1" "file_2" ... "file_9"

Robin Vowels

unread,
Apr 19, 2021, 11:06:39 PM4/19/21
to
On Tuesday, April 20, 2021 at 8:47:02 AM UTC+10, nik.....@cabana wrote:
> Read(10, *) CaseNum(I), & ! 1 case no variable
> & Input_files(I,1:9) !9 file names
> is giving me below error message for first line
>
> Error 1 error #5082: Syntax error, found '&' when expecting one of: ( <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ..
.
Looks like you are using a FORTRAN 77 compiler.
The correct way for a continuation is to use a non-blank character
(and not a zero) in column 6 of the second line. (The & is not required on the first line.)
On the other hand, ! is Fortran 90, so it looks like your Fortran 90 compiler is broken.

FortranFan

unread,
Apr 19, 2021, 11:12:42 PM4/19/21
to
@Nik,

You may want to also post at the Fortran Discourse site where you can use markdown your code, images, etc. and which can make it easier for other readers to give you suggestions on what you can try:
https://fortran-lang.discourse.group/

Thomas Koenig

unread,
Apr 20, 2021, 1:06:18 AM4/20/21
to
nik@cabana <nikhil...@gmail.com> schrieb:
> Read(10, *) CaseNum(I), & ! 1 case no variable
> & Input_files(I,1:9) !9 file names
>
> is giving me below error message for first line
>
> Error 1 error #5082: Syntax error, found '&' when expecting one of: ( <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ..
>
> File containing these lines is saved as .for if that is the issue.

Probably. The source is valid free from, but invalid fixed form.

AFAIK, *.for is for fixed form. Try renaming to *.f90 and see
if this helps.

gah4

unread,
Apr 20, 2021, 5:19:47 AM4/20/21
to
On Monday, April 19, 2021 at 10:06:18 PM UTC-7, Thomas Koenig wrote:

(snip)

> Probably. The source is valid free from, but invalid fixed form.

> AFAIK, *.for is for fixed form. Try renaming to *.f90 and see
> if this helps.

It might be valid fixed-form with a news reader that removes leading
blanks when submitting posts.

bruno

unread,
Apr 21, 2021, 7:31:56 AM4/21/21
to
I think the : is not allowed for what you aim to to.
bruno
0 new messages