Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gfortran module definition

Status
Not open for further replies.

sidderj

Technical User
Jun 9, 2016
5
GB
Hi all,

I am struggling to get a module working, it returns the error:

$ gfortran -o executable variable1.f95

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20):
undefined reference to `main'
collect2: error: ld returned 1 exit status

I'm using Ubuntu MATE V16.04 running Gfortran v5.4

I've noticed I have to call the module with the actual name 'variable1 otherwise it Gfortran won't see it.

The module definition follows:

MODULE variable1


implicit none

SAVE

integer nmax !number of steps in problem
integer isn !integration step number
double precision stepsize,fintim
double precision printinterval, printtime
integer Imax !number of state variables
integer I,a,ii,b !a = 0, predictor step,
!1= corrector step
integer ifintim,Irecipstepsize,Itime
double precision, ALLOCATABLE :: y:),:)
double precision, ALLOCATABLE :: ydot:),:)
double precision, ALLOCATABLE :: ydum:))
double precision, DIMENSION:),:), ALLOCATABLE :: dydt


double precision TMD,MM,VW,PO,B1,B2,MF,cpgmix,gasvi
double precision Twout,HW,TM,Xd,PI,HI,QM,HZ,htcw,di,tout
double precision KW,KTI,KTO,CPw,KTempd,KPecon,KPdrum
double precision KWgas,KTOgas,KTIgas,KTempg,CPgas

double precision TsoPL,HsoPL,RsoPL,TMPL,QMPL
double precision WsiPL,TgiPL,TgoPL,TgoPLD,WgiPL
double precision WgiFS,TMPLD,HsoPLD,PsoPL,QradPL,PgiPL,PgoPL
double precision RhogPL,RhogPLD,PsoPLD,TgoFS,Gasconst

double precision QMFS,WsiFS,WsoSM,TgoFSD
double precision WgiFRH,WgiPSH,TMFSD,HsoFSD,PsoFS,PsoFSD,PsoFS_D,QradFS
double precision PgoFS,RhogFS,RhogFSD,TgoFRH,HsoSM,TgoPSH
double precision HsoPSH,TMPSH,PsoPSH,RhogPSH,QradPSH,RsoPSH
double precision HsoPSHD,TMPSHD,PsoPSHD,RhogPSHD,TgoPSHD,QMPSH,WsiPSH
double precision PgoPSH,TsoPSH
double precision TsoFRH,HsoFRH,WgiPRHT,RsoFRH,TMFRH,PsoPRHT,HsoPRHT
double precision QMFRH,WsiFRH,WsoRSM,WsoRSMD,TgoFRHD,TMFRHD,HsoFRHD,PsoFRH
double precision PsoFRHD,QradFRH,PgoFRH,RhogFRH,RhogFRHD,TgoPRHT,HsoFRHSM
double precision TsoPRHT,RsoPRHT,TMPRHT,HsoPRHTD,TMPRHTD,TgoPRHTD
double precision PsoPRHTD,RhogPRHTD,PsoPRHB,HsoPRHB,QMPRHT,WsiPRHT
double precision WgiPRHB,QradPRHT,PgoPRHT,RhogPRHT,TgoPRHB,PsoCRHM
double precision WgiHGT,HsoCRHM
double precision TsoPRHB,RsoPRHB,TMPRHB,HsoPRHBD,TMPRHBD,TgoPRHBD
double precision PsoPRHBD,RhogPRHBD,QMPRHB,WsiPRHB,RhogPRHB,PgoPRHB
double precision QradPRHB
double precision PgoRHECON,RhogRHECON,WgiRHECON,WgiRHGDamper,RhogRHECOND
double precision PgoSHECON,RhogSHECON,WgiSHECON,WgiSHGDamper,RhogSHECOND
double precision WgiCGT,PgoECONmix,RhogECONmix,RhogECONmixD
double precision TgoECONmix,TgoECONmixD,WgiAHMILL,PgiAHMILL,RhoigAHMILL
double precision RhoigAHMILLD,TgiAHMILL,TgiAHMILLD
double precision TgoAHMILL,TgoAHMILLD,WleakAHMILL,TMAHMILL,TMAHMILLD
double precision WgoAHMILL,PgoAHMILL,RhogAHMILL,RhogAHMILLD,TgdownAHMILL
double precision MMAHMILL,AsurfaceAHMILL,khtcAHMILL

double precision WgiAHMAIN,PgiAHMAIN,RhoigAHMAIN,WgoAHMAIN
double precision RhoigAHMAIND,TgiAHMAIN,TgiAHMAIND

double precision TgoAHMAIN1,TgoAHMAIN1D,WleakAHMAIN1,TMAHMAIN1,TMAHMAIN1D
double precision WgiAHMAIN1,WgoAHMAIN1,PgoAHMAIN1,RhogAHMAIN1,RhogAHMAIN1D
double precision MMAHMAIN,AsurfaceAHMAIN,khtcAHMAIN,WgoAHMAIN1D

double precision TgoAHMAIN2,TgoAHMAIN2D,WleakAHMAIN2,TMAHMAIN2,TMAHMAIN2D
double precision WgoAHMAIN2,PgoAHMAIN2,WgiAHMAIN2
double precision RhogAHMAIN2,RhogAHMAIN2D

double precision TleakAHMILL,TleakAHMAIN1,TleakAHMAIN2
integer OPMOFRAHMILL,OPMOFRAHMAIN1,OPMOFRAHMAIN2
integer AHTYPEAHMILL,AHTYPEAHMAIN


double precision RhogiPL,RhogiPLD

double precision WgiDamper1,RhogDamper1D,WgiDamper2,RhogDamper2D

double precision TgiPRE,TgiPRED,WgiPRE,PgiPRE,VolgPRE,RhoigPRE,RhoigPRED
double precision TgoPRE,TgoPRED,WgoPRE,PgoPRE,VolgPRECIP,RhogPRE,RhogPRED

double precision IGVposA,IGVposAD,PgiPL_lag,PgiPL_lagD
double precision Intac, IntacD,Contr_out
double precision manDVID
integer AMFLAGID

double precision, parameter :: CPM = 0.465d0 !tube material specific heat capacity KJ/kgK
double precision, parameter :: RHOM = 7.833d3 ! carbon steel density kg/m3


! real(8) gasflow,gasvol


double precision PRhpt,R3hpt,HsoCRSH_fit,Tsihpt,wgIDfan
double precision vgIDfan, PgoID, Pgstack, KglossID

double precision Tgog1,Tgog2,Tgog3,Rhog1,Rhog2,Rhog3
double precision Tgog1D,Tgog2D,Tgog3D,Rhog1D,Rhog2D,Rhog3D
double precision time,Wgin1,Wgin2,Wgin3,Wgin4,Wgin5,Wgin6
double precision kgloss,pgo1,pgo2,pgo3,Tgdown3,KQloss1,volgas1
double precision Rgas,Tgin1,Wgo1,Wgo2,Wgo3,CPgas1,CPgas2,CPgas3

! set up pre calculated values
! fuel is FyF @ 2.09% O2 wet
double precision, parameter :: CO2 = 0.233d0
double precision, parameter :: H2O = 0.0345d0
double precision, parameter :: O2 = 0.0222d0
double precision, parameter :: N2 = 0.708d0
double precision, parameter :: SO2 = 0.0017d0

! determine gas constant for mixture
double precision, parameter :: Ro = 8.3144d0 !kJ/kmole K
double precision, parameter :: Mwcot = 44.d0
double precision, parameter :: Mwoxy = 32.d0
double precision, parameter :: Mwnit = 28.d0
double precision, parameter :: Mwsuldi = 64.d0
double precision, parameter :: Mwmoist = 18.d0
double precision, parameter :: qh1 = 1.d5 !kW
double precision, parameter :: qh2 = 1.d5
double precision, parameter :: qh3 = 1.d5


END MODULE variable1
!---------------------------------------------------------------
 
You've got a module - the module won't do anything unless you have a program that calls it. Try something like
Code:
module modulename
...
end module
program anyname
   use modulename

   ! call routines from modulename
end program

Alternatively, you can put the program in a different file and build both files together
 
Hi xwb,

I am using this module in a main program via the USE statement, I should have mentioned this, sorry.
 
Does variable1.f95 contain the program?

If it doesn't, you have to add the file to the compile/link line
 
Oh boy...you really need to go beyond scalars, that declaration is a bit ridiculous.

You need your own type definitions (like C structs) and collect related variables...instead of all those common sufixes you are using.
 
Hi salgerman,

yes you're probably right. However, the data definitions are the least of my problems currently. I'd just like to get something working
 
Baby steps, baby steps...

[tt]
module myvars_mod
implicit none
integer i, j, k
end module myvars_mod

program main
use myvars_mod
implicit none
j = 3
write(*,*) "j = ", j
end program main
[/tt]

Start with something like that; then, move the module to another file, etc.
 
I have gotten the same type errors when using code::blocks. then I just gave the command directly in Dos to gfortran having nothing to do with code::blocks and then mine worked.

like i use
gfortran -c modulename.f95
gfortran main program.f95 modulename.o

It also worked in directly at dos prompt BUT NOT in code;;blocks when
put them both in the same file with the module part first( though don't know whether that is really necessary) with the single
command

gfortran main program.f95
 
Thanks zmth, I'll try what you suggest. Despite contributions from others none of which worked I might have a chance now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top