I have a simple subroutine in fortran and i want to call it from matlab. Why do i get "1 unresolved external" when i compile?
- From: "panos agrapidis" <agrapas@xxxxxxxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 13:05:53 -0500
Hi, i am at the last stage of my thesis (optimization of thermal
systems using matlab), and i'm stack at this part for a long time. I
would appreciate your help.
I use the compaq visual fortran 6.6 compiler
The program accepts 5 input variables and it gives out only one (F).
but when I compile i get the message:
Creating library _lib6564.lib and object _lib6564.exp
opencycle5.obj : error LNK2001: unresolved external symbol _F@20
opencycle5.dll : fatal error LNK1120: 1 unresolved externals
This is my program:
subroutine opencycle(F,RPC,TR3,HC,RPB,HT)
real*8 W,CF,HU,P1,T1,CP,RG,RK,HR,C11,C12,C21,C22,C23
real*8 C24,C25,C31,C32,C33,C34,C35,RPM,TRM
real*8 RR,TR2,RPT,TR4,MA,MF,Z1,Z2,Z3,ZF
real*8 RPC,TR3,HC,RPB,HT,F
W=10000.0
HU=42500.0
T1=293.0
HR=7500.0
RPM=100.0
TRM=5.2
P1=1.000
CF=.200
CP=1.000
RG=.287
RK=1.400
C11=39.5
C12=.900
C21=5.600
C22=.995
C23=5.000
C24=.018
C25=28.000
C31=266.300
C32=.920
C33=5.000
C34=.036
C35=56.000
RR = 1.-1./RK
TR2 = 1.+(RPC**RR-1.)/HC
RPT = RPB*RPC
TR4 = TR3*(1.-HT*(1.-RPT**(-RR)))
MA = W/(CP*T1*(TR3-TR4-TR2+1.))
MF = MA*CP*T1*(TR3-TR2)/HU
Z1 = C11*MA*RPC*dlog(RPC)/(C12-HC)
Z2 = C21*MA*(1.+C23*dexp(C24*TR3*T1-C25))/(C22-RPB)
Z3 = C31*MA*dlog(RPT)*(1.+C33*dexp(C34*TR3*T1-C35))/(C32-HT)
ZF = 3.6*CF*MF*HR
F = Z1+Z2+Z3+ZF
return
end
C -------------------------
C THE GATEWAY ROUTINE
C -------------------------
subroutine mexFunction(nlhs,plhs,nrhs,prhs)
C ----------------------------
C DECLARATION OF THE VARIABLES
C ----------------------------
integer*8 plhs(*), prhs(*)
integer*8 nlhs, nrhs
integer*8 mxGetPr, mxCreateDoubleMatrix, mxGetM, mxGetN
integer*8 m, n, size
integer*8 F_PR, RPC_PR, TR3_PR, HC_PR, RPB_PR, HT_PR
real*8 F, RPC, TR3, HC, RPB, HT
C -------------------------------------
C CHECK FOR PROPER NUMBER OF ARGUMENTS
C -------------------------------------
If(nrhs.ne.5) then
call mexErrMsgTxt('5 ARGUMENTS REQUIRED')
elseif(nlhs.ne.1) then
call mexErrMsgTxt('1 OUTPUT ARGUMENT REQUIRED')
endif
C ----------------------------
C CREATE POINTERS
C ----------------------------
RPC_PR=mxGetPr(prhs(1))
TR3_PR=mxGetPr(prhs(2))
HC_PR=mxGetPr(prhs(3))
RPB_PR=mxGetPr(prhs(4))
HT_PR=mxGetPr(prhs(5))
m=mxGetM(prhs(1))
n=mxGetN(prhs(1))
size=m*n
if (size.gt.1) then
call mexErrMsgTxt('THINGS ARE NOT GOING PRETTY WELL')
endif
C ----------------------------
C CREATE OUTPUT
C ----------------------------
plhs(1)=mxCreateDoubleMatrix(m,n,0)
F_PR=mxGetPr(plhs(1))
call mxCopyPtrToReal8(RPC_PR, RPC, size)
call mxCopyPtrToReal8(TR3_PR, TR3, size)
call mxCopyPtrToReal8(HC_PR, HC, size)
call mxCopyPtrToReal8(RPB_PR, RPB, size)
call mxCopyPtrToReal8(HT_PR, HT, size)
-------------------------------------------------------
C CALL THE COMPUTATIONAL SUBROUTINE
C -------------------------------------------------------
call opencycle(F,RPC,TR3,HC,RPB,HT)
-------------------------------------------------------
C LOAD THE DATA INTO F_PR WHICH IS THE OUTPUT TO MATLAB
C -------------------------------------------------------
call mxCopyReal8ToPtr(F,F_PR,size)
return
end
.
- Follow-Ups:
- Prev by Date: Re: Java from Matlab Two weeks with out a solution
- Next by Date: How to update model parameters in Simulink during simulation
- Previous by thread: radius
- Next by thread: Re: I have a simple subroutine in fortran and i want to call it from matlab. Why do i get "1 unresolved external" when i compile?
- Index(es):