Re: dimension error

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon Feb 03 2014 - 14:22:00 MST

A variable in NCL that appears as:
     u1 = new((/nlev,nlat,mlon/),float)
will appear in fortran as
     real u1(mlon,nlat,nlev)

In NCL the fastest varying dimension is the rightmost dimension;
In fortran " " " " " leftmost dimension.

The rule is 'fastest varying dimension in one language
              maps into the fastest varying dimension in the
              other language.

Change the fortran code

     real spd(nlev,nlat,mlon), dir(nlev,nlat,mlon)
     real u1(nlev,nlat,mlon), v1(nlev,nlat,mlon)
     real u2(nlev,nlat,mlon), v2(nlev,nlat,mlon)

To

     real spd(mlon,nlat,nlev), dir(mlon,nlat,nlev)
     real u1(mlon,nlat,nlev), v1(mlon,nlat,nlev)
     real u2(mlon,nlat,nlev), v2(mlon,nlat,nlev)

Likely, you will have to change your looping also

Good luck

On 2/3/14, 2:09 PM, Gurer, Kemal@ARB wrote:
> Hello,
>
> I am trying to combine an external routine with the ncl. WRAPIT seems to be working fine. I also tested the subroutine separately to make sure it works. The following ncl script gives dimension error during the call to the subroutine. Could you tell me where I am setting the values wrong? The ncl script, output, and beginning of external routine are given below. Thanks.
>
> Kemal.
>
> ------------------------ test.ncl script --------------------------
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> external EX01 "./vad.so"
>
> begin
>
> ; Open some netCDF files.
>
> a = addfile("test.nc","r")
>
> ; Read variables
>
> spd1 = a->VEL
> spd = spd1(0,:,:,:)
> dir1 = a->AZIM
> dir = dir1(0,:,:,:)
>
> printVarSummary(spd)
>
> dims = dimsizes(spd)
> nlev = dims(0)
> nlat = dims(1)
> mlon = dims(2)
>
> print(nlev)
> print(nlat)
> print(mlon)
>
> u1 = new((/nlev,nlat,mlon/),float)
> v1 = new((/nlev,nlat,mlon/),float)
> u2 = new((/nlev,nlat,mlon/),float)
> v2 = new((/nlev,nlat,mlon/),float)
>
> printVarSummary(u1)
>
> EX01::vad(spd,dir,nlev,nlat,mlon,u1,v1,u2,v2)
>
> end
> ----------------------------- end of script -------------------------------
>
> ----------------------- beginning of external routine -------------------
> C NCLFORTSTART
> subroutine vad(spd,dir,nlev,nlat,mlon,u1,v1,u2,v2)
  C NCLEND
> --------------------- end of external routine (snipped) -----------------------
>
> ----------------------------- beginning of ncl output ----------------------
> Variable: spd
> Type: float
> Total Size: 4711252 bytes
> 1177813 values
> Number of Dimensions: 3
> Dimensions and sizes: [z | 13] x [y | 301] x [x | 301]
> Coordinates:
> z: [0.3..1.5]
> y: [-150..150]
> x: [-150..150]
> Number Of Attributes: 3
> missing_value : ( -32768, -32768 )
> add_offset : 0
> scale_factor : 100
>
>
> Variable: nlev
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 13
>
>
> Variable: nlat
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 301
>
>
> Variable: mlon
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 301
>
> Variable: u1
> Type: float
> Total Size: 4711252 bytes
> 1177813 values
>
> Variable: u1
> Type: float
> Total Size: 4711252 bytes
> 1177813 values
> Number of Dimensions: 3
> Dimensions and sizes: [13] x [301] x [301]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : 9.96921e+36
>
> fatal:vad: dimension size of dimension (2) of spd must be equal to the value of nlev
> fatal:Execute: Error occurred at or near line 37 in file test.ncl
>
> ----------------------- end of output ----------------------
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> 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 Feb 3 14:21:47 2014

This archive was generated by hypermail 2.1.8 : Fri Feb 07 2014 - 16:39:11 MST