Why not just work with the C++ code? use f2c, then clean up the C++ code and dump fortran altogether.

If the code is small, it's a good idea. If it's a lot code, you'd probably be better off leaving it in fortran.

On 25 Oct 2006, at 13:43, Franco Vaccari wrote:

Hi all, new to the list...

I'm trying to get a plugin (Mach-O) starting from fortran code. Not knowing any C/C++ (and XCode as well...) the way I went is:

0) prepare a stupid fortran code for testing, that writes a record to a text file

1) use f2c to translate fortran to C++ (f2c -C++ hello.f)

2) installed the plugin template prepared by Dave Addey and create a new project per Dave instructions (thanks Dave...)

3) added f2c.h and libf2c.a to the project, and added the f2c translated code to the cpp code coming from the template

4) modified the array of global methods to include my method

5) build for PPC

6) create the plugin with RB Plugin Converter


In the end I've got the plugin working. But a couple of improvements are needed, and I'm here for some help...

a) the text file is created in / while typically it has to appear in a user-specified path. In a previously tried strategy I simply compiled the fortran code with g77/g95, put the executable in the app/Contents/MacOS folder and call it from RB using the shell class. In such a way the output file was created in the folder currently used by the user, but if I moved my app to another machine I had to recompile the fortran code there (probably because of different configuration), while I'd like to have my app running on whatever Mac, possibly without the developer tools installed there, and I thought that maybe a plugin would be the best way to go...

b) I have f2c installed by fink, and it is not UB. Can I create the PPC plugin on a PPC Mac, the Intel plugin on an Intel Mac, and somehow put the two outcomes together before running RB Plugin Converter on any of the two platforms) to obtain a UB plugin?

c) how to add win32 compatibility to the plugin?


Thanks in advance for any help (details below for whoever may be interested), and be careful that I might be very dangerous in my requests, given my above mentioned ignorance....

Franco


----------------
The details
----------------

0) prepare a stupid fortran code for testing, that writes a record to a text file

      subroutine hello
      open(1,file="hello.txt")
      write(1,'(a)') "Hello!"
      close(1)
      return
      end

1) use f2c to translate fortran to C++ (f2c -C++ hello.f)

/* test.f -- translated by f2c (version 20030320).
   You must link the resulting object file with the libraries:
        -lf2c -lm   (in that order)
*/

#ifdef __cplusplus
extern "C" {
#endif
#include "f2c.h"

/* Table of constant values */

static integer c__1 = 1;

/* Subroutine */ int hello_()
{
    /* System generated locals */
    olist o__1;
    cllist cl__1;

    /* Builtin functions */
integer f_open(olist *), s_wsfe(cilist *), do_fio(integer *, char *,
            ftnlen), e_wsfe(), f_clos(cllist *);

    /* Fortran I/O blocks */
    static cilist io___1 = { 0, 1, 0, "(a)", 0 };


    o__1.oerr = 0;
    o__1.ounit = 1;
    o__1.ofnmlen = 9;
    o__1.ofnm = "hello.txt";
    o__1.orl = 0;
    o__1.osta = 0;
    o__1.oacc = 0;
    o__1.ofm = 0;
    o__1.oblnk = 0;
    f_open(&o__1);
    s_wsfe(&io___1);
    do_fio(&c__1, "Hello!", (ftnlen)6);
    e_wsfe();
    cl__1.cerr = 0;
    cl__1.cunit = 1;
    cl__1.csta = 0;
    f_clos(&cl__1);
    return 0;
} /* hello_ */

#ifdef __cplusplus
        }
#endif

2) installed the plugin template prepared by Dave Addey and create a new project per Dave instructions (thanks Dave...)

3) added f2c.h and libf2c.a to the project, and added the f2c translated code to the cpp code coming from the template

4) modified the array of global methods to include my method

...
...
// stick any global methods into an array, ready for registration below
static REALmethodDefinition pluginMethodArray[] = {
{ (REALproc) CurrentArchitecture, REALnoImplementation, "CurrentArchitecture() as Integer" },
        { (REALproc) hello, REALnoImplementation, "hello() as Integer" },
};

...
...

5) build for PPC

6) created the plugin with RB Plugin Converter



--------------------
Franco Vaccari
Trieste - Italy
--------------------



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>



--
http://elfdata.com/plugin/



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to