Commit de3ce1d6 authored by Momme Butenschoen's avatar Momme Butenschoen

Cleaned up whitespaces and tabs.

parent f7746bd7
#!/usr/bin/python
#
# Copyright 2014 Plymouth Marine Laboratory
#
#
# This file is part of the SSB-ERSEM library.
#
# SSB-ERSEM is free software: you can redistribute it and/or modify it
# under the terms of the Lesser GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
#
# SSB-ERSEM is free software: you can redistribute it and/or modify it
# under the terms of the Lesser GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SSB-ERSEM is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser
#
# SSB-ERSEM is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser
# NU General Public License for more details.
# You should have received a copy of the Lesser GNU General Public License
# You should have received a copy of the Lesser GNU General Public License
# along with SSB-ERSEM. If not, see <http://www.gnu.org/licenses/>.
#
#
# Address:
# Plymouth Marine Laboratory
# Prospect Place, The Hoe
# Plymouth, PL1 3DH, UK
#
#
# Email:
# ssm@pml.ac.uk
#
......@@ -43,12 +43,12 @@
# The adaptation is based on the version 2.0 as downloaded from
# http://acmg.seas.harvard.edu/geos/wiki_docs/protex/protex.tar.gz
#
# Python class to produce a \LaTeX compatible document
# from a DAO Fortran source code with standard Pro\TeX
# Python class to produce a \LaTeX compatible document
# from a DAO Fortran source code with standard Pro\TeX
# prologues.
# By default, output is directed to stdout.
#
# \noindent
#
# \noindent
# {\bf Command Line Switches:} \vspace{0.2cm}
#
# \begin{center}
......@@ -89,10 +89,10 @@
# For a more detailed description of ProTeX functionality,
# DAO Prologue and other conventions, consult:
#
# Sawyer, W., and A. da Silva, 1997: ProTeX: A Sample
# Sawyer, W., and A. da Silva, 1997: ProTeX: A Sample
# Fortran 90 Source Code Documentation System.
# DAO Office Note 97-11
#
#
# !AUTHOR:
# ! Momme Butensch\xf6n
#
......@@ -108,7 +108,7 @@
# 05Aug1998 Sawyer Fixed LPChang-bug-support-for-files-with-underscores
# 10Oct1998 da Silva Introduced -f option for removing source file info
# from subsection, etc. Added help (WS).
# 06Dec1999 C. Redder Added LaTeX command "\label{sec:prologues}" just
# 06Dec1999 C. Redder Added LaTeX command "\label{sec:prologues}" just
# after the beginning of the proglogue section.
# 13Dec1999 C. Redder Increased flexbility in command-line
# interface. The options can appear in any
......@@ -128,7 +128,7 @@
# 22Oct2014 M. Butenschoen Conversion to python with consistent changes
# to use part for top-level and section for 2nd
# level. Introduced -d option.
# 22Oct2014 M. Butenschoen -h option produces human-readable
# 22Oct2014 M. Butenschoen -h option produces human-readable
# documentation with desciptions only omitting
# any iformation on the code.
# Help string is now obtained by calling without# argument
......@@ -248,9 +248,9 @@ class PyProTex:
self.opt["s"]=1
self.opt["l"]=0
# Determine the type of code, set corresponding search strings
# ------------------------------------------------------------
# DEFAULT: FORTRAN
# Determine the type of code, set corresponding search strings
# ------------------------------------------------------------
# DEFAULT: FORTRAN
if self.opt["A"]: # ADA
self.comment_string = '--'
self.boi_string = '--BOI'
......@@ -263,7 +263,7 @@ class PyProTex:
self.eoc_string = '--EOC'
self.boe_string = '--BOE'
self.eoe_string = '--EOE'
elif self.opt["C"]: # C
elif self.opt["C"]: # C
self.comment_string = '//'
self.boi_string = '//BOI'
self.eoi_string = '//EOI'
......@@ -281,13 +281,13 @@ class PyProTex:
self.eoi_string = '#EOI'
self.bop_string = '#BOP'
self.eop_string = '#EOP'
self.bopi_string = '#BOPI'
self.eopi_string = '#EOPI'
self.bopi_string = '#BOPI'
self.eopi_string = '#EOPI'
self.boc_string = '#BOC'
self.eoc_string = '#EOC'
self.boe_string = '#BOE'
self.eoe_string = '#EOE'
else:
else:
self.comment_string = '!'
self.boi_string = '!BOI'
self.eoi_string = '!EOI'
......@@ -300,10 +300,10 @@ class PyProTex:
self.boe_string = '!BOE'
self.eoe_string = '!EOE'
# Set date
# --------
# Set date
# --------
self.Date = strftime("%a %b %d %T %Z",localtime())
# Initial LaTeX stuff
# -------------------
self.Str=""
......@@ -322,32 +322,32 @@ class PyProTex:
if not files: self.print_help()
for f in files:
# Set file name parameters
# ------------------------
# Set file name parameters
# ------------------------
self.InputFile = f
self.all_path_components = self.InputFile.split("/")
self.FileBaseName = self.all_path_components[-1].replace("_","\_")
# Open current file
# -----------------
# Open current file
# -----------------
try:
fid=open(self.InputFile,'r')
except:
raise RunTimeError,"Unable to open {}".format(self.InputFile)
# Print page header
# -----------------
# Print page header
# -----------------
if self.opt["g"]:
self.shname = " "
self.lnname = " "
self.units = " "
self.dims = " "
self.locs = " "
self.shname = " "
self.lnname = " "
self.units = " "
self.dims = " "
self.locs = " "
else:
self.Str+="\n\markboth{{Left}}{{Source File: {}, Date: {}}}\n\n".format(self.FileBaseName,self.Date)
self.Str+="\n\markboth{{Left}}{{Source File: {}, Date: {}}}\n\n".format(self.FileBaseName,self.Date)
# Process input file line by line:
# ---------------------------------------------------------
# Process input file line by line:
# ---------------------------------------------------------
Lines=fid.readlines()
for line in Lines:
......@@ -378,30 +378,30 @@ class PyProTex:
self.Str+="{} ".format(f)
return
# Start the intro at new line and switch intro on
# -------------------------------------------
# Start the intro at new line and switch intro on
# -------------------------------------------
if Fld[0] == self.boi_string:
self.Str+="\n"
self.intro = 1
return
# If within intro and title is given print title and switch title page on
# -------------------------------------------
# If within intro and title is given print title and switch title page on
# -------------------------------------------
if len(Fld)>1 and Fld[1] == '!TITLE:':
if self.intro:
title = "{}".format(" ".join(*Fld[2]))
self.tpage = 1
return
# If within intro and author is given print title and switch title page on
# -------------------------------------------
# If within intro and author is given print title and switch title page on
# -------------------------------------------
if len(Fld)>1 and Fld[1] == '!AUTHOR:':
if self.intro:
author = Fld[2]
self.tpage = 1
return
# If within intro and affiliation is given print title and set title page
# If within intro and affiliation is given print title and set title page
# -------------------------------------------
if len(Fld)>1 and Fld[1] == '!AFFILIATION:':
if self.intro:
......@@ -409,16 +409,16 @@ class PyProTex:
self.tpage = 1
return
# If within intro and date is given print date and switch title page on
# -------------------------------------------
# If within intro and date is given print date and switch title page on
# -------------------------------------------
if len(Fld)>1 and Fld[1] == '!DATE:':
if self.intro:
self.date="{}".format(" ".join(*Fld[2]))
self.tpage = 1
return
# If within intro and introduction is given print introduction header and switch title page on
# -------------------------------------------
# If within intro and introduction is given print introduction header and switch title page on
# -------------------------------------------
if len(Fld)>1 and Fld[1] == '!INTRODUCTION:':
if self.intro:
self.self,do_beg()
......@@ -430,8 +430,8 @@ class PyProTex:
self.Str+="\part{{ {} }}\n".format(" ".join(*Fld[2:]))
return
# close introduction and switch off intro
# -------------------
# close introduction and switch off intro
# -------------------
if Fld[0] == self.eoi_string:
self.Str+=" \n"
......@@ -440,10 +440,10 @@ class PyProTex:
self.intro = 0
return
# Beginning of prologue : print header and
# switch on prologue
# switch off verb, source and inspec
# ---------------------
# Beginning of prologue : print header and
# switch on prologue
# switch off verb, source and inspec
# ---------------------
if Fld[0] == self.bop_string:
self.skip=0
if self.source: self.do_eoc()
......@@ -452,7 +452,7 @@ class PyProTex:
self.do_beg()
if self.first or self.opt["n"]:
if not (self.opt["b"] or self.opt["g"]):
self.Str+="\part{Routine/Function Prologues} \label{app:ProLogues}\n"
self.Str+="\part{Routine/Function Prologues} \label{app:ProLogues}\n"
else:
self.Str+=" \n"
self.Str+="\mbox{}\hrulefill\\ \n"
......@@ -465,8 +465,8 @@ class PyProTex:
self.set_missing() # initialise keyword check
return
# Beginning of internal prologue (switchable)
# ------------------------------
# Beginning of internal prologue (switchable)
# ------------------------------
if Fld[0] == self.bopi_string:
if self.opt["i"]:
self.prologue = 0 #No internal prologue with i option
......@@ -476,7 +476,7 @@ class PyProTex:
self.Str+="%/////////////////////////////////////////////////////////////\n"
self.do_beg()
if self.first or self.opt["n"]:
if not (self.opt["b"] or self.opt["g"]):
if not (self.opt["b"] or self.opt["g"]):
self.Str+="\part{Routine/Function Prologues} \label{{app:ProLogues}}\n"
else:
self.Str+=" \n"
......@@ -490,8 +490,8 @@ class PyProTex:
self.set_missing() # initialise keyword check
return
# A new subroutine/function
# -------------------------
# A new subroutine/function
# -------------------------
if len(Fld)>1 and Fld[1] == '!ROUTINE:':
if self.prologue:
self.name_is = " ".join(Fld[2:])
......@@ -505,8 +505,8 @@ class PyProTex:
self.first = 0
return
# A new Module
# ------------
# A new Module
# ------------
if len(Fld)>1 and Fld[1] == '!MODULE:':
if self.prologue:
self.name_is = " ".join(Fld[2:])
......@@ -517,21 +517,21 @@ class PyProTex:
else:
if self.opt["f"]:
self.Str+="\n\section{{Module: {} }}\n\n".format(name)
else:
else:
self.Str+="\n\section{{Module: {} (Source: {})}}\n\n".format(name,self.FileBaseName)
self.have_name = 1
self.have_intf = 1 # fake, does not need one.
self.first = 0
return
# A new include file
# ------------------
# A new include file
# ------------------
if len(Fld)>1 and Fld[1] == '!INCLUDE:':
if self.prologue:
self.name_is = " ".join(Fld[2:])
name=self.name_is.replace("_","\_")# Replace "_" with "\_"
if self.opt["n"] and not self.first: self.Str+="\n\\newpage\n"
if self.opt["f"]:
if self.opt["f"]:
self.Str+="\n\subsection{{Include File {} }}\n\n".format(name)
else:
self.Str+="\n\subsection{{Include File {} (Source: {})}}\n\n".format(name,self.FileBaseName)
......@@ -540,8 +540,8 @@ class PyProTex:
self.first = 0
return
# A new INTERNAL subroutine/function
# ----------------------------------
# A new INTERNAL subroutine/function
# ----------------------------------
if len(Fld)>1 and Fld[1] == '!IROUTINE:':
if self.prologue:
self.name_is = " ".join(Fld[2:])
......@@ -555,19 +555,19 @@ class PyProTex:
self.have_name = 1
return
# A new CONTAINED subroutine/function
# ----------------------------------
# A new CONTAINED subroutine/function
# ----------------------------------
if len(Fld)>1 and Fld[1] == '!CROUTINE:': # Contained routine
if self.prologue:
self.name_is = " ".join(Fld[2:])
name=self.name_is.replace("_","\_")# Replace "_" with "\_"
words = name.split()
words = name.split()
self.Str+="\n\subsection{{{}}}\n\n".format(name)
self.have_name = 1
return
# A new CLASS
# ------------
# A new CLASS
# ------------
if len(Fld)>1 and Fld[1] == '!CLASS:':
if self.prologue:
self.name_is = " ".join(Fld[2:])
......@@ -582,8 +582,8 @@ class PyProTex:
self.first = 0
return
# A new Method
# -------------------------
# A new Method
# -------------------------
if len(Fld)>1 and Fld[1] == '!METHOD:':
if self.prologue:
self.name_is = " ".join(Fld[2:])
......@@ -598,8 +598,8 @@ class PyProTex:
self.first = 0
return
# A new function
# -------------------------
# A new function
# -------------------------
if len(Fld)>1 and Fld[1] == '!FUNCTION:':
if self.prologue:
self.name_is = " ".join(Fld[2:])
......@@ -613,8 +613,8 @@ class PyProTex:
self.first = 0
return
# Description: what follows will be regular LaTeX (no verbatim)
# -------------------------------------------------------------
# Description: what follows will be regular LaTeX (no verbatim)
# -------------------------------------------------------------
if "!DESCRIPTION:" in Rec:
if self.prologue:
self.skip=0
......@@ -634,8 +634,8 @@ class PyProTex:
self.have_desc = 1
return
# Handle optional keywords (these will appear as verbatim)
# --------------------------------------------------------
# Handle optional keywords (these will appear as verbatim)
# --------------------------------------------------------
if self.prologue:
for key in self.keys:
if key in Rec:
......@@ -652,19 +652,19 @@ class PyProTex:
if self.opt["g"]:
if ("/IMPORT STATE/" in key) or ("/EXPORT STATE/" in key) or ("/INTERNAL STATE/" in key):
if self.inspec:
self.beg_item()
self.beg_item()
self.Str+="\n \\bigskip \n {{\\bf {} }} \n\n".format(k[1:ln])
self.hed_item()
self.inspec = 1
self.initem = 0
return
self.hed_item()
self.inspec = 1
self.initem = 0
return
else:
self.Str+="\n{{\\bf {}}}".format(k[1:ln]) # italics
self.Str+="\n{{\\bf {}}}".format(k[1:ln]) # italics
else:
if ("/USES/" in key) or ("/INPUT/" in key) or ("/OUTPUT/" in key) or ("/PARAMETERS/" in key) or ("/VALUE/" in key) or ("/ARGUMENTS/" in key):
self.Str+="\n{{\em {}}}".format(k[1:ln]) # italics
self.Str+="\n{{\em {}}}".format(k[1:ln]) # italics
else:
self.Str+="\n{{\\sf {}}}".format(k[1:ln]) # san serif
self.Str+="\n{{\\sf {}}}".format(k[1:ln]) # san serif
#switch verbatim back on:
self.Str+="\n\\begin{verbatim}"
self.verb = 1
......@@ -674,14 +674,14 @@ class PyProTex:
if key == "!REVISION HISTORY:": self.have_hist = 1
return
# End of prologue
# ---------------
# End of prologue
# ---------------
if Fld[0] == self.eop_string:
if self.verb: #close and switch off verbatim
self.Str+="\n\end{verbatim}\n"
self.verb = 0
if self.opt["g"] and self.inspec:
self.beg_item()
self.beg_item()
self.inspec = 0
self.prologue = 0 #switch off prologue
if self.opt["l"]:
......@@ -691,14 +691,14 @@ class PyProTex:
if not self.opt["s"]:
# End of Internal Prologue
# ------------------------
# End of Internal Prologue
# ------------------------
if Fld[0] == self.eopi_string:
if self.verb: #close and switch off verbatim
self.Str+="\n\end{verbatim}\n"
self.verb = 0
if self.opt["g"] and self.inspec:
self.beg_item()
self.beg_item()
self.inspec = 0
self.prologue = 0
if self.opt["l"]:
......@@ -707,8 +707,8 @@ class PyProTex:
return
#
# Beginning of source code section
# --------------------------------
# Beginning of source code section
# --------------------------------
if Fld[0] == self.boc_string:
self.Str+=" \n"
self.Str+="%/////////////////////////////////////////////////////////////\n"
......@@ -719,16 +719,16 @@ class PyProTex:
self.verb = 1
return
# End of source code
# ------------------
# End of source code
# ------------------
if Fld[0] == self.eoc_string:
self.do_eoc() #if source is still active close it and close verbatim
self.prologue = 0
return
# Beginning of example prologue
# (separated in latex source but not in output)
# Beginning of example prologue
# (separated in latex source but not in output)
# -----------------------------
if Fld[0] == self.boe_string:
if self.source: self.do_eoc() #if source is still active close it and close verbatim
......@@ -740,8 +740,8 @@ class PyProTex:
self.source = 0
return
# End of example prologue
# -----------------------
# End of example prologue
# -----------------------
if Fld[0] == self.eoe_string:
if self.verb:
self.Str+="\n\end{verbatim}\n"
......@@ -752,31 +752,31 @@ class PyProTex:
else:
return
# Prologue or Introduction, print regular line (except for !)
# -----------------------------------------------------------
# Prologue or Introduction, print regular line (except for !)
# -----------------------------------------------------------
if not self.skip and (self.prologue or self.intro):
if self.verb and len(Fld)==1 and Fld[0]==self.comment_string:
return
elif(self.opt["g"]):
if self.verb and len(Fld)==2 and Fld[0]=='implicit':
return
return
elif self.verb and len(Fld)==1 and Fld[0] == 'private':
return
return
elif len(Fld)>1 and Fld[1] == "\\ev": # special handling
Rec = self.comment_string+" \end{verbatim}"
Rec=Rec.replace(self.comment_string," ") # replace comment string with blank
if self.opt["g"] and self.inspec:
if Fld[0] == "call":
self.beg_item()
self.beg_item()
return
elif len(Fld)>1 and Fld[1] == "=":
self.prc_item(Fld)
else:
self.Str+="\n{}".format(Rec)
self.Str+="\n{}".format(Rec)
self.descr_verb = 0
# Source code: print the full line
# --------------------------------
# Source code: print the full line
# --------------------------------
if self.source and not self.skip:
self.Str+="\n"+Rec
return
......@@ -787,7 +787,7 @@ class PyProTex:
def CheckOpts(self,optStr,quiet_mode=0):
"""Checks options against a given list. Outputs error message
for any invalid option.
string: optStr - options to be checked. (e.g. -df+x) The
string must begin with a positive or
negative sign. If no sign appears at the
......@@ -806,7 +806,7 @@ class PyProTex:
not recognized as a list of options
= 1 if all options are valid.
> 1 for the number of invalid options.
"""
"""
if ( optStr=="+" or optStr=="-" ): return -1
Options = [c for c in optStr] #split up string in single characters
......@@ -841,7 +841,7 @@ class PyProTex:
= -1 if the arguement, options, is
not recognized as a list of options.
= 0 otherwise
"""
"""
if optStr == "+" or optStr == "-": return -1
Options = [c for c in optStr] #split up string in single characters
......@@ -858,11 +858,11 @@ class PyProTex:
return 0
def SetLanguage(self,optStr):
"""Sets the language option.
The last input option that is a LanguageOption will overrule
all others, i.e. for all other language options in the list,
"""Sets the language option.
The last input option that is a LanguageOption will overrule
all others, i.e. for all other language options in the list,
opt_[option] is set to 0. Other options are ignored.
string: optStr - options to be checked. (e.g. -df+x) The
list must begin with a positive or
negative sign. If no sign appears at the
......@@ -872,7 +872,7 @@ class PyProTex:
= -1 if the arguement, options, is
not recognized as a list of options.
= 0 otherwise
"""
"""
if optStr == "+" or optStr == "-": return -1
Options = [c for c in optStr] #split up string in single characters
......@@ -942,16 +942,16 @@ class PyProTex:
Str+="\\markboth{}{}\n"
Str+="%-------------------------------------------------------------\n"
# in your main document before you include any protex-generated files
# for the first time, if you define these three variables as length
# in your main document before you include any protex-generated files
# for the first time, if you define these three variables as length
# settings (like this:)
# \newlength{\oldparskip}
# \newlength{\oldparindent}
# \newlength{\oldbaselineskip}
# then 1) comment in all the lines below, and 2) find the 3 reset lines
# further down and comment in them as well.
# then protex will override the paragraph and skip settings during
# the source sections, but will restore the original document settings
# further down and comment in them as well.
# then protex will override the paragraph and skip settings during
# the source sections, but will restore the original document settings
# at the end. if someone can figure out how to check to see if a
# latex variable exists, and do a conditional section, we could make
# this fully self-contained.
......@@ -994,7 +994,7 @@ class PyProTex:
return Str
def do_beg(self,):
"""Add title page to output string."""
"""Add title page to output string."""
if not self.opt["b"]:
if self.begdoc == 0:
if self.tpage:
......@@ -1023,7 +1023,7 @@ class PyProTex:
self.have_intf = 0; # have interface?
self.have_hist = 0; # have revision history?
self.name_is = "UNKNOWN";
def check_if_all_there(self,):
"""Checking for section attributes."""
self.check_error(self.have_name,"!(I)ROUTINE:")
......@@ -1037,21 +1037,21 @@ class PyProTex:
raise RunTimeError,"ProTeX: invalid prologue, missing {}: in {}".format(tag,self.name_is)
def hed_item(self,):
self.Str+="\\bigskip\n{{ \\bf \sf \n"
self.Str+="\makebox[.9 in][l]{{Short Name }} \n"
self.Str+="\makebox[.9 in][l]{{Units }} \n"
self.Str+="\makebox[.7 in][l]{{Dims }} \n"
self.Str+="\makebox[.7 in][l]{{Vert Loc }} \n"
self.Str+="\makebox[4. in][l]{{Long Name }} \n"
self.Str+="}} \n \n"
self.Str+="\\bigskip\n{{ \\bf \sf \n"
self.Str+="\makebox[.9 in][l]{{Short Name }} \n"
self.Str+="\makebox[.9 in][l]{{Units }} \n"
self.Str+="\makebox[.7 in][l]{{Dims }} \n"
self.Str+="\makebox[.7 in][l]{{Vert Loc }} \n"
self.Str+="\makebox[4. in][l]{{Long Name }} \n"
self.Str+="}} \n \n"
def beg_item(self,):
if self.initem:
if self.intv:
self.Str+="\makebox[1.05 in][l]{{\$\overline{{\\rm \\bf {} }}\$}} \n".format(self.shname)
else:
self.Str+="\makebox[1.05 in][l]{{\\bf {} }} \n".format(self.shname)
self.Str+="\makebox[.9 in][l]{{ {} }} \n".format(units)
self.Str+="\makebox[1.05 in][l]{{\\bf {} }} \n".format(self.shname)
self.Str+="\makebox[.9 in][l]{{ {} }} \n".format(units)
if self.dims != " ":
if self.dims != 'GEOS\_DIMSHORZONLY':
self.Str+="\makebox[.7 in][l]{{HorzOnly}}\n"
......@@ -1107,7 +1107,7 @@ class PyProTex:
self.locs = valStr.upper()
elif self.name == "AVERAGING_INTERVAL":
self.intv = 1
if __name__=="__main__":
files=[]
opts=[]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment