I am working on a function that pulls information from nasa's website using ftp. The directory string that I am pulling from currently can only pull information from 2020, how do I change it so that the user can enter any day from 2000 forward to pull information from? Both the dirStr and fileStr have 2020 hard coded into it, how can I get that to change depending on what the user gives?
% Function that pulls all available ephemeris data from the 4 major GNSS constellations
% If a duplicate file is downloaded, then the new download file will replace the
% previous file.
function fetchRinex(startUtc, stopUtc) % start and stop UTC is in the following format [YYYY MM DD 12 0 0]
% If no start date is given then the computer's current date and time is
% taken
if nargin==0
startUtc = fix(clock);
end
% If no stop date is given then the start date will also be the stop date
if nargin<2
stopUtc = startUtc;
end
gpsStartTime = utc2gps(startUtc);
gpsStopTime = utc2gps(stopUtc);
gpsStartTimeSec = gpst2sec(gpsStartTime);
gpsStopTimeSec = gpst2sec(gpsStopTime);
% Build up a vector of time stamps to pull data
timeVectGpsSec = (gpsStartTimeSec:86400:gpsStopTimeSec)';
days2get = length(timeVectGpsSec); % days to get
% Convert that time vector back to UTC to extract the day number into the
% year.
timeVectGps = sec2gpst(timeVectGpsSec);
[utcTime, leapSecs, doy] = gps2utc(timeVectGps);
% Website from where we are pulling ephemeris data
ftpobj = ftp('cddis.nasa.gov');
dirStr = sprintf('/gnss/data/daily/2020/brdc/') ;
cd(ftpobj, dirStr);
for i=1:days2get
fileStr = sprintf('BRDC00IGS_R_2020%03d0000_01D_MN.rnx.gz', doy(i));
d=dir(ftpobj,fileStr);
if isempty(d) % if the file doesn't exist then a popup error message will be displayed
f = errordlg(['File: ' fileStr ' does not exist',' Please try again ']); % this message will be displayed in the popup dialog
continue % if the file does not exist then the function stops
end
mget(ftpobj, fileStr, '.'); % if the file exists it will be retrieved
end
% unzip file to subdirectory titled "RINEX", if the subdirectory does not
% exist then it will be created
gunzip('*.gz', 'RINEX');
delete('*.gz'); % delete the zipped file leaving only the unzipped version
Best Answer