Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oceano2python
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
US191
Oceano2python
Commits
fd6f7801
Commit
fd6f7801
authored
6 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
tested
parent
4af66dbb
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
file_extractor.py
+14
-5
14 additions, 5 deletions
file_extractor.py
tests/test_roscop.py
+1
-1
1 addition, 1 deletion
tests/test_roscop.py
with
15 additions
and
6 deletions
file_extractor.py
+
14
−
5
View file @
fd6f7801
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
file_extractor.py
file_extractor.py
'''
'''
import
fileinput
import
fileinput
import
toml
class
FileExtractor
:
class
FileExtractor
:
...
@@ -16,27 +17,35 @@ class FileExtractor:
...
@@ -16,27 +17,35 @@ class FileExtractor:
# public:
# public:
self
.
file
=
file
self
.
file
=
file
# private:
# private:
self
.
__hash
=
{}
self
.
__headeer
=
{}
self
.
__data
=
{}
# constructor build objet by reading the file
# constructor build objet by reading the file
self
.
read
()
# overloading operators
# overloading operators
def
__str__
(
self
):
def
__str__
(
self
):
'''
overload string representation
'''
'''
overload string representation
'''
return
'
Class FileExtractor, file: %s, size = %d
'
%
(
self
.
file
,
len
(
self
))
return
'
Class FileExtractor, file: %s, size = %d
'
%
(
self
.
file
,
len
(
self
))
# read code roscop file
# read code roscop file
def
read
(
self
):
def
read
(
self
,
keys
,
dic
):
for
line
in
fileinput
.
input
(
for
line
in
fileinput
.
input
(
self
.
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
)):
self
.
file
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
)):
if
line
[
0
]
==
'
#
'
or
line
[
0
]
==
'
*
'
:
continue
# iterate over the lines of opened file "fileName"
# iterate over the lines of opened file "fileName"
# ------------------------------------------------
# ------------------------------------------------
print
(
line
)
p
=
line
.
split
()
for
k
in
keys
:
print
(
"
{}
"
.
format
(
p
[
dic
[
k
]]),
end
=
''
)
print
()
# for testing in standalone context
# for testing in standalone context
# ---------------------------------
# ---------------------------------
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
fe
=
FileExtractor
(
'
data/cnv/fr29001.cnv
'
)
fe
=
FileExtractor
(
'
data/cnv/fr29001.cnv
'
)
fe
.
read
()
cfg
=
toml
.
load
(
'
tests/test.toml
'
)
dic
=
cfg
[
'
split
'
][
'
ctd
'
]
fe
.
read
([
'
PRES
'
,
'
TEMP
'
,
'
PSAL
'
,
'
DOX2
'
],
dic
)
This diff is collapsed.
Click to expand it.
tests/test_roscop.py
+
1
−
1
View file @
fd6f7801
...
@@ -43,7 +43,7 @@ class testRoscop(unittest.TestCase):
...
@@ -43,7 +43,7 @@ class testRoscop(unittest.TestCase):
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
PSAL
'
)[
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
PSAL
'
)[
'
standard_name
'
],
'
sea_water_salinity
'
)
'
standard_name
'
],
'
sea_water_salinity
'
)
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
PSAL
'
)[
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
PSAL
'
)[
'
unit
s
'
],
'
1
'
)
'
convention
s
'
],
'
PSU
'
)
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
PSAL
'
)[
self
.
assertEqual
(
self
.
r
.
returnCode
(
'
PSAL
'
)[
'
comment
'
],
'
Ocean practical salinity (PSS-78)
'
)
'
comment
'
],
'
Ocean practical salinity (PSS-78)
'
)
...
...
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