Example 2 : Lazily Read

Two-dimensional fields are read from the netcdf file generated in Example1, and then re-written to a new netcdf file.

using NCTiles,NetCDF

inputs=NCTiles.NCTILES_TESTCASES
NCTiles.ensure_testcases_installed()

outputs = joinpath(tempdir(),"NCTILES_TESTCASES_OUTPUT/")
if ~ispath(outputs); mkpath(outputs); end

Using NCDatasets backend

file_in=outputs*"ex1/ex1_NCDatasets.nc"
~isfile(file_in) ? error("Running Example1 first is needed to run Example2") : nothing

file_out=outputs*"ex2/ex2_NCDatasets.nc"
if ~ispath(outputs*"ex2/"); mkpath(outputs*"ex2/"); end

README = readlines(joinpath(inputs,"README"))
3-element Vector{String}:
 "Please replace this placeholder file with a descriptive"
 "paragraph that may provide a product name, version #,"
 "and contact point for user support."

Get all the metadata from the file and set up NCvars

ncvars,ncdims,fileatts = readncfile(file_in)
(Dict{String, NCvar}("ETAN" => NCvar("ETAN", "m", NCvar[NCvar("lon_c", "degrees_east", 720, NCData("/tmp/NCTILES_TESTCASES_OUTPUT/ex1/ex1_NCDatasets.nc", "lon_c", NCDatasets, Float64), Dict("units" => "degrees_east", "long_name" => "longitude"), NCDatasets), NCvar("lat_c", "degrees_north", 360, NCData("/tmp/NCTILES_TESTCASES_OUTPUT/ex1/ex1_NCDatasets.nc", "lat_c", NCDatasets, Float64), Dict("units" => "degrees_north", "long_name" => "latitude"), NCDatasets), NCvar("tim", "days since 1992-01-01", 3, NCData("/tmp/NCTILES_TESTCASES_OUTPUT/ex1/ex1_NCDatasets.nc", "tim", NCDatasets, Dates.DateTime), Dict("units" => "days since 1992-01-01", "long_name" => "tim", "standard_name" => "time"), NCDatasets)], NCData("/tmp/NCTILES_TESTCASES_OUTPUT/ex1/ex1_NCDatasets.nc", "ETAN", NCDatasets, Float32), Dict("units" => "m", "long_name" => "Surface Height Anomaly"), NCDatasets)), Dict{String, NCvar}("lon_c" => NCvar("lon_c", "degrees_east", 720, NCData("/tmp/NCTILES_TESTCASES_OUTPUT/ex1/ex1_NCDatasets.nc", "lon_c", NCDatasets, Float64), Dict("units" => "degrees_east", "long_name" => "longitude"), NCDatasets), "lat_c" => NCvar("lat_c", "degrees_north", 360, NCData("/tmp/NCTILES_TESTCASES_OUTPUT/ex1/ex1_NCDatasets.nc", "lat_c", NCDatasets, Float64), Dict("units" => "degrees_north", "long_name" => "latitude"), NCDatasets), "tim" => NCvar("tim", "days since 1992-01-01", 3, NCData("/tmp/NCTILES_TESTCASES_OUTPUT/ex1/ex1_NCDatasets.nc", "tim", NCDatasets, Dates.DateTime), Dict("units" => "days since 1992-01-01", "long_name" => "tim", "standard_name" => "time"), NCDatasets)), Dict{Any, Any}("missing_value" => NaN, "ntile" => 1.0, "itile" => 1.0, "_FillValue" => NaN))

Rewrite to a file

write(ncvars,file_out,README=README,globalattribs=fileatts)
closed Dataset

Using NetCDF backend

file_out=outputs*"ex2/ex2_NetCDF.nc"
ncvars,ncdims,fileatts = readncfile(file_in,NetCDF)
write(ncvars,file_out,README=README,globalattribs=fileatts)

This page was generated using Literate.jl.