Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29274 Discussions

Development of Fortran COM server for import into Matlab

sethwe
Beginner
854 Views
I am trying to develop a COM server to allow importing of Fortran-compiled codes into Matlab. I am using Visual Studio 2005 and have just followed the worked example in the help file to create the 'Adder' server in out-of-process (.exe) mode. It seems to compile successfully, but I can't load it into Matlab. Specifically, although it recognises the COM server, it can't seem to recognise the contents (message of: '1x1 struct array with no fields').

>> h = actxserver('Adder.AddingMachine', 'interface', 'IAdd')
h =
COM.Adder_AddingMachine
>> get(h)
1x1 struct array with no fields.
>>

Doing the same on a COM server that someone else has developed gives me:

>> h = actxserver('ELogitSrvr.ELogitObj')
h =
COM.ELogitSrvr_ELogitObj

>> get(h)
data_matrix: [1x53 char]
case_id: [1x53 char]
var_names: [1x53 char]
ncase: [1x53 char]
nvar: [1x53 char]
...

i.e. it loads the variables properly. As such I am fairly sure I am missing a step in the Fortran compilation, rather than any problem with the Matlab loading. I get exactly the same problem when doing this to a range of other worked examples.

Thanks
0 Kudos
5 Replies
Peter_Priestley
Beginner
854 Views

Your COM Server can have Methods and/or Properties, and I think herein is the difference between the two examples.

I'm not familiar with Matlab script, but get(h) appears to be listing the 'Properties' of the Elogit COM object. I think you probably got the Elogit server from 'Developing Statistical Software in Fortran 95' by Lemmon & Schafer, the Properties are listed in table 7.2 on page 256, the Elogit Methods are listed in table 7.3 on page 257.

The Adder server does not have any Properties (and its a bit vague how to create Properties using the Intel Fortran COM Server tools, I read thatyou have to separately create 'get_myproperty' and 'put_myproperty' methods with the same dispid but I haven't tried it). The Adder server does have 3 methods, 'Clear', 'Add' and 'GetValue'.

Perhaps that's the expected response from get(h) when the COM server objecthas no Properties?
0 Kudos
eos_pengwern
Beginner
854 Views

I haven't tried setting up a COM object in Fortran for interfacing to MATLAB (it looked a bit too complicated for what I needed), but I have found that calling a Fortran DLL from MATLAB is straightforward and very effective. My experiences are documented here.

It may not work so well if you particularly need to pass structures, rather than just scalars and arrays of C-style numbers.

Stephen.
0 Kudos
sethwe
Beginner
854 Views
Quoting - eos pengwern

I haven't tried setting up a COM object in Fortran for interfacing to MATLAB (it looked a bit too complicated for what I needed), but I have found that calling a Fortran DLL from MATLAB is straightforward and very effective. My experiences are documented here.

It may not work so well if you particularly need to pass structures, rather than just scalars and arrays of C-style numbers.

Stephen.

Stephen

Thanks for your help. I can see that setting up a COM object for interfacing to Matlab is probably somewhat over my head at the moment so will stick to using dll's as you recommend.

I have tried to implement your example code but I think I am missing something. In particular you are calling a subroutine 'S_pol_single_prec' (which wasn't included in the example), which is also the name of the interface. I wrote a simple subroutine and placed it inside the module, however i get the error 'The name of the module procedure conflicts with a name in the encompassing scoping unit'.

I am having trouble understanding the use of the 'interface' in this context. Do I need to place the subroutine in another module? I am sure I'm not getting something terribly simple here.

Please excuse my ignorance - thus far I have been using Fortran for simple numerical computations and so haven't needed to deal with many of these concepts before.

Best regards

Seth

0 Kudos
eos_pengwern
Beginner
854 Views
Seth,

The rules for when to use an interface block in Fortran can certainly get a bit confusing. In my example, 'S_pol_single_prec' was a subroutine contained in its own separate file (i.e. "S_pol_single_prec.f90"). For this reason, the interface block was necessary. If the subroutine belonged to the same module as the calling routine (i.e. 'c_interfaces'), then the interface block should have been omitted or it would indeed give the error you described. Likewise, if the subroutine were in a separate module (let's call it "S_pol_gubbins"), then again the interface block would be inappropriate and should be replaced with a simple "use S_pol_gubbins" statement.

It is quite simple once you get the hang of it. Honest.

Stephen.
0 Kudos
Steven_L_Intel1
Employee
854 Views
0 Kudos
Reply