[ncl-talk] Using WRAPIT with string variables
Dennis Shea
shea at ucar.edu
Wed Aug 2 08:27:14 MDT 2017
You can pass strings to and from fortran subroutines.
============= test fortran subroutine: str.f
C NCLFORTSTART
subroutine teststr(strin,strout)
implicit none
character*(*) strin, strout
C NCLEND
print *,"fortran: strin=",strin
strout = strin // strin ! create return string
print *, "fortran: strout=", strout
return
end
=========================Create str.so
%> WRAPIT str.f
There will be some warning messages
============== NCL script: str.ncl
external STRING "./str.so"
stri = "Foo" ; input
stro = new( 1, "string") ; reserve space for return string
STRING::teststr(stri, stro)
print("after fortran: stro="+stro)
=============
%> ncl str.ncl
=============output
fortran: strin=Foo
fortran: strout=FooFoo
(0) after fortran: stro=FooFoo
On Wed, Aug 2, 2017 at 6:13 AM, Barry Lynn <barry.h.lynn at gmail.com> wrote:
> Hi:
>
> As you may have read before, you can't pass string variables through the
> subroutine call using WRAPIT. Perhaps you could pass a single character,
> but I am not sure.
>
> There is a simple way around this.
>
> One can produce a csv file through a simple write statement in the *.f
> program. Then, open the file in ncl.
>
> A one line output (here).
>
> Tel Aviv University , Mostly Sunny ,
>
> Then, you can read it in the ncl program this way.
>
> asc_file = "weather_type.csv"
>
> lines = asciiread(asc_file,-1,"string")
>
> print(lines)
>
> delim = ","
>
> station = str_get_field(lines,1,delim)
>
> weather_type = str_get_field(lines,2,delim)
>
> print("station = " + station)
>
> print("weather_type = " + weather_type)
>
>
> Just in case you want to read in a real value, you can do the following.
>
> Latitude = tofloat(str_get_field(lines,2,delim))
>
> )
>
>
>
> --
> Barry H. Lynn, Ph.D
> Senior Lecturer,
> The Institute of the Earth Science,
> The Hebrew University of Jerusalem,
> Givat Ram, Jerusalem 91904, Israel
> Tel: 972 547 231 170
> Fax: (972)-25662581
>
> C.E.O, Weather It Is, LTD
> Weather and Climate Focus
> http://weather-it-is.com
> Jerusalem, Israel
> Local: 02 930 9525
> Cell: 054 7 231 170
> Int-IS: x972 2 930 9525
> US 914 432 3108 <(914)%20432-3108>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170802/d69235f8/attachment.html
More information about the ncl-talk
mailing list