Re: WRAPIT: can not transfer string array to fortran subroutine

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Fri, 01 May 2009 14:25:58 -0600

To my knowledge, you can pass *one* string from NCL to
a fortran subroutine that has a variable declared as character

     character*(*) foo

=====

You can pass *one* fortran character variable back to NCL.
NCL will accept as character ... not string. then you must
use chartostring to a make a string.

======

You can not pass an array of strings to NCL [written in C]
or
pass an array of fortran character variable back to NCL.

======

I do not know the details but I believe this type of interlanguage
communication traditionally was not defined.

D

guangshan chen wrote:
> Dear all,
>
> Here is my ncl script and fortran program. I want to ncl generate a
> string array and use fortran program
> print them out.
>
> ; load build-in functions
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>
> ;load external functions should be included path"
> external write_array "./write_string.so"
>
> begin
>
> string_s = new((/5,5/),string)
> string_s = "Hello"
>
> print(string_s)
>
> write_array::write_string(5,5,string_s)
>
> end
>
> C NCLFORTSTART
> subroutine write_string(nu_lat,nu_lon,data_array)
> integer nu_lon, nu_lat
> character*(*) data_array(nu_lon,nu_lat)
> C NCLEND
> integer i, j
>
> do j = 1, nu_lat
> do i = 1, nu_lon
> write(*,*) i,j,"data_array = ",data_array(i,j)
> end do
> end do
>
> return
> end
>
> But Fortran program can not get data and print out. The following is
> my results:
> (0,0) Hello
> (0,1) Hello
> (0,2) Hello
> (0,3) Hello
> (0,4) Hello
> (1,0) Hello
> (1,1) Hello
> (1,2) Hello
> (1,3) Hello
> (1,4) Hello
> (2,0) Hello
> (2,1) Hello
> (2,2) Hello
> (2,3) Hello
> (2,4) Hello
> (3,0) Hello
> (3,1) Hello
> (3,2) Hello
> (3,3) Hello
> (3,4) Hello
> (4,0) Hello
> (4,1) Hello
> (4,2) Hello
> (4,3) Hello
> (4,4) Hello
> 1 1 data_array = Hello
> 2 1 data_array =
> 3 1 data_array =
> 4 1 data_array = {5
> 5 1 data_array =
> 1 2 data_array =
> 2 2 data_array = ??
> 3 2 data_array = ʽ
> 4 2 data_array = ?N
> 5 2 data_array = 8?
> 1 3 data_array = ?8Ͻ
> 2 3 data_array = 8?
> 3 3 data_array =@
> 4 3 data_array = [3 *
> 5 3 data_array = ?
> 1 4 data_array =
> 2 4 data_array = ?..
> 3 4 data_array = 9/9
> 4 4 data_array =
> 5 4 data_array =
> 1 5 data_array =
> 2 5 data_array = `?
> 3 5 data_array =
> 4 5 data_array =
> 5 5 data_array = pZ3
>
>
> I have no idea. Where is the problem? Thanks.
>
> Guangshan
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri May 01 2009 - 14:25:58 MDT

This archive was generated by hypermail 2.2.0 : Fri May 01 2009 - 15:10:00 MDT