Skip to content
Snippets Groups Projects
Commit aadf5c70 authored by leprob001's avatar leprob001
Browse files

Refactoring for better usage. Added save RIC file and its test.

parent 10316f59
No related branches found
No related tags found
No related merge requests found
function [success] = save()
%SAVE Test function for saving a RIC file.
% Uses a test rfb data file from the data folder. Uses only dummy fields
% for saving, because the actual algorithm for creating the data is not yet
% implemented.
[currentDirectory, ~, ~] = fileparts(mfilename('fullpath'));
dataFileName = fullfile(currentDirectory, '..', 'data', '0272.rfb');
rfb = artoa.load.rfb(dataFileName);
data = [];
data(:, 1) = rfb.DATA(1:13, rfb.VARIABLE_LIST.time_of_arrival(1));
data(:, 2) = str2num(cell2mat(rfb.SAT_DATA(:, 1)));
data(:, 3) = str2num(cell2mat(rfb.SAT_DATA(:, 2)));
data(:, 4) = rfb.DATA(1:13, rfb.VARIABLE_LIST.temperature);
data(:, 5) = rfb.DATA(1:13, rfb.VARIABLE_LIST.pressure);
saveToFilename = fullfile(currentDirectory, '..', 'data', 'testOutput.ric');
success = artoa.save.ric(saveToFilename, num2str(rfb.FLOAT.floatname), num2str(rfb.FLOAT.cycle(1)), data);
end
function [ddmmyyyy] = rafosJulianDay(pRafosJulianDay)
%RAFOSJULIANDAY Converts the given rafos julian day to DDMMYYYY.
%
% Parameters:
% pRafosJulianDay (double) The input time format.
offset = 2451545;
convertedTime = artoa.vendor.greg_0h(pRafosJulianDay + offset);
ddmmyyyy = [convertedTime(:, 3) convertedTime(:, 2) convertedTime(:, 1)];
end
......@@ -31,6 +31,6 @@ else
clear parameter_error;
end
rfbfile = artoa.data.load.tomlini(pFilename);
rfbfile = artoa.load.tomlini(pFilename);
end
File moved
function [ success ] = ric(pFilename, pFloatname, pCurrentCycle, pData)
%RIC Saves the given data to the filename in RIC format.
%
% Parameters:
% pFilename (string) The destination filename.
% pFloatname (string) The name of the float.
% pCurrentCycle (string) The current cycle.
% pData (matrix) The data that should be written to the RIC file.
% Each line contains one set of data. The matrix format needs to
% be the following:
% TIME LAT LON TEMP PRES
% The TIME needs to be in julian rafos day format.
%% Initialize return variables
success = false;
%% Initialize variables required for processing
%% Parameter check
parameterError = false;
if (~ischar(pFilename))
warning([mfilename ': Given filename is not a string!']);
parameterError = true;
end
if (~ischar(pFloatname))
warning([mfilename ': Given float name is not a string!']);
parameterError = true;
end
if (~ischar(pCurrentCycle))
warning([mfilename ': Given current cycle is not a string!']);
parameterError = true;
end
if (size(pData, 2) ~= 5)
warning([mfilename ': Given data has ' site(pData, 2) ' columns, but 5 expected!']);
parameterError = true;
end
if (parameterError)
return;
else
clear parameterError;
end
%% Replace all NaN with default values
defaultValue = -999;
for i = 1:size(pData, 2)
nanIndex = find(isnan(pData(:, i)));
if ~isempty(nanIndex)
pData(nanIndex, i) = repmat(defaultValue, 1, size(pData, 1));
end
clear nanIndex;
end
%% Generate file format
offsetHour = 0.0000000001;
offsetRafosJulianDay = 2440000;
fileString = '';
for i = 1:size(pData, 1)
ddmmyyyy = artoa.convert.rafosJulianDay(pData(i, 1));
ddmmyyyy(3) = mod(ddmmyyyy(3), 100);
hour = 24 * (pData(i, 1) - floor(pData(i, 1))) + offsetHour;
minute = round(hour - floor(hour));
second = round(minute - floor(minute));
hour = floor(hour);
minute = round(minute);
fileString = [ ...
fileString ...
pFloatname ' - cycle ' pCurrentCycle ...
' ' ...
num2str(ddmmyyyy(3), '%2.2i') ...
num2str(ddmmyyyy(2), '%2.2i') ...
num2str(ddmmyyyy(1), '%2.2i') ...
num2str(hour, '%2.2i') ...
num2str(minute, '%2.2i') ...
num2str(second, '%2.2i') ...
num2str(pData(i, 2), '%7.3f') ...
num2str(pData(i, 3), '%8.3f') ...
' 0' ...
' -999.000' ...
' -999.000' ...
' ' ...
num2str(pData(i, 4), '%7.2f') ...
' ' ...
num2str(pData(i, 5), '%7.2f') ...
' ' ...
num2str((pData(i, 1) + offsetRafosJulianDay), '%8.0f') ...
'.\n' ...
];
end
%% Save to file
fid = fopen(pFilename, 'w');
fprintf(fid, fileString);
fclose(fid);
%% Update return variable
success = true;
end
\ No newline at end of file
function [gtime]=greg_0h(jourjul)
% GREGORIAN Converts Julian day numbers to corresponding Gregorian calendar dates
% Formally, Julian days start and end at noon.
% In this convention, Julian day 2440000 begins at
% 00 hours, May 23, 1968.
%
% ==========================================
% greg_0h.m = contraire de jul_0h.m
% ==========================================
%
% Usage: [gtime]=greg_0h(jourjul)
%
% jourjul... input decimal Julian day number
%
% gtime is a six component Gregorian time vector
% i.e. gtime=[yyyy mo da hr mi sec]
% gtime=[1989 12 6 7 23 23.356]
%
% yr........ year (e.g., 1979)
% mo........ month (1-12)
% d........ corresponding Gregorian day (1-31)
% h........ decimal hours
%
% Revised T.Terre
%
% Ajout TT pour pb de conversion 07 00 00 == retourne en 06 59 60 ?
% Ca permet d'avoir la date juste a la dizaine de us pres.
% 10/05/2001
%
fac = 10^9;
jourjul= round(fac*jourjul+0.5)/fac;
% Fin ajout TT
secs=rem(jourjul,1)*24*3600;
%
% Ajout TT pour pb de conversion 07 00 00 == retourne en 06 59 60 ?
% Ca permet d'avoir la date juste a la dizaine de us pres.
% 10/05/2001
%
secs = round(fac*secs + 0.5)/fac;
% Fin ajout TT
j = floor(jourjul) - 1721119;
in = 4*j -1;
y = floor(in/146097);
j = in - 146097*y;
in = floor(j/4);
in = 4*in +3;
j = floor(in/1461);
d = floor(((in - 1461*j) +4)/4);
in = 5*d -3;
m = floor(in/153);
d = floor(((in - 153*m) +5)/5);
y = y*100 +j;
mo=m-9;
yr=y+1;
i=(m<10);
mo(i)=m(i)+3;
yr(i)=y(i);
hour=floor(secs/3600);
min=floor(rem(secs,3600)/60);
sec=rem(secs,60);
gtime=[yr(:) mo(:) d(:) hour(:) min(:) sec(:)];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment