Re: 3D variable from multiple addfile reads of 2D data?

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed Jan 11 2012 - 12:24:31 MST

Just to add a bit to Dennis' suggestion: his method gives you the time dimension on the left side, which you will need to reorder for your purposes. The docs tell you how to do that.

In this case, where you want to put the time dimension on the right, your method might be competitive in performance. As far as the syntax of your code fragment goes, try modifying it as follows:

do i = 0, nlist1 - 1

     grib_in1= addfile(list1(i),"r")

     Newx(:,:,i) = (/grib_in1->AIA_P0_L10_GLC0/)

end do

You can copy the coordinate information from the variable in the file using copy_VarMeta (see the doc; you need to load a script library to get this).
Since you have an extra dimension compared to the variable in the file, you will need to invoke it as follows:

copy_VarMeta(grib_in1->AIA_P0_L10_GLC0, Newx(0,:,:))

to make the dimensions equal. Finally, if you want coordinate information for the time dimension, you will need to create it yourself.

 -dave

On Jan 10, 2012, at 9:02 PM, Dennis Shea wrote:

> diri = "./" ; input directory
> fili = systemfunc("cd "+diri+" ; ls foo*grb")
> print(fili)
> ; force 'time' dimension
> setfileoption("grb","SingleElementDimensions","Initial_time")
>
> f = addfiles(diri+fili, "r")
> x = f[:]->FOO ; concatente all times
> printVarSummary(x)
>
> ======
> If you are new to NCL, please read the mini-Language manual
> http://www.ncl.ucar.edu/Document/Manuals/
>
> Good Luck
>
>
> On 1/10/12 7:58 PM, Chris Herbster wrote:
>> I've been playing around a bit trying to see if I can figure this out.
>>
>> I was able to create an array with the correct dimensions with:
>>
>> Newx = new ((/225,301,nlist1/),float)
>>
>> printVarSummary (Newx)
>>
>>
>> which yields:
>> Variable: Newx
>> Type: float
>> Total Size: 1625400 bytes
>> 406350 values
>> Number of Dimensions: 3
>> Dimensions and sizes: [225] x [301] x [6]
>> Coordinates:
>> Number Of Attributes: 1
>> _FillValue : 9.96921e+36
>>
>>
>> An initial victory! For this test there are just 6 input files (6 hours).
>>
>> Next I try to process a list of files, filling the variable "x" (in
>> the code below)
>>
>> ; Open each file and read the data
>>
>> do i = 0, nlist1 - 1
>>
>> grib_in1= addfile(list1(i),"r")
>>
>> x = grib_in1->AIA_P0_L10_GLC0
>>
>> Newx = (/x(:,:),i/)
>>
>> end do
>>
>>
>> I know this isn't the correct syntax to do what I want, as I get the
>> following error that the arrays are not the same dimensions. (I've
>> tried a variety of permutations of "(" and "/" arrangements but have
>> just gotten other errors.)
>>
>> fatal:_NclBuildArray: each element of a literal array must have the same
>> number of dimensions
>> fatal:Execute: Error occurred at or near line 50 in file make3d-correl.ncl
>>
>> Can someone out there help with the syntax (or proper method) to do
>> this? Thanks!
>>
>> Chris H.
>>
> _______________________________________________
> 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 Jan 11 12:24:41 2012

This archive was generated by hypermail 2.1.8 : Wed Jan 18 2012 - 09:21:55 MST