[ncl-talk] Fortran 90 extension with wrapit

Dennis Shea shea at ucar.edu
Fri Dec 1 11:18:04 MST 2017


In short, the answer to your question is 'no! No! NO!!!'   :-)

>From the NCL archives:

The general rule of array passing from one language to another is:
The fastest varying dimension of one language maps into fastest varying
dimension of the other language.

In fortran (column major), the leftmost dimension varies fastest.
In NCL (row major) , the rightmost dimension varies fastest.
------
Specifically see Section 7.7 at:
       http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf

The following is extracted from 7.7:

Consider the following two arrays where N=2 and M=3:
        ncl: x(N,M) <==> x(M,N) :Fortran

               x(0,0) <==> x(1,1)
               x(0,1) <==> x(2,1)
               x(0,2) <==> x(3,1)

               x(1,0) <==> x(1,2)
               x(1,1) <==> x(2,2)
               x(1,2) <==> x(3,2)

Please note:



*This means that an array in NCL:  x(N,M) needs ***NO*** reordering for
fortran code dimensioned x(M,N)*
*D*





On Fri, Dec 1, 2017 at 11:00 AM, Marston Ward <marston.johnston at gu.se>
wrote:

> Hi Mary,
>
> I’m running into the issue where the dimensions are switched between NCL
> and FORTRAN.
> For example, when I pass a 2D variable: GBIN(NLAT,NLON) to the fortran
> subroutine, I have to switch the dimensions to GBIN(NLON,NLAT).
> My question is, how do I handle a 3D array which is declared B(M,N,Z) in
> NCL? I suspect that Z and M switches places in the fortran script?
> This is assuming WRAPIT can handle higher dimensions than 2. I could not
> find an example in the docs.
>
> Cheers,
> /M
>
> *Marston S. Ward*
>
> On 1 Dec 2017, 16:45 +0100, Mary Haley <haley at ucar.edu>, wrote:
>
> Hi Marston,
>
> A tip: you can add the "-d" option to WRAPIT to get some really verbose
> output. This helped me see that it was this step that was causing the
> warning:
>
> wrapit77 < binning_statsF90.stub > WRAPIT.c
>
> I took a look at binning_statsF90.stub and saw two issues.
> [1] There are certain rules about a stub file used with WRAPIT. One is
> that the "C NCLFORTSTART" and "C NCLEND" lines must start in the first
> column:
>
> C NCLFORTSTART
>        subroutine bin_stats(sf,nlat,nlon,missing,tb_bins,ntb_bins,
> . . .
> C NCLEND
>
>
> [2] The "+" continuation character is starting in column 7. These have to
> be in column 6. This is a Fortran 77 rule. To fix, simply remove one space
> before the "+":
>
> C NCLFORTSTART
>        subroutine bin_stats(sf,nlat,nlon,missing,tb_bins,ntb_bins,
>      +     ntb_binsc,lat_bins,nlat_bins,nlat_binsc,gbin,lsm,
>      +     lat2d,outbin,outbin2)
>        integer j,tb,la,jl,jk
>        integer nlat_bins,ntb_bins,nlat_binsc,ntb_binsc
>        integer tb_bins(ntb_bins)
>        integer lat_bins(nlat_bins)
>        integer nlat,nlon,sf
>        real    missing
>        real    gbin(nlat,nlon),lsm(nlat,nlon),lat2d(nlat,nlon)
>        real    outbin(sf,ntb_binsc),
>      + outbin2(sf,nlat_binsc,ntb_binsc)
> C NCLEND
>
> --Mary
>
> On Fri, Dec 1, 2017 at 5:59 AM, Marston Ward <marston.johnston at gu.se>
> wrote:
>
>> Hi,
>>
>> I’ve written a F90 routine to do some heavy calculations within NCL.
>> I’ve followed the instructions on how to write the “stub” file:
>> https://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#FixingCommonProblems
>> ,
>> how to make sure there are no stray characters in code, as well as made
>> sure the routine compiles as a standalone.
>> However, when I run WRAPIT -in  stubfile myfile.F90 I get the following,
>> despite that the SO file is created. I’ve not yet check the SO file but
>> wanted to
>> check with the NCL experts with experience in F90 routines and WRAPIT.
>> My files are attached and here is the error message when compiling (which
>> is not much to go on):
>>
>> $ WRAPIT -in binning_statsF90.stub binning_stats.F90
>>
>> WRAPIT Version: 120209
>> /software/apps/comp_wrapper/intel/ifort
>> A syntax error occurred while parsing:
>> COMPILING binning_stats.F90
>> LINKING
>> END WRAPIT
>>
>> Would appreciate some thoughts on what’s going on. Just to reiterate a
>> bit. I’ve gone through the trouble shooting part of the doc and made sure
>> I’ve not made some mistakes that WRAPIT can’t handle, but fortran can.
>>
>> /M
>>
>> *Marston S. Ward*
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> 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/20171201/e506a04e/attachment.html>


More information about the ncl-talk mailing list