Re: Calling Fortran 90 subroutine from NCL complains about array dimensions

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 25 2014 - 08:20:56 MDT

An NCL array (say) x(ntim,nlat,mlon) has the rightmost dimension varying
fastest (row major).
The *same array *in fortran is x(mlon,nlat,ntim) and the leftmost dimension
varies fastest (column major).

Please see the 'Mini-Language Manual':
    http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf

Section 7.7 NCL/Fortran array mapping

The rule “fastest varying dimesnsion in one language map to the fas=
test
varying dimension in another language”
applies here.

       NCL Fortran
x(time,lev,lat,lon) <=map=> x(lon,lat,lev,time)

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)

40
nyrLast
=
999
; last year
do
nyear=nyrStrt,nyrLast
print (“
----
“+nyear+”
----
”)
;
acquire
12
MSS files
for year
hpsscmd =
"hsi
-
q
'
cd "+ hpssi +" ; lcd "+diri+
\
" ; prompt
; mget "+
fili+nyear+"
-
[0
-
1][0
-
9].nc
'
"
print
("
hpsscmd= "+ hpsscmd)
print (“hpsscmd=“+hpss
cmd)
system
(hpss
cmd)
; strip off the TEMP variable
ncocmd = “
ncrcat

v TEMP

+diri+fili+”
*
.nc “+
\
diro+filo+nyear+”.nc”
print (“ncocmd=“+ncocmd)
system
(ncocmd)
; remove the monthly files
rmcmd = “

rm

“+diri+fili+nyear+ ”.nc”
print
(“rmcmd=“+rmcmd)
system
(rmcmd)
end do




On Tue, Jun 24, 2014 at 2:23 PM, Ekin Akoglu <ekin@ims.metu.edu.tr> wrote:

> Dear all,
>
> I could not figure out why but I couldn't manage to make a Fortran 90
> subroutine work with a call in an NCL script. WRAPIT compiles and creates
> the *.so file without problems. But the NCL script gives error on line wi=
th
> the call to the F90 code. The error is:
>
> fatal:depth_integrator: dimension size of dimension (2) of layer_thicknes=
s
> must be equal to the value of nlayer
> fatal:["Execute.c":8567]:Execute: Error occurred at or near line 90 in
> file layers.ncl
>
> I understand that something does not fit when passing between NCL and F90
> and it is the array dimensioning. However, I couldn't figure out what is
> wrong.I also examined Example 5 (
> https://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#Example_5) for
> differences in array dimensions between NCL and Fortran to no avail. I
> would be glad if you could provide some help. Attached is the NCL script,
> F90 code and the stub file for your reference.
>
> Thank you in advance.
>
> Kind regards,
>
> Ekin
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

Received on Wed Jun 25 02:21:08 2014

This archive was generated by hypermail 2.1.8 : Wed Jul 23 2014 - 15:33:46 MDT