MEX fortran help with dummy arguments

I receive the following errors when try to compile my mex file:
pitchmex.f90(54): error #6451: A dummy argument name is required in this context. [NB]
INTEGER(4), INTENT(IN) :: NB ! Number of blades.
-------------------------------^
pitchmex.f90(54): error #6279: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association [NB]
INTEGER(4), INTENT(IN) :: NB ! Number of blades.
-------------------------------^
compilation aborted for pitchmex.f90 (code 1)
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'pitchmex.f90' failed.
*************************************************************
Does mex allow for dummy arguments to be passed? I have my variables declared as follows:
INTEGER(4) :: NB ! Number of blades.
REAL(ReKi) :: BlPitch (NB) ! Current values of the blade pitch angles (rad)
(-)
REAL(ReKi) :: HSS_Spd ! HSS speed (rad/s)
REAL(ReKi) :: TFOutput(NB) ! Desired pitch angles returned by this subroutine (rad)
etc...
Is there a problem with making an array with NB size? Is there a way to fix this so I don't have to "hardwire" in a value for NB in the mex routine?
Chris

1 comentario

Chris
Chris el 18 de Feb. de 2013
the NB is declared as follows:
INTEGER(4), INTENT(IN) :: NB
Forgot to include the INTENT(IN)

Iniciar sesión para comentar.

Respuestas (1)

James Tursa
James Tursa el 18 de Feb. de 2013
Editada: James Tursa el 18 de Feb. de 2013

0 votos

The compiler is telling you that NB needs to come from an argument list (i.e., a dummy variable). I.e., it is expecting that this statement is inside a subroutine or function and that NB is listed as an argument. Can you post the code above this for the subroutine or function statement? Are BlPitch and TFOutput arguments? Or are they local variables? If local, keep in mind that they will be allocated off of the stack, not the heap, so if NB is very large you will risk a seg fault by blowing your stack size.

5 comentarios

Chris
Chris el 25 de Feb. de 2013
Hi James,
BLPitch is an input argument with TFOutput is the output argument. The code posted above is as follows:
#include <fintrf.h>
SUBROUTINE mexFunction(nlhs, plhs, nrhs, prhs)
USE NWTC_Library
IMPLICIT none
!----------------------------------------------------------------------------------------------
! define right- and left-hand side arguments of the MATLAB function we're creating
!----------------------------------------------------------------------------------------------
INTEGER :: nlhs
INTEGER :: nrhs
mwPointer :: plhs(*)
mwPointer :: prhs(*)
Then I have my pointers declared for the mex file. The goal is to interface with the following subroutine and declarations.
SUBROUTINE PitchCntrl ( BlPitch, ElecPwr, HSS_Spd, GBRatio, TwrAccel, NB, ZTime, DT, DirRoot, TFOutput )
USE NWTC_Library
IMPLICIT NONE
! Passed variables:
INTEGER(4), INTENT(IN ) :: NB
REAL(ReKi), INTENT(IN ) :: BlPitch (NB)
REAL(ReKi), INTENT(IN ) :: DT
REAL(ReKi), INTENT(IN ) :: ElecPwr
REAL(ReKi), INTENT(IN ) :: GBRatio
REAL(ReKi), INTENT(IN ) ::HSS_Spd
REAL(ReKi), INTENT(OUT) ::TFOutput(NB)
REAL(ReKi), INTENT(IN ) ::TwrAccel
REAL(ReKi), INTENT(IN ) ::ZTime
James Tursa
James Tursa el 25 de Feb. de 2013
What is ReKi and how/where is it declared?
Is SUBROUTINE PitchCntrl part of a module? Or are you intending this to be an implicit interface?
Chris
Chris el 25 de Feb. de 2013
Hi James,
ReKi = 8 (declared in NWTC_Library) and it is intended to be an implicit interface.
Last question and then I can post your mex interface code. What do you want the syntax for calling the mex function to be? E.g., would it be this:
function TFOutput = PitchCntrl(BlPitch,DT,ElecPwr,GBRatio,HSS_Spd,TwrAccel,Ztime)
which assumes that NB will be calculated inside mexFunction based on the size of the BlPitch that is passed in from MATLAB.
Chris
Chris el 15 de Mayo de 2013
TFOutput = PitchCntrol( BlPitch, ElecPwr, HSS_Spd, GBRatio, TwrAccel, NB, ZTime, DT, DirRoot)
Can NB be passed or is a work around needed?

Iniciar sesión para comentar.

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de Feb. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by