NCL Home>
Application examples>
File IO ||
Data files for examples
Spanning Multiple Files
Allows the user to span multiple files. It does not copy over meta data.
These must be explicitly assigned.
begin
;========================
; get list of all files and open as "one big file"
;========================
all_files = systemfunc ("ls /fs/cgd/data0/casguest/CLASS/ann*.nc")
fall = addfiles (all_files, "r") ; note the "s" of addfile
;========================
; choose how files are combined and read in variable across files
;========================
ListSetType (fall, "cat") ; concatenate or "merge" (default)
T = fall[:]->T ; note syntax [:]
;========================
; unlike addfile(no s), addfile(s) does not read in the meta data.
; these must be explicitly assigned
;========================
; name the dimensions
T!0 = "time"
T!1 = "lev"
T!2 = "lat"
T!3 = "lon"
; read in the coordinate arrays and assign
T&time = fall[:]->time ; time coord variable
T&lev = fall[0]->lev ; get lev from the 1st file
T&lat = fall[0]->lat ; get lat from the 1st file
T&lon = fall[0]->lon ; get lon from the 1st file
end
addfiles does not copy meta data to the new variable.
addfiles_GetVar will.
Example Script
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
begin
fils = systemfunc ("ls /fs/cgd/data0/casguest/CLASS/ann*.nc")
f = addfiles (fils, "r") ; note the "s" of addfile
T = addfiles_GetVar (f, fils, "T")
end