Fortran Fortran on ubuntu using f95 code help

AI Thread Summary
The discussion focuses on troubleshooting a Fortran code that encounters multiple syntax errors, specifically a missing parenthesis error, a syntax error related to a continuation line, and an expectation for an END program statement. The code aims to prompt the user for a reaction type and validate the input. Key issues identified include the need for proper continuation lines due to Fortran's column limitations, which can lead to compilation errors. The suggestion is made to use gfortran for compilation, as it appears to handle the code without errors, particularly on Ubuntu 12.04. The importance of ensuring that all syntax adheres to Fortran's formatting rules is emphasized to avoid such errors.
bkent9
Messages
4
Reaction score
0
I have the following code with error- I want this general flow. Errors I get are missing ')' at the do while line,
syntax error on the line started with ****(not part of program added after fact)
and expecting END Program statement at line end do

counter=1
user_reaction =3
do while (counter .le. 3 .and. user_reaction .ne. 1 .and. user_reaction .ne. 2)

counter= counter+1
print *, "What reaction would like to look at:"
print *, "1)GP to EP"
print *, "2)GP to Klo"
if (counter.eq. 3) then
**** print *, "Please type a '1' for reaction GP to EP" &
"and '2' for the reaction GP to Klo"
end if
read *, user_reaction
end do
if (user_reaction .ne. 1 .and. user_reaction .ne. 2)
print *, "Failed to get a valid result. Program terminates in error."
STOP
end if
 
Last edited:
Technology news on Phys.org
Code:
      program bkent
      implicit none

      integer :: counter, user_reaction

      counter=1
      user_reaction =3
      do while ((counter .le. 3) .and. (user_reaction .ne. 1) .and. &
                (user_reaction .ne. 2))
      
         counter = counter + 1
         print *, "What reaction would like to look at:"
         print *, "1)GP to EP"
         print *, "2)GP to Klo"
         if (counter.eq. 3) then
            print *, "Please type a 1 for reaction GP to EP", &
            "and 2 for the reaction GP to Klo"
         end if
         read *, user_reaction
      end do
      if ((user_reaction .ne. 1) .and. (user_reaction .ne. 2)) then
         print *, "Failed to get a valid result. Program terminates in error."
         STOP
      end if

      stop
      return

      end program bkent
 
still seeing an error. something else must be off. here is the whole (non commented out) program. I am compiling using the command f95 -o extract extract_file.f

program extract_file

C this program is designed to obtain data from the two files for my two reactions

C user input variables
integer user_reaction
double precision user_energy, user_binWidth
integer counter

c values obtained from data files are stored in these variables
integer num_data_at_mmtm
integer r
real momentum_val
integer gpep, gpklo, SGTi, DSGi
real min_energy(2)
character headerline*50, obs*3 !there is a headerline that I don't want
! obs=observable for given data

C file names and creation
character directory*24
character*9 subdirectory(2)
character*10 filename(2)
directory = '/home/usersname/Desktop/' !usersname entered later on--> temp line
subdirectory(1) = 'GP to EP'
subdirectory(2) = 'GP to KLo'
filename(1) = 'gpep072211'
filename(2) = 'gpkl060311'
c open (unit=gpep,file=filename(1),blank='null')
c open (unit=gpklo,file=filename(2),blank='null')
c open (unit=SGTi,file=gpep_SGT,status='new')
c open (unit=DSGi,file=gpep_DSG,status='new')

C this section pertains to user selected reaction type to analyze
counter=1
user_reaction =3
do while ((counter .le. 3) .and. (user_reaction .ne. 1) .and. &
(user_reaction .ne. 2))

counter = counter + 1
print *, "What reaction would like to look at:"
print *, "1)GP to EP"
print *, "2)GP to Klo"
if (counter.eq. 3) then
print *, "Please type a 1 for reaction GP to EP", &
"and 2 for the reaction GP to Klo"
end if
read *, user_reaction
end do
if ((user_reaction .ne. 1) .and. (user_reaction .ne. 2)) then
print *, "Failed to get a valid result. Program terminates in error."
STOP
end if
stop
return
end program extract_file
 
Try gfortran. Also, why you get the missing ) error is because fortran code can only be 71 or 81 (I can't remember) column spaces long. You need to do a continuation.
 
Works perfectly OK (compiles without any errors) in gfortran on Ubuntu 12.04.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
2
Views
1K
Replies
4
Views
2K
Replies
17
Views
6K
Replies
19
Views
2K
Replies
8
Views
4K
Replies
5
Views
5K
Back
Top