From 1c0216bd60aead90b78eeecd5ea251182e61b46a Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Mon, 20 Dec 2021 15:51:14 +0100
Subject: [PATCH] Polish

---
 Common/write_eddy.f90                         |  3 +-
 .../Documentation_texfol/documentation.tex    | 37 ++++++++++++-------
 Convert_Matlab/inst_eddies_v6.py              |  2 +-
 Inst_eddies/Analysis/plot_eddy_contours.py    |  3 +-
 .../Documentation_texfol/documentation.tex    |  2 +-
 5 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/Common/write_eddy.f90 b/Common/write_eddy.f90
index 22fa2ff7..aa4263a7 100644
--- a/Common/write_eddy.f90
+++ b/Common/write_eddy.f90
@@ -71,8 +71,7 @@ contains
     call dbf_write_attribute_03(hshp%outermost, ishape, hshp%out_ssh, &
          e%out_cont%ssh)
     call dbf_write_attribute_03(hshp%outermost, ishape, hshp%out_date, date)
-    call dbf_write_attribute_03(hshp%outermost, ishape, hshp%out_eddy_index, &
-         i)
+    call dbf_write_attribute_03(hshp%outermost, ishape, hshp%out_eddy_index, i)
     call dbf_write_attribute_03(hshp%outermost, ishape, hshp%out_radius4, &
          e%radius4)
 
diff --git a/Convert_Matlab/Documentation_texfol/documentation.tex b/Convert_Matlab/Documentation_texfol/documentation.tex
index 4cd6b639..c18f3f90 100644
--- a/Convert_Matlab/Documentation_texfol/documentation.tex
+++ b/Convert_Matlab/Documentation_texfol/documentation.tex
@@ -1,4 +1,4 @@
-\documentclass[a4paper,french]{article}
+\documentclass[a4paper,english]{article}
 
 \usepackage[utf8]{inputenc}
 
@@ -35,10 +35,12 @@
 \section{Identification of instantaneous eddies}
 \label{sec:identification}
 
-$e_\mathrm{max}(k)$ is stored in Matlab variables Nanti and Ncyclo.
+For the definition of eddy index $e$, $e_\mathrm{max}$, $E$ and the
+node index, see the documentation of the program \verb+inst_eddies+.
 
-In the Matlab program, the node index $n'$ is different than in the
-Fortran program:
+In the Matlab program, $e_\mathrm{max}$ for each date is stored in
+Matlab variables Nanti and Ncyclo. The node index $n'$ is different
+than in the Fortran program:
 \begin{equation*}
   n' = k' E + e
 \end{equation*}
@@ -49,22 +51,29 @@ dates.
 \begin{equation*}
   k' = \left \lfloor \frac{n' - 1}{E} \right \rfloor
 \end{equation*}
-The suite of processed dates (in the Matlab date format) is stored in
-the array \verb+date_num+. From $n'$ we can compute $k'$ and $e$, and
-then the date $d$ from \verb+date_num[k']+, without any search. But
-the reverse conversion needs a search: from $d$ and $e$, we need to
-search \verb+date_num+ to get $k'$, then $n'$.
-
-Let $d_\mathrm{init}$ be the value of $d$ for the first date of the
+The suite of processed dates is stored in the array \verb+date_num+
+(in the Matlab date format). From $n'$ we can compute $k'$ and $e$,
+and then the date from \verb+date_num[k']+, without any search. But
+the reverse conversion needs a search: from the date and $e$, we need
+to search \verb+date_num+ to get $k'$, then $n'$.
+
+For a given date, let $d$ be the corresponding number of days since
+1950-1-1. Let $d_\mathrm{init}$ be the value of $d$ for the first date of the
 dataset. To convert from $n'$ to the node index $n$ of the Fortran
-convention, we note that:
+convention, we compute:
 \begin{equation*}
-  k := d - d_\mathrm{init} = \mathtt{date\_num[k']} - \mathtt{date\_num[0]}
+  d = \mathtt{to\_days\_1950}(\mathtt{date\_num[k']})
 \end{equation*}
 and we can choose:
 \begin{equation*}
-  n = n' + (k - k') E
+  n = n' + (d - k') E
 \end{equation*}
+Equivalently, we can write:
+\begin{align*}
+  d - k' & = d - d_\mathrm{init} + d_\mathrm{init} - k' \\
+  & = \mathtt{date\_num[k']} - \mathtt{date\_num[0]} + d_\mathrm{init} - k'
+\end{align*}
+which avoids a call to \verb+to_days_1950+.
 
 \section{Instantaneous eddies}
 
diff --git a/Convert_Matlab/inst_eddies_v6.py b/Convert_Matlab/inst_eddies_v6.py
index ee573103..a85588cf 100755
--- a/Convert_Matlab/inst_eddies_v6.py
+++ b/Convert_Matlab/inst_eddies_v6.py
@@ -136,7 +136,7 @@ d = my_date - datetime.date(1950, 1, 1)
 d = d.days
 
 if len(sys.argv) == 3:
-    final_date = parser.parse(sys.argv[2], yearfirst=True, dayfirst = False)\
+    final_date = parser.parse(sys.argv[2], yearfirst = True, dayfirst = False)\
                        .date()
 else:
     final_date = my_date
diff --git a/Inst_eddies/Analysis/plot_eddy_contours.py b/Inst_eddies/Analysis/plot_eddy_contours.py
index 5962b7bd..7be6ee57 100755
--- a/Inst_eddies/Analysis/plot_eddy_contours.py
+++ b/Inst_eddies/Analysis/plot_eddy_contours.py
@@ -147,8 +147,7 @@ if __name__ == "__main__":
     import netCDF4
 
     parser = argparse.ArgumentParser()
-    parser.add_argument("-d", "--date", type = int,
-                        help = "date, as days since 1950-1-1")
+    parser.add_argument("-d", "--date", type = int, help = "date index")
     parser.add_argument("-g", "--grid", help = "plot grid",
                         action = "store_true")
     parser.add_argument("-w", "--window", help = "choose a limited plot window",
diff --git a/Inst_eddies/Documentation_texfol/documentation.tex b/Inst_eddies/Documentation_texfol/documentation.tex
index fd0adb27..7c38a40b 100644
--- a/Inst_eddies/Documentation_texfol/documentation.tex
+++ b/Inst_eddies/Documentation_texfol/documentation.tex
@@ -229,7 +229,7 @@ read shapefiles: dbfinfo, shpinfo, dbfdump and shpdump (analogous to
 ncdump for NetCDF files). If you have a Linux Debian-type distribution
 (Ubuntu, LinuxMint etc.), you can install these tools with:
 \begin{verbatim}
-sudo apt-get install shapelib
+sudo apt install shapelib
 \end{verbatim}
 The tools are available on Ciclad. You can also access the shapefiles
 programmatically with a number of computer languages. From Python, one
-- 
GitLab