Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
38 Views

ERROR - Syntax error, found....

I have this error and my code is just below, can someone help me?

read_co2atm.f90(1): error #5082: Syntax error, found '(' when expecting one of: <END-OF-STATEMENT> ;
       program read_co2atm(futr_scen, nco2rec, yrco2rec, atmco2rec)
--------------------------^
read_co2atm.f90(21): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: <REAL_KIND_CON> <REAL_CONSTANT> <DBLPRC_CONSTANT> <DBLPRC_KIND_CON> <QUAPRC_CONSTANT> ...
       OPEN(luco2+1, FILE='splmlo_co2_noces.dat', FORM='formatted',
--------------------------------------------------------------------^
read_co2atm.f90(22): error #5082: Syntax error, found '&' when expecting one of: <LABEL> <END-OF-STATEMENT> ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
      &     STATUS='old')
------------^
read_co2atm.f90(22): error #5276: Unbalanced parentheses
      &     STATUS='old')
------------------------^
read_co2atm.f90(22): error #5082: Syntax error, found ')' when expecting one of: <END-OF-STATEMENT> ;
      &     STATUS='old')
------------------------^
read_co2atm.f90(33): error #5082: Syntax error, found '&' when expecting one of: <LABEL> <END-OF-STATEMENT> ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
      &      yrco2rec(irec),atmco2rec(irec)
-------------^
read_co2atm.f90(39): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: <REAL_KIND_CON> <REAL_CONSTANT> <DBLPRC_CONSTANT> <DBLPRC_KIND_CON> <QUAPRC_CONSTANT> ...
       WRITE(*,*) 'Atm. CO2:  No. of entries for 1-box atmosphere =',
---------------------------------------------------------------------^
read_co2atm.f90(40): error #5082: Syntax error, found '&' when expecting one of: <LABEL> <END-OF-STATEMENT> ; TYPE INTEGER REAL COMPLEX BYTE CHARACTER CLASS DOUBLE ...
     &            nco2rec
------------------^
compilation aborted for read_co2atm.f90 (code 1)

 

 

My code

       program read_co2atm(futr_scen, nco2rec, yrco2rec, atmco2rec)

       IMPLICIT NONE

       INTEGER maxrec, nmxr
       PARAMETER (maxrec=1200, nmxr=700)

       REAL yrco2rec(maxrec), atmco2rec(maxrec)
       INTEGER luco2, irec
       INTEGER nco2rec
       INTEGER is, ireadf
       INTEGER nsipl, nstab

       REAL futco2(nmxr,8)
       REAL dummy

       CHARACTER*4 futr_scen


       luco2=50
       OPEN(luco2+1, FILE='splmlo_co2_noces.dat', FORM='formatted',
      &     STATUS='old')

       WRITE(*,*)'  '
       WRITE(*,*)'--------------------------------------------------'
       WRITE(*,*)'Atm. CO2 from fit to Siple-Mauna Loa record'
       WRITE(*,*)'--------------------------------------------------'


       DO irec=1,maxrec

        READ(luco2+1,*,ERR=222,END=222)
      &      yrco2rec(irec),atmco2rec(irec)
        nco2rec = irec
       END DO

 222   CONTINUE

       WRITE(*,*) 'Atm. CO2:  No. of entries for 1-box atmosphere =',
     &            nco2rec

       CLOSE(luco2+1)

       RETURN
       END

 

 

 

 

 

0 Kudos
14 Replies
Highlighted
Black Belt
38 Views

The Program statement should

  1. The Program statement should not have an argument list.
  2. Most of your lines have seven leading blanks instead of the usual six.
  3. Continuation marks '&' should be in column-6, but you have them in column-7.
  4. The main program unit should not contain a RETURN statement

 

0 Kudos
Highlighted
Beginner
38 Views

Thanks mecej4

Thanks mecej4

but now is showing this
 

 >$ifort read_co2atm.f90

 /opt/intel/opt/intel/compilers_and_libraries_2016.2.181/linux/compiler/lib/intel64_lin/for_main.o: In function `main':
 for_main.c:(.text+0x2a): undefined reference to `MAIN__'

 

 

0 Kudos
Highlighted
Black Belt
38 Views

Sorry, I overlooked the name

Sorry, I overlooked the name that you gave the file a suffix of ".f90", which is meant to be used for free-format Fortran source. Your file is fixed-format source, so you should call it "read_co2atm.f".

Please attach your updated code and state what name you gave to the source file.

When you attach source code, please do so using the {...} code button on the tool bar, and choose "Fortran".

0 Kudos
Highlighted
Beginner
38 Views

ERROR

ERROR

$ifort read_co2atm.f
read_co2atm.f(21): error #5082: Syntax error, found '&' when expecting one of: <REAL_KIND_CON> <REAL_CONSTANT> <DBLPRC_CONSTANT> <DBLPRC_KIND_CON> <QUAPRC_CONSTANT> ...
      OPEN(luco2+1, FILE='splmlo_co2_noces.dat', FORM='formatted', &
-------------------------------------------------------------------^
read_co2atm.f(23): error #5276: Unbalanced parentheses
           STATUS='old')
-----------------------^
read_co2atm.f(23): error #5082: Syntax error, found ')' when expecting one of: <END-OF-STATEMENT> ;
           STATUS='old')
-----------------------^
read_co2atm.f(33): error #5082: Syntax error, found '&' when expecting one of: , <REAL_KIND_CON> <REAL_CONSTANT> <DBLPRC_CONSTANT> <DBLPRC_KIND_CON> <QUAPRC_CONSTANT> ...
      READ(luco2+1,*,ERR=222,END=222) &
--------------------------------------^
read_co2atm.f(34): error #5082: Syntax error, found ',' when expecting one of: => = . [ % (
           yrco2rec(irec),atmco2rec(irec)
-------------------------^
read_co2atm.f(40): error #5082: Syntax error, found '&' when expecting one of: <REAL_KIND_CON> <REAL_CONSTANT> <DBLPRC_CONSTANT> <DBLPRC_KIND_CON> <QUAPRC_CONSTANT> ...
      WRITE(*,*) 'Atm. CO2:  No. of entries for 1-box atmosphere =', &
---------------------------------------------------------------------^
read_co2atm.f(41): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: => = . [ % ( :
                nco2rec
-----------------------^
compilation aborted for read_co2atm.f (code 1)

 

CODE

 

      SUBROUTINE read_co2atm(futr_scen, nco2rec, yrco2rec, atmco2rec)

      IMPLICIT NONE 

      INTEGER maxrec, nmxr
      PARAMETER (maxrec=1200, nmxr=700)

      REAL yrco2rec(maxrec), atmco2rec(maxrec)
      INTEGER luco2, irec
      INTEGER nco2rec
      INTEGER is, ireadf
      INTEGER nsipl, nstab

      REAL futco2(nmxr,8)
      REAL dummy

      CHARACTER*4 futr_scen


      luco2=50
      OPEN(luco2+1, FILE='splmlo_co2_noces.dat', FORM='formatted', &
 
           STATUS='old')

      WRITE(*,*)'  '
      WRITE(*,*)'--------------------------------------------------'
      WRITE(*,*)'Atm. CO2 from fit to Siple-Mauna Loa record'
      WRITE(*,*)'--------------------------------------------------'


      DO irec=1,maxrec

      READ(luco2+1,*,ERR=222,END=222) &
           yrco2rec(irec),atmco2rec(irec)
       nco2rec = irec
      END DO

222   CONTINUE

      WRITE(*,*) 'Atm. CO2:  No. of entries for 1-box atmosphere =', &
                nco2rec

      CLOSE(luco2+1)
      END









 

 

0 Kudos
Highlighted
Black Belt
38 Views

Well, you converted the

Well, you converted the program to a subroutine.

You used incorrect notation for indicating continuation lines. An '&' character at the end of a line is used to indicate continuation in free-format. In fixed-format, you place one of the acceptable continuation characters in column-6. Please read your Fortran textbook/manual to get these requirements right.

A subroutine cannot be run by itself. It has to be called by another subprogram or main program. Every program must contain one and only one main program unit and, if needed, any number of subroutine and function subprograms.

0 Kudos
Highlighted
Beginner
38 Views

Dear mecej4

Dear mecej4

I was confused and sent the wrong codes...

PROGRAM try_read_co2atm
C     ------------------------------------------------------------------
C     Test PROGRAM to READ historical atmospheric CO2 (uatm)
C 
      IMPLICIT NONE 

      INTEGER maxrec, nmxr
      PARAMETER (maxrec=1200, nmxr=700)

      REAL yrco2rec(maxrec), atmco2rec(maxrec)
      INTEGER luco2, irec
      INTEGER nco2rec
      INTEGER is, ireadf
      INTEGER nsipl, nstab

      REAL futco2(nmxr,8)
      REAL dummy

      CALL read_co2atm('test', nco2rec, yrco2rec, atmco2rec)

      DO irec=1,nco2rec
        WRITE(*,'(2f8.2)') yrco2rec(irec),atmco2rec(irec)
      END DO

      STOP 
      END

 

SUBROUTINE read_co2atm(futr_scen, nco2rec, yrco2rec, atmco2rec)

      IMPLICIT NONE 

      INTEGER maxrec, nmxr
      PARAMETER (maxrec=1200, nmxr=700)

      REAL yrco2rec(maxrec), atmco2rec(maxrec)
      INTEGER luco2, irec
      INTEGER nco2rec
      INTEGER is, ireadf
      INTEGER nsipl, nstab

      REAL futco2(nmxr,8)
      REAL dummy

      CHARACTER*4 futr_scen

C     OPEN FILE
C     ---------
      luco2=50
      OPEN(luco2+1, FILE='splmlo_co2_noces.dat', FORM='formatted', 
     &     STATUS='old')
C     --------------------------
C     Get atmospheric CO2 data
C     --------------------------
      WRITE(*,*)'  '
      WRITE(*,*)'--------------------------------------------------'
      WRITE(*,*)'Atm. CO2 from fit to Siple-Mauna Loa record'
      WRITE(*,*)'--------------------------------------------------'

C     ----------------------------------
C     READ historical co2 concentrations
C     ----------------------------------
C     READ(luco2+1,200)
C 200  FORMAT(////)

      DO irec=1,maxrec
C           Read from splco2.dat (historical emissions)
        READ(luco2+1,*,ERR=222,END=222)
     &      yrco2rec(irec),atmco2rec(irec)
        nco2rec = irec
      END DO

 222  CONTINUE

       WRITE(*,*) 'Atm. CO2:  No. of entries for 1-box atmosphere =',
     &            nco2rec

      CLOSE(luco2+1)

      RETURN
      END
 

 

0 Kudos
Highlighted
Black Belt
38 Views

The program comprising the

The program comprising the two files that you displayed in #7 compile and link fine. However, I cannot run the program since I do not have the data file that it needs to read.

Is your problem solved at this point?

0 Kudos
Highlighted
Beginner
38 Views

Not yet..

Not yet..

Now I have this

$ ifort try_read_co2atm.f
/tmp/iforteO9RD2.o: In function `MAIN__':
try_read_co2atm.f:(.text+0x51): undefined reference to `read_co2atm_'

 

0 Kudos
Highlighted
Black Belt
38 Views

You need to specify all the

You need to specify all the sources needed. If your subroutine is in a file that you named read_co2atm.f, the command to compile and link would be

     $ ifort try_read_co2atm.f read_co2atm.f

If you had more subroutines/functions in more source files, and those routines are needed to run your program, you should have listed all of them, as well.

0 Kudos
Highlighted
Beginner
38 Views

Thank you very much

Thank you very much
I had a little thought about my knowlodge in Fortran
Clearly I was wrong

 

Thanks again..

0 Kudos
Highlighted
38 Views

I am unable to get my results

I am unable to get my results from this code and I cant understand what are the errors can someone correct my code?

thankyou

 

! program to trace the path of a charged particle under certain magnetic field 

      program tracer
      implicit none
      real*8 etahe,etaox,alphastar,KE,omega,t,k,Bx
     
      !initial values
      ke=ke*2*10**6*e
      omega=0.001
      t=0
      k=0.21
      etahe = 0.2
      etaox=0
      alpstar=0.01
      x=0.24

!dispersion relation to obtain wave vector(number) k
      eps1=(1/alphastar*eps)*[(1-etahe-etaox)/(1-x**2)+4*etahe/(1-4**2*
     &x**2)+16*etaox/(1-16**2*x**2)]
      eps2=(1/alphastar*eps*x)*[1-(1-etahe-etaox)/(1-x**2)+etahe/
     &(1-4**2*x**2)-etaox/(1-16**2*x**2)]
      eps3=-(1/alphastar*eps**2*x**2)
      n**2=1/2*(cos(theta))**2*(eps1*(1+(cos(theta))**2))+sqrt(eps1**2*
     &(1-(cos(theta))**2)+4*eps2**2*(cos(tehta)**2))

      
! Normalization of equations
!choice of normalization
      KE=KE/mc**2
      ω=ω/Ωeo
      t=tΩeo
      k=kc/Ωeo
      Bx=Bx/Bzo
      E=E/cBzo
      p=p/mc
      x=x/(c/Ωeo)
      y=y/(c/Ωeo)
      z=z/(c/Ωeo)
      
      
      pꞌ⊥o=sqrt(KE**2+2KE)
      pꞌzo=sqrt(KE**2+2KE)
      γ=KE+1
      
      
      
      
      
!polarization equations in normalized form

      Bꞌwx=(kꞌ/ωꞌ)*cos(ψ)*Eꞌwy
      Eꞌwy=(1/cos(ψ))*[(ωꞌ/kꞌ)*Bꞌwx]
      Bꞌwz=(kꞌ/ωꞌ)*sin(ψ)*Eꞌwy
      Eꞌwx=Eꞌwy*(ϵ1-(kꞌ/ωꞌ)**2)/ϵ2
      Eꞌwz=Eꞌwx*((kꞌ/ωꞌ)**2)*cos(ψ)*sin(ψ))/(ϵ3-(kꞌ/ωꞌ)**2)*sin**2(ψ) ! < 0 for ψ<π/2
      Bꞌwy=(kꞌ/ωꞌ)*cos(ψ)*Eꞌwx+(kꞌ/ωꞌ)*sin(ψ)*Eꞌwzwe
      ω1=(-Ωe/2)*(Bꞌwx+Bꞌwy)
      ω2=(-Ωe/2)*(Bꞌwx-Bꞌwy)
      a1=(-e*Bzo*c/2)*(Eꞌwx+Eꞌwy)
      a2=(-e*Bzo*c/2)(Eꞌwx-Eꞌwy)
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η/dtꞌ)=(dθ/dtꞌ)+ωꞌ-kꞌz(dxꞌ/dtꞌ)-kꞌx(dxꞌ/dtꞌ)

!normalization
      dz/dt=pz/γ*m
      dꞌz/dtꞌ=pꞌz/γ

!normalization
      dxꞌ/dtꞌ=(1/γ)*pxꞌ*cos(η-Φ)

!normalization
      dyꞌ/dtꞌ=(1/γ)*pꞌ⊥*sin(η-Φ)
      
      
      !evolution of pitch angle
      cos(alpha)=pz/sqrt(pz**2+p⊥**2)
!runge-kutta subroutine
      
!------------------------------------------------
!    Classical 4th-order Runge-Kutta method(OK)
!------------------------------------------------
    SUBROUTINE rk4(y,x,h,derivs)
!----------------------------------
    include "data.inc"
!----------------------------------
    REAL*8 h,x,dydx(ndim,nv),y(ndim,nv)
    EXTERNAL derivs
! Given values for the variables y(1:n) and their derivatives dydx(1:n) known at x, use
! the fourth-order Runge-Kutta method to advance the solution over an interval h and return
! the incremented variables as yout(1:n), which need not be a distinct array from y. The
! user supplies the subroutine derivs(x,y,dydx), which returns derivatives dydx at x.
    INTEGER i,j
    REAL*8 h6,hh,xh,dym(ndim,nv),dyt(ndim,nv),yt(ndim,nv)

    hh=h*0.5
    h6=h/6.
    xh=x+hh
!----------------------------------------------
    call derivs(x,y,dydx)  ! First step
!----------------------------------------------
    do 10 j=1,nv
    do 10 i=1,ndim 
        yt(i,j)=y(i,j)+hh*dydx(i,j)
10    continue
    call derivs(xh,yt,dyt) ! Second step
    do 11 j=1,nv
    do 11 i=1,ndim    
        yt(i,j)=y(i,j)+hh*dyt(i,j)
11    continue
    call derivs(xh,yt,dym) ! Third step
    do 12 j=1,nv
    do 12 i=1,ndim
        yt(i,j)=y(i,j)+h*dym(i,j)
        dym(i,j)=dyt(i,j)+dym(i,j)
12    continue
    call derivs(x+h,yt,dyt) ! Fourth step
    do 13 j=1,nv            ! Accumulate increments with proper weights
    do 13 i=1,ndim    
        y(i,j)=y(i,j)+h6*(dydx(i,j)+dyt(i,j)+2.*dym(i,j))
13    continue

    return
    END
      ! before obtianing re-genaralize the equations

      KE=KE*mc**2
      ω=ω*Ωeo
      t=t/Ωeo
      k=k*Ωeo/c
      Bx=Bx*Bzo
      E=E*cBzo
      p=p*mc
      x=x*(c/Ωeo)
      y=y*(c/Ωeo)
      z=z*(c/Ωeo)


!results
      
      open(1,file='my_code_output.txt',status='new')
      read(1,*)x
      write(*,*)x
      read(1,*)y
      write(*,*)y
      read(1,*)z
      write(*,*)z
      read(1,*)location
      write(*,*)location
      read(1,*)p⊥
      write(*,*)p⊥
      read(1,*)pz
      write(*,*)pz
      pitch angle 
      x, y, z location
       pㅗ
       p//
 

0 Kudos
Highlighted
Black Belt
38 Views

Large parts of your "code"

Large parts of your "code" are not Fortran at all. Simply listing equations will not result in their getting solved. You have a subroutine, RK4, which presumably integrates ODEs. However, that subroutine is never called from any of the lines that you showed.

Please take a course in Fortran and numerical methods, or learn the required material by reading textbooks and online tutorials.

Let's look at the last part of your "code". You open a file with STATUS='NEW'; this action, if it succeeds, will create a new file with no contents. You then attempt to read from that file, but there is nothing in the file to read!

Mathematical symbols such as ㅗ cannot be used in variable names.

0 Kudos
Highlighted
38 Views

' cannot be use as symbol

' cannot be use as symbol constituent. 'this is text' "in addition to this"

Jim Dempsey

0 Kudos
Highlighted
New Contributor I
38 Views

There are very many sample of

There are very many sample of ODE solvers on the web with many manuals.  

If you are able to do the math for program to trace the path of a charged particle under certain magnetic field - then learning Fortran is simple and really you should have learnt to program before you got to a physics course that set a problem such as  -- program to trace the path of a charged particle under certain magnetic field 

Usually in the academic world you are expected to do your own work -- 

 

 

0 Kudos