0

I have tried to download a climate model output from esgf website (https://esgf-node.llnl.gov/search/cmip6/ using the following R code.

###########################################################################
    rm(list=ls())
    library("epwshiftr")
    
    #this indexes all the information about the models
    test = init_cmip6_index(
        activity = "ScenarioMIP",
        variable = c("pr"),
        frequency = "day",
        experiment = c("ssp245"),
        source = c("GFDL-ESM4"),
        variant = "r1i1p1f1",
        replica = FALSE,
        latest = TRUE,
        resolution = c("100 km"),
        limit = 10000L,
        data_node = NULL,
        years = NULL,
        save = FALSE
    )
    #to print the unique model
    unique(test$source_id)
    test$file_url
    
    fileurl <- test$file_url
    directory <- file.path(setwd("E:/New_Future/GFDL-ESM4/SSP245/"),fsep = .Platform$file.sep)
    
    lapply(fileurl, function(url) download.file(url, file.path(directory, basename(url))))
###########################################################################

All the required files are downloaded using the Code. But, the problem is I couldn't access the downloaded nc files in CDO (it says open failed and no such file or directory) or in r (Error in ncatt_get(ncfile):Error, first passed argument must be an object of class ncdf4). Is there a problem with the code or am I missing something? Here is simple code for downloading one file:

directory <- file.path(setwd("E:/New_Future/GFDL-ESM4/SSP245/"),fsep = .Platform$file.sep)
download.file("http://esgdata.gfdl.noaa.gov/thredds/fileServer/gfdl_dataroot4/ScenarioMIP/NOAA-GFDL/GFDL-ESM4/ssp245/r1i1p1f1/
              day/pr/gr1/v20180701/pr_day_GFDL-ESM4_ssp245_r1i1p1f1_gr1_20150101-20341231.nc",
              file.path(directory, basename("pr_day_GFDL-ESM4_ssp245_r1i1p1f1_gr1_20150101-20341231.nc")))
Yon Balcha
  • 29
  • 6
  • CDO does not work on Windows, but you seem to be using Windows. If you can use Linux or the subsystem if you want to use CDO – Robert Wilson Oct 21 '22 at 10:01
  • I am using UBUNTU on windows and it works. I am doing different operations using CDO on files that I downloaded from the esgf website but, the issue is I want to facilitate the downloading process using R. – Yon Balcha Oct 21 '22 at 10:49
  • Please modify your code so that it is a minimal reproducible example. You only need 2-3 lines of code at most to reproduce the problem. Just provide us with 1 url that is not downloading instead of code (rm etc.) that is irrelevant – Robert Wilson Oct 21 '22 at 10:52
  • @ Robert Wilson Just in case the issue isn't downloading the file but, after the file is downloaded it doesn't open. Based on your suggestion I added a reproducible code with one url at the end of the main question above. – Yon Balcha Oct 21 '22 at 11:24
  • You say that CDO is saying file does not exist. Are you actually providing the correct path to CDO/R? I can't imagine CDO would give that error if the path exists. For me, downloading and viewing that url worked fine on Ubuntu – Robert Wilson Oct 21 '22 at 12:03
  • @Robert Wilson. When i type "ls" on the CDO i can see the file is there but, when I check it with cdo -showatts pr_day_GFDL-ESM4_ssp245_r1i1p1f1_gr1_20150101-20341231.nc it fails to give the infos. – Yon Balcha Oct 21 '22 at 12:16
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/248966/discussion-between-yon-balcha-and-robert-wilson). – Yon Balcha Oct 21 '22 at 12:23

0 Answers0