Re: do-loop / ind() ncl question

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu, 3 May 2007 08:18:29 -0600 (MDT)

On Wed, 2 May 2007, Edward Myers wrote:

> Hi,
>
> I have a three-dimensional array, temp(time, z_level, horizontal_node), that
> stores ocean temperature as a function of time, vertical level and the
> horizontal node of a triangular mesh. I would like to plot the surface
> temperature, so I use the water level at each node to determine which
> z-coordinate z_level to use (each node can have a different z_level where the
> surface is located). Therefore, I have another array, vsurf(horizontal_node)
> that tells which z_level that particular node's water level falls within.
> Currently, I am doing the following to extract the surface temperature:
>
> temp_surf=new(nnodes,"float")
> do jj=0,nnodes-1
> temp_surf(jj)=temp(nn,vsurf(jj),jj)
> end do
>
> nnodes are the number of horizontal grid nodes, and nn is a time index that
> is being looped on outside of this statement.
>
> Rather than the do-loop I currently have, is there an easier way of doing
> this operation? It seems like the ind() function could potentially be used,
> but I wasn't sure... Any ideas would be greatly appreciated!
>
> Thanks,
> Ed Myers

Hi Ed,

I couldn't think of another way to do this loop, especially since you
are subscripting two dimensions of a 3D array, and in a somewhat
random fashion given the use of the vsurf array.

I think there's a kludgy way to do this. First, you can convert temp
to a 2D array that contains the vsurf(jj),jj elements in the correct
order:

     temp2d = temp(nn,vsurf,:) ; nnodes x nnodes array

Now, you basically want to grab all the values along the diagonal,
correct? You can then do this with a combination of onedtond and
ndtooned:

     temp1d = ndtooned(temp2d) ; so we can subscript easier
     temp_surf = temp1d(0::nnodes+1) ; grab every nnodes+1-th value

You can condense this a little more with:

     temp1d = ndtooned(temp(nn,vsurf,:))
     temp_surf = temp1d(0::nnodes+1) ; Grab every nnodes+1-th value

--Mary

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu May 03 2007 - 08:18:29 MDT

This archive was generated by hypermail 2.2.0 : Tue May 08 2007 - 09:54:33 MDT