Compilation problem with gfortran


 
Thread Tools Search this Thread
Top Forums Programming Compilation problem with gfortran
# 1  
Old 07-28-2011
Compilation problem with gfortran

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 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!
# 2  
Old 07-28-2011
Hi.
Code:
8.115 IARGC - Get the number of command line arguments

...

Syntax:
    RESULT = IARGC() 

excerpt from IARGC - The GNU Fortran Compiler

found by Googling fortran iargc example

So, for example:
Code:
program f1

! @(#) f1	Demonstrate Fortran-90.

if ( iargc() /= 0 ) then
  write(*,*) " Number of arguments: ", iargc()
endif

end program f1

when compiled with gfortran one.f90 and then executed, produces:
Code:
% ./a.out 
% ./a.out x y z
  Number of arguments:            3

Note that:
Quote:
... In new code, programmers should consider the use of the COMMAND_ARGUMENT_COUNT intrinsic defined by the Fortran 2003 standard.

op.cit.
Best wishes ... cheers, drl
# 3  
Old 07-29-2011
Thank you, but I don't really understand. I'm not the original creator of the program. Can you explain me what do I need to change in my code in order to compile? I replace iargc by COMMAND_ARGUMENT_COUNT but it didn't worked.

Sorry but I'm far to be an expert in fortran...

Thank you
# 4  
Old 07-29-2011
Hi.

How is my use of iargc in the example "f1" different from your use of iargc? ... cheers, drl
# 5  
Old 08-01-2011
Ok I did the changes and it's better... but not yet perferct.

Now I have the following errors:

Code:
[greg@Uranus:~/WRF/WPS/data/SRTM_conversion]$ make
gfortran -c -ffree-form -O -fconvert=big-endian -frecord-marker=4 rd_wr_formatted.f90
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


Last edited by leroygr; 08-01-2011 at 04:41 AM..
# 6  
Old 08-01-2011
Hi.

An undefined reference means that there is no matching subroutine or function available by that name.

The iargc_ symbol seems odd. In the example I posted, the external is found in a standard shared library (output is from the command nm):
Code:
Looking at /usr/lib/libgfortran.so.3
00000000000b8fe0 T _gfortran_iargc

What exactly did you change for the iargc correction?

Your make output did not show that the c routines were compiled. Do you know if they were?

My sense is that you may need to do some additional work to allow c routines to be called from Fortran-90-compiled source, but we can get to that later.

Please post results for running these commands:
Code:
uname -a
gfortran --version
nm rd_wr_formatted.o

Here's the output from my system, you should expect something similar:
Code:
Linux leap 2.6.26-2-amd64 #1 SMP Tue Jan 25 05:59:43 UTC 2011 x86_64 GNU/Linux

GNU Fortran (Debian 4.3.2-1.1) 4.3.2

0000000000000000 T MAIN__
                 U _gfortran_iargc
                 U _gfortran_set_options
                 U _gfortran_st_write
                 U _gfortran_st_write_done
                 U _gfortran_transfer_character
                 U _gfortran_transfer_integer
0000000000000000 r options.0.903

Best wishes ... cheers, drl
# 7  
Old 08-01-2011
For iargc correction, I've juste added (). Here is my full 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

So for the the iargc correction is:

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

I think that the c routines were compiled because I have the outputs (read_geogrid.o & write_geogrid.o) needed for compiling the fortran program (I think this is made when I'm running the makefile).

Here is the result for the commands you asked:

Code:
Linux Uranus 2.6.32-33-generic #70-Ubuntu SMP Thu Jul 7 21:09:46 UTC 2011 i686 GNU/Linux

GNU Fortran (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2010 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING


00000000 T MAIN__
         U _gfortran_concat_string
         U _gfortran_getarg_i4
         U _gfortran_os_error
         U _gfortran_runtime_error
         U _gfortran_set_convert
         U _gfortran_set_options
         U _gfortran_set_record_marker
         U _gfortran_st_close
         U _gfortran_st_open
         U _gfortran_st_read
         U _gfortran_st_read_done
         U _gfortran_st_write
         U _gfortran_st_write_done
         U _gfortran_string_len_trim
         U _gfortran_string_trim
         U _gfortran_transfer_character
         U _gfortran_transfer_integer
         U _gfortran_transfer_real
         U free
         U iargc_
         U malloc
00000060 r options.0.1519
         U write_geogrid_

Thank you very much for your help... It's not always easy to be a newbie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

GFORTRAN library problem: libgFORTRAN.so.1 cannot open....

I've received some executable script for test, but executing this script continuously give me following message ./example: error while loading shared libraries: libgfortran.so.1: cannot open shared object file: No such file or directory Google search told me to do as following $... (1 Reply)
Discussion started by: exsonic
1 Replies

2. Programming

problem compiling with gfortran in two different debian releases

Hello, I hope this is the correct forum for this post. I have the following problem: A Fortran 77 program that has to deal with several large matrices (each approx. 5000 x 5000) and uses lapack and blas subroutines has been correctly compiled and executed using Debian Etch. When I tried... (1 Reply)
Discussion started by: currix
1 Replies

3. Programming

gfortran compiling problem,calling too many arguments

Hello, My problem is with compiling a program modelling shallow water. In it there is a subroutine called stat with 9 parameters. In the main program it is called with 9 parameters also I'm running Ubuntu 11.04 with gfortran version 4.5. Thanks. ---------- Post updated at 11:57 PM... (0 Replies)
Discussion started by: b_franz
0 Replies

4. AIX

Problem in compilation.

Hi, I am executing the below mentioned code:- proc SQLCHECK=SEMANTICS iname=CDBInteractor.pc parse=none code=cpp cpp_suffix=cpp g++ -c main.cpp g++ -o pre_request_engine main.o -I/oracle/oracle/app/product/10g/precomp -L/oracle/oracle/app/product/10g/lib32 -lnsl -ldl And... (2 Replies)
Discussion started by: tushar_tus
2 Replies

5. Programming

C Compilation problem

Dear all I am new to C programming In response to the post cat get_time.c #include <stdlib.h> #include <sys/time.h> main() { struct timeval tv; struct timezone tz; struct tm *tm; gettimeofday(&tv, &tz); tm=localtime(&tv.tv_sec); printf("... (2 Replies)
Discussion started by: on9west
2 Replies

6. AIX

Compilation problem

hi, I first want to apologize for my poor english ! I'm a newbe on Unix system and I have to install NRPE on an AIX 5.3. I have downloaded the NRPE Source code and i need to compile them... the problem is, when I do a: ./configure --enable-command-args --disable-ssl it returns me :... (1 Reply)
Discussion started by: Cyr1us
1 Replies

7. AIX

Pro C Compilation problem

Hi, I have AIX 5.3 and my code is written in proc . i am getting following error during compilation Please help?////..... :-d: Compiling with RMS cc -w -q32 -qidirfirst -ISource/Header -I/usr/vacpp/include -q32 -DRMS -DDISEC -DDBG -DBIGENDIAN -DBIT32 -c -q32... (0 Replies)
Discussion started by: ajaysahoo
0 Replies

8. Programming

Compilation problem on HP-UX

Hi, Environment : HP-UX avalon B.11.11 U 9000/800 3547052374 unlimited-user license aCC version :aCC: HP ANSI C++ B3910B A.03.37 I need to find a way out of this errors.can anyone help me . $ aCC db.cc -I$ORACLE_HOME/rdbms/public -I/disk1/oracle/product/10.2.0.2/* Error (future)... (1 Reply)
Discussion started by: varuntayur
1 Replies

9. Programming

compilation problem

i have a class name 1.c in tht i am using function n wich has his body in 2.c and declaration in 2.h now how can i compile 1.c. ex; 1.c int main() { //some data n(10); //somedata } ***** 2.c int n(int k) { //some data } int main() { some data (2 Replies)
Discussion started by: phani_sree
2 Replies

10. Solaris

compilation problem

I am compiling a software named wine When i run make then at the end following error generated. DVAPI32_ -foversion.res version.rc ld.so.1: ../../tools/wrc/wrc: fatal: relocation error: file ../../tools/wrc/wrc: symbol wine_casemap_upper: referenced symbol not found *** Signal 9 make:... (0 Replies)
Discussion started by: mansoorulhaq
0 Replies
Login or Register to Ask a Question