Created
January 5, 2022 07:17
-
-
Save nmathewa/3ec569dedb39da943625dd4950888ac3 to your computer and use it in GitHub Desktop.
create netcdf using julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Importing libraries | |
using NCDataFrame | |
using NCDatasets | |
# create an dnetcdf dataset | |
dset = NCDataset("test.nc","c") | |
# Writing attributes | |
dset.attrib["Author"] = "Julia NCdataset" | |
# defining dimension (lat and lon) | |
defDim(dset,"lon",50),defDim(dset,"lat",50) | |
# creating null variable space for temp,lat and lon values | |
temp = defVar(dset,"temp",Float64,("lon","lat")) | |
lon_v = defVar(dset,"lon",Float64,("lon",)) | |
lat_v = defVar(dset,"lat",Float64,("lat",)) | |
# Creating random data points for temp and usual range arrays for | |
temp_data = rand(12:30,30,30) | |
lon_data = collect(range(70, length = 30,stop=80)) | |
lat_data = collect(range(10, length = 30,stop=20)) | |
# assigning values to predefined variable data points | |
temp[:,:] = temp_data | |
lon_v[:],lat_v[:] = lon_data,lat_data | |
# writing variable attributes | |
temp.attrib["Units"] = "degree Celsius" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment