;---------------------------------------------------------------
;-- DKRZ NCL Light Hands-On EGU 2014 SPM1.12
;--
;-- Example script: ex_netcdf_1.ncl (basic script)
;--
;-- Settings: convert temperature in Kelvin to Celsius,
;-- write variable to new netcdf file
;--
;-- 2014-03-22 Karin Meier-Fleischer (meier-fleischer@dkrz.de)
;---------------------------------------------------------------
begin
outfile = "t_in_Celsius_1.nc"
if (isfilepresent(outfile)) then
system("rm -rf "+outfile) ;-- make sure that file does not exist
end if
fin = addfile("ECHAM5_OM_A1B_t_20010101.nc","r") ;-- open data file
fout = addfile(outfile,"c") ;-- create new file (netcdf 3)
filedimdef(fout,"time",-1,True) ;-- make time and UNLIMITED dimension
tK = fin->t ;-- get variable
tC = tK ;-- copy variable and its related dimensions
; and attributes
tC = tK - 273.15 ;-- convert from Kelvin to Celsius
tC@units = "Celsius" ;-- define new units
fout->tC = tC ;-- write variable to new netCDF file
end