# NetCDF files (*.nc) can be read by a variety of softwares # (e.g., C, C++, Fortran, Phyton, R, Matlab) # For more information on NetCDF files please visit: # http://www.unidata.ucar.edu/software/netcdf/ # This is a generic R program to read arrays from the # Very High Resolution Climatology NetCDF files: # VHRFC.nc - Very High Resolution Full Climatology # VHRAC.nc - Very High Resolution Annual Cycle # VHRDC.nc - Very High Resolution Diurnal Cycle # VHRMC.nc - Very High Resolution Monthly Cycle # VHRSC.nc - Very High Resolution Seasonal Cycle # # Written by: Rachel Albrecht, University of Sao Paulo, Brazil #--------------------------------------------------------------- # R is a free software environment for statistical computing # and graphics. It compiles and runs on a wide variety of UNIX # platforms, Windows and MacOS. # To download R, please choose your preferred CRAN mirror: # https://cran.r-project.org/mirrors.html # More information can be found at R Project homepage: # https://www.r-project.org/ #---------------------------------------------------------------- # This program requires "ncdf4" package # (https://cran.r-project.org/web/packages/ncdf4/index.html) # For a simple installation, use the command below: # install.packages("ncdf4") require(ncdf4) #-- Opening an existing netCDF file for reading ncin <- nc_open("VHRFC.nc") #-- Printing on screen NetCDF variables, dimensions and attributes print(ncin) #-- Reading SDS arrays and grids from an existing netCDF file: # Available SDS names are: # Longitude # Latitude # VHR*C_LIS_FRD (=Flash Rate Density) lon <- ncvar_get(ncin,"Longitude") lat <- ncvar_get(ncin,"Latitude",verbose=F) head(lat) frd <- ncvar_get(ncin,"VHRFC_LIS_FRD",verbose=F) #-- Reading Global attributes att<-ncatt_get( ncin,0) #-- Reading FRD attritubutes attfrd <- ncatt_get( ncin,"VHRFC_LIS_FRD") #-- Closing an open netCDF file nc_close(ncin) #-- printing on screen the first or last parts of the variable head(lon) head(lat) head(frd) # To read other data sets (e.g., VHRAC.nc, VHRDC.nc, VHRMC.nc, VHRSC.nc) just replace the file name # and varid in nc_open() and ncvar_get() functions above.