Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
artoa4argo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
argoTools
artoa4argo
Commits
1e483351
Commit
1e483351
authored
5 years ago
by
leprob001
Browse files
Options
Downloads
Patches
Plain Diff
Added function for saving the data as rfc file and its test.
parent
865ff516
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
+tests/+rfc/save.m
+32
-0
32 additions, 0 deletions
+tests/+rfc/save.m
lib/+artoa/+save/rfc.m
+141
-0
141 additions, 0 deletions
lib/+artoa/+save/rfc.m
with
173 additions
and
0 deletions
+tests/+rfc/save.m
0 → 100644
+
32
−
0
View file @
1e483351
function
[
success
]
=
save
()
%SAVE Test function for saving a RFC 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
);
% IFLAG MESSAGE_NUMBER MESSAGE_DATE TEMP PRES LAT LON u v w
lineCount
=
size
(
rfb
.
DATA
,
1
);
data
=
[];
data
(:,
1
)
=
repmat
(
999
,
lineCount
,
1
);
data
(:,
2
)
=
rfb
.
DATA
(
1
:
lineCount
,
rfb
.
VARIABLE_LIST
.
line_number
);
data
(:,
3
)
=
artoa
.
convert
.
dmy2rd
(
rfb
.
DATA
(:,
4
),
rfb
.
DATA
(:,
3
),
rfb
.
DATA
(:,
2
));
% + artoa.convert.hms2rd(rfb.DATA(:, 5), rfb.DATA(:, 6), rfb.DATA(:, 7));
data
(:,
4
)
=
rfb
.
DATA
(
1
:
lineCount
,
rfb
.
VARIABLE_LIST
.
temperature
);
data
(:,
5
)
=
rfb
.
DATA
(
1
:
lineCount
,
rfb
.
VARIABLE_LIST
.
pressure
);
data
(:,
6
)
=
repmat
(
999
,
lineCount
,
1
);
data
(:,
7
)
=
repmat
(
999
,
lineCount
,
1
);
data
(:,
8
)
=
repmat
(
999
,
lineCount
,
1
);
data
(:,
9
)
=
NaN
(
1
,
lineCount
);
data
(:,
10
)
=
repmat
(
999
,
lineCount
,
1
);
saveToFilename
=
fullfile
(
currentDirectory
,
'..'
,
'data'
,
'testOutput.rfc'
);
success
=
artoa
.
save
.
rfc
(
saveToFilename
,
rfb
.
FLOAT
,
data
);
end
This diff is collapsed.
Click to expand it.
lib/+artoa/+save/rfc.m
0 → 100644
+
141
−
0
View file @
1e483351
function
[
success
]
=
rfc
(
pFilename
,
pFloatDetails
,
pData
)
%RFC Saves the given data to the filename in RFC format.
%
% Parameters:
% pFilename (string) The destination filename.
% pFloatDetails (struct) The FLOAT section that is stored in an RFB
% file.
% pData (matrix) The data that should be written to the RFC file.
% Each line contains one set of data. The matrix format needs to
% be the following:
% IFLAG MESSAGE_NUMBER MESSAGE_DATE TEMP PRES LAT LON u v w
%% Initialize return variables
success
=
false
;
%% Initialize variables required for processing
headerLineIndicator
=
"** "
;
%% Parameter check
parameterError
=
false
;
if
(
~
isstring
(
pFilename
)
&&
~
ischar
(
pFilename
))
warning
([
mfilename
': Given filename is neither a string nor a char!'
]);
parameterError
=
true
;
end
if
(
~
isstruct
(
pFloatDetails
))
warning
([
mfilename
': Given float details is not a struct!'
]);
parameterError
=
true
;
end
expectedDataColumns
=
10
;
if
(
size
(
pData
,
2
)
~=
expectedDataColumns
)
warning
([
mfilename
': Given data has '
site
(
pData
,
2
)
' columns, but '
...
num2str
(
expectedDataColumns
)
' expected!'
]);
parameterError
=
true
;
end
if
(
parameterError
)
return
;
else
clear
parameterError
;
end
%% Replace all NaN with default values
defaultValues
=
repmat
(
-
999
,
10
);
defaultValues
(
4
)
=
-
9.99
;
% temperature default value
% start at index 4 because the first three do not have default values
for
i
=
4
:
size
(
pData
,
2
)
nanIndex
=
find
(
isnan
(
pData
(:,
i
)));
if
~
isempty
(
nanIndex
)
pData
(
nanIndex
,
i
)
=
repmat
(
defaultValues
(
i
),
1
,
size
(
pData
,
1
));
end
clear
nanIndex
;
end
%% Prepare header and add it to the file string
% FLOAT NAME
floatname
=
num2str
(
pFloatDetails
.
floatname
);
% FLOAT CYCLE
cycle
=
num2str
(
pFloatDetails
.
cycle
(
1
));
% LAUNCH PARAMETER
launchPositionLat
=
num2str
(
pFloatDetails
.
cycle
(
2
),
'%3.2f'
);
launchPositionLon
=
num2str
(
pFloatDetails
.
cycle
(
3
),
'%3.2f'
);
launchTime
=
[
pFloatDetails
.
launchtime
,
0
];
launchTimeRafosDays
=
num2str
(
...
artoa
.
convert
.
dmy2rd
(
launchTime
(
3
),
launchTime
(
2
),
launchTime
(
1
))
...
);
launchTime
=
num2str
(
launchTime
);
% RECOVER PARAMETER
recoverTime
=
[
pFloatDetails
.
recovertime
,
0
];
recoverTimeRafosDays
=
num2str
(
...
artoa
.
convert
.
dmy2rd
(
recoverTime
(
3
),
recoverTime
(
2
),
recoverTime
(
1
))
...
);
recoverTime
=
num2str
(
recoverTime
);
% FIRST SURFACE POSITION
surfacePositionLat
=
num2str
(
pFloatDetails
.
cycle
(
9
),
'%3.2f'
);
surfacePositionLon
=
num2str
(
pFloatDetails
.
cycle
(
10
),
'%3.2f'
);
% CYCLE PARAMETER
floatCycleStartTime
=
[
pFloatDetails
.
cycle
(
4
:
8
),
0
];
% seconds always zero
floatCycleStartTimeRafosDays
=
num2str
(
...
artoa
.
convert
.
dmy2rd
(
floatCycleStartTime
(
3
),
floatCycleStartTime
(
2
),
floatCycleStartTime
(
1
))
...
+
artoa
.
convert
.
hms2rd
(
floatCycleStartTime
(
4
),
floatCycleStartTime
(
5
),
0
)
...
);
floatCycleStartTime
=
num2str
(
floatCycleStartTime
);
floatCycleEndTime
=
[
pFloatDetails
.
cycle
(
11
:
15
),
0
];
% seconds always zero
floatCycleEndTimeRafosDays
=
num2str
(
...
artoa
.
convert
.
dmy2rd
(
floatCycleEndTime
(
3
),
floatCycleEndTime
(
2
),
floatCycleEndTime
(
1
))
...
+
artoa
.
convert
.
hms2rd
(
floatCycleEndTime
(
4
),
floatCycleEndTime
(
5
),
0
)
...
);
floatCycleEndTime
=
num2str
(
floatCycleEndTime
);
header
=
{
...
[
'** Float: '
floatname
],
...
[
'** Variables: InterpFlag LineNum RafosDay Temp Pres Lat Lon U V W'
],
...
[
'** Units : # # # degC dbar deg deg cm/s cm/s mm/s'
],
...
[
'** Dummies : NA NA NA -9.99 -999 999 999 999 999 999'
],
...
[
'** Cycle : '
cycle
],
...
[
'** Launch position (Cycle Start position): '
...
launchPositionLat
' '
launchPositionLon
],
...
[
'** Surface position (Cycle End position) : '
...
surfacePositionLat
' '
surfacePositionLat
],
...
[
'** Cycle Start time : '
floatCycleStartTime
' (RAFOS day '
floatCycleStartTimeRafosDays
')'
],
...
[
'** Launch time : '
launchTime
' (RAFOS day '
launchTimeRafosDays
')'
],
...
[
'** Cycle End time : '
floatCycleEndTime
' (RAFOS day '
floatCycleEndTimeRafosDays
')'
],
...
[
'** First surface Position time : '
recoverTime
' (RAFOS day '
recoverTimeRafosDays
')'
]
...
};
fileString
=
[
strjoin
(
header
,
newline
)
newline
];
%% Generate file format
for
i
=
1
:
size
(
pData
,
1
)
line
=
{
...
num2str
(
pData
(
i
,
1
),
'%2d'
)
...
num2str
(
pData
(
i
,
2
),
'%3d'
)
...
num2str
(
pData
(
i
,
3
),
'%8.2f'
)
...
num2str
(
pData
(
i
,
4
),
'%6.3f'
)
...
num2str
(
pData
(
i
,
5
),
'%6.1f'
)
...
num2str
(
pData
(
i
,
6
),
'%9.3f'
)
...
num2str
(
pData
(
i
,
7
),
'%8.3f'
)
...
num2str
(
pData
(
i
,
8
),
'%9.2f'
)
...
num2str
(
pData
(
i
,
9
),
'%7.2f'
)
...
num2str
(
pData
(
i
,
10
),
'%7.2f'
)
};
fileString
=
[
fileString
strjoin
(
line
)
newline
];
end
%% Save to file
fid
=
fopen
(
pFilename
,
'w'
);
fprintf
(
fid
,
fileString
);
fclose
(
fid
);
%% Update return variable
success
=
true
;
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment