gitinore *.txt files
[wrf-fire-matlab.git] / smoke / ts_smoke.R
blob615e66f162be428c1e331ed42004c50cefebbe27
1 library(ncdf4)
3 # Open the netCDF file
4 nc <- nc_open("wrfout.nc")
6 # Get the variable you need
7 pm25 <- ncvar_get(nc, "tr17_1", start = c(1, 1, 1, nctime), count = c(-1, -1, -1, 1))
8 lon <- ncvar_get(nc, "XLONG")
9 lat <- ncvar_get(nc, "XLAT")
11 # Close the netCDF file
12 nc_close(nc)
14 # Create a new netCDF file with the variable you extracted
15 nc_new <- nc_create("smoke.nc")
16 ncvar_def(nc_new, "pm25", "double", dim = list("south_north", "west_east", "bottom_top", "time"))
17 ncvar_put(nc_new, "pm25", pm25)
18 ncvar_def(nc_new, "lon", "double", dim = list("south_north", "west_east"))
19 ncvar_put(nc_new, "lon", lon)
20 ncvar_def(nc_new, "lat", "double", dim = list("south_north", "west_east"))
21 ncvar_put(nc_new, "lat", lat)
22 nc_close(nc_new)