LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-08-2013, 07:41 AM   #1
Zope
LQ Newbie
 
Registered: Jan 2013
Posts: 7

Rep: Reputation: Disabled
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...
 
Old 03-08-2013, 08:03 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gfortran compiler sujatabhattacharyya Linux - Newbie 1 07-12-2012 11:29 AM
problem calling fftw3 library function while using gfortran compiler. Please help. buddyamit Programming 5 07-08-2011 12:07 AM
gfortran gives different output after installation openSUSE 11.3 Victorray Linux - Software 2 08-16-2010 02:39 PM
Build scripts say my C compiler cannot make executable output noware Linux - Software 2 06-07-2006 02:15 PM
can't run the executable file after compiling with g++ compiler moondog1129 Linux - Laptop and Netbook 2 02-06-2006 09:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration