[ncl-talk] convert non-regular 1d to regular 2d array
Wang, Jiali
jialiwang at anl.gov
Thu Aug 15 22:23:01 MDT 2019
Dear NCL team,
I have a 1D dataset like below: you can see that I have different number of data for each time step. Now I like to convert this 1d array to a regular 2d array by assigning -999 for those grid points where don’t have numbers.
1d array:
=======================
time
data
1
22
1
12
2
27
2
11
2
37
3
18
3
26
3
24
3
10
=======================
2d array: (x=4 data points for each time, y=3 time steps)
=======================
22
12
-999
-999
27
11
37
-999
18
26
24
10
=======================
I have been trying to use function ‘where’ but couldn’t get it working. Can you please advise?
ID = new ((/3, 4/), “loat”)
do i = 0, 2 ; time step
ID (i,:) = where(data(:,0) .eq. (i+1), data(:,1), -999) ;; this won’t work because the dimensions on left and right are different (4 vs 9). But if I set a j=0 to 3 for ID (i, j), then I am not sure how to set it for data..
end do
Thank you!
Jiali
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190816/931127d8/attachment.html>
More information about the ncl-talk
mailing list