RNetCDF icon indicating copy to clipboard operation
RNetCDF copied to clipboard

An error occurred while using the utcal.nc function to converte the time amounts to UTC date.

Open PanfengZhang opened this issue 9 months ago • 0 comments

An error occurred while using the utcal.nc function to converte the time amounts to UTC date.

The example of .nc data is from NCEP (https://psl.noaa.gov/thredds/fileServer/Datasets/ncep.reanalysis/Monthlies/surface/slp.mon.ltm.1991-2020.nc)

library(RNetCDF)

diri = "C:/Rmet/data/slp.mon.ltm.1991-2020.nc"
fin <- open.nc(diri)
time <- var.get.nc(fin, variable = "time")
time_units <- att.get.nc(fin, variable = "time", attribute = "units")

utcal.nc(time_units, time, type = "c")
##  [1] "0000-12-30 UTC" "0001-01-30 UTC" "0001-02-27 UTC" "0001-03-30 UTC"
##  [5] "0001-04-29 UTC" "0001-05-30 UTC" "0001-06-29 UTC" "0001-07-30 UTC"
##  [9] "0001-08-30 UTC" "0001-09-29 UTC" "0001-10-30 UTC" "0001-11-29 UTC"

utcal.nc(time_units, time, type = "s")
##  [1] "01-01-01 00:00:00" "01-02-01 00:00:00" "01-03-01 00:00:00"
##  [4] "01-04-01 00:00:00" "01-05-01 00:00:00" "01-06-01 00:00:00"
##  [7] "01-07-01 00:00:00" "01-08-01 00:00:00" "01-09-01 00:00:00"
## [10] "01-10-01 00:00:00" "01-11-01 00:00:00" "01-12-01 00:00:00"

When the type parameter is set to n or s, the returned dates are inconsistent. According to the metadata information of the data, it is known that it is correct when setting s.

PanfengZhang avatar May 04 '24 12:05 PanfengZhang