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
4fcd8a35
Commit
4fcd8a35
authored
5 years ago
by
leprob001
Browse files
Options
Downloads
Patches
Plain Diff
Added function to save data as .trj4 files and its test.
parent
ad44221e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
+tests/+trj4/save.m
+28
-0
28 additions, 0 deletions
+tests/+trj4/save.m
lib/+artoa/+save/trj4.m
+87
-0
87 additions, 0 deletions
lib/+artoa/+save/trj4.m
with
115 additions
and
0 deletions
+tests/+trj4/save.m
0 → 100644
+
28
−
0
View file @
4fcd8a35
function
[
success
]
=
save
()
%SAVE Test function for saving a TRJ4 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
);
header
=
"Created in 2019"
+
newline
+
"a multiline test header"
;
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
);
data
(:,
6
)
=
rfb
.
DATA
(
1
:
13
,
rfb
.
VARIABLE_LIST
.
pressure
);
data
(:,
7
)
=
rfb
.
DATA
(
1
:
13
,
rfb
.
VARIABLE_LIST
.
temperature
);
saveToFilename
=
fullfile
(
currentDirectory
,
'..'
,
'data'
,
'testOutput.trj4'
);
success
=
artoa
.
save
.
trj4
(
saveToFilename
,
header
,
data
);
end
This diff is collapsed.
Click to expand it.
lib/+artoa/+save/trj4.m
0 → 100644
+
87
−
0
View file @
4fcd8a35
function
[
success
]
=
trj4
(
pFilename
,
pHeader
,
pData
)
%TRJ4 Saves the given data to the filename in TRJ4 format.
%
% Parameters:
% pFilename (string) The destination filename.
% pHeader (string) The header that will be prepended to the file. Can
% be a multiline string/string array.
% pData (matrix) The data that should be written to the TRJ4 file.
% Each line contains one set of data. The matrix format needs to
% be the following:
% TIME LAT LON TEMP PRES VLAT VLON
%% 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 not a string!'
]);
parameterError
=
true
;
end
if
(
~
isstring
(
pHeader
))
warning
([
mfilename
': Given header is not a string!'
]);
parameterError
=
true
;
end
if
(
size
(
pData
,
2
)
~=
7
)
warning
([
mfilename
': Given data has '
site
(
pData
,
2
)
' columns, but 7 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
%% Prepare header and add it to the file string
preparedHeader
=
splitlines
(
pHeader
);
fileString
=
''
;
for
i
=
1
:
length
(
preparedHeader
)
fileString
=
fileString
+
headerLineIndicator
+
preparedHeader
{
i
}
+
newline
;
end
%% Generate file format
for
i
=
1
:
size
(
pData
,
1
)
line
=
{
...
num2str
(
pData
(
i
,
1
),
'%7.2f'
),
num2str
(
pData
(
i
,
2
),
'%8.3f'
),
num2str
(
pData
(
i
,
3
),
'%8.3f'
),
num2str
(
pData
(
i
,
4
),
'%7.1f'
),
num2str
(
pData
(
i
,
5
),
'%7.2f'
),
num2str
(
pData
(
i
,
6
),
'%8.3f'
),
num2str
(
pData
(
i
,
7
),
'%8.3f'
),
};
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