[ncl-talk] Fwd: appending columns of a 2d array to a list

David Gill gill at ucar.edu
Fri Aug 18 12:14:45 MDT 2017


Subject: appending columns of a 2d array to a list
Folks,
I am really new to NCL and am using NCL because that is what the original
processing script uses.

I am building a table that has columns that have the same type of data
within the column. Each row of the table represents a different US county.
The columns have information such as the state, the county name, latitude,
longitude. So, within the column the data is the same type, and along a row
the data type changes.I have no troubles manually constructing this table
for a few.

Where things are not working for me is that I want to add a few hundred
more columns of data. I have this data inside a 2d array. I know this 2d
data is OK, because I can print it and manipulate it. I am not able to
column-wise append the data to the existing part of my list.

The start of my list works fine (a combination of integers, strings, and
floats):

      ;**********************************************
      ; Fill in all of the columns (location + lots of days), for each row
(list of counties)
      ;**********************************************
      nf_each_county = new(dimsizes(states),integer)
      nf_each_county = nf
      alist1  = NewList("fifo")
      ListAppend(alist1,nf_each_county)
      ListAppend(alist1,states)
      ListAppend(alist1,county)
      ListAppend(alist1,lat0)
      ListAppend(alist1,lon0)
The problem is trying to get the columns of the 2d array appended to the
list. I have tried everything I can think of.

This does not work, jamming in a full 2d array.

             ListAppend(alist1,x0(:,:))

This does not work, trying to use each column via an index:

      i = 0
      do while(i.lt.nDays)
         ListAppend(alist1,x0(i,:))
          i=i+1
      end do

This does not work, trying to use a temporary 1d array (I put in the delete
because of complaints that I was trying to overwrite):
      i = 0
      do while(i.lt.nDays)
         xtemp = x0(i,:)
         ListAppend(alist1,xtemp)
         delete(xtemp)
          i=i+1
      end do

Unfortunately, the only thing that I have found that does work is to append
each column separately, where a new 1d array is created for each column.
This works when no deleting is going on.

      xtemp0 = x0(0,:)
      ListAppend(alist1,xtemp0)
      xtemp1 = x0(1,:)
      ListAppend(alist1,xtemp1)
      xtemp2= x0(2,:)
      ListAppend(alist1,xtemp2)

As a hack, I can do this, but for several hundred extra coluns, this
requires writing a script to write NCL code. The code is now quite brittle
and not able to be generalized because of this set of assignments.


I also tried another method, using a list constructor.

This does not work:

       alist1  = [/nf_each_county, states, county, lat0, lon0,\
              x0(:,:)/]

As above, if I explicitly list out the columns (from the 2d array), then
everything is OK:

       alist1  = [/nf_each_county, states, county, lat0, lon0,\
               x0(0,:),x0(1,:),x0(2,:)/]

I would sure appreciate any advice - again, a real noob. Using version
6.1.2.

Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170818/f8db745e/attachment.html 


More information about the ncl-talk mailing list