Re: avg function-Number of subscripts do not match number of dimensions of variable

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed Feb 29 2012 - 12:56:24 MST

The error message is describing the problem. In your code you create the variables S_CTL and S_BT with 2 dimensions, the second being a single element dimension. I think you simply need to
change the lines

S_CTL = new((/nfl,1/),float)
S_BT = new((/nfl,1/),float)
to
S_CTL = new(nfl,float) ; the (/ .. /) enclosure is not needed if you have only 1 dimension
S_BT = new(nfl,float)

unless you really have a use for that single element dimension. If so you would need to reference it in the avg call, e.g.:

m(i)= avg(S_CTL(i::24,0))

 -dave

 

On Feb 29, 2012, at 12:31 PM, Guo Zhang wrote:

> Hi,
>
> I want to calculate monthly mean daily variation. The files are splited every hour. When I use avg function, I have this error 'Number of subscripts do not match number of dimensions of variable,(1) Subscripts used, (2) Subscripts expected'.
> Can anyone help me?Thanks.
> The script and error are as below.
>
> Best,
> Guo
>
> begin
> fil0 = systemfunc("ls /d1/model/guoz/CTL/HRLDAS_MP/Run/Glees/200907*.LDASOUT_DOMAIN1")+".nc"
> fil1 = systemfunc("ls /d1/model/guoz/BT/HRLDAS_MP/Run/Glees/200907*.LDASOUT_DOMAIN1")+".nc"
> nfl = dimsizes(fil0)
> S_CTL = new((/nfl,1/),float)
> S_BT = new((/nfl,1/),float)
> do ifl = 0,nfl-1
> f = addfile(fil0(ifl),"r")
> f1 = addfile(fil1(ifl),"r")
> S_CTL = f->SSOIL(:,0,0)
> S_BT = f1->SSOIL(:,0,0)
> end do
> ; ListSetType (f,"cat")
> print(dimsizes(fil0))
> printVarSummary(S_CTL)
> printVarSummary(S_BT)
> nhour = 24
> t=ispan(0,nhour-1,1)
> m=new(nhour,float)
> n=new(nhour,float)
> ; p=new(nhour,float)
> do i=0,nhour-1
> m(i)= avg(S_CTL(i::24))
> n(i)= avg(S_BT(i::24))
> ; p(i)= avg(SOBS(i::24))
> end do
> print(m)
> print(n)
>
>
> Copyright (C) 1995-2009 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 5.1.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> (0) 744
>
> Variable: S_CTL
> Type: float
> Total Size: 2976 bytes
> 744 values
> Number of Dimensions: 2
> Dimensions and sizes: [744] x [1]
> Coordinates:
> Number Of Attributes: 5
> stagger : -
> units : W m{-2}
> description : Heat flux into the soil
> MemoryOrder : XY
> _FillValue : -999
>
> Variable: S_BT
> Type: float
> Total Size: 2976 bytes
> 744 values
> Number of Dimensions: 2
> Dimensions and sizes: [744] x [1]
> Coordinates:
> Number Of Attributes: 5
> stagger : -
> units : W m{-2}
> description : Heat flux into the soil
> MemoryOrder : XY
> _FillValue : -999
> fatal:Number of subscripts do not match number of dimensions of variable,(1) Subscripts used, (2) Subscripts expected
> fatal:Execute: Error occurred at or near line 30 in file 200907_H.ncl
> _______________________________________________
> 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 Wed Feb 29 12:56:34 2012

This archive was generated by hypermail 2.1.8 : Mon Mar 05 2012 - 14:12:07 MST