read_etopo.lua


NAME
    read_etopo

FUNCTION
    read_etopo(fname)

NOTES
    Reads global relief data from a ETOPO file in netCDF format.
    Data files should be those used by NOAA's Ferret program.
    The relief dataset name must be ROSE.

INPUTS
    fname - file name

OUTPUTS
    a 2D-zeArray object with vector correspoding to longitude
    from east to west and record corresponding to latitude
    from south to north.

SOURCE

require("register")

function read_etopo(fname)

    local nc, arr, rose = zeUtl.new("cdf", "double", "float")
    nc:open(fname)
    nc:getvar("ROSE", rose)

    -- Convert data from float to double

    local ptr, type = rose:getptr()
    local n = rose:size()
    arr:setptr(ptr, type, n)
    
    if (n == 180 * 90) then
        arr:reshape(180, 90)
        arr:transpose()
	    arr:shift(-10)
    elseif (n == 360 * 180) then
        arr:reshape(360, 180)
        arr:transpose()
	    arr:shift(-20)
    elseif (n == 540 * 270) then
        arr:reshape(540, 270)
        arr:transpose()
	    arr:shift(-30)
    elseif (n == 1081 * 540) then
        arr:reshape(1081, 540)
        arr:transpose()
	    arr:shift(-60)
    elseif (n == 4320 * 2161) then
        arr:reshape(4320, 2161)
        arr:transpose()
    end
    
    return arr
end