I am trying to get specific variables out of a NETcdf file using ncdf4 and the ncvar_get() function. When I open the file and print() it I can see the available variables but when I try get them out I get
"vobjtovarid4: error #F: I could not find the requsted var (or dimvar) in the file!"
[1] "var (or dimvar) name: precipitation"
[1] "file name: /Users/megmccann/Documents/Prec data/Prec data/cru_ts3.24.1901.2015.pre.dat.nc"
Error in vobjtovarid4(nc, varid, verbose = verbose, allowdimvar = TRUE) : Variable not found
Here is my script:
prec.ex.nc <- nc_open("/Users/megmccann/Documents/Prec data/Prec data/cru_ts3.24.1901.2015.pre.dat.nc")
print(prec.ex.nc)
File /Users/megmccann/Documents/Prec data/Prec data/cru_ts3.24.1901.2015.pre.dat.nc (NC_FORMAT_CLASSIC):
1 variables (excluding dimension variables):
double pre[lon,lat,time]
long_name: precipitation
units: mm/month
correlation_decay_distance: 450
_FillValue: 9.96920996838687e+36
missing_value: 9.96920996838687e+36
3 dimensions:
lon Size:720
long_name: longitude
units: degrees_east
lat Size:360
long_name: latitude
units: degrees_north
time Size:1380 *** is unlimited ***
long_name: time
units: days since 1900-1-1
calendar: gregorian
9 global attributes:
Conventions: CF-1.4
title: CRU TS3.24 Precipitation
institution: Data held at British Atmospheric Data Centre, RAL, UK.
source: Run ID = 1610031104
Data generated by BADC from: pre.1609291528.dtb history: Wed 19 Oct 2016 10:53:41 BST : User ianharris : Program makegridsauto.for called by update.for references: Information on the data is available at http://badc.nerc.ac.uk/data/cru/ comment: Access to these data is available to any registered CEDA user. contact: BADC acknowledgement: This update was supported by NERC NCAS and by NERC SMURPHS (NE/N006348/1)
precipitation <- ncvar_get(prec.ex.nc, "precipitation")
longitude <- ncvar_get(prec.ex.nc, "longitude")
latitude <- ncvar_get(prec.ex.nc, "latitude")
t <- ncvar_get(prec.ex.nc, "time")
Where I get the error code for all variables except time? I used the exact same code for a different NETcdf file for Temperature_anomalies and it worked fine?