In case it might be helpful, here is what I did to retrieve the information I was looking for (Time and Variable for each Band).
I had to install GDAL to use library(gdalUtils).
It's based of course on the answer by @Spacedman.
info<-gdalinfo('file.grib')
Filter and retrieve the information of interest (as seen here).
grib1<-as.data.frame(info)
grib1<-as.data.frame(grib1[grep(pattern='Band|GRIB_COMMENT|GRIB_REF_TIME', x=info),])
colnames(grib1)<-c('raw_')
Clean a little bit (with the help of this post, among others).
grib1 <- grib1 %>%
mutate(content = case_when(
startsWith(as.character(raw_),'Band', trim=TRUE) ~ gsub(".*Band (.+) Block.*", "\\1",raw_),
startsWith(as.character(raw_),'GRIB_C', trim=TRUE) ~ sub(".*=", "", raw_),
startsWith(as.character(raw_),'GRIB_R', trim=TRUE) ~ gsub(".*= (.+) sec.*", "\\1",raw_)
)
)
grib1 <- grib1 %>%
mutate(column = case_when(
startsWith(as.character(raw_),'Band', trim=TRUE) ~ 'Band',
startsWith(as.character(raw_),'GRIB_C', trim=TRUE) ~ 'Variable',
startsWith(as.character(raw_),'GRIB_R', trim=TRUE) ~ 'Time'
)
)
grib1<-grib1[,-1]
Variables to columns and time readable (as seen here).
grib1$id<-sort(rep(1:72,3))
grib1<-dcast(grib1, formula = id ~ column, value.var='content')
grib1<-grib1 %>% mutate(
Time = as.POSIXct(as.numeric(as.character(Time)),origin="1970-01-01")
)
grib1<-grib1[,-1]
gdalinfo <fname.grb>
. Or download in netCDF (these are definitely well labeled)