Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CALIPSO - Combining mAchine Learning and optImization for Planetary remote Sensing missiOns
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
Roberto Orosei
CALIPSO - Combining mAchine Learning and optImization for Planetary remote Sensing missiOns
Commits
dd812ca8
Commit
dd812ca8
authored
5 months ago
by
Roberto Orosei
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
4c154231
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
MARSIS_dataset/processing_scripts/read_MARSIS_NCSIM.m
+140
-0
140 additions, 0 deletions
MARSIS_dataset/processing_scripts/read_MARSIS_NCSIM.m
with
140 additions
and
0 deletions
MARSIS_dataset/processing_scripts/read_MARSIS_NCSIM.m
0 → 100644
+
140
−
0
View file @
dd812ca8
function
MarsisIdr
=
read_MARSIS_NCSIM
(
NCSimFile
,
ParameterName
,
StartRecord
,
StopRecord
,
SkipRecords
)
if
contains
(
NCSimFile
,
'_SS1_TRK_CMP_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
elseif
contains
(
NCSimFile
,
'_SS1_TRK_RAW_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
elseif
contains
(
NCSimFile
,
'_SS2_TRK_CMP_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
elseif
contains
(
NCSimFile
,
'_SS2_TRK_RAW_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
elseif
contains
(
NCSimFile
,
'_SS3_TRK_CMP_M_NCSIM.DAT'
),
[
RecordBytes
,
Parameter
,
OffsetBytes
,
OffsetBits
,
Items
,
Precision
,
OutputPrecision
,
MachineFormat
,
ItemBytes
,
ItemBits
]
=
MARSIS_SS3_TRK_CMP_NCSIM
;
elseif
contains
(
NCSimFile
,
'_SS3_TRK_RAW_M_NCSIM.DAT'
),
[
RecordBytes
,
Parameter
,
OffsetBytes
,
OffsetBits
,
Items
,
Precision
,
OutputPrecision
,
MachineFormat
,
ItemBytes
,
ItemBits
]
=
MARSIS_SS3_TRK_RAW_NCSIM
;
elseif
contains
(
NCSimFile
,
'_SS4_TRK_CMP_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
elseif
contains
(
NCSimFile
,
'_SS4_TRK_RAW_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
elseif
contains
(
NCSimFile
,
'_SS5_TRK_CMP_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
elseif
contains
(
NCSimFile
,
'_SS5_TRK_RAW_M_NCSIM.DAT'
),
disp
(
'This type of file cannot be read yet'
),
return
else
error
(
'read_MARSIS_NCSIM:FileTypeUnknown'
,
'File %s does not follow standard naming conventions, file type could not be determined.'
,
NCSimFile
)
end
% The data product file is opened.
fid
=
fopen
(
NCSimFile
,
'r'
);
if
fid
<
0
error
(
'read_MARSIS_NCSIM:MissingInputFile'
,
...
'The required data product file %s could not be opened.'
,
...
NCSimFile
)
end
% The length in bytes of the data product file is retrieved, and divided by
% the length of a file record in bytes to obtain the number of records in
% the file.
fseek
(
fid
,
0
,
'eof'
);
FileBytes
=
ftell
(
fid
);
FileRecords
=
FileBytes
/
RecordBytes
;
if
round
(
FileRecords
)
~=
FileRecords
fclose
(
fid
);
error
(
'read_MARSIS_NCSIM:FractionalNumberOfRecords'
,
...
'The data product file %s contains %f records, a non integer number of records.'
,
...
NCSimFile
,
FileRecords
)
end
% If the only input argument is the name of a data product file, the
% function returns the number of records contained in that file.
if
nargin
==
1
MarsisIdr
=
FileRecords
;
fclose
(
fid
);
return
end
% The name of the parameter to be extracted from the data product file is
% compared to the list of parameters in the data product, to determine its
% position in the list.
ParameterIndex
=
strcmp
(
Parameter
,
ParameterName
);
ParameterIndex
=
find
(
ParameterIndex
==
1
);
if
isempty
(
ParameterIndex
)
fclose
(
fid
);
error
(
'read_MARSIS_NCSIM:ParameterNotFound'
,
...
'The parameter %s is not listed among those contained in a MARSIS IDR FRM data product.'
,
...
ParameterName
)
end
% If input values are not provided, default values are assigned to
% StartRecord, StopRecord and SkipRecords
if
nargin
<
3
StartRecord
=
1
;
end
if
nargin
<
4
StopRecord
=
FileRecords
;
end
if
nargin
<
5
SkipRecords
=
1
;
end
% StartRecord, StopRecord and SkipRecords are checked for consistency.
if
StartRecord
<
1
||
StartRecord
>
FileRecords
fclose
(
fid
);
error
(
'read_MARSIS_NCSIM:InvalidValueForStartRecord'
,
...
'The first record to be extracted is record %g, which is outside the valid interval [ 1, %g ].'
,
...
StartRecord
,
FileRecords
)
end
if
StopRecord
<
1
||
StopRecord
>
FileRecords
fclose
(
fid
);
error
(
'read_MARSIS_NCSIM:InvalidValueForStopRecord'
,
...
'The last record to be extracted is record %g, which is outside the valid interval [ 1, %g ].'
,
...
StopRecord
,
FileRecords
)
end
if
SkipRecords
<
1
||
SkipRecords
>
FileRecords
fclose
(
fid
);
error
(
'read_MARSIS_NCSIM:InvalidValueForSkipRecords'
,
...
'The number of records to be skipped is %g, which is outside the valid interval [ 1, %g ].'
,
...
SkipRecords
,
FileRecords
)
end
if
StopRecord
<
StartRecord
fclose
(
fid
);
error
(
'read_MARSIS_NCSIM:StopRecordBeforeStartRecord'
,
...
'The first record to be extracted is record %g and is greater than last record to be extracted, which is record %g.'
,
...
StartRecord
,
StopRecord
)
end
% the number of records to be extracted fromn the data product file is
% determined.
Records
=
length
(
StartRecord
:
SkipRecords
:
StopRecord
);
if
Records
==
0
fclose
(
fid
);
error
(
'read_MARSIS_NCSIM:NoRecordsExtracted'
,
...
'The combination of StartRecord = %g, StopRecord = %g, SkipRecords = %g does not allow the extraction of records from this data product file.'
,
...
StartRecord
,
StopRecord
,
SkipRecords
)
end
% The requested parameter is extracted from the data product file.
offset
=
(
StartRecord
-
1
)
*
RecordBytes
+
OffsetBytes
(
ParameterIndex
);
fseek
(
fid
,
offset
,
'bof'
);
pad
=
fread
(
fid
,
OffsetBits
(
ParameterIndex
),
'ubit1'
,
MachineFormat
{
ParameterIndex
}
);
size
=
[
Items
(
ParameterIndex
),
Records
];
precision
=
[
int2str
(
Items
(
ParameterIndex
)
),
'*'
,
Precision
{
ParameterIndex
},
'=>'
,
OutputPrecision
{
ParameterIndex
}
];
if
(
ItemBytes
(
ParameterIndex
)
>=
1
)
&&
(
ItemBits
(
ParameterIndex
)
==
0
)
skip
=
(
SkipRecords
-
1
)
*
RecordBytes
+
RecordBytes
-
Items
(
ParameterIndex
)
*
ItemBytes
(
ParameterIndex
);
elseif
(
ItemBytes
(
ParameterIndex
)
==
0
)
&&
(
ItemBits
(
ParameterIndex
)
>=
1
)
skip
=
(
SkipRecords
-
1
)
*
RecordBytes
*
8
+
RecordBytes
*
8
-
Items
(
ParameterIndex
)
*
ItemBits
(
ParameterIndex
);
else
error
(
'read_MARSIS_NCSIM:WrongParameterFormat'
,
...
'The parameter %s is described as being %g bytes long and %g bits long.'
,
...
Parameter
{
ParameterIndex
},
ItemBytes
(
ParameterIndex
),
ItemBits
(
ParameterIndex
)
)
end
machineformat
=
MachineFormat
{
ParameterIndex
};
MarsisIdr
=
fread
(
fid
,
size
,
precision
,
skip
,
machineformat
);
fclose
(
fid
);
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