<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Access Fortran module from C in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686516#M40498</link>
    <description>First, let me echo all that Steven wrote - you would do well to share listings and map files and be explicit about what you are attempting to solve and what the variance from what you expected is.&lt;BR /&gt;&lt;BR /&gt;That said, please remember that variables in a MODULE are not a 1-for-1 replacement for a named COMMON.  There is no sequencing or ordering of data layout - the compiler and linker are free to place the actual individual data elements anywhere at all - so a struct is not likely, no matter what compile-time alignment/padding options are chosen, to map to a real*4 and two integer*4 variables laid out sequentially.&lt;BR /&gt;&lt;BR /&gt;You could possibly get close to it if there was a TYPE definition with SEQUENCE with the three data elements within it - or use the non-standard STRUCTURE/RECORD similarly.&lt;BR /&gt;&lt;BR /&gt;But one of the reasons Fortran introduced MODULE in the 1st place was to break the requirement for knowledge of the underlying physical memory layout.</description>
    <pubDate>Tue, 14 Sep 2010 19:58:14 GMT</pubDate>
    <dc:creator>Mike Kier</dc:creator>
    <dc:date>2010-09-14T19:58:14Z</dc:date>
    <item>
      <title>Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686512#M40494</link>
      <description>How can I access a Fortran data module from C?&lt;BR /&gt;&lt;BR /&gt;MODULE test&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;SAVE&lt;BR /&gt;INTEGER*4 a1&lt;BR /&gt;INTEGER*4 a2&lt;BR /&gt;REAL*4    b1&lt;BR /&gt;END MODULE test&lt;BR /&gt;&lt;BR /&gt;In the VMS Fortran User Manual there is an example how C and HP Fortran code can access common block of data:&lt;BR /&gt;&lt;BR /&gt;The C structure&lt;BR /&gt;struct s&lt;BR /&gt;{&lt;BR /&gt;int a1;&lt;BR /&gt;int a2;&lt;BR /&gt;float b1;&lt;BR /&gt;} test;&lt;BR /&gt;&lt;BR /&gt;works with an common block like&lt;BR /&gt;&lt;BR /&gt;COMMON /test/ a1,a2,b1&lt;BR /&gt;&lt;BR /&gt;but when using the module, the linker finds the symbols but the C program doesn't have the right addresses for the variables a1, a2 and b1.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Sep 2010 15:34:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686512#M40494</guid>
      <dc:creator>Michael Menge</dc:creator>
      <dc:date>2010-09-14T15:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686513#M40495</link>
      <description>&lt;!--!*#--&gt;As usual, it might help if you showed actual&lt;BR /&gt;code, with actual build commands, and with&lt;BR /&gt;actual results.&lt;BR /&gt;&lt;BR /&gt;&amp;gt; [...] the C program doesn't have the right&lt;BR /&gt;&amp;gt; addresses for the variables a1, a2 and b1.&lt;BR /&gt;&lt;BR /&gt;And you determined this how, exactly?</description>
      <pubDate>Tue, 14 Sep 2010 16:48:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686513#M40495</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-09-14T16:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686514#M40496</link>
      <description>&lt;!--!*#--&gt;Also, as usual, it might help if you&lt;BR /&gt;explained the actual problem which you are&lt;BR /&gt;trying to solve, instead of asking how to&lt;BR /&gt;implement what may be a sub-ideal "solution"&lt;BR /&gt;to that problem.&lt;BR /&gt;&lt;BR /&gt;I haven't used Fortran much since it was&lt;BR /&gt;still FORTRAN, before it got all fancy and&lt;BR /&gt;stuff, so I've never fired a MODULE statement&lt;BR /&gt;in anger before, and so I know nothing, but&lt;BR /&gt;between the Language Reference Manual and&lt;BR /&gt;/LIST and /MAP, I did get the following to&lt;BR /&gt;do something which might be slightly&lt;BR /&gt;interesting:&lt;BR /&gt;&lt;BR /&gt;alp $ type test_mod.for&lt;BR /&gt;      MODULE test&lt;BR /&gt;      IMPLICIT NONE&lt;BR /&gt;      SAVE&lt;BR /&gt;      INTEGER*4 a1&lt;BR /&gt;      INTEGER*4 a2&lt;BR /&gt;      REAL*4 b1&lt;BR /&gt;      END MODULE test&lt;BR /&gt;&lt;BR /&gt;alp $ type test_main.for             &lt;BR /&gt;C     Module test program -- Fortran calls C.&lt;BR /&gt;&lt;BR /&gt;      program test_main&lt;BR /&gt;&lt;BR /&gt;      use test      &lt;BR /&gt;&lt;BR /&gt;      a1 = 1&lt;BR /&gt;      a2 = 2&lt;BR /&gt;      b1 = 1.0&lt;BR /&gt;&lt;BR /&gt;      print *, a1, a2, b1&lt;BR /&gt;      call mod_c&lt;BR /&gt;      print *, a1, a2, b1&lt;BR /&gt;&lt;BR /&gt;      end&lt;BR /&gt;&lt;BR /&gt;alp $ type mod_c.c&lt;BR /&gt;extern int $test$a1;&lt;BR /&gt;extern int $test$a2;&lt;BR /&gt;extern float $test$b1;&lt;BR /&gt;&lt;BR /&gt;void mod_c( void)&lt;BR /&gt;{&lt;BR /&gt;    $test$a1 = 51;&lt;BR /&gt;    $test$a2 = 52;&lt;BR /&gt;    $test$b1 = 51.;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;alp $ fort test_mod&lt;BR /&gt;alp $ fort test_main&lt;BR /&gt;alp $ cc mod_c&lt;BR /&gt;alp $ link test_main, test_mod, mod_c &lt;BR /&gt;alp $ run test_main&lt;BR /&gt;          1           2   1.000000    &lt;BR /&gt;         51          52   51.00000    &lt;BR /&gt;&lt;BR /&gt;Again, knowing approximately nothing about&lt;BR /&gt;what you're actually trying to do, I have no&lt;BR /&gt;real idea if that's at all useful.&lt;BR /&gt;&lt;BR /&gt;Note that with the info provided here, you&lt;BR /&gt;should be able to reproduce my results.  You&lt;BR /&gt;should be able to say that, too, about your&lt;BR /&gt;own questions.</description>
      <pubDate>Tue, 14 Sep 2010 17:54:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686514#M40496</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-09-14T17:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686515#M40497</link>
      <description>Steven has shown how scalar  variables in a module can be accessed by their global symbols as $module$name.&lt;BR /&gt;But those scalars are not structures to be used in Your C procedure, and their allocation order and alignment is defined by the compiler internals.&lt;BR /&gt;&lt;BR /&gt;If You want to pass a structure to a C procedure, You have to somehow pass its address to the C procedure, e.g. as an argument, if You want to avoid commons.&lt;BR /&gt;&lt;BR /&gt;Example:&lt;BR /&gt;Fortran module test_mod.f90:&lt;BR /&gt;&lt;BR /&gt;MODULE test&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;structure /test_mod/&lt;BR /&gt;INTEGER*4 a1&lt;BR /&gt;INTEGER*4 a2&lt;BR /&gt;REAL*4 b1&lt;BR /&gt;end structure&lt;BR /&gt;END MODULE test&lt;BR /&gt;&lt;BR /&gt;C procedure mod_c.c:&lt;BR /&gt;&lt;BR /&gt; struct test_mod&lt;BR /&gt;{&lt;BR /&gt;int a1;&lt;BR /&gt;int a2;&lt;BR /&gt;float b1;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;void mod_c(struct test_mod *t) {&lt;BR /&gt; t-&amp;gt;a1=10; t-&amp;gt;a2=20; t-&amp;gt;b1=20.0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Fortran main test_main.f90:&lt;BR /&gt;&lt;BR /&gt;      program test_main&lt;BR /&gt;&lt;BR /&gt;      use test      &lt;BR /&gt;&lt;BR /&gt;      record /test_mod/ t&lt;BR /&gt;      t.a1 = 1&lt;BR /&gt;      t.a2 = 2&lt;BR /&gt;      t.b1 = 1.0&lt;BR /&gt;&lt;BR /&gt;      print *, t&lt;BR /&gt;      call mod_c(t)&lt;BR /&gt;      print *, t&lt;BR /&gt;&lt;BR /&gt;      end&lt;BR /&gt;&lt;BR /&gt;Fortran test_mod&lt;BR /&gt;Fortran test_main&lt;BR /&gt;cc mod-c&lt;BR /&gt;link test_main,test_mod,mod_c&lt;BR /&gt;run test_main&lt;BR /&gt;Result&lt;BR /&gt;          1           2   1.000000    &lt;BR /&gt;         10          20   20.00000    &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Sep 2010 19:57:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686515#M40497</guid>
      <dc:creator>Joseph Huber_1</dc:creator>
      <dc:date>2010-09-14T19:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686516#M40498</link>
      <description>First, let me echo all that Steven wrote - you would do well to share listings and map files and be explicit about what you are attempting to solve and what the variance from what you expected is.&lt;BR /&gt;&lt;BR /&gt;That said, please remember that variables in a MODULE are not a 1-for-1 replacement for a named COMMON.  There is no sequencing or ordering of data layout - the compiler and linker are free to place the actual individual data elements anywhere at all - so a struct is not likely, no matter what compile-time alignment/padding options are chosen, to map to a real*4 and two integer*4 variables laid out sequentially.&lt;BR /&gt;&lt;BR /&gt;You could possibly get close to it if there was a TYPE definition with SEQUENCE with the three data elements within it - or use the non-standard STRUCTURE/RECORD similarly.&lt;BR /&gt;&lt;BR /&gt;But one of the reasons Fortran introduced MODULE in the 1st place was to break the requirement for knowledge of the underlying physical memory layout.</description>
      <pubDate>Tue, 14 Sep 2010 19:58:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686516#M40498</guid>
      <dc:creator>Mike Kier</dc:creator>
      <dc:date>2010-09-14T19:58:14Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686517#M40499</link>
      <description>If You can't modify the C procedure passinf the fortran structure as an argument, a PUBLIC structure definition in the fortran module can also be used:&lt;BR /&gt;test_mod.f90:&lt;BR /&gt;&lt;BR /&gt;MODULE test&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;structure /test_mod/&lt;BR /&gt;INTEGER*4 a1&lt;BR /&gt;INTEGER*4 a2&lt;BR /&gt;REAL*4 b1&lt;BR /&gt;end structure&lt;BR /&gt;public&lt;BR /&gt;record /test_mod/ public_mod&lt;BR /&gt;END MODULE test&lt;BR /&gt;&lt;BR /&gt;mod_c.c:&lt;BR /&gt;&lt;BR /&gt; struct test_mod&lt;BR /&gt;{&lt;BR /&gt;int a1;&lt;BR /&gt;int a2;&lt;BR /&gt;float b1;&lt;BR /&gt;};&lt;BR /&gt;&lt;BR /&gt;extern struct test_mod $test$public_mod;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;void mod_c() {&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;  $test$public_mod.a1=10;&lt;BR /&gt;  $test$public_mod.a2=20;&lt;BR /&gt;  $test$public_mod.b1=20.0;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;test_main.f90:&lt;BR /&gt;      program test_main&lt;BR /&gt;&lt;BR /&gt;      use test      &lt;BR /&gt;&lt;BR /&gt;      public_mod.a1 = 1&lt;BR /&gt;      public_mod.a2 = 2&lt;BR /&gt;      public_mod.b1 = 1.0&lt;BR /&gt;&lt;BR /&gt;      print *, public_mod&lt;BR /&gt;      call mod_c()&lt;BR /&gt;      print *, public_mod&lt;BR /&gt;&lt;BR /&gt;      end&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Sep 2010 20:16:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686517#M40499</guid>
      <dc:creator>Joseph Huber_1</dc:creator>
      <dc:date>2010-09-14T20:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686518#M40500</link>
      <description>C is pass by value or by reference (i.e. pass address), Fortran is almost always pass by reference.</description>
      <pubDate>Wed, 15 Sep 2010 01:36:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686518#M40500</guid>
      <dc:creator>John McL</dc:creator>
      <dc:date>2010-09-15T01:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686519#M40501</link>
      <description>Michael,&lt;BR /&gt;&lt;BR /&gt;  I think you need to provide more information here. What code do you have? What can be changed? What cannot? Why is it necessary to share data directly? (I find that "naked" data structures are a mistake, even between modules in the same language).&lt;BR /&gt;&lt;BR /&gt;Although OpenVMS was specifically designed to allow development of programs in multiple languages, it's not always the most optimal approach.&lt;BR /&gt;&lt;BR /&gt;  Most of the time you would only attempt it if you have two large chunks of code in different langauges and want to use them together, without recoding one in the other language.&lt;BR /&gt;&lt;BR /&gt;  Cross language procedure calls are relatively simple - it's just a matter of getting the order, data type and passing mechanism of arguments to match up. However, cross mapping DATA can be a problem. Apart from the obvious issues of alignment, there are more obscure issues. For example, note that, in theory, a C compiler is allowed to reorder fields within a structure. Forcing specific fields to be in specific places can be a problem. Code should be written so that it does NOT depend on data adjacency.&lt;BR /&gt;&lt;BR /&gt;  One approach may be to convert a data interface into a procedural one. For example, define routines a1, a2 and b1, each with an optional argument. Always return the corresponding data value, and the argument is present, set the value. That can make the object look like a variable, but eliminates the issue of data mapping.&lt;BR /&gt;&lt;BR /&gt;x=a1();   -- fetch the value of a1 into x&lt;BR /&gt;a1(y);    -- set a1 to y&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Sep 2010 03:23:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686519#M40501</guid>
      <dc:creator>John Gillings</dc:creator>
      <dc:date>2010-09-15T03:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686520#M40502</link>
      <description>Our MIP optimizing source consists of more than 120 fortran routines and many data is hold in about 20 modules (variables, structures, arrays, also allocatable structures and arrays, linked lists etc., so no common blocks). The system has an input, modelling (generating the matrix), solving and output part.&lt;BR /&gt;Now the modelling part will be written in FLOPC++ and for the solving part we will use a standard MIP solver like CPLEX, Gurobi or Xpress. The question was, how to access from C/C++ the data the fortran routines read in and save in the data modules.&lt;BR /&gt;Steven's reply shows how to access the data in a fortran module, it works fine.&lt;BR /&gt;Using upper and lower characters in variable/structure/array names you have to look at the resolution of global symbols in linker and debugger too.</description>
      <pubDate>Wed, 15 Sep 2010 09:51:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686520#M40502</guid>
      <dc:creator>Michael Menge</dc:creator>
      <dc:date>2010-09-15T09:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686521#M40503</link>
      <description>SDL can simplify the maintenance of this stuff.&lt;BR /&gt;&lt;BR /&gt;SDL (in this case) is the Structure Definition Language, and it allows you to have one source file with the structures and related, and to use SDL compiler to create language-specific include files.&lt;BR /&gt;&lt;BR /&gt;It'll be work to get to SDL, but it'll repay you by avoiding the effort involved in tracking and updating the various programs accessing your data structures; from having to keep the source code of all of your different programs all in synchronization as the data structure definitions shift.&lt;BR /&gt;&lt;BR /&gt;SDL is on the Freeware.</description>
      <pubDate>Wed, 15 Sep 2010 13:06:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686521#M40503</guid>
      <dc:creator>Hoff</dc:creator>
      <dc:date>2010-09-15T13:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Access Fortran module from C</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686522#M40504</link>
      <description>&lt;!--!*#--&gt;&amp;gt; Sep 14, 2010 17:48:00 GMT   0 pts&lt;BR /&gt;&lt;BR /&gt;Some people seem never to learn the important&lt;BR /&gt;lesson.</description>
      <pubDate>Wed, 15 Sep 2010 13:32:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/access-fortran-module-from-c/m-p/4686522#M40504</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-09-15T13:32:25Z</dc:date>
    </item>
  </channel>
</rss>

