Script to download NASA-MERRA reanalysis in netCdf using wget

Purpose

The NASA-MERRA reanalysis website can generate a text file with a list of URL that you fetch with wget. My last request was too large and exceeded the server capacity so I wrote this Matlab script that writes the text file with URL automatically and then fetches them with wget. Simply choose the date range. This downloads 8-times daily data in netCdf files.

Code

date1=datenum(1979,1,1);
date2=datenum(2012,12,31);
 
 
%sample='http://goldsmr3.sci.gsfc.nasa.gov/daac-bin/OTF/HTTP_services.cgi?FILENAME=%2Fdata%2Fs4pa%2FMERRA%2FMAI3CPASM.5.2.0%2F1979%2F01%2FMERRA100.prod.assim.inst3_3d_asm_Cp.19790101.hdf&FORMAT=TmV0Q0RGLw&BBOX=-90%2C-180%2C90%2C180&TIME=1979-01-01T00%3A00%3A00%2F1979-01-01T21%3A00%3A00&LABEL=MERRA100.prod.assim.inst3_3d_asm_Cp.19790101.SUB.nc&FLAGS=&SHORTNAME=MAI3CPASM&SERVICE=SUBSET_LATS4D&LAYERS=LAYER_1000%2C975%2C950%2C925%2C900%2C875%2C850%2C825%2C800%2C775%2C750%2C725%2C700%2C650%2C600%2C550%2C500%2C450%2C400%2C350%2C300%2C250%2C200%2C150%2C100%2C70%2C50%2C40%2C30%2C20%2C10%2C7%2C5%2C4%2C3%2C2%2C1%2C0_7%2C0_5%2C0_4%2C0_3%2C0_1&VERSION=1.02&VARIABLES=h%2Ct%2Cu%2Cv%2Cepv%2Comega'
 
f = fopen('listformatlab', 'w');
for i=date1:date2
yyyy=num2str(year(i),'%0.4i');
mm=num2str(month(i),'%0.2i');
dd=num2str(day(i),'%0.2i');
%sample;
ins='300';
if datenum(i)<=datenum(2000,01,31)
ins='200';
end
if year(i)<=1992
ins='100';
end
 
address=['http://goldsmr3.sci.gsfc.nasa.gov/daac-bin/OTF/HTTP_services.cgi?FILENAME=%2Fdata%2Fs4pa%2FMERRA%2FMAI3CPASM.5.2.0%2F',yyyy,'%2F',mm,'%2FMERRA',ins,'.prod.assim.inst3_3d_asm_Cp.',yyyy,mm,dd,'.hdf&FORMAT=TmV0Q0RGLw&BBOX=-90%2C-180%2C90%2C180&TIME=','1979','-','01','-','01','T00%3A00%3A00%2F','1979','-','01','-','01','T21%3A00%3A00&LABEL=MERRA',ins,'.prod.assim.inst3_3d_asm_Cp.',yyyy,mm,dd,'.SUB.nc&FLAGS=&SHORTNAME=MAI3CPASM&SERVICE=SUBSET_LATS4D&LAYERS=LAYER_1000%2C975%2C950%2C925%2C900%2C875%2C850%2C825%2C800%2C775%2C750%2C725%2C700%2C650%2C600%2C550%2C500%2C450%2C400%2C350%2C300%2C250%2C200%2C150%2C100%2C70%2C50%2C40%2C30%2C20%2C10%2C7%2C5%2C4%2C3%2C2%2C1%2C0_7%2C0_5%2C0_4%2C0_3%2C0_1&VERSION=1.02&VARIABLES=h%2Ct%2Cu%2Cv%2Cepv%2Comega'];
 
fprintf(f,'%s\n',address);
end
 
pause(2);
fclose(f);
pause(2);
 
system(['wget -r -P data6xdaily/ --content-disposition -i listformatlab'])

One thought on “Script to download NASA-MERRA reanalysis in netCdf using wget

  1. Qi

    Thank you very much! The script is easy to use and very helpful!

    I found 6 variables (h, t u, v, epv, omega) in the .nc.
    I would like to ask: how to choose other variables like mixing ratio, relative humidity and precip? and could I select the levels of interest?

    Any hints would be much appreciated!
    Best,
    Qi

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *