Re: chars and f77

From: Josh Hacker (hacker AT XXXXXX)
Date: Fri Jul 30 2004 - 10:46:52 MDT


Thanks for the response Rick.

My question concerns how to deal with an array of strings, rather than just a single string (the latter of which I have done several times in wrappers).

In the meantime, I have found a rather ugly work-around...

Cheers,
Josh

On Fri, Jul 30, 2004 at 10:39:02AM -0600, Rick Grubin wrote:
> Hi Josh,
>
> > I know that passing characters to f77 routines is tricky, but I hope
> > that someone has done this before: I want to fill an array of strings
> > in the f77 routine - how do I handle that?
>
> I'll try to handle this in two parts; first, the NCL part.
>
> > -------------
> > external MYMOD "./my_mod.f"
> >
> > begin
> >
> > char_array = new((/1000,14/),char)
> >
> > MYMOD::my_mod(char_array)
> >
> > end
>
> A good place to start for information on extending NCL by writing your own
> wrapper as a shared library is:
> http://ngwww.ucar.edu/ngdoc/ng/ref/ncl/NclExtend.html#wrapit77
>
> One thing of note in your code above:
>
> > external MYMOD "./my_mod.f"
>
> This should be
> external MYMOD "./my_mod.so"
>
> because you must reference the shared object you've created, not Fortran
> source code.
>
> [Warning: my ability with/knowledge of Fortran is limited!]
> Second, for your external Fortran code:
>
> > C NCLFORTSTART
> > subroutine my_mod(ch_array)
> >
> > character*14 ch_array(1000)
> >
> > C NCLEND
> >
> > C fill the array
> >
> > end
>
> Follow the steps #1 - #4 as described in the URL above. To do so, you'll
> need to break up your Fortran code into file that defines a "wrapper block"
> (say, 'myMod.wib') and a source code file (say, 'myMod.f'). You'll
> create a shared object (say, 'myMod.so'), which can then be referenced
> with the 'external' statement in NCL.
>
> A couple of notes:
>
> 1. I would suggest not using underscores ('_') in your code, as the
> process to create C source code and shared objects intermixes Fortran
> and C code. There are issues with name mangling and underscores at
> compile/link time, see: http://ngwww.ucar.edu/ncl-talk/all/0204.html
> for a more detailed answer.
>
> 2. Passing character arrays (strings) back and forth between Fortran and
> NCL can be problematic; see the bottom of the URL referenced above
> regarding extending NCL with your own wrapper, and also this example:
> http://ngwww.ucar.edu/ngdoc/ng/ref/ncl/NclExtend.html#Example_4
>
> -Rick.
> --
> Rick Grubin Visualization + Enabling Technologies
> Scientific Computing Division National Center for Atmospheric Research
> grubin AT ucar.edu 303.497.1832

-- 
Joshua Hacker
Research Applications Program
NCAR/UCAR
email: hacker AT ucar.edu
voice: 303-497-8188
fax: 303-497-8401

_______________________________________________ ncl-talk mailing list ncl-talk AT ucar.edu http://mailman.ucar.edu/mailman/listinfo/ncl-talk



This archive was generated by hypermail 2b29 : Fri Jul 30 2004 - 13:13:25 MDT