Filter löschen
Filter löschen

How to have a string change based on user input

5 Ansichten (letzte 30 Tage)
Nathan Jalal
Nathan Jalal am 7 Jul. 2020
Kommentiert: Les Beckham am 9 Jul. 2020
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

Akzeptierte Antwort

Les Beckham
Les Beckham am 8 Jul. 2020
I've not tried accessing this data source or running your code, but I'm pretty sure that you need to change the following lines of code to access years other than 2020:
dirStr = sprintf('/gnss/data/daily/2020/brdc/') ;
fileStr = sprintf('BRDC00IGS_R_2020%03d0000_01D_MN.rnx.gz', doy(i));
You need to extract the year from your input startUtc and replace '2020' with a %d, and after the format string add the year variable. For example:
dirStr = sprintf('/gnss/data/daily/%d/brdc/', year) ;
Handling time ranges that cross years could get slightly more complicated.
  2 Kommentare
Nathan Jalal
Nathan Jalal am 8 Jul. 2020
How can I make it so that 'year' variable is equal to the first four digits from the startUTC input?
Les Beckham
Les Beckham am 9 Jul. 2020
The following will extract the year from the startUtc vector (assuming that, as shown above, it is generated by calling fix(clock)), or at least in the same format when it is passed in as an argument to your function.
year = startUtc(1);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB Report Generator finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by