r - error when specifying latitute dimension when reading Netcdf files -


i want read 2 netcdf files (climate data 2 years) , combine data of 1 single grid (lon [15] , lat[15]) array (named prec_year), script below.

i got error:

"error in r_nc_get_vara_double: netcdf: index exceeds dimension bound var: precip  ndims: 3   start: 0,4294967284,59count: 366,1,1error in get.var.ncdf   (ex.nc, "precip", start = c(lon[1], lat[15], 1),  :  

c function r_nc_get_vara_double returned error"

but when dont specify lat[], example "start = c(lon[1], 1,1)", works fine. please (1) why got error, , (2) how fix it?

many thanks! --------------------

setwd ("d://historic climate data/aphrodyte/prec_025/join 2 years") prec_origin <- c(1:2) filenames <- list.files(pattern = null, all.files = false)  for(i in filenames){ filepath <- file.path("d://historic climate data/aphrodyte/prec_025/join 2 years/",paste    (i,sep=""))     ex.nc = open.ncdf (filepath, readunlim=false)     lon = get.var.ncdf( ex.nc, "longitude")          # coordinate variable   lat = get.var.ncdf( ex.nc, "latitude")          # coordinate variable   day =  get.var.ncdf( ex.nc, "time")            # time variable   #change lon[x] , lat[y] select different files/locations comparison   prec_year = get.var.ncdf(ex.nc, "precip", start = c(lon[1],lat[15],1), count = c(1,1,-1))     prec_origin <- c(prec_origin, prec_year)  #combine data 1 array   close.ncdf (ex.nc)  }  prec_origin <- prec_origin[-(1:2)] # delete first 2 rows- -------------- [1] "file d://historic climate data/aphrodyte/prec_025/join 2     years//aphro_ma_025deg_v1003r1.1952.nc has 3 dimensions:" [1] "time   size: 366" [1] "longitude   size: 360" [1] "latitude   size: 280" [1] "------------------------" [1] "file d://historic climate data/aphrodyte/prec_025/join 2 years//aphro_ma_025deg_v1003r1.1952.nc has 2 variables:" [1] "float precip[longitude,latitude,time]  longname:daily precipitation analysis interpolated onto 0.25deg grids [mm/day] missval:-99.9000015258789" [1] "float rstn[longitude,latitude,time]  longname:ratio of 0.05deg-grids station [%]     missval:-99.9000015258789" 

in "start" function need define index number, , not actual value wish start.

i believe looking for:

prec_year = get.var.ncdf(ex.nc, "precip", start = c(1,15,1), count = c(1,1,-1)) 

lon[1] doesn't produce error because gives coordinate can index (for longitude; 1:360). however, output not want (if understood you're question).

as information, if want select region based on pre-selected coordinates, follows (maybe not shortest code):

lon_select=which(x<=10 & x>=20) lat_select=which(y<=40 & y>=50)  precip=get.var.ncdf(ex.nc,"precip",start=c(lon_select[1],lat_select[1],1), count=c(length(lon_select),length(lat_select),-1)) 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -