我正在打开一个netcdf文件,并希望使用非重复的方法将所有变量提取到它们自己的变量名中。
目前,我可以使用以下方法来执行此操作
#route of file we want to open
fn <- "grid_T_19800105.nc"
#opens netCDF file
nc <- nc_open(fn)
#Extracts latitude and longitude matrices into variables
nav_lat <- ncvar_get(nc,"nav_lat")
nav_long <- ncvar_get(nc,"nav_lon")
#Extracts depth levels
depth <- ncvar_get(nc,"deptht")
#Extracts Temperature
votemper <- ncvar_get(nc,"votemper")
#Extracts Salinity
vosaline <- ncvar_get(nc,"vosaline")
#Extracts sea surface height
sossheig <- ncvar_get(nc,"sossheig")
#Extracts ice fraction
soicecov <- ncvar_get(nc,"soicecov")
#Close ncdf file to avoid memory loss
nc_close(nc)
但似乎有一种更快的方法来做到这一点。目前我正在尝试
#route of file we want to open
fn <- "grid_T_19800105.nc"
#opens netCDF file
nc <- nc_open(fn)
variables <- names(nc$var)
apply(variables,ncvar_get)
但这会返回错误
match.fun(FUN)中出错:缺少参数“FUN”,没有默认值
1条答案
按热度按时间2guxujil1#
一个可能的解决方案是使用for循环: