LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-25-2019, 05:50 AM   #1
Fpaul8
LQ Newbie
 
Registered: Jul 2019
Posts: 16

Rep: Reputation: Disabled
Error: Expected variable in READ statement at (1)


Hello!

I am transfering old program from FORTRAN 4 (OC: RSX – 11M) to gfortran and its shows an Error:

READ (1,*)(TI0(I),I=1,NN2
1
Error: Expected variable in READ statement at (1)

What shoul I do?

Sincerely,
Fpaul8
 
Old 07-25-2019, 05:56 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
didn't you miss a closing parenthesis?
 
1 members found this post helpful.
Old 07-25-2019, 10:03 AM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by pan64 View Post
didn't you miss a closing parenthesis?
Yeah... That wasn't valid syntax with the PDP-11 compilers either. :^)
 
Old 07-25-2019, 09:19 PM   #4
Fpaul8
LQ Newbie
 
Registered: Jul 2019
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hi all,

Thank you for quick answers.
I am sorry but I missed one bracket when pasted code.
I am getting the same errors ( You can see part of code below):

145 READ (1, *) NN1, NN2, N3, N4, N5
146 READ (1, *) (TN1 (I), I=1, NN1)
147 READ (1, *) (SN1 (I), I=1, NN1)
148 READ (1, *) (TIO (I), I=1, NN2)
149 READ (1, *) (SIO (I), I=1, NN2)

VibeOPS.f:148.18:

READ (1, *) (TIO (I), I=1, NN2)
1
Error: Expected variable in READ statement at (1)
VibeOPS.f:149.18:

READ (1, *) (SIO (I), I=1, NN2)
1
Error: Expected variable in READ statement at (1)


Thank you
 
Old 07-30-2019, 09:45 AM   #5
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by Fpaul8 View Post
Hi all,

Thank you for quick answers.
I am sorry but I missed one bracket when pasted code.
I am getting the same errors ( You can see part of code below):

145 READ (1, *) NN1, NN2, N3, N4, N5
146 READ (1, *) (TN1 (I), I=1, NN1)
147 READ (1, *) (SN1 (I), I=1, NN1)
148 READ (1, *) (TIO (I), I=1, NN2)
149 READ (1, *) (SIO (I), I=1, NN2)

VibeOPS.f:148.18:

READ (1, *) (TIO (I), I=1, NN2)
1
Error: Expected variable in READ statement at (1)
VibeOPS.f:149.18:

READ (1, *) (SIO (I), I=1, NN2)
1
Error: Expected variable in READ statement at (1)


Thank you
I haven't had a lot of trouble compiling old FORTRAN-IV or F77 code other than dealing with indentation problems but I'll take a stab at this. (Full disclosure: it's been quite a while since I wrote FORTRAN code in my sleep.)

Qs:

* Can you provide a little context? Single READ statements aren't a lot of help.

* Have you tried a smaller version of the program that isn't compiling that isolates one of the problematic statements? Something small enough that you could paste it in a post (inside "code" directives, of course.) This program wouldn't have to actually do anything useful but it if fails to compile in the same way others could cut-n-paste it into a file on their system and hack at it until it does compile. Example:
Code:
      program test
      parameter (nn2 = 10)
      dimension tio(nn2)
      integer*2 i

      read(1, *) (tio(i), i=1, nn2)
      end
Compiles just fine. (It's useless but it compiles.)

UPDATE:

About that error message...

I suspect that it's pointing to line:column what the compiler sees an error. If so, that seems to indicate that the variable "I" is the problem. Have you done something like
Code:
IMPLICIT NONE
and then forget to declare "I"? Or declare "I" to be something other than an integer? Adding the "implicit none" to my little test program resulted in errors but not what you are seeing.

Again, context will help.


Cheers...

Last edited by rnturn; 07-30-2019 at 10:00 AM.
 
1 members found this post helpful.
Old 07-31-2019, 10:24 PM   #6
Fpaul8
LQ Newbie
 
Registered: Jul 2019
Posts: 16

Original Poster
Rep: Reputation: Disabled
Fortran IV and gfortran

Hello all !

Thank you for your help.
I found mistakes.
When I describing the variables, I made a typo and instead TIO and SIO I put zero on the end (TI0 and SI0).
This is old program in Fortran IV( Consists around 1500 lines) worked well and now I am trying to “reanimate” it.
I got more errors, but I am trying to fix it by myself.


Also, when compiling code, you recommended :

1 program test
2 parameter (nn2 = 10)
3 dimension tio(nn2)
4 integer*2 i
5 read(1, *) (tio(i), i=1, nn2
6 end

I received an error:

At line 5 of file programtest.f (unit = 1, file = 'fort.1')
Fortran runtime error: End of file

What’s wrong with it?


Another issue: when I tried to install Fortran Analyzer that you recommended my MacBook doesn’t allow to do it.


Sincerely,
Fpaul8

Last edited by Fpaul8; 08-01-2019 at 09:52 PM.
 
Old 08-01-2019, 10:13 AM   #7
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by Fpaul8 View Post
Hello all !

Thank you for your help.
I found mistakes.
When I describing the variables, I made a typo and instead TIO and SIO I put zero on the end (TI0 and SI0).
This is old program that I wrote long time ago in Fortran IV( Consists around 1500 lines) worked well and now I am trying to “reanimate” it.
I got more errors, but I am trying to fix it by myself.
Hmm... So I'm guessing that "TIO" was declared to be an array but "TI0" was not, right? :^)

"Back in the day"... I would ask the compilers to produce a detailed listing and examine the list of defined variables at the bottom and look for variables that were used but not declared to show spelling errors. (This was mainly using the IBM compilers on VM/CMS but I think it was also an option on the DEC compilers---no idea whether GNU even generates a listing). The other thing you could do is to add "implicit none" right after the "program" statement. That'll cause the compiler to holler about each and every undeclared variable. (Sort of like "use strict" in Perl.)

Quote:
Also, when compiling code, you recommended :

1 program test
2 parameter (nn2 = 10)
3 dimension tio(nn2)
4 integer*2 i
5 read(1, *) (tio(i), i=1, nn2
6 end

I received an error:

MacBook-Pro-2:Vibe_OPS_30.01.17 Pavel$ ./programtest programtest.f
At line 5 of file programtest.f (unit = 1, file = 'fort.1')
Fortran runtime error: End of file

What’s wrong with it?
My goal with the throwaway program was to isolate the READ and see if the compiler balked at it for some reason. The "0" vs. "O" error is pretty common (I sure do it a lot---bummer that those keys are so close). Glad you found it. BTW: One way to make it easier for others to read the code is to enclose it in the "code" tags used on this site. Highlight the code and click on the "pound sign" above the Message field. It turns the text into monospaced typeface and the zeroes will be rendered with a little dot in the middle---at least they do on my desktop. Another thing you could do would be to use lowercase characters in your code. Except for the IBM FORTRAN-IV and FORT-H compilers and DEC FORTRAN-IV compilers, lowercase characters in statements have been acceptable in FORTRAN source code. I recall that the RT-11 and RSX-11M-PLUS F77 compilers did as did VAX FORTRAN as do the GNU compilers. With lowercase statements ("o" and "0" are readily differentiated).

As for that error message: I get it, too. I never opened an actual file to be attached to unit "1". (Remember from above: I was only using the compiler to verify syntax) Try:
Code:
      program test
      implicit none
      integer*2 nn2
      parameter (nn2 = 10)
      real*4 tio(nn2)
      integer*1 i

      open(1, file='test.data')
      read(1, *) (tio(i), i=1, nn2)
      close(1)
      write(*, '(1x, f10.1)') (tio(i), i=1, nn2)

      end
with a file 'test.data' that contains 1 record with 10 numbers/record (remember: nn2=10).

Simple test:
Code:
$ gfortran -o test test.f
$ cat test.data
1. 2. 3. 4. 5. 6. 7. 8. 9. 0.
$ ./test
        1.0
        2.0
        3.0
        4.0
        5.0
        6.0
        7.0
        8.0
        9.0
        0.0
$
Quote:
Another issue: when I tried to install Fortran Analyzer that you recommended my MacBook doesn’t allow to do it.
Fortran Analyzer?

I don't recall recommending such a thing but I'm definitely intrigued...
"lint" for FORTRAN?

Cheers...
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash read input in case statement not working as expected woodson2 Programming 10 10-05-2018 10:44 AM
Perl switch statement throwing error like Bad case statement (invalid case value?) kavil Programming 2 10-07-2010 04:50 AM
expected declaration or statement at end of input eMCeee89 Programming 1 05-04-2009 02:54 AM
error: expected declaration or statement at end of input ? psernaalvarez Programming 3 02-16-2008 02:35 PM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 08:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration