How to write the MATLAB Script for download data?

  1. Access the Product webpage in the PODAAC

    image.png

  2. Click Data Access

    image.png

  3. DIRECT ACCESS > access HTTPS Link

    image.png

  4. You have to “Sign In” and Choose ‘sample day’ for get the longitude, latitude information.

    image.png

  5. Click the Opendap and set the option like below

    1. Download Encoding : NetCDF-4
    2. add the Variables : “lat” and “lon

    image.png

  6. Click Get Data

  7. Make new folder for MATLAB Workspace.

    Move the nc file in the new folder

    (You can change the name of nc file)

    image.png

  8. Open the new MATLAB script and read the longitude, latitude information of the NC file.

    %% read 'lon', 'lat' data from NC file
    clc; clear;
    
    fnm = 'sample_lonlat_20020601_MUR_41.nc4';
    ncdisp(fnm)
    
    lon = ncread(fnm, 'lon'); 
    lat = ncread(fnm, 'lat'); 
    
  9. Find the index of region where you want to download

    Spatial_area = [24, 35, 121, 132];
    
    idlat(1) = findnearpoint(lat, Spatial_area(1));
    idlat(2) = findnearpoint(lat, Spatial_area(2));
    idlon(1) = findnearpoint(lon, Spatial_area(3));
    idlon(2) = findnearpoint(lon, Spatial_area(4));
    
    function id = findnearpoint(base, target)
    % find nearest point of "target" from "base"
    [~, id] = min(abs(base-target));
    end
    
  10. Prepare the period information with proper format

    period = [2014, 1, 1; 2014, 1, 5];
    period2 = datetime(period);
    period3 = period2(1):days(1):period2(2);
    
  11. Back to the website - Add the Variables (time and variables you want) - Copy raw Data Link

    image.png

  12. If the url is like this,

    https://opendap.earthdata.nasa.gov/providers/POCLOUD/collections/GHRSST Level 4 MUR Global Foundation Sea Surface Temperature Analysis (v4.1)/granules/20020601090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.dap.nc4?dap4.ce=/time[0:1:0];/lat[0:1:17998];/lon[0:1:35999];/analysed_sst[0:1:0][0:1:17998][0:1:35999]

    Then, you can split this link into like this

    1. https://opendap.earthdata.nasa.gov/providers/POCLOUD/collections/GHRSST Level 4 MUR Global Foundation Sea Surface Temperature Analysis (v4.1)/granules/
    2. 20020601
    3. 090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.dap.nc4?dap4.ce=
    4. /time[0:1:0];/lat[0:1:17998];/lon[0:1:35999];/analysed_sst[0:1:0][0:1:17998][0:1:35999]

    Then, you should change the “2” and “4” in the MATLAB.

  13. The example is like this.

    %% load data with URL
    
    % If the downloaded file has the SAME NAME, INCREASE the value of lag_time
    lag_time = 3; % seconds between download each files
    
    for loop = 1:length(period3)
        period4 = period3(loop); period5 = datevec(period4); period5 = period5(1:3);
        period6 = sprintf("%d%02.0f%02.0f", period5);
    
        url1 = "<https://opendap.earthdata.nasa.gov/providers/POCLOUD/collections/>" + ...
            "GHRSST%20Level%204%20MUR%20Global%20Foundation%20Sea%20Surface%20Temperature%20Analysis%20(v4.1)" + ...
            "/granules/";
    
        url2 = period6;
    
        url3 = "090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.dap.nc4?dap4.ce=";
    
        url4 = sprintf("/time[0:1:0];/lat[%d:1:%d];/lon[%d:1:%d];/analysed_sst[0:1:0][%d:1:%d][%d:1:%d]", ...
            idlat(1)-1, idlat(2)-1, idlon(1)-1, idlon(2)-1, ...
            idlat(1)-1, idlat(2)-1, idlon(1)-1, idlon(2)-1);
    
        url5 = strcat(url1, url2, url3, url4);
        web(url5)
    
        pause(lag_time);
    end
    

    Finally, you can automatically download the data!

    image.png