LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   My output file from gfortran compiler is not executable (https://www.linuxquestions.org/questions/programming-9/my-output-file-from-gfortran-compiler-is-not-executable-4175453256/)

Zope 03-08-2013 07:41 AM

My output file from gfortran compiler is not executable
 
Hi

I'm trying to run a F90 program to extract and arrange some data from a netcdf sets of files.

the program is as follows:

program netcdftobinary
implicit none
include 'netcdf.inc'
!include '/usr/local/include/netcdf.inc'

integer i,j, k, l
integer sta
integer ncid,varid
integer dmon

character(LEN=5),DIMENSION(12):: month
character(LEN=4),DIMENSION(23)::year
character*100 ifile
character*10 var
character*2 blu

real rainf(67420,31)
real rainfmonav(67420)
real suma

month=(/'01','02','03','04','05','06','07','08','09','10','11','12'/)
year=(/'1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1 993','1994','1995',&
'1996','1997','1998','1999','2000','2001'/)
var='Rainf'

do i=1,23
do j=1,12
ifile='Rainf_daily_WFD_GPCC_'//year(i)//month(j)//'.nc'
sta=nf_open(ifile,0,ncid)
if(sta.ne.NF_NOERR)then
write(*,*) 'OPEN ERROR MULA'
stop
end if
sta=nf_inq_varid(ncid,var,varid)
select case (j)
case (1,3,5,7,8,10,12)
dmon=31
case (2)
dmon=28
case (4,6,9,11)
dmon=30
end select
sta=nf_get_var_real(ncid,varid,rainf)
do k=1,67420
suma=0
do l=1,dmon
suma=suma+rainf(k,l)
end do
rainfmonav(k)=suma/dmon
end do
open(1,file='rainf_'//year(i)//month(j)//'.txt',status='new')
do k=1,67420
write(1,*)rainfmonav(k)
end do
close (1)
end do
end do

stop
end program

as you can see I have this two statements:

include 'netcdf.inc'
!include '/usr/local/include/netcdf.inc'

I got instruction to include netcdf.inc with the full path but when I compiled I got:

Error: Can't open included file.

Then I did some Google search and found that I could include the file like

include 'netcdf.inc' and that I should run the program using:

gfortran -I/usr/local/include/ -c netcdftobinary.F90

hence include 'netcdf.inc' is in the program and include 'full path' is a comment.

when I run gfortran -I/usr/local/include/ -c netcdftobinary.F90 everything seems OK but the output file is not an executable. It's not colored as executable and when I try to execute I get

Permission denied.

I checked the permissions of the file and they are free. Does anyone know why this might happen?

Excuse me if it's too simple but I'm learning...

colucix 03-08-2013 08:03 AM

Remove the -c option and compile again. Using -c the compiled file is not linked to the required shared libraries and it results in a sort of pre-executable. If you remove -c you should tell the compiler where the NetCDF libraries are. For example, assuming you installed them in /usr/local, the command should be:
Code:

gfortran -I/usr/local/include -o netcdftobinary netcdftobinary.F90 -L/usr/local/lib -lnetcdff -lnetcdf
Notice the -lnetcdff -lnetcdf specification: it is required for NetCDF version 4+, since the shared libraries have been splitted in two files. Also I added the -o netcdftobinary option to override the default value of the name of the executable (a.out). Hope this helps.


All times are GMT -5. The time now is 05:13 AM.