Re: array definitions

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Oct 11 2013 - 10:21:26 MDT

Claudia,

[I had already typed most of this when I saw Dennis' reply. I decided to send this anyway since it has some additional information, and it also reiterates much of what Dennis said.]

You have a loop that goes from i=0,0, which I assume eventually will be your time loop. Inside this loop you are reading a GRIB file, which is nlat x nlon. I assume that this nlat x nlat will be the same size for every loop iteration?

If so, then I think you simply need to move the creation of the YesNoArray, UArray, and VArray to inside an "if" statement that looks like this:
             

;---Create 3D arrays first time in the loop
  if(i.eq.0) then
    YesNoArray = new((/nhours,nlat,nlon/),integer)
    UArray = new((/nhours,nlat,nlon/),float)
    VArray = new((/nhours,nlat,nlon/),float)
  end if

where "nhours" is equal to:

 hh = (/"00","03","06"/)
 nhours = dimsizes(hh)

Inside your "k" loop, then, you need to add an extra leftmost index:

  do k = 0,dim_i-1
    tempi = jet_i(k)-1 ;adjust array for (0-348) subscripting
    tempj = jet_j(k)-1 ;adjust array for (0-276) subscripting
    YesNoArray(i,tempj,tempi) = 1
    UArray(i,tempj,tempi) = u_wnd(k)
    VArray(i,tempj,tempi) = v_wnd(k)
  end do

Please note that you had this code, which really doesn't make sense:

                nlat!0 ="lat"
                mlon!0 ="lon"

I'm not sure why you were naming the dimensions of nlat and mlon, as this kind of thing is usually reserved for arrays, and not scalars.

In terms of using the same geographical coordinates: these are 2D lat/lon arrays that you are reading in, and there's no way to directly associate 2D lat/lon arrays with a data array, like you can with 1D lat/lon arrays

If you do a "printVarSummary" on one of the GRIB variables you read in:

  printVarSummary(u)

it might have a "coordinates" attribute that looks like this:

         coordinates : gridlat_221 gridlon_221

This is one way that you can "associate" 2D lat/lon arrays with your data variable. This special attribute just tells you the name of the lat/lon 2D arrays that are associated with this variable, so you know the correct name of the variable to retrieve off the file.

You can do something similar for your UArray/VArray (and any other variables you create) and create a "coordinates" attribute for them. This really only has any meaning if you write these variables to a NetCDF file, and you write both the variables and the lat/lon arrays:

;---Set attributes for UArray and VArray
UArray@units = "…" ; enter appropriate units here
VArray@units = "…" ; ditto
UArray@long_name = "…." ; enter appropriate long name here
VArray@long_name = "…." ; ditto
. . .
UArray@coordinates = "gridlat_221 gridlon_221"
VArray@coordinates = "gridlat_221 gridlon_221"

Additionally, you may want to create a "time" coordinate variable for your time dimension. In this case, you *would* have a one-dimensional variable, which means you can treat it as a 1D coordinate array:

 yyyy = "2009"
 mm = "03"
 dd = "23"
 hh = (/"00","03","06"/)
 nhours = dimsizes(hh)

 years = new(nhours,integer)
 months = new(nhours,integer)
 days = new(nhours,integer)
 hours = new(nhours,integer)
 mins = new(nhours,integer)
 seconds = new(nhours,integer)
 years = toint(yyyy)
 months = toint(mm)
 hours = toint(hh)
 days = toint(dd)
 mins = 0
 seconds = 0

 units = "hours since 2009-01-01"

 time = cd_inv_calendar(years,months,days,hours,mins,seconds,units,0)

UArray!0 = "time"
UArray&time = time
VArray!0 = "time"
VArray&time = time

Then, to write to a NetCDF file:

;--Write to NetCDF file
fout_name = "output.nc"
system("rm -f " + fout_name)
fout = addfile(fout_name,"c")
fout->U = UArray
fout->V = VArray
fout->gridlat_221 = lat
fout->gridlon_221 = lon

--Mary

On Oct 10, 2013, at 9:12 PM, Claudia Walters <ckwalter@umich.edu> wrote:

> I am having difficulty with some array definitions. I am using NARR data for part of the study and would like to create arrays from text files that use the same geographic coordinates as the NARR data. In addition, I would like to store the data from the 2D array in a 3D array with time as an additional dimension. What is the best way to achieve that?
>
> Thank you,
>
> Claudia K. Walters, Ph.D.
> Assistant Research Scientist
> Collegiate Lecturer
> Department of Social Sciences
> University of Michigan - Dearborn
> 4901 Evergreen Road
> Dearborn, MI 48128
> Email: ckwalter@umich.edu
> Phone: (313) 593-5636
>
> <Array_Dimensions.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 Fri Oct 11 10:21:36 2013

This archive was generated by hypermail 2.1.8 : Tue Oct 22 2013 - 10:35:27 MDT