LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Syntax error when compiling (https://www.linuxquestions.org/questions/linux-newbie-8/syntax-error-when-compiling-755531/)

Laughing_Man 09-16-2009 12:31 AM

Syntax error when compiling
 
Not sure if this is the place to be asking, but I've got a FORTRAN issue that is driving me crazy.

I've added an OPEN/READ statement to a preexisting energy balance model because i need to run the code with changing atmospheric variables:

Code:


c        Distribute cosq, fraq, from latitudinal to global ebm arrays

      ie = 0
      do j=1,nlat
        do i=1,mlon(j)
          ie = ie + 1
          cosq(ie) = cosq2(j)
          fraq(ie) = fraq2(j)
        enddo
      enddo

c        Solar radiation

                OPEN(500,FILE = 'inputfile.dat')
                READ(500, 550) abs, trans, ref
                        550 format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
                PRINT 550, abs, trans, ref

      zt = trans              ! atmos transmissivity
      zr = ref                ! atmos reflectivity  (see searchalb.for)
c    zt = 0.62              ! 777
c    zr = 0.22              ! 777
      za = abs                ! atmos absorbtivity

      do i=1,nebm

everything was working fine until I added the OPEN, READ, format, and PRINT lines. Now I get the following errors upon compiling:

Code:

fortcom: Error: atmos.F, line 72: Syntax error, found INTEGER_CONSTANT '550' when expecting one of: <LABEL> <END-OF-STATEMENT> ; BLOCK BLOCKDATA PROGRAM TYPE COMPLEX BYTE CHARACTER ...
                        550 format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
------------------------^
fortcom: Error: atmos.F, line 72: Syntax error, found IDENTIFIER 'PE6' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ...
                        550 format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
---------------------------------------------^
fortcom: Error: atmos.F, line 72: Syntax error, found IDENTIFIER 'PE6' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ...
                        550 format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
---------------------------------------------------------------^
fortcom: Error: atmos.F, line 72: Syntax error, found IDENTIFIER 'PE6' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ...
                        550 format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
-------------------------------------------------------------------------------^
compilation aborted for atmos.F (code 1)
make: *** [atmos.o] Error 1

I've tried a few things:
->If I move the format line to the left, then the same error pops up, but the 550 is replaces with a "*".
->If I move the rest of it to the left I get a bunch of problems related to the 'j=1,nlat' part.
->If I change the order of the PRINT and format statements, same errors, no change.
->If I move the block to the right no change in the errors occurs (expectedly).

Unfortunately, the code's *enormous*, so numbering the lines would be a bitch. Anyone have any ideas?

chrism01 09-16-2009 01:51 AM

Here we go
Quote:

The statement label may be placed anywhere in columns 1 through 5 of the initial line of the statement.
http://www.fortran.com/F77_std/rjcnf...-3.html#sh-3.4

but see http://www.cs.mtu.edu/~shene/COURSES...05/format.html for different and allegedly better solution

Laughing_Man 09-16-2009 03:26 AM

aah, but when I move the FORMAT line to the left I get this:

Code:

echo '** Compiling atmos.F'
** Compiling atmos.F
ifort -r8 -DLINUX  -O2 -I. -I/[##(file location)##]-c atmos.F
fortcom: Error: atmos.F, line 72: Syntax error, found IDENTIFIER 'PE6' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ...
    * format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
------------------------^
fortcom: Error: atmos.F, line 72: Syntax error, found IDENTIFIER 'PE6' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ...
    * format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
------------------------------------------^
fortcom: Error: atmos.F, line 72: Syntax error, found IDENTIFIER 'PE6' when expecting one of: .EQV. .NEQV. .XOR. .OR. .AND. .LT. < .LE. <= .EQ. == .NE. /= .GT. > ...
    * format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
----------------------------------------------------------^
fortcom: Error: atmos.F, line 71: This label has not been defined as a FORMAT label.  [550]
                READ(500,550) abs, trans, ref50
-------------------------^
fortcom: Error: atmos.F, line 72: The highest data type rank permitted is INTEGER(KIND=8).  [.0]
    * format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
---------------------------^
fortcom: Error: atmos.F, line 72: The highest data type rank permitted is INTEGER(KIND=8).  [.0]
    * format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
---------------------------------------------^
fortcom: Error: atmos.F, line 72: The highest data type rank permitted is INTEGER(KIND=8).  [.0]
    * format("abs = ",1PE6.0,"trans = ",1PE6.0,"ref = ",1PE6.0)
-------------------------------------------------------------^
fortcom: Error: atmos.F, line 71: Constants and expressions are invalid in read-only I/O lists.  [REF50FORMAT]
                READ(500,550) abs, trans, ref50
------------------------------------------^
fortcom: Error: atmos.F, line 73: This label has not been defined as a FORMAT label.  [550]
                PRINT 550, abs, trans, ref
----------------------^
fortcom: Error: atmos.F, line 71: This label is undefined.  [550]
                READ(500,550) abs, trans, ref50
-------------------------^
compilation aborted for atmos.F (code 1)
make: *** [atmos.o] Error 1


lutusp 09-16-2009 03:59 AM

Quote:

Originally Posted by Laughing_Man (Post 3684690)
aah, but when I move the FORMAT line to the left I get this:

[ snip huge Fortran compiler error list ]

Here's how to write and compile a computer program:

1. Write a one-line program. Compile it.

2. Did it compile and run? If not, go back to step 1. If it did, go to step 3.

3. Add ONE LINE to your computer program and recompile it. Did it compile and run? If so, repeat. If not, go back to step 1.

In fact, here's your first Fortran program, gratis:

Code:

program hello
  print *,"Hello World!"
end program hello

But believe me when I tell you, there is no point in compiling a program that you don't understand, to then see a screenful of errors that you don't understand, and then post the error list to a discussion board hoping someone else will sort out the problems. This is called "programming by newsgroup" and it is fantastically unproductive.

Choose a manageable programming task. Complete it successfully. Then choose a more challenging programming task, but in small increments that you both understand and control.

That way, rather than relying on experts, you become an expert.

Laughing_Man 09-16-2009 11:29 AM

I'm not writing this, I'm altering a preexisting program to do something else....

I've fixed many of the problems already, this last one I'm having trouble with.

lutusp 09-16-2009 12:26 PM

Quote:

Originally Posted by Laughing_Man (Post 3685361)
I'm not writing this, I'm altering a preexisting program to do something else....

I've fixed many of the problems already, this last one I'm having trouble with.

Fair enough. But at some point, you may want to ask yourself whether it might be more useful to abandon this Fortran program and create the function you are after from first principles.

I say this because you know what the program must do and you intend to test its ability to do that, meaning you won't be accepting anything on blind faith. Given that premise, you might be better off writing the program in a modern language, one that has a future (Fortran only has a past) as well as having more control over the process and the outcome.

I say this because I have been in any number of similar positions during my time at NASA. In modern times, with the wide number of programming choices available, it is even easier to decide to cut one's losses and recreate a program's functions from scratch.

Laughing_Man 09-16-2009 01:15 PM

:) I'm a research assistant for NASA. One of their astrobiology research teams specifically.

I'm using an old energy balance model for Earth (originally written by my advisor's advisor), but have changed it to work for ancient Mars. We need to cover various possible atmospheres - hence the changing input for 'atmos.F'.

The ebm is enormous, with a dozen different make files, so starting over from scratch would take months. Everything's awesome (after some debugging), with the exception of this one block I've added to the atmospheric file. Totally frustrating.

bbneo 09-16-2009 04:26 PM

Good luck. Been there. Sometimes these things can be maddening. I've done some scientific programming in C and fortran in the past and these types of bugs make you a better person. ;-) (At least you feel great relief when you figure them out.)

I would recommend carefully reviewing the compile time options and any compiler switches that might affect this module to see if there is anything that might affect this particular syntax.

I'm not familiar with PE6... Is that a short-hand number syntax that you have to enable a special compiler switch to recognize?

chrism01 09-16-2009 06:03 PM

I recommend you try my 2nd link, that bypasses the issue.

Another thing I do in any lang for an error I don't get; write a short-as-possible example of the problem code and debug that.
Once you've solved it there, you can dd it to the real program.
Don't keep messing with the big program.


All times are GMT -5. The time now is 04:51 PM.