[ad_1]
I have a NetCDF dataset with two climate scenarios (rcp & hist), both of them containing 30 files. Each file is either with the variable "pr", "tas", "tasmax", or "tasmin". To read in the current file's variable with ncvar_get I wrote a huge if else block within a for loop, that in the end applies a function that I think is not of importance here:
for(i in 1:length(hist.files.cl))
hist.data <- nc_open(hist.files.cl[i])
rcp.data <- nc_open(rcp.files.cl[i])
if(grepl("pr", hist.data$filename))
hist.var <- ncvar_get(hist.data, "pr")
rcp.var <- ncvar_get(rcp.data, "pr")
else if (grepl("tas", hist.data$filename))
hist.var <- ncvar_get(hist.data, "tas")
rcp.var <- ncvar_get(rcp.data, "tas")
else if (grepl("tasmax", hist.data$filename))
hist.var <- ncvar_get(hist.data, "tasmax")
rcp.var <- ncvar_get(rcp.data, "tasmax")
else
hist.var <- ncvar_get(hist.data, "tasmin")
rcp.var <- ncvar_get(rcp.data, "tasmin")
then do something with hist.var and rcp.var...
Now, R gives me an Error, that I cannot explain:
[1] "vobjtovarid4: error #F: I could not find the requsted var (or dimvar) in the file!"
[1] "var (or dimvar) name: tas"
[1] "file name: /data/historical/tasmax_ICHEC-EC-EARTH_DMI-HIRHAM5_r3i1p1.nc"
Error in vobjtovarid4(nc, varid, verbose = verbose, allowdimvar = TRUE) :
Variable not found
Yes, I understand that R doesn't find "tas", but that is just the reason why that else if("tas") statement is followed by another else if statement. It is as if R would not consider the following else if statement. Someone who sees the problem?
Thanks a lot in advance!
[ad_2]
لینک منبع