""" Open file """
nc = netCDF4.Dataset(filename, 'w', format='NETCDF3_CLASSIC')
""" Define dimensions """
nc.createDimension('time', time.size)
nc.createDimension('lon', lon.size)
nc.createDimension('lat', lat.size)
""" Define variables """
nc_time = nc.createVariable('time', np.dtype('int32').char, ('time,'))
nc_time.long_name = 'Year'
nc_time.units = 'year'
nc_lat = nc.createVariable('lat', np.dtype('float32').char, ('lat',))
nc_lat.long_name = 'Latitude'
nc_lat.units = 'degree'
nc_lon = nc.createVariable('lon', np.dtype('float32').char, ('lon',))
nc_lon.long_name = 'Longitude'
nc_lon.units = 'degree'
nc_prcp = nc.createVariable('prcp', np.dtype('float32').char, ('time','lat','lon'))
nc_prcp.long_name = 'Total Precipitation'
nc_prcp.units = 'mm/day'
nc_Rnet = nc.createVariable('Rnet', np.dtype('float32').char, ('time','lat','lon'))
nc_Rnet.long_name = 'Net Radiation'
nc_Rnet.units = 'W/m2'
""" Set values """
nc_time[:] = time
nc_lat[:] = lat
nc_lon[:] = lon
nc_prcp[:] = prcp
nc_Rnet[:] = Rnet
nc.close()