[ncl-talk] assigning 2d values to 1d array along the perimeter
Gurer, Kemal@ARB
kemal.gurer at arb.ca.gov
Thu Nov 19 10:10:29 MST 2020
Dear ncl'ers,
I have a 2d gridded temperature data on a rectangular domain with (j,i) = (nlats-1,nlons-1) dimensions
and need to add 1-grid cell perimeter around the rectangular domain into a 1d array in anti-clockwise direction
sequentially as boundary conditions (please see the figure below):
(nlats-1,0) 3rd segment (left) (nlats-1,nlons-1)
o--------------------------------o
| |
| |
| |
| |
| |
| |
4th segment(down) | |
| | 2nd segment (up)
| j |
| |
| |
| |
| |
| |
| |
| i |
o--------------------------------o
(0,0) (0,nlons-1)
1st segment (right)
I am assigning the 1d variable, t1d, with the values of t2d along the perimeter of the domain. I need to mention that
I am shifting the values in each perimeter section, 1-grid cell below, right, above and left of the corresponding
perimeter section, respectively, to create 1-grid cell boundary along the perimeter that allows me to write the corner
values twice to complete the perimeter of the boundary condition in t1d array.
While the bottom W-E and right S-N values are correctly filled, I cannot confirm the correct values of t1d
on the top E-W and left N-S section of the domain by looking at the printout.
Could you help me to identify where I am making the logic/index mistake during the assignment, or I may have populated
the 1d array properly, but my print statements maybe incorrect? I would appreciate any help.
Thank you very much.
Kemal.
------------
Assignment:
t1d(0:nlons-1) = (/ t2d(0,0:nlons-1) /) ; bottom perimeter
t1d(nlons:nlons+nlats-1) = (/ t2d(0:nlats-1,nlons-1) /) ; right perimeter
t1d(nlons+nlats:nlons+nlats+nlons-1) = (/ t2d(nlats-1,nlons-1:0:-1) /) ; top perimeter
t1d(nlons+nlats+nlons:2*nlats+2*nlons-1) = (/ t2d(nlats-1:0:-1,0) /) ; left perimeter
To print:
print2d("t2d(0,0)="+t2d(0,0)+", t2d(0,1)="+t2d(0,1)+", t2d(0,2)="+t2d(0,2))
print2d("t1d(0)="+t1d(0)+", t1d(1)="+t1d(1)+", t1d(2)="+t1d(2))
print2d("")
print2d("t2d(0,nlons-3)="+t2d(0,nlons-3)+", t2d(0,nlons-2)="+t2d(0,nlons-2)+", t2d(0,nlons-1)="+t2d(0,nlons-1))
print2d("t1d(nlons-3)="+t1d(nlons-3)+", t1d(nlons-2)="+t1d(nlons-2)+", t1d(nlons-1)="+t1d(nlons-1))
print2d("t2d(0,nlons-1)="+t2d(0,nlons-1)+", t2d(1,nlons-1)="+t2d(1,nlons-1)+", t2d(2,nlons-1)="+t2d(2,nlons-1))
print2d("t1d(nlons)="+t1d(nlons)+", t1d(nlons+1)="+t1d(nlons+1)+", t1d(nlons+2)="+t1d(nlons+2))
print2d("t2d(nlats-3,nlons-1)="+t2d(nlats-3,nlons-1)+", t2d(nlats-2,nlons-1)="+t2d(nlats-2,nlons-1)+", t2d(nlats-1,nlons-1)="+t2d(nlats-1,nlons-1))
print2d("t1d(nlons+nlats-3)="+t1d(nlons+nlats-3)+", t1d(nlons+nlats-2)="+t1d(nlons+nlats-2)+", t1d(nlons+nlats-1)="+t1d(nlons+nlats-1))
print2d("t2d(nlats-1,nlons-1)="+t2d(nlats-1,nlons-1)+", t2d(nlats-1,nlons-2)="+t2d(nlats-1,nlons-2)+", t2d(nlats-1,nlons-3)="+t2d(nlats-1,nlons-3))
print2d("t1d(nlons+nlats-1)="+t1d(nlons+nlats-1)+", t1d(nlons+nlats)="+t1d(nlons+nlats)+", t1d(nlons+nlats+1)="+t1d(nlons+nlats+1))
Results:
(0) t2d(0,0)=292.185, t2d(0,1)=292.21, t2d(0,2)=292.221
(0) t1d(0)=292.185, t1d(1)=292.21, t1d(2)=292.221
(0)
(0) t2d(0,nlons-3)=311.413, t2d(0,nlons-2)=310.999, t2d(0,nlons-1)=309.555
(0) t1d(nlons-3)=311.413, t1d(nlons-2)=310.999, t1d(nlons-1)=309.555
(0)
(0) t2d(0,nlons-1)=309.555, t2d(1,nlons-1)=309.37, t2d(2,nlons-1)=308.421
(0) t1d(nlons)=309.555, t1d(nlons+1)=309.37, t1d(nlons+2)=308.421
(0)
(0) t2d(nlats-3,nlons-1)=302.655, t2d(nlats-2,nlons-1)=301.317, t2d(nlats-1,nlons-1)=302.387
(0) t1d(nlons+nlats-3)=302.655, t1d(nlons+nlats-2)=301.317, t1d(nlons+nlats-1)=302.387
(0)
(0) t2d(nlats-1,nlons-1)=302.387, t2d(nlats-1,nlons-2)=306.002, t2d(nlats-1,nlons-3)=307.029
(0) t1d(nlons+nlats-1)=302.387, t1d(nlons+nlats)=291.174, t1d(nlons+nlats+1)=291.15
(0)
(0) t2d(nlats-1,0)=291.174, t2d(nlats-1,1)=291.15, t2d(nlats-1,2)=291.146
(0) t1d(nlons+nlats+nlons-1)=302.387, t1d(nlons+nlats+nlons-2)=306.002, t1d(nlons+nlats+nlons-3)=307.029
(0)
(0) t2d(nlats-1,0)=291.174, t2d(nlats-2,0)=291.182, t2d(nlats-3,0)=291.197
(0) t1d(nlons+nlats+nlons-1)=302.387, t1d(nlons+nlats+nlons)=292.185, t1d(nlons+nlats+nlons+1)=292.122
(0)
(0) t2d(2,0)=292.047, t2d(1,0)=292.122, t2d(0,0)=292.185
(0) t1d(2*nlons+2*nlats-3)=291.197, t1d(2*nlons+2*nlats-2)=291.182, t1d(2*nlons+2*nlats-1)=291.174
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201119/59b73eaf/attachment.html>
More information about the ncl-talk
mailing list