Re: Trouble passing array to f90 subroutine using WRAPIT

From: <brownrig_at_nyahnyahspammersnyahnyah>
Date: Mon Aug 26 2013 - 20:29:53 MDT

David,

We can most likely get you a 6.2.0-prerelease; let me get back to you
in the morning on that.

Rick

On Mon, 26 Aug 2013 19:25:40 -0400
  David Rasmussen <drasmussen@ucdavis.edu> wrote:
> I am on a mac with the current version of NCL: 6.1.2
>
> Like Dennis, I too produce the error with the current version:
>
> (0) xtas(1,1) in NCL: 0.387302
> At line 6 of file writearr2.f90 (unit = 6, file = 'stdout')
> Internal Error: list_formatted_write(): Bad type
>
> Both Rick and Dennis had success running the code with NCL 6.2.0 on
>a Mac.
> Are binaries of NCL 6.2.0 for OS X available as beta software at
>this time?
>
>
>
> On Mon, Aug 26, 2013 at 5:19 PM, Dennis Shea <shea@ucar.edu> wrote:
>
>> To my knowledge, there has been nothing explicitly
>> done with NCL's WRAPIT in a *long* time.
>>
>> I used the following and added one extra print [write(*/6,...) ]:
>>
>>
>> subroutine writearr(ntim,nmod,xtas)
>> implicit none
>> integer, intent(in) ::ntim,nmod
>> real, intent(in) ::xtas(ntim,nmod)
>>
>> print*,"f90: xtas(1,1)=", xtas(1,1)
>>
>> write(*,'(f6.3)') xtas(1,1) <==== or write(6,....)
>> return
>> end subroutine writearr
>>
>>
>> ****ON MY MAC****, the , as yet unreleased NCL v6.2.0 works
>>perfectly !
>>
>> %> ncl write.ncl_so
>>
>> Copyright (C) 1995-2013 - All Rights Reserved
>>
>> University Corporation for Atmospheric Research
>> NCAR Command Language Version 6.2.0-23Aug2013_0133 <========
>>
>> The use of this software is governed by a License Agreement.
>> See http://www.ncl.ucar.edu/ for more details.
>> (0) xtas(1,1) in NCL: 0.387302
>> f90: xtas(1,1)= 0.323710531
>> 0.324
>> =================
>>
>> However, ****ON MY MAC****, with the current version of NCL: 6.1.2
>>
>> %> ncl write.ncl_so
>>
>> Copyright (C) 1995-2013 - All Rights Reserved
>>
>> University Corporation for Atmospheric Research
>> NCAR Command Language Version 6.1.2
>>
>> The use of this software is governed by a License Agreement.
>> See http://www.ncl.ucar.edu/ for more details.
>>
>> (0) xtas(1,1) in NCL: 0.387302
>> At line 6 of file writearr2.f90 (unit = 6, file = 'stdout')
>> Internal Error: list_formatted_write(): Bad type
>>
>> *************************************************************
>>
>> However, on 2 independent linux systems (local divisional
>> computers and on the yellowstone complex) the code
>> works just fine with 6.1.2
>>
>> D
>>
>>
>>
>>
>> On 8/26/13 1:43 PM, David Rasmussen wrote:
>>
>>> I forgot to mention that when I tried passing a 2-D integer array, I
>>> re-declared all relevant variables as integers.
>>>
>>> What I found is that using...
>>>
>>> C NCLFORTSTART
>>> subroutine writeint(ntim,nmod,xtas)
>>> implicit none
>>> integer ntim,nmod
>>> integer xtas(nmod,ntim)
>>> C NCLEND
>>>
>>> ...works as expected. When I re-declare all relevant variables as
>>> floats/reals and use the following...
>>>
>>>
>>> C NCLFORTSTART
>>> subroutine writeflt(ntim,nmod,xtas)
>>> implicit none
>>>
>>> integer ntim,nmod
>>> real xtas(nmod,ntim)
>>> C NCLEND
>>>
>>> ...I get the error:
>>>
>>> Line: 32 write(6,'(f6.3)') xtas(1,1)
>>>
>>> At line 32 of file writearr.f90 (unit = 6, file = 'stdout')
>>> Fortran runtime error: Expected REAL for item 2 in formatted
>>>transfer, got
>>> CHARACTER
>>> (f6.3)
>>>
>>> ...when I print xtas(1,1) unformatted (i.e. using print*), I get
>>>"????" (4
>>> question marks).
>>>
>>> I am also changing data types & format codes in my .f90 and data
>>>types in
>>> my .ncl file in between these tests. Everything compiles without
>>>error.
>>>
>>> There seems to be an issue passing float/reals. I also tried passing
>>> double
>>> precision and the same result occurred. I am not sure why I am
>>> experiencing
>>> this behavior.
>>>
>>>
>>> On Mon, Aug 26, 2013 at 3:22 PM, Dennis Shea <shea@ucar.edu> wrote:
>>>
>>> Below you created
>>>>
>>>>
>>>> C NCLFORTSTART
>>>>>>> subroutine writearr(ntim,nmod,xtas)
>>>>>>> integer ntim,nmod
>>>>>>> real xtas(nmod,ntim)
>>>>>>> C NCLEND
>>>>>>>
>>>>>>
>>>> which declares 'xtas' as type 'real' (ie, a float)
>>>>
>>>> If you passed integers in 'xtas', there would be a problem.
>>>> However, passing variables of type float/real should be
>>>> exactly what is expected. Just the opposite of what you
>>>> stated below. One approach to writing floats and
>>>> integers is:
>>>>
>>>>
>>>>
>>>> C NCLFORTSTART
>>>> subroutine writeint(ntim,nmod,xtas)
>>>> implicit none
>>>> integer ntim,nmod
>>>> integer xtas(nmod,ntim)
>>>> C NCLEND
>>>>
>>>>
>>>>
>>>>
>>>> On 8/26/13 12:55 PM, David Rasmussen wrote:
>>>>
>>>> I take back some of what I said. The problem seems to be dependent
>>>>on
>>>>> the
>>>>> variable type. I can pass 2-D integer arrays just fine, but I have
>>>>> trouble
>>>>> with floats, which is what I would like to pass between NCL and my
>>>>>f90
>>>>> subroutine.
>>>>>
>>>>>
>>>>> On Mon, Aug 26, 2013 at 1:34 PM, David Rasmussen <
>>>>> drasmussen@ucdavis.edu
>>>>>
>>>>>> wrote:
>>>>>>
>>>>>
>>>>> No errors now, but when I print elements of the array I just get 4
>>>>>
>>>>>> question marks (i.e "????") (I am guessing one for each byte?)
>>>>>>
>>>>>> When I try and format the output, Fortran tells me that my format
>>>>>> choice
>>>>>> is invalid because the data is of type character....
>>>>>>
>>>>>> Line: 32 write(6,'(f6.3)') xtas(1,1)
>>>>>>
>>>>>> At line 32 of file writearr.f90 (unit = 6, file = 'stdout')
>>>>>> Fortran runtime error: Expected REAL for item 2 in formatted
>>>>>>transfer,
>>>>>> got
>>>>>> CHARACTER
>>>>>> (f6.3)
>>>>>>
>>>>>> I am able to print results from passed 1-D arrays OK. For passing
>>>>>>2-D
>>>>>> arrays, does anything else special need to happen besides swapping
>>>>>> array
>>>>>> dimensions in the stub file? Again, my subroutine is f90.
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>>
>>>>>> On Mon, Aug 26, 2013 at 11:07 AM, Dennis Shea <shea@ucar.edu> wrote:
>>>>>>
>>>>>> Computer rule: Fastest varying dimension maps into fastest
>>>>>>
>>>>>>> varying dimension. NCL (row major like C) is 0 based and the
>>>>>>> rightmost dimension varies fastest. Fortran is column major
>>>>>>> and the leftmost dimension varies fastest.
>>>>>>>
>>>>>>> Dimension order and subscripting are different for different
>>>>>>> languages.
>>>>>>>
>>>>>>> NCL: x(NA,NB,NC) <===> x(NC,NC,NA) : fortran
>>>>>>>
>>>>>>> In computer memory, think of the arrays as a long linear list and
>>>>>>>the
>>>>>>> elements are accessed via a particular language's conventions
>>>>>>>
>>>>>>> See: page 37: http://www.ncl.ucar.edu/****
>>>>>>> Document/Manuals/language_man.******<http://www.ncl.ucar.edu/***
>>>>>>> *Document/Manuals/language_**man.**<http://www.ncl.ucar.edu/**Document/Manuals/language_man.**>
>>>>>>> >
>>>>>>> pdf <http://www.ncl.ucar.edu/****Document/Manuals/language_man.**
>>>>>>> **pdf
>>>>>>><http://www.ncl.ucar.edu/**Document/Manuals/language_man.**pdf>
>>>>>>> <http://www.ncl.ucar.edu/**Document/Manuals/language_man.**pdf<http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf>
>>>>>>> >
>>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> ---
>>>>>>> It should be:
>>>>>>>
>>>>>>>
>>>>>>> C NCLFORTSTART
>>>>>>> subroutine writearr(ntim,nmod,xtas)
>>>>>>> integer ntim,nmod
>>>>>>> real xtas(nmod,ntim)
>>>>>>> C NCLEND
>>>>>>>
>>>>>>> Note:No data rearranging should be done.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 8/26/13 8:47 AM, David Rasmussen wrote:
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>>>
>>>>>>>> I would like to write an array of data to a text file, similar to
>>>>>>>> this
>>>>>>>> request from a previous thread:
>>>>>>>> http://www.ncl.ucar.edu/******Support/talk_archives/2012/*****
>>>>>>>> *0230.html<http://www.ncl.ucar.edu/****Support/talk_archives/2012/****0230.html>
>>>>>>>> <http://www.ncl.**ucar.edu/**Support/talk_**
>>>>>>>> archives/2012/**0230.html<http://www.ncl.ucar.edu/**Support/talk_archives/2012/**0230.html>
>>>>>>>> >
>>>>>>>> <http://www.ncl.ucar.**edu/**Support/talk_archives/**2012/**
>>>>>>>> 0230.html<http://www.ncl.ucar.**edu/Support/talk_archives/**
>>>>>>>> 2012/0230.html<http://www.ncl.ucar.edu/Support/talk_archives/2012/0230.html>
>>>>>>>> >
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>> I have chosen to use WRAPIT to write my data to disk.
>>>>>>>>
>>>>>>>> I am trying to pass an array to an f90 subroutine, but NCL/WRAPIT
>>>>>>>> keeps
>>>>>>>> telling me that my array is not dimensioned correctly.
>>>>>>>>
>>>>>>>> I have an array defined in the driving NCL script as:
>>>>>>>>
>>>>>>>> xtas(ntim,nmod), where ntim=34675, nmod=33
>>>>>>>>
>>>>>>>> I would like to pass this array to a f90 routine. When I try and do
>>>>>>>> this,
>>>>>>>> the routine expects xtas to be dimensioned xtas(nmod,ntim) which is
>>>>>>>> NOT
>>>>>>>> how
>>>>>>>> it is defined in the driving NCL script...
>>>>>>>>
>>>>>>>> fatal:writearr: dimension size of dimension (1) of xtas must be
>>>>>>>>equal
>>>>>>>> to
>>>>>>>> the value of ntim
>>>>>>>> fatal:["Execute.c":8128]:******Execute: Error occurred at or near
>>>>>>>> line
>>>>>>>>
>>>>>>>> 226
>>>>>>>>
>>>>>>>> in
>>>>>>>> file extract_BCSD_lat_lon.ncl
>>>>>>>>
>>>>>>>> The call to the routine in the NCL script is:
>>>>>>>> WRITEARRAY::writearr(ntim,******nmod,xtas)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Immediately before calling the f90 routine, I do
>>>>>>>> "printVarSummary(xtas)"...
>>>>>>>>
>>>>>>>> I get...
>>>>>>>>
>>>>>>>> Variable: xtas
>>>>>>>> Type: float
>>>>>>>> Total Size: 4577100 bytes
>>>>>>>> 1144275 values
>>>>>>>> Number of Dimensions: 2
>>>>>>>> Dimensions and sizes: [34675] x [33]
>>>>>>>> Coordinates:
>>>>>>>> Number Of Attributes: 1
>>>>>>>> _FillValue : -999.999
>>>>>>>>
>>>>>>>> The print summary for xtas is as expected...xtas(ntim,nmod)...
>>>>>>>>
>>>>>>>> my stub file is:
>>>>>>>>
>>>>>>>> C NCLFORTSTART
>>>>>>>> subroutine writearr(ntim,nmod,xtas)
>>>>>>>> integer ntim,nmod
>>>>>>>> real xtas(ntim,nmod)
>>>>>>>> C NCLEND
>>>>>>>>
>>>>>>>> my f90 routine is:
>>>>>>>>
>>>>>>>> subroutine writearr(ntim,nmod,xtas)
>>>>>>>> integer ntim, nmod
>>>>>>>> real xtas(ntim,nmod)
>>>>>>>>
>>>>>>>> print*, xtas
>>>>>>>>
>>>>>>>> return
>>>>>>>> end subroutine writearr
>>>>>>>>
>>>>>>>> Both compile with no errors.
>>>>>>>>
>>>>>>>> Other info:
>>>>>>>>
>>>>>>>> WRAPIT Version: 120209
>>>>>>>> OPERATING SYSTEM: Darwin
>>>>>>>> FORTRAN COMPILER (f90c): gfortran
>>>>>>>> FORTRAN COMPILER OPTIONS (fopts): -m64 -fPIC -v -c
>>>>>>>> -fno-second-underscore
>>>>>>>> gcc -m64 -c -fno-common -I/usr/local/ncl-6.1.2/include WRAPIT.c
>>>>>>>> COMPILING writearr.f90
>>>>>>>> gfortran -m64 -fPIC -v -c -fno-second-underscore writearr.f90
>>>>>>>> Using built-in specs.
>>>>>>>> COLLECT_GCC=gfortran
>>>>>>>> COLLECT_LTO_WRAPPER=/usr/******local/gfortran/libexec/gcc/**
>>>>>>>> x86_64-apple-darwin11/4.6.2/******lto-wrapper
>>>>>>>> Target: x86_64-apple-darwin11
>>>>>>>> Configured with: ../gcc-4.6.2-RC-20111019/******configure
>>>>>>>> --prefix=/usr/local/gfortran
>>>>>>>> --with-gmp=/Users/fx/devel/******gcc/deps-static/x86_64
>>>>>>>> --enable-languages=c,c++,******fortran,objc,obj-c++
>>>>>>>>
>>>>>>>>
>>>>>>>> --build=x86_64-apple-darwin11
>>>>>>>> Thread model: posix
>>>>>>>> gcc version 4.6.2 20111019 (prerelease) (GCC)
>>>>>>>> COLLECT_GCC_OPTIONS='-mmacosx-******version-min=10.8.3' '-m64'
>>>>>>>> '-fPIC'
>>>>>>>> '-v'
>>>>>>>> '-c'
>>>>>>>> '-fno-second-underscore' '-mtune=core2'
>>>>>>>> /usr/local/gfortran/libexec/******gcc/x86_64-apple-darwin11/4.**
>>>>>>>> 6.**
>>>>>>>>
>>>>>>>> **2/f951
>>>>>>>>
>>>>>>>> writearr.f90 -fPIC -quiet -dumpbase writearr.f90
>>>>>>>> -mmacosx-version-min=10.8.3 -m64 -mtune=core2 -auxbase writearr
>>>>>>>> -version
>>>>>>>> -fPIC -fno-second-underscore -fintrinsic-modules-path
>>>>>>>> /usr/local/gfortran/lib/gcc/******x86_64-apple-darwin11/4.6.2/**
>>>>>>>> ****finclude
>>>>>>>> -o
>>>>>>>> /var/folders/fl/******p8bxmn6x0gb7vk2qlzv90bdh0000gn**
>>>>>>>> ****/T//cc8VXUoN.s
>>>>>>>>
>>>>>>>>
>>>>>>>> GNU Fortran (GCC) version 4.6.2 20111019 (prerelease)
>>>>>>>> (x86_64-apple-darwin11)
>>>>>>>> compiled by GNU C version 4.6.2 20111019 (prerelease), GMP version
>>>>>>>> 5.0.2,
>>>>>>>> MPFR version 3.0.1-p4, MPC version 0.9
>>>>>>>> GGC heuristics: --param ggc-min-expand=100 --param
>>>>>>>> ggc-min-heapsize=131072
>>>>>>>> GNU Fortran (GCC) version 4.6.2 20111019 (prerelease)
>>>>>>>> (x86_64-apple-darwin11)
>>>>>>>> compiled by GNU C version 4.6.2 20111019 (prerelease), GMP version
>>>>>>>> 5.0.2,
>>>>>>>> MPFR version 3.0.1-p4, MPC version 0.9
>>>>>>>> GGC heuristics: --param ggc-min-expand=100 --param
>>>>>>>> ggc-min-heapsize=131072
>>>>>>>> COLLECT_GCC_OPTIONS='-mmacosx-******version-min=10.8.3' '-m64'
>>>>>>>> '-fPIC'
>>>>>>>>
>>>>>>>> '-v'
>>>>>>>>
>>>>>>>> '-c'
>>>>>>>> '-fno-second-underscore' '-mtune=core2'
>>>>>>>> as -arch x86_64 -force_cpusubtype_ALL -o writearr.o
>>>>>>>> /var/folders/fl/******p8bxmn6x0gb7vk2qlzv90bdh0000gn**
>>>>>>>> ****/T//cc8VXUoN.s
>>>>>>>> COMPILER_PATH=/usr/local/******gfortran/libexec/gcc/x86_64-**
>>>>>>>> apple-darwin11/4.6.2/:/usr/******local/gfortran/libexec/gcc/**
>>>>>>>> x86_64-apple-darwin11/4.6.2/:/******usr/local/gfortran/**
>>>>>>>> libexec/****
>>>>>>>> gcc/x86_64-apple-darwin11/:/******usr/local/gfortran/lib/gcc/****
>>>>>>>> x86_64-apple-darwin11/4.6.2/:/******usr/local/gfortran/lib/**
>>>>>>>> gcc/****
>>>>>>>> x86_64-apple-darwin11/
>>>>>>>> LIBRARY_PATH=/usr/local/******gfortran/lib/gcc/x86_64-apple-******
>>>>>>>> darwin11/4.6.2/:/usr/local/******gfortran/lib/gcc/x86_64-**
>>>>>>>> apple-****
>>>>>>>> darwin11/4.6.2/../../../:/usr/******lib/
>>>>>>>> COLLECT_GCC_OPTIONS='-mmacosx-******version-min=10.8.3' '-m64'
>>>>>>>> '-fPIC'
>>>>>>>>
>>>>>>>> '-v'
>>>>>>>>
>>>>>>>> '-c'
>>>>>>>> '-fno-second-underscore' '-mtune=core2'
>>>>>>>> SHARED OBJECT NAME (SharedObj): writearr2.so
>>>>>>>> LINKER SUFFIX (ld_suffix): WRAPIT.o writearr.o
>>>>>>>> -L/usr/local/gfortran/lib/
>>>>>>>> -o writearr2.so
>>>>>>>>
>>>>>>>> LINKING
>>>>>>>> gcc -m64 -bundle -flat_namespace -undefined suppress WRAPIT.o
>>>>>>>> writearr.o
>>>>>>>> -L/usr/local/gfortran/lib/ -o writearr2.so -lgfortran
>>>>>>>> END WRAPIT
>>>>>>>>
>>>>>>>> I must be missing something here. I am not trying to do anything
>>>>>>>> complicated. Thanks in advance.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> ______________________________******_________________
>>>>>>>>
>>>>>>>>
>>>>>>>> ncl-talk mailing list
>>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>>> http://mailman.ucar.edu/******mailman/listinfo/ncl-talk<http://mailman.ucar.edu/****mailman/listinfo/ncl-talk>
>>>>>>>> <http**://mailman.ucar.edu/**mailman/**listinfo/ncl-talk<http://mailman.ucar.edu/**mailman/listinfo/ncl-talk>
>>>>>>>> >
>>>>>>>> <http**://mailman.ucar.edu/**mailman/**listinfo/ncl-talk<http://mailman.ucar.edu/mailman/**listinfo/ncl-talk>
>>>>>>>> <ht**tp://mailman.ucar.edu/mailman/**listinfo/ncl-talk<http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>>>>>>>> >
>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>
>>>
>>>
>>> ______________________________**_________________
>>>
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/**mailman/listinfo/ncl-talk<http://mailman.ucar.edu/mailman/listinfo/ncl-talk>
>>>
>>>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Aug 26 20:30:03 2013

This archive was generated by hypermail 2.1.8 : Fri Aug 30 2013 - 14:04:57 MDT