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
9900b584
Commit
9900b584
authored
6 years ago
by
jacques Grelet
Browse files
Options
Downloads
Patches
Plain Diff
update script syntax for python3
parent
0f871a74
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ctd.py
+22
-20
22 additions, 20 deletions
ctd.py
with
22 additions
and
20 deletions
ctd.py
+
22
−
20
View file @
9900b584
...
...
@@ -8,7 +8,7 @@ Python script for extracting data from SBE-processing files and write out
in various format used by datagui, ODV, Netcdf.
usage:
$ python ctd.py [options] <files>
$ python
3
ctd.py [options] <files>
options are:
...
...
@@ -35,7 +35,7 @@ options are:
--type=<instrument_type>
example:
$ python ctd.py --cycle_mesure=PIRATA-FR29 --institut=IRD --plateforme=
"
THALASSA
"
--sn=09P01263 --type=SBE911+ --pi=BOURLES --date_debut=01/03/2019 --date_fin=04/04/2019 data/asc/fr29???.hdr --echo --local --ascii
$ python
3
ctd.py --cycle_mesure=PIRATA-FR29 --institut=IRD --plateforme=
"
THALASSA
"
--sn=09P01263 --type=SBE911+ --pi=BOURLES --date_debut=01/03/2019 --date_fin=04/04/2019 data/asc/fr29???.hdr --echo --local --ascii
"""
import
sys
,
re
,
getopt
,
string
,
fileinput
...
...
@@ -110,14 +110,14 @@ re_longitude = re.compile(r"NMEA\s+Longitude\s*[:=]\s*(\d+)\s+(\d+.\d+)\s+(\w)")
# script with special attribute __doc__ and quit
# ---------------------------------------------------------------
def
usage
():
print
__doc__
print
(
__doc__
)
sys
.
exit
()
# ------------------------------------------------
# display version and quit
# ------------------------------------------------
def
version
():
print
"
%s: %s
"
%
(
sys
.
argv
[
0
],
VERSION
)
print
(
"
%s: %s
"
%
(
sys
.
argv
[
0
],
VERSION
)
)
sys
.
exit
()
#------------------------------------------------------------------------------
...
...
@@ -190,8 +190,8 @@ try:
# if bad option, display an error message and usage
# -------------------------------------------------
except
getopt
.
GetoptError
,
err
:
print
str
(
err
)
except
getopt
.
GetoptError
as
err
:
print
(
str
(
err
)
)
usage
()
# iterate over options list
...
...
@@ -237,9 +237,9 @@ for option, value in options:
# for debug only, display arg list
# --------------------------------
if
debug
==
1
:
print
"
Args: %s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\n
"
%
\
print
(
"
Args: %s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\t
%s
\n
"
%
\
(
cycle_mesure
,
plateforme
,
date_debut
,
date_fin
,
institut
,
code_oopc
,
pi
)
,
code_oopc
,
pi
)
)
# open ascii files
# ----------------
...
...
@@ -269,16 +269,16 @@ if xml:
if
echo
:
# display selected output format
# ------------------------------
print
"
Output:
"
,
if
(
ascii
):
print
"
ASCII
"
,
if
(
xml
)
:
print
"
XML
"
,
if
(
odv
)
:
print
"
ODV
"
,
print
(
"
Output:
"
)
if
(
ascii
):
print
(
"
ASCII
"
)
if
(
xml
)
:
print
(
"
XML
"
)
if
(
odv
)
:
print
(
"
ODV
"
)
# display header
# --------------
print
"
\n
//%s %s %s %s %s %s
"
%
\
(
cycle_mesure
,
plateforme
,
institut
,
type
,
sn
,
pi
)
print
"
File St Date Heure Latitude Longitude Profondeur
"
print
(
"
\n
//%s %s %s %s %s %s
"
%
\
(
cycle_mesure
,
plateforme
,
institut
,
type
,
sn
,
pi
)
)
print
(
"
File St Date Heure Latitude Longitude Profondeur
"
,
end
=
''
)
# iterate over file list getting with getopt.gnu_getopt
# ----------------------------------------------------
...
...
@@ -287,7 +287,7 @@ for fileName in args:
# display processed filename
# suppress '\n' character written at the end with a comma
# -------------------------------------------------------
if
echo
:
print
"
\n
%s
"
%
(
fileName
),
if
echo
:
print
(
"
\n
%s
"
%
(
fileName
),
end
=
''
)
# extract station number from file name using compiled regexp
# -----------------------------------------------------------
...
...
@@ -297,7 +297,7 @@ for fileName in args:
# open current file
# TODOS: add some tests on file existence
# ---------------------------------------
file
=
open
(
fileName
,
"
r
"
)
file
=
open
(
fileName
,
"
r
"
,
encoding
=
"
ISO-8859-1
"
)
# read each line of current file
# ------------------------------
...
...
@@ -365,8 +365,8 @@ for fileName in args:
# display header information in console
# -------------------------------------
if
echo
:
print
"
%03d %s %s %s %5.0f
"
%
\
(
station
,
dateTime
,
latitude_str
,
longitude_str
,
float
(
Pres
)),
if
echo
:
print
(
"
%03d %s %s %s %5.0f
"
%
\
(
station
,
dateTime
,
latitude_str
,
longitude_str
,
float
(
Pres
)),
end
=
''
)
# write station header to ascii files
# -----------------------------------
...
...
@@ -391,7 +391,7 @@ for fileName in args:
# we don't use __builtin__ readline method of file object that haven't
# method to get read line number
# --------------------------------------------------------------------
file
=
fileinput
.
input
(
fileName
)
file
=
fileinput
.
input
(
fileName
,
openhook
=
fileinput
.
hook_encoded
(
"
ISO-8859-1
"
)
)
# iterate over the lines of opened file "fileName"
# ------------------------------------------------
...
...
@@ -431,6 +431,8 @@ for fileName in args:
# end of loop over files
# ----------------------
if
echo
:
print
(
"
\n
"
)
# close files
# -----------
...
...
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