NCL Home> Application examples> File IO || Data files for examples >read ascii

Gridded Data

    The file:

    Lat    Lon   Temp
    33.3   76.5   22.4
    33.3   76.4   21.3
    33.3   76.4   24.7
    .
    .
    .
    etc

    ; read in the data

    nlon = 89
    nlat = 240
    nlatnlon = nlon * nlat
    data=asciiread("file",(/nlatnlon,3/),"float") 

    ; convert data to something useful
    ; size of grid: (/240,89/) (Note 240 * 89 = 2130)

    temp1D = data(:,2)                  ; 1st create a 1d array
    temp2D = onedtond(temp1D,(/nlat,nlon/)) ; now grid the data

    ; now extract the lat coordinates from the data array
    ; we have to find one lat point for each nlon points of
    ; longitude

    lat = data(::nlon,0)

    ; now extract the lon coordinates
    lon  = data(0:nlon-1,1)

    ; now assign named dimensions 

    temp2D!0 = "lat"
    temp2D!1 = "lon"

    ; now assign coordinate variables

    temp2D&lat = lat
    temp2D&lon = lon