Fortran on ubuntu using f95 code help

In summary, 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 docounter=1 user_reaction =3do while (counter .le. 3 .and. user_reaction .ne. 1 .and. user_reaction .ne. 2)counter= counter+1print *, "What reaction would like to look at:")print *, "1)GP to EP"print *, "2)GP to Klo"if (counter.eq. 3) then****print *, "
  • #1
bkent9
4
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
  • #2
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
 
  • #3
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
 
  • #4
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.
 
  • #5
Works perfectly OK (compiles without any errors) in gfortran on Ubuntu 12.04.
 

1. What is Fortran?

Fortran is a high-level programming language used for scientific and numerical computing. It was first developed in the 1950s and is still widely used in fields such as engineering, physics, and finance.

2. How do I install Fortran on Ubuntu?

To install Fortran on Ubuntu, you can use the command line interface and type "sudo apt-get install gfortran". This will install the GNU Fortran compiler, which is the most commonly used compiler for Fortran on Ubuntu. Alternatively, you can also use a package manager such as Synaptic or Ubuntu Software Center.

3. What is F95 code?

F95 code refers to code written in the Fortran 95 programming language. It is an updated version of Fortran with added features such as improved array handling and support for modules. F95 code can generally be compiled and run on newer versions of Fortran, such as Fortran 2003 or Fortran 2018.

4. How do I compile and run Fortran code on Ubuntu?

To compile and run Fortran code on Ubuntu, you can use the "gfortran" command followed by the name of your source code file. For example, if your file is named "myprogram.f95", you would type "gfortran myprogram.f95" in the command line. This will create an executable file, which you can then run by typing "./a.out".

5. Are there any resources available for learning Fortran on Ubuntu?

Yes, there are several resources available for learning Fortran on Ubuntu. You can find tutorials and guides online, as well as books and courses specifically focused on Fortran programming. Additionally, the Fortran community is very active and you can find support and help through forums and online communities.

Similar threads

  • Programming and Computer Science
Replies
2
Views
786
  • Programming and Computer Science
Replies
4
Views
499
  • Programming and Computer Science
Replies
22
Views
633
  • Programming and Computer Science
Replies
4
Views
262
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
Back
Top