Hi Bruce,
Yes, this is possible with C, and actually I believe it is possible
with Fortran, if your strings are the same length.
To do it in C, you can't use WRAPIT to create a shared object file
(*.so) unfortunately; you have to create this yourself.
I've attached a sample "ex06.c" C file, that shows a very simple
procedure that takes an array of strings and prints them out. This is
a procedure, so it doesn't return any values.
I've also attached a sample ex06.ncl script that calls the shared
object once you've built it.
If you are not sure how to build a shared object from a C wrapper
file, then you can use WRAPIT to help you with this. Create some dummy
Fortran subroutine called "dummy.f":
C NCLFORTSTART
subroutine f (x, nq)
real x(nq)
C NCLEND
print "hello, I don't do anything."
stop
end
and process it with WRAPIT using:
WRAPIT -d dummy.f
You will see a bunch of stuff echoed. The important thing is how
"WRAPIT.c" is compiled, and how "dummy.so" is created.
For example, on a Mac, you might see several lines of output,
including:
gcc -c -fno-common -I/usr/local/include WRAPIT.c
...
gcc -bundle -flat_namespace -undefined suppress WRAPIT.o dummy.o -o dummy.so -L/sw/lib -lg2c
You can then use these two lines to help you figure out how to compile
"ex06.c" and "ex06.so":
gcc -c -fno-common -I/usr/local/include ex06.c
...
gcc -bundle -flat_namespace -undefined suppress ex06.o -o ex06.so -L/sw/lib -lg2c
You will then be able to run ex06.ncl.
Let me know if you have any questions about all of this.
--Mary
On Mon, 4 Feb 2008, Lunde, Bruce N CIV NAVOCEANO, NP1 wrote:
> Hello,
>
> On your "Extending NCL" page
>
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclExtend.shtml
>
> I have seen a comment that you cannot pass arrays of
> strings (character variables) to/from NCL from/to
> Fortran.
>
> I was wondering if this is possible with C ?
>
> Thanks, Bruce
>
> =====
> Bruce Lunde
> Bruce.Lunde_at_navy.mil
> 228-688-5843
> Code NP1
> Naval Oceanographic Office
> Stennis Space Center, MS
> =====
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
This archive was generated by hypermail 2.2.0 : Mon Feb 04 2008 - 10:52:23 MST