;---Create a dummy 2D array. nx = 10 ny = 5 data = new((/ny,nx/),float) do i=0,ny-1 data(i,:) = (i+1.)*ispan(1,10,1) end do ;---Give the 2D array some coordinate values. data!0 = "y" data!1 = "x" data&x = ispan(1,nx,1)*1. ; Make sure coord arrays data&y = ispan(1,ny,1)*1. ; are of type float. ;---Print to see what it looks like. ; printVarSummary(data) print("------------------------------------------------------------") opt = True opt@title = "The original data array" fmt = "10f7.2" write_matrix(data,fmt,opt) ;---Try different types of coordinate subscripting to see what happens. ; ; This will give you a single value at exactly the location ; where the Y coordinate array is equal to "2", and the ; X coordinate array is equal to "5": ; print("------------------------------------------------------------") print("data({2},{5}) = " + data({2},{5})) ; ; You get an error if you try to use single-value coordinate ; values that don't exactly equal your coordinate arrays. ; ; Here, the X coord value "5" is okay, but the Y coord ; value, "5.5" is not. ; print("------------------------------------------------------------") print("You should see an error with 'data({5.5},{5})'") print("data({5.5},{5}) = " + data({5.5},{5})) print("------------------------------------------------------------") ;---These values are okay. print("data({5.0},{5}) = " + data({5.0},{5})) print("------------------------------------------------------------") ;---Try using ranges for coordinate values. ;---These ranges exactly match coord values. opt@title = "data({1:3},{5:7})" write_matrix(data({1:3},{5:7}),fmt,opt) print("------------------------------------------------------------") ;---What happens when your ranges are not exactly equal? opt@title = "data({1.5:3.5},{5:7})" write_matrix(data({1:3},{5:7}),fmt,opt) print("------------------------------------------------------------") ;---This will give you an error, because the first range given is outside. print("You should see an error with 'data({-1.5:0.},{5:7})'") opt@title = "data({-1.5:0.},{5:7})" write_matrix(data({-1.5:0.},{5:7}),fmt,opt) print("------------------------------------------------------------") ;---You can mix and match index and coordinate subscripting ;---This will give you all rows, but just a subset of the columns. opt@title = "all rows, just some cols: data(:,{3.5:8.1})" write_matrix(data(:,{3.5:8.1}),fmt,opt) print("------------------------------------------------------------") ;---This will give you all columns, but just a subset of the rows. opt@title = "all cols, just some rows: data({0.0:2.3},:)" write_matrix(data({0.0:2.3},:),fmt,opt) print("------------------------------------------------------------")