Compilation problem with gfortran

  • Fortran
  • Thread starter leroygr
  • Start date
  • Tags
    Gfortran
In summary: Error: Expected a right parenthesis in expression at (1)make: *** [rd_wr_formatted.o] Error 1In summary, the conversation is about a user trying to compile a f90 program with gfortran on Ubuntu using a makefile. The program calls 2 routines written in C and the makefile contains various commands and flags for compilation. The user encounters an error while trying to compile and seeks help in understanding and resolving it.
  • #1
leroygr
5
0
Hello everyone,

I'm trying since a few days to compile a f90 program with gfortran (on Ubuntu) with a makefile. The fortran program calls 2 routines written in C.

Here is my makefile:

Code:
FC              =       gfortran
SFC             =       gfortran
FFLAGS          =       -ffree-form -O -fconvert=big-endian -frecord-marker=4
F77FLAGS        =       -ffixed-form -O -fconvert=big-endian -frecord-marker=4
FNGFLAGS        =       $(FFLAGS)
LDFLAGS         =
CC              =       gcc
SCC             =       gcc
CFLAGS          =
CPP             =       /usr/bin/cpp -C -P -traditional
CPPFLAGS        =       -D_UNDERSCORE -DBYTESWAP -DLINUX -DIO_NETCDF -DBIT32 -DNO_SIGNAL
RANLIB          =       ranlib

all: rd_wr_formatted.exe

clean:
    rm -f *.o rd_wr_formatted.exe

rd_wr_formatted.exe: rd_wr_formatted.o read_geogrid.o write_geogrid.o
    $(FC) $(LDFLAGS) -o rd_wr_formatted.exe rd_wr_formatted.o read_geogrid.o write_geogrid.o

rd_wr_formatted.o: rd_wr_formatted.f90
    $(FC) -c $(FFLAGS) rd_wr_formatted.f90

read_geogrid.o: read_geogrid.c
    $(CC) -c $(CFLAGS) read_geogrid.c

write_geogrid.o: write_geogrid.c
    $(CC) -c $(CFLAGS) write_geogrid.c

Here is my fortran 90 program code:

Code:
program rd_wr_binary

   implicit none

   integer, external :: iargc

   integer :: istatus
   character (len=256) :: fname

   real, allocatable, dimension(:,:) :: rarray
!   real, allocatable, dimension(:,:) :: rarrayIN
   integer :: nx           ! x-dimension of the array
   integer :: ny           ! y-dimension of the array
   integer :: nz           ! z-dimension of the array
   integer :: isigned      ! 0=unsigned data, 1=signed data
   integer :: endian       ! 0=big endian, 1=little endian
   real :: scalefactor     ! value to divide array elements by before truncation to integers
   integer :: wordsize     ! number of bytes to use for each array element
 
   integer :: i
   integer :: j

   
!-----------------------------------------    
   if (iargc /= 1) then
     write(0,*) ' '
     write(0,*) 'Usage: rd_wr_binary.exe <filename>'
     write(0,*) ' '
     stop
   end if

   call getarg(1, fname)


   !
   ! The following must be set before compiling
   !
   nx = 1200
   ny = 1200
   nz = 1
   isigned = 0
   endian = 0
   wordsize = 4 
   scalefactor = 1.0

!   allocate(rarrayIN(nx,ny))
   allocate(rarray(nx,ny))


   !
   ! Read data from geogrid binary format using read_geogrid()
   !
!   call read_geogrid(fname, len_trim(fname), rarray, nx, ny, nz, isigned, endian, scalefactor, wordsize, istatus)
!   if (istatus /= 0) then
!      write(0,*) 'Error while reading '//trim(fname)//'. Quitting.'
!   end if
!

!
! We read formatted data instead of binary input file 
!   
    open(10, file=trim(fname), form='formatted', status='old')
   
    do j=1,ny
       read(10,33) (rarray(i,j),i=1,nx)
       write(*,*) i,j,rarray(nx,j)
    end do
 33    format(f6.1, 12000f7.1)    
! 33    format(18500f7.1) 

   close(10) 

! ------------ IF we need FLIP file -----
!      NO FLIP file!
!----------------------------------------
!        do j = 1,ny
!          do i = 1,nx
!            rarray(i,j) = rarrayIN(i,j)
!          enddo
!            write(*,*) i,j,rarray(nx,j)
!        enddo  
!--------------- end of FLIP/no FLIP ----  
   !
   ! Modify the field as necessary
   !

   !
   ! Write data to geogrid binary format using write_geogrid()
   !
   call write_geogrid(trim(fname)//'.bin', len_trim(trim(fname)//'.bin'), rarray, nx, ny, nz, isigned, endian, scalefactor, wordsize)

!   deallocate(rarrayIN) 
   deallocate(rarray)
   
   write(0,*) 'JOB finished OK!' 

end program rd_wr_binary

When I try to compile using "make" command, I get this error message that I don't understand:

Code:
[greg@Uranus:~/WRF/WPS/data/SRTM_to_geogrid]$ make
gfortran -c -ffree-form -O -fconvert=big-endian -frecord-marker=4 rd_wr_formatted.f90
rd_wr_formatted.f90:25.12:

   if (iargc /= 1) then
            1
Error: Function 'iargc' requires an argument list at (1)
rd_wr_formatted.f90:30.6:

   end if
      1
Error: Expecting END PROGRAM statement at (1)
rd_wr_formatted.f90:90.132:

fname)//'.bin'), rarray, nx, ny, nz, isigned, endian, scalefactor, wordsize
                                                                           1                                                         
Error: Syntax error in argument list at (1)
rd_wr_formatted.f90:90.132:

fname)//'.bin'), rarray, nx, ny, nz, isigned, endian, scalefactor, wordsize
                                                                           1                                                         
Warning: Line truncated at (1)
make: *** [rd_wr_formatted.o] Error 1

Can someone help me? I'm really really blocked...

Thank you very much!

Greg
 
Technology news on Phys.org
  • #2
With the statement,

Code:
if (iargc /= 1) then

Are you trying to say "if iargc does not equal 1, then..."? If so, I would recommend using,

Code:
if (iargc .ne. 1) then

I'm not sure about the "Error: Expecting END PROGRAM statement", but it could have to do with the "stop" being there. See if ".ne." changes that. The last two errors you are getting are due to Fortran truncating programs at the 72nd column by default. If you type out something like,

Code:
!23456789012345678901234567890123456789012345678901234567890123456789012

Somewhere in your program, you can tell what line to do continuations at. Making those multiple line statements will fix those errors.

Hope that helped.

It doesn't look like anything is wrong with your makefile, just the code.
 
  • #3
Yes indeed.

I did the modification you proposed but I got the same error...
 
  • #4
The compiler thinks iargc is an external function and not an integer. After doing a web search, iargc is a function. You'll need to add code like this:

Code:
      integer argcount
      ...
      argcount = iargc()
      ...
      if(1 /= argcount)then
      ...

I don't know if this is allowed

Code:
      ...
      if(1 /= iargc() )then
      ...
 
Last edited:
  • #5
Why is iargc defined as external?
 
  • #6
I don't know exactly why... To be honest I'm not the author of the program. I try to use it for SRTM data to WRF geogrid binary data conversion. I understand what the program does generally, but unfortunately not all the code lines.

I'll try to add rcgldr's code.
 
  • #7
I replaced

Code:
 if (iargc /= 1) then
     write(0,*) ' '
     write(0,*) 'Usage: rd_wr_binary.exe <filename>'
     write(0,*) ' '
    ! stop
   end if

by

Code:
 if (iargc() /= 1) then
     write(0,*) ' '
     write(0,*) 'Usage: rd_wr_binary.exe <filename>'
     write(0,*) ' '
    ! stop
   end if

It is better by I have the following errors now:

Code:
[greg@Uranus:~/WRF/WPS/data/SRTM_conversion]$ make
gfortran  -o rd_wr_formatted.exe rd_wr_formatted.o read_geogrid.o write_geogrid.o
rd_wr_formatted.o: In function `MAIN__':
rd_wr_formatted.f90:(.text+0x39): undefined reference to `iargc_'
rd_wr_formatted.f90:(.text+0x639): undefined reference to `write_geogrid_'
collect2: ld returned 1 exit status
make: *** [rd_wr_formatted.exe] Error 1

Any idea?
 
  • #8
leroygr said:
Any idea?
You need to include library names in the make file for the link step. Apparently it's not defaulting to include the libraries you need to use iargc().
 
  • #9
Ok! Can you explain to me how to do that? (I'm quite a newbie sorry ...)
 
  • #10

1. What is a compilation problem with gfortran?

A compilation problem with gfortran refers to an error or issue that occurs during the process of converting human-readable source code into machine-executable code using the gfortran compiler.

2. Why does a compilation problem with gfortran occur?

Compilation problems with gfortran can occur due to a variety of reasons, such as syntax errors in the source code, incompatible library versions, or missing dependencies.

3. How can I fix a compilation problem with gfortran?

The solution to a compilation problem with gfortran depends on the specific issue. Some common ways to fix such problems include checking for and correcting any syntax errors, ensuring all necessary libraries and dependencies are installed, and updating to the latest version of gfortran.

4. Are there any resources available for troubleshooting compilation problems with gfortran?

Yes, there are various online resources and forums where you can find help and solutions for compilation problems with gfortran. The official gfortran website also offers documentation and support for common issues.

5. Can I avoid compilation problems with gfortran altogether?

While it is not always possible to completely avoid compilation problems with gfortran, some steps you can take to reduce the likelihood of encountering them include writing clean and error-free code, keeping your libraries and dependencies up-to-date, and using a compatible version of gfortran for your source code.

Back
Top