├── .github ├── dependabot.yml └── workflows │ ├── deploy-docs.yml │ └── tests.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CHANGES.txt ├── LICENSE.CSIRO ├── LICENSE.txt ├── MANIFEST.in ├── README.md ├── docs ├── Makefile ├── UNESCO-TechPaper44_eo.pdf ├── conf.py ├── eos80.rst ├── extras.rst ├── geostrophic.rst ├── index.rst ├── library.rst └── readme_link.md ├── pyproject.toml ├── requirements-dev.txt ├── requirements.txt ├── ruff.toml └── seawater ├── __init__.py ├── constants.py ├── eos80.py ├── extras.py ├── geostrophic.py ├── library.py └── tests ├── data ├── Endeavor_Cruise-88_Station-61-64-gvel.csv ├── Endeavor_Cruise-88_Station-61.csv ├── Endeavor_Cruise-88_Station-64.csv └── shapes.npz ├── matlab_test.txt ├── seawater_v3_3 ├── Contents.m ├── sw_adtg.m ├── sw_alpha.m ├── sw_aonb.m ├── sw_beta.m ├── sw_bfrq.m ├── sw_c3515.m ├── sw_cndr.m ├── sw_copy.m ├── sw_cp.m ├── sw_dens.m ├── sw_dens0.m ├── sw_dist.m ├── sw_dpth.m ├── sw_f.m ├── sw_fp.m ├── sw_g.m ├── sw_gpan.m ├── sw_gvel.m ├── sw_info.m ├── sw_new.m ├── sw_pden.m ├── sw_pres.m ├── sw_ptmp.m ├── sw_salds.m ├── sw_salrp.m ├── sw_salrt.m ├── sw_sals.m ├── sw_salt.m ├── sw_satAr.m ├── sw_satN2.m ├── sw_satO2.m ├── sw_seck.m ├── sw_smow.m ├── sw_svan.m ├── sw_svel.m ├── sw_swvel.m ├── sw_temp.m ├── sw_test.m └── sw_ver.m ├── sw_test.py ├── test_input_shapes.py └── test_result_comparison.py /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # See https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/keeping-your-actions-up-to-date-with-dependabot 2 | 3 | version: 2 4 | updates: 5 | 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | interval: "daily" 10 | labels: 11 | - "Bot" 12 | groups: 13 | github-actions: 14 | patterns: 15 | - '*' 16 | -------------------------------------------------------------------------------- /.github/workflows/deploy-docs.yml: -------------------------------------------------------------------------------- 1 | name: Documentation 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | release: 9 | types: 10 | - published 11 | 12 | jobs: 13 | build-docs: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: checkout 18 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 19 | with: 20 | fetch-depth: 0 21 | 22 | - name: Setup Micromamba 23 | uses: mamba-org/setup-micromamba@b09ef9b599704322748535812ca03efb2625677b # v2.0.5 24 | with: 25 | environment-name: TEST 26 | init-shell: bash 27 | create-args: >- 28 | python=3 --file requirements.txt --file requirements-dev.txt --channel conda-forge 29 | 30 | - name: Install erddapy 31 | shell: bash -l {0} 32 | run: | 33 | python -m pip install -e . --no-deps --force-reinstall 34 | 35 | - name: Build documentation 36 | shell: bash -l {0} 37 | run: > 38 | set -e 39 | && pushd docs 40 | && make clean html linkcheck 41 | && popd 42 | 43 | - name: Deploy 44 | if: success() && github.event_name == 'release' 45 | uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e #v4 46 | with: 47 | github_token: ${{ secrets.GITHUB_TOKEN }} 48 | publish_dir: docs/_build/html 49 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Full Tests 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: [main] 7 | 8 | jobs: 9 | run: 10 | runs-on: ${{ matrix.os }} 11 | strategy: 12 | matrix: 13 | python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] 14 | os: [ubuntu-latest] 15 | fail-fast: false 16 | 17 | steps: 18 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 19 | 20 | - name: Setup Micromamba Python ${{ matrix.python-version }} 21 | uses: mamba-org/setup-micromamba@b09ef9b599704322748535812ca03efb2625677b # v2.0.5 22 | with: 23 | environment-name: TEST 24 | init-shell: bash 25 | create-args: >- 26 | python=${{ matrix.python-version }} --file requirements.txt --file requirements-dev.txt octave --channel conda-forge 27 | 28 | - name: Install seawater 29 | shell: bash -l {0} 30 | run: | 31 | python -m pip install -e . --no-deps --force-reinstall 32 | 33 | - name: Full Tests 34 | shell: bash -l {0} 35 | run: | 36 | python -m pytest -rxs --doctest-modules --pyargs seawater 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | docs/_build/ 3 | python-test.txt 4 | seawater.egg-info/ 5 | seawater/_version.py 6 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | exclude: seawater/tests/seawater_v3_3/ 2 | 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.6.0 6 | hooks: 7 | - id: trailing-whitespace 8 | - id: check-ast 9 | - id: debug-statements 10 | - id: end-of-file-fixer 11 | - id: check-docstring-first 12 | - id: check-added-large-files 13 | exclude_types: [yaml] 14 | - id: requirements-txt-fixer 15 | - id: file-contents-sorter 16 | files: requirements-dev.txt 17 | 18 | - repo: https://github.com/keewis/blackdoc 19 | rev: v0.3.9 20 | hooks: 21 | - id: blackdoc 22 | 23 | - repo: https://github.com/codespell-project/codespell 24 | rev: v2.3.0 25 | hooks: 26 | - id: codespell 27 | exclude: > 28 | (?x)^( 29 | .*\.yaml 30 | )$ 31 | args: 32 | - --ignore-words-list=pres,delt,arry 33 | 34 | - repo: https://github.com/asottile/add-trailing-comma 35 | rev: v3.1.0 36 | hooks: 37 | - id: add-trailing-comma 38 | 39 | - repo: https://github.com/astral-sh/ruff-pre-commit 40 | rev: v0.4.6 41 | hooks: 42 | - id: ruff 43 | args: ["--fix", "--show-fixes"] 44 | - id: ruff-format 45 | 46 | 47 | - repo: https://github.com/tox-dev/pyproject-fmt 48 | rev: 2.1.3 49 | hooks: 50 | - id: pyproject-fmt 51 | 52 | ci: 53 | autofix_commit_msg: | 54 | [pre-commit.ci] auto fixes from pre-commit.com hooks 55 | 56 | for more information, see https://pre-commit.ci 57 | autofix_prs: false 58 | autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' 59 | autoupdate_schedule: monthly 60 | skip: [] 61 | submodules: false 62 | -------------------------------------------------------------------------------- /CHANGES.txt: -------------------------------------------------------------------------------- 1 | Changelog 2 | --------- 3 | 4 | Version 3.3.3 5 | 6 | * Unified code base for python 2 and 3, we no longer use 2to3 to convert. 7 | 8 | Version 3.3.2 9 | 10 | * Fixed py3k bug that prevent installation. 11 | 12 | Version 3.3.1 13 | 14 | * Both `gpan` and `bfrq` accepts 3D arrays now. 15 | * Fixed inconsistency in use of ITS-90 and increased convergence precision from 1e-4 to 1e-10 for `cndr`. Note: Not sure if this fix is needed. However, it is in the original version! 16 | 17 | Version 3.2 18 | 19 | * Corrected sign of potential vorticity in `bfrq`. 20 | 21 | Version 3.1 22 | 23 | * Added `swvel` to compute surface wave velocity. 24 | 25 | Version 3.0 26 | 27 | * Converted code so that temperature is now ITS-90 throughout. 28 | 29 | Version 2.0.2 30 | 31 | * Coding changes to enable functions to return the same shape vector as the input arguments. In previous releases, some functions returned column vectors for row vector input. Also some other tidying up. 32 | 33 | Version 2.0.1 34 | 35 | * New routine `satAr`. Solubility of Ar in seawater. 36 | * New routine `satN2`. Solubility of N2 in seawater. 37 | * New routine `satO2`. Solubility of O2 in seawater. 38 | * Updated `test` to include tests for above. 39 | 40 | Version 1.2e 41 | 42 | * Fixed bug in `alpha` where temp used in calculations regardless of the keyword. 43 | 44 | Version 1.2d 45 | 46 | * `bfrq` now also returns potential vorticity. Thanks to Greg Johnson (gjohnson@pmel.noaa.gov). 47 | * OMEGA=7.29e-5 was changed to OMEGA=7.292e-5 in `gvel` to be consistent with `f`. 48 | * **Important API change**: The usage of `alpha`, `beta` and `aonb` routines has changed! All these routines expect (S,T,P) to be passed instead of (S,PTMP,P) as in previous releases of seawater. Fast execution can still be obtained by passing ptmp=True. 49 | 50 | 51 | Version 1.2c 52 | 53 | * Fixed a bug in `bfrq` where empty LAT was needed as argument when no latitude values are being passed. 54 | * Now pass PRESSURE instead of DEPTH, more consistent though only a negligible change is answers. 55 | 56 | Version 1.2b 57 | 58 | * First official release and announcement on the networks. 59 | -------------------------------------------------------------------------------- /LICENSE.CSIRO: -------------------------------------------------------------------------------- 1 | SEAWATER - originally developed by Phil Morgan, CSIRO 2 | 3 | Translated from matlab CSIRO seawater toolbox Version 3.3 4 | 5 | SOFTWARE LICENCE AGREEMENT 6 | 7 | 1.0 Grant of Licence 8 | 9 | 1.1 The CSIRO Division of Oceanography (herein referred to as 10 | "CSIRO") hereby grants you (hereinafter referred to as 11 | the "Licencee"), subject to the Licencee agreeing to 12 | comply with the terms and conditions of this Agreement, a 13 | non-transferable, non-exclusive licence to use the 14 | computer programs described in this document (hereinafter 15 | referred to as the "Software") for the purpose of 16 | the Licencee's computing activity. 17 | 18 | 1.2 CSIRO hereby grants the Licencee the right to make copies 19 | of the Software for the purpose of the Licencee's 20 | computing activity only. 21 | 22 | 1.3 The benefit of the rights granted to the Licencee by the 23 | Licence and this Agreement generally shall be personal to 24 | the Licencee and the Licencee shall not mortgage, charge, 25 | assign, rent, lease, sell or otherwise dispose of or 26 | transfer the same or any part to any third party. 27 | 28 | 1.4 Unless otherwise agreed in writing or provided for in 29 | this Agreement, CSIRO shall be under no obligation or 30 | responsibility to provide the Licencee with any training, 31 | maintenance services, enhancements or updates of the 32 | Software or any services whatsoever. 33 | 34 | 2.0 Acknowledgment by the Licencee 35 | 36 | 2.1 The Licencee acknowledges and agrees that it shall not: 37 | 38 | (i) sell, let for hire or by way of trade, offer or 39 | exhibit or expose for sale or hire or otherwise 40 | distribute the Software for the purposes of trade or 41 | any other purpose; 42 | 43 | (ii) authorise or assist any third person to do any 44 | of the acts set out in (i) above; 45 | 46 | (iii) modify the Software source code without advising 47 | CSIRO. 48 | 49 | 2.2 The Licencee agrees that: 50 | 51 | (a) CSIRO is the owner of all copyright and other 52 | Intellectual Property Rights subsisting in the 53 | Software; 54 | 55 | (b) this document must be properly cited in any 56 | publication reporting results derived from this 57 | document or obtained from application and use of this 58 | software. Any of the Licencee's documentation 59 | describing results generated by the Licencee's 60 | use of the Software will contain an acknowledgement 61 | of CSIRO's ownership of the Software; 62 | 63 | (c) CSIRO reserves all rights in the Software other than 64 | the rights granted to the Licencee by this 65 | Agreement; 66 | 67 | (d) each item of the Software will display a banner 68 | summarising the terms of this Agreement and 69 | acknowledging the source of the Software, and the 70 | contents of a banner will not be modified and its 71 | display will not be inactivated by the Licencee 72 | without the approval of CSIRO. 73 | 74 | 3.0 Indemnity 75 | 76 | 3.1 To the full extent permitted by law, CSIRO excludes any 77 | and all liability in respect of any loss or damage, 78 | whether personal (includes death or illness) or of 79 | property and whether direct, consequential or special 80 | (including consequential financial loss or damage) of 81 | the Licencee, its officers, agents and employees or any 82 | third party howsoever caused, which may be suffered or 83 | incurred or which may arise directly or indirectly in 84 | respect of or arising out of the Licencee's use or 85 | inability to use the Software or the failure or omission 86 | on the part of CSIRO to comply with the conditions and 87 | warranties under this Licence Agreement. Insofar as 88 | liability for loss or damages under or pursuant to such 89 | legislation cannot be excluded, CSIRO's liability for 90 | loss or damages shall be limited to the amount of One 91 | Dollar ($1.00). 92 | 93 | 3.2 CSIRO make no warranties, expressed or implied, and 94 | excludes all other warranties representations, terms or 95 | conditions, whether express or implied, oral or written, 96 | statutory or otherwise, relating in any way to the 97 | Software, or to this Agreement, including any implied 98 | warranty of merchantability or of fitness for particular 99 | purpose. To the full extent permitted by the law of the 100 | Commonwealth of Australia or the laws of any State or 101 | Territory of Australia, any conditions or warranties 102 | imposed by such legislation are hereby excluded. In so 103 | far as liability under or pursuant to such legislation 104 | may not be excluded, CSIRO's liability to the Licencee 105 | pursuant to this Agreement shall be limited as set out in 106 | clause 3.1 hereof. 107 | 108 | 3.3 The Licencee acknowledges and agrees that the Software 109 | was developed for CSIRO research purposes and may have 110 | inherent defects, errors or deficiencies, and that it is 111 | the responsibility of the Licencee to make its own 112 | assessment of the suitability of the Software for the 113 | purpose of the Licencee's computing activity. The 114 | Licencee will use the Software, and advice, opinions or 115 | information supplied by CSIRO, its officers, employees or 116 | agents concerning the Software at the Licencee's own 117 | risk. 118 | 119 | 3.4 The Licencee hereby releases and indemnifies and shall 120 | 121 | Continue to release and indemnify CSIRO, its officers, 122 | employees and agents from and against all actions, 123 | claims, proceedings or demands (including those brought 124 | by third parties) which may be bought against it or them, 125 | whether on their own or jointly with the Licencee and 126 | whether at common law, in equity or pursuant to statute or 127 | otherwise, in respect of any loss, death, injury, illness 128 | or damage (whether personal or property, and whether 129 | direct or consequential, including consequential 130 | financial loss) and any infringement of copyright, 131 | patents, trade marks, designs or other Intellectual 132 | Property Rights, howsoever arising out of the Licencee's 133 | exercise of its rights under this Agreement and from and 134 | against all damages, costs and expenses incurred in 135 | defending or settling any such claim, proceeding or 136 | demand. 137 | 138 | 3.5 The Licencee's obligation to indemnify CSIRO and its 139 | officers, employees and agents set out in clause 3.4 140 | hereof is a continuing obligation separate from 141 | and independent of the Licencee's other obligations under 142 | this Agreement, and shall survive all expiration or 143 | termination o 144 | f this Agreement. 145 | 146 | 4.0 Termination 147 | 148 | 4.1 The Licence shall terminate immediately upon the Licencee 149 | breaching any term or condition of this Agreement whether 150 | or not CSIRO is aware of the occurrence of the breach at 151 | the time that it happens. 152 | 153 | 4.2 CSIRO may terminate the Licence on reasonable grounds by 154 | notice in writing to the Licencee, and such notice of 155 | termination shall be effective immediately upon receipt 156 | by the Licencee. 157 | 158 | DISCLAIMER: 159 | This software is provided "as is" without warranty of any kind. 160 | See the file copy for conditions of use and licence. 161 | 162 | 163 | Computational routines for the properties of sea water 164 | 165 | SEAWATER - developed by Phil Morgan and 166 | Lindsay Pender (Lindsay.Pender@csiro.au) CSIRO 167 | 168 | 169 | DESCRIPTION: 170 | SEAWATER is a toolkit of PYTHON routines for calculating the 171 | properties of sea water. They are a self contained library and 172 | are extremely easy to use and will run on all computers that 173 | support NumPy. 174 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Filipe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.txt 2 | include README.md 3 | include pyproject.toml 4 | include LICENSE.CSIRO 5 | 6 | graft seawater 7 | 8 | prune .github 9 | prune *.egg-info 10 | prune docs 11 | prune seawater/tests 12 | 13 | exclude .coveragerc 14 | exclude ruff.toml 15 | exclude .gitignore 16 | exclude .isort.cfg 17 | exclude .pre-commit-config.yaml 18 | exclude *.yml 19 | exclude seawater/_version.py 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-seawater 2 | 3 | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.11395.svg)](https://zenodo.org/records/11395) 4 | ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/seawater) 5 | [![Tests](https://github.com/pyoceans/python-seawater/actions/workflows/tests.yml/badge.svg)](https://github.com/pyoceans/python-seawater/actions/workflows/tests.yml) 6 | ![PyPI - License](https://img.shields.io/pypi/l/seawater) 7 | 8 | [![No Maintenance Intended](https://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 9 | 10 | This is a Python re-write of the CSIRO seawater toolbox 11 | ([SEAWATER-3.3](https://www.cmar.csiro.au/datacentre/ext_docs/seawater.html)) 12 | for calculating the properties of sea water. The package uses the 13 | formulas from Unesco's joint panel on oceanographic tables and 14 | standards, UNESCO 1981 and UNESCO 1983 (EOS-80). 15 | 16 | The EOS-80 library is considered now obsolete; it is provided here for 17 | compatibility with old scripts, and to allow a smooth transition to the 18 | new [TEOS-10](https://www.teos-10.org/). 19 | 20 | ## Warning 21 | 22 | The Python version default output unit for sw.dist is *km* instead of 23 | *nm*. 24 | 25 | Here we assume pressure as the first dimension, i.e. M pressure by N 26 | positions (See the table below). The Matlab version does some guessing 27 | at this that we simply ignore to avoid confusions. 28 | 29 | | **P** | **S** | **T** | 30 | |------:|:-------:|:-------:| 31 | | 10 | 34.5487 | 28.7856 | 32 | | 50 | 34.7275 | 28.4329 | 33 | | 125 | 34.8605 | 22.8103 | 34 | | 250 | 34.6810 | 10.2600 | 35 | | 600 | 34.5680 | 6.8863 | 36 | | 1000 | 34.5600 | 4.4036 | 37 | 38 | The current version was tested against the Matlab seawater v3.3 39 | reproducing all functions and results from that release. 40 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | 15 | .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest 16 | 17 | help: 18 | @echo "Please use \`make ' where is one of" 19 | @echo " html to make standalone HTML files" 20 | @echo " dirhtml to make HTML files named index.html in directories" 21 | @echo " pickle to make pickle files" 22 | @echo " json to make JSON files" 23 | @echo " htmlhelp to make HTML files and a HTML help project" 24 | @echo " qthelp to make HTML files and a qthelp project" 25 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 26 | @echo " changes to make an overview of all changed/added/deprecated items" 27 | @echo " linkcheck to check all external links for integrity" 28 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 29 | 30 | clean: 31 | -rm -rf $(BUILDDIR)/* 32 | 33 | html: 34 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 35 | @echo 36 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 37 | 38 | dirhtml: 39 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 40 | @echo 41 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 42 | 43 | pickle: 44 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 45 | @echo 46 | @echo "Build finished; now you can process the pickle files." 47 | 48 | json: 49 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 50 | @echo 51 | @echo "Build finished; now you can process the JSON files." 52 | 53 | htmlhelp: 54 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 55 | @echo 56 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 57 | ".hhp project file in $(BUILDDIR)/htmlhelp." 58 | 59 | qthelp: 60 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 61 | @echo 62 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 63 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 64 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/seawater.qhcp" 65 | @echo "To view the help file:" 66 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/seawater.qhc" 67 | 68 | latex: 69 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 70 | @echo 71 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 72 | @echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \ 73 | "run these through (pdf)latex." 74 | 75 | changes: 76 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 77 | @echo 78 | @echo "The overview file is in $(BUILDDIR)/changes." 79 | 80 | linkcheck: 81 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 82 | @echo 83 | @echo "Link check complete; look for any errors in the above output " \ 84 | "or in $(BUILDDIR)/linkcheck/output.txt." 85 | 86 | doctest: 87 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 88 | @echo "Testing of doctests in the sources finished, look at the " \ 89 | "results in $(BUILDDIR)/doctest/output.txt." 90 | -------------------------------------------------------------------------------- /docs/UNESCO-TechPaper44_eo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyoceans/python-seawater/a9e687c51d557b847cf9165d05ffa0093722f202/docs/UNESCO-TechPaper44_eo.pdf -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # 2 | # seawater documentation build configuration file, created by 3 | # sphinx-quickstart on Tue Aug 10 16:47:25 2010. 4 | # 5 | # This file is execfile()d with the current directory set to its containing dir. 6 | # 7 | # Note that not all possible configuration values are present in this 8 | # autogenerated file. 9 | # 10 | # All configuration values have a default; values that are commented out 11 | # serve to show the default. 12 | 13 | 14 | # If extensions (or modules to document with autodoc) are in another directory, 15 | # add these directories to sys.path here. If the directory is relative to the 16 | # documentation root, use os.path.abspath to make it absolute, like shown here. 17 | # sys.path.append(os.path.abspath('.')) 18 | 19 | # -- General configuration ----------------------------------------------------- 20 | 21 | # Add any Sphinx extension module names here, as strings. They can be extensions 22 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 23 | 24 | extensions = [ 25 | "myst_parser", 26 | "sphinx.ext.autodoc", 27 | "sphinx.ext.mathjax", 28 | "sphinx.ext.doctest", 29 | "matplotlib.sphinxext.plot_directive", 30 | "numpydoc", 31 | ] 32 | 33 | # Add any paths that contain templates here, relative to this directory. 34 | templates_path = ["_templates"] 35 | 36 | # The suffix of source filenames. 37 | source_suffix = ".rst" 38 | 39 | # The encoding of source files. 40 | # source_encoding = 'utf-8' 41 | 42 | # The master toctree document. 43 | master_doc = "index" 44 | 45 | # General information about the project. 46 | import datetime 47 | 48 | year = datetime.datetime.now(tz=datetime.timezone.utc).date().year 49 | 50 | project = "seawater" 51 | copyright = f"2010-{year}, Filipe Fernandes" 52 | 53 | # The version info for the project you're documenting, acts as replacement for 54 | # |version| and |release|, also used in various other places throughout the 55 | # built documents. 56 | # 57 | # The short X.Y version. 58 | from seawater import __version__ 59 | 60 | version = __version__ 61 | # The full version, including alpha/beta/rc tags. 62 | release = __version__ 63 | 64 | # The language for content autogenerated by Sphinx. Refer to documentation 65 | # for a list of supported languages. 66 | # language = None 67 | 68 | # There are two options for replacing |today|: either, you set today to some 69 | # non-false value, then it is used: 70 | # today = '' 71 | # Else, today_fmt is used as the format for a strftime call. 72 | # today_fmt = '%B %d, %Y' 73 | 74 | # List of documents that shouldn't be included in the build. 75 | # unused_docs = [] 76 | 77 | # List of directories, relative to source directory, that shouldn't be searched 78 | # for source files. 79 | exclude_trees = ["_build"] 80 | 81 | # The reST default role (used for this markup: `text`) to use for all documents. 82 | # default_role = None 83 | 84 | # If true, '()' will be appended to :func: etc. cross-reference text. 85 | # add_function_parentheses = True 86 | 87 | # If true, the current module name will be prepended to all description 88 | # unit titles (such as .. function::). 89 | # add_module_names = True 90 | 91 | # If true, sectionauthor and moduleauthor directives will be shown in the 92 | # output. They are ignored by default. 93 | # show_authors = False 94 | 95 | # The name of the Pygments (syntax highlighting) style to use. 96 | pygments_style = "sphinx" 97 | 98 | # A list of ignored prefixes for module index sorting. 99 | # modindex_common_prefix = [] 100 | 101 | 102 | # -- Options for HTML output --------------------------------------------------- 103 | 104 | # The theme to use for HTML and HTML Help pages. Major themes that come with 105 | # Sphinx are currently 'default' and 'sphinxdoc'. 106 | html_theme = "sphinxdoc" 107 | 108 | # Theme options are theme-specific and customize the look and feel of a theme 109 | # further. For a list of options available for each theme, see the 110 | # documentation. 111 | # html_theme_options = {} 112 | 113 | # Add any paths that contain custom themes here, relative to this directory. 114 | # html_theme_path = [] 115 | 116 | # The name for this set of Sphinx documents. If None, it defaults to 117 | # " v documentation". 118 | # html_title = None 119 | 120 | # A shorter title for the navigation bar. Default is the same as html_title. 121 | # html_short_title = None 122 | 123 | # The name of an image file (relative to this directory) to place at the top 124 | # of the sidebar. 125 | # html_logo = None 126 | 127 | # The name of an image file (within the static path) to use as favicon of the 128 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 129 | # pixels large. 130 | # html_favicon = None 131 | 132 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 133 | # using the given strftime format. 134 | # html_last_updated_fmt = '%b %d, %Y' 135 | 136 | # If true, SmartyPants will be used to convert quotes and dashes to 137 | # typographically correct entities. 138 | # html_use_smartypants = True 139 | 140 | # Custom sidebar templates, maps document names to template names. 141 | # html_sidebars = {} 142 | 143 | # Additional templates that should be rendered to pages, maps page names to 144 | # template names. 145 | # html_additional_pages = {} 146 | 147 | # If false, no module index is generated. 148 | # html_use_modindex = True 149 | html_domain_indices = ["py-modindex"] 150 | 151 | # If false, no index is generated. 152 | # html_use_index = True 153 | 154 | # If true, the index is split into individual pages for each letter. 155 | # html_split_index = False 156 | 157 | # If true, links to the reST sources are added to the pages. 158 | # html_show_sourcelink = True 159 | 160 | # If true, an OpenSearch description file will be output, and all pages will 161 | # contain a tag referring to it. The value of this option must be the 162 | # base URL from which the finished HTML is served. 163 | # html_use_opensearch = '' 164 | 165 | # If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml"). 166 | # html_file_suffix = '' 167 | 168 | # Output file base name for HTML help builder. 169 | htmlhelp_basename = "seawaterdoc" 170 | 171 | 172 | # -- Options for LaTeX output -------------------------------------------------- 173 | 174 | # The paper size ('letter' or 'a4'). 175 | # latex_paper_size = 'letter' 176 | 177 | # The font size ('10pt', '11pt' or '12pt'). 178 | # latex_font_size = '10pt' 179 | 180 | # Grouping the document tree into LaTeX files. List of tuples 181 | # (source start file, target name, title, author, documentclass [howto/manual]). 182 | latex_documents = [ 183 | ( 184 | "index", 185 | "seawater.tex", 186 | "seawater Documentation", 187 | "Filipe Fernandes", 188 | "manual", 189 | ), 190 | ] 191 | 192 | # The name of an image file (relative to this directory) to place at the top of 193 | # the title page. 194 | # latex_logo = None 195 | 196 | # For "manual" documents, if this is true, then toplevel headings are parts, 197 | # not chapters. 198 | # latex_use_parts = False 199 | 200 | # Additional stuff for the LaTeX preamble. 201 | # latex_preamble = '' 202 | 203 | # Documents to append as an appendix to all manuals. 204 | # latex_appendices = [] 205 | 206 | # If false, no module index is generated. 207 | # latex_use_modindex = True 208 | -------------------------------------------------------------------------------- /docs/eos80.rst: -------------------------------------------------------------------------------- 1 | :mod:`eos80` 2 | ------------ 3 | 4 | .. automodule:: seawater.eos80 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/extras.rst: -------------------------------------------------------------------------------- 1 | :mod:`extras` 2 | ------------- 3 | 4 | .. automodule:: seawater.extras 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/geostrophic.rst: -------------------------------------------------------------------------------- 1 | :mod:`geostrophic` 2 | ------------------ 3 | 4 | .. automodule:: seawater.geostrophic 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Documentation 2 | ============= 3 | 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | 8 | readme_link 9 | 10 | eos80 11 | geostrophic 12 | extras 13 | library 14 | 15 | Indices and tables 16 | ================== 17 | 18 | * :ref:`genindex` 19 | * :ref:`modindex` 20 | * :ref:`search` 21 | -------------------------------------------------------------------------------- /docs/library.rst: -------------------------------------------------------------------------------- 1 | :mod:`library` 2 | -------------- 3 | 4 | .. automodule:: seawater.library 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /docs/readme_link.md: -------------------------------------------------------------------------------- 1 | ```{include} ../README.md 2 | ``` 3 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | build-backend = "setuptools.build_meta" 3 | requires = [ 4 | "setuptools>=42", 5 | "setuptools-scm", 6 | "wheel", 7 | ] 8 | 9 | [project] 10 | name = "seawater" 11 | description = "Seawater Library for Python" 12 | readme = "README.md" 13 | license = { file = "LICENSE.txt" } 14 | maintainers = [ 15 | { name = "Filipe Fernandes", email = "ocefpaf+seawater@gmail.com" }, 16 | ] 17 | requires-python = ">=3.8" 18 | classifiers = [ 19 | "Programming Language :: Python :: 3 :: Only", 20 | "Programming Language :: Python :: 3.8", 21 | "Programming Language :: Python :: 3.9", 22 | "Programming Language :: Python :: 3.10", 23 | "Programming Language :: Python :: 3.11", 24 | "Programming Language :: Python :: 3.12", 25 | ] 26 | dynamic = [ 27 | "dependencies", 28 | "version", 29 | ] 30 | urls.documentation = "https://pyoceans.github.io/python-seawater" 31 | urls.homepage = "https://pypi.org/project/seawater/" 32 | urls.repository = "https://github.com/pyoceans/python-seawater" 33 | 34 | [tool.setuptools] 35 | packages = [ 36 | "seawater", 37 | ] 38 | # include-package-data = true 39 | 40 | [tool.setuptools.dynamic] 41 | dependencies = { file = [ 42 | "requirements.txt", 43 | ] } 44 | 45 | [tool.setuptools_scm] 46 | write_to = "seawater/_version.py" 47 | write_to_template = "__version__ = '{version}'" 48 | tag_regex = "^(?Pv)?(?P[^\\+]+)(?P.*)?$" 49 | 50 | [tool.check-manifest] 51 | ignore = [ 52 | "*.yml", 53 | "docs", 54 | "docs/*", 55 | "seawater/tests", 56 | "seawater/tests/*", 57 | ] 58 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | matplotlib 2 | myst-parser 3 | numpydoc 4 | oct2py 5 | pytest 6 | sphinx 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy<2 2 | scipy 3 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | line-length = 90 2 | 3 | lint.select = ["ALL"] 4 | 5 | lint.ignore = [ 6 | "ANN001", # Missing type annotation for function argument 7 | "ANN002", # Missing type annotation for `*arys` 8 | "ANN101", # Missing type annotation for `self` in method 9 | "ANN201", # Missing return type annotation for public function 10 | "ANN202", # Missing return type annotation for private function 11 | "D100", # Missing docstring in public module 12 | "D101", # Missing docstring in public class 13 | "D102", # Missing docstring in public method 14 | "D203", # 1 blank line required before class docstring 15 | "D205", # 1 blank line required between summary line and description 16 | "D213", # incompatible. Ignoring `multi-line-summary-second-line` 17 | "D400", # First line should end with a period 18 | "D401", # First line of docstring should be in imperative mood 19 | "D415", # First line should end with a period, question mark, or exclamation point 20 | "D417", # Missing argument descriptions in the docstring 21 | "ERA001", # Found commented-out code 22 | "N802", # Function name `test_satAr` should be lowercase 23 | "N803", # Argument name should be lowercase 24 | "N806", # Variable should be lowercase 25 | "N816", # Variable `db2Pascal` in global scope should not be mixedCase 26 | "PLR2004", # Magic value used in comparison 27 | "TRY003", # Avoid specifying long messages outside the exception class 28 | "UP031", # Use format specifiers instead of percent format 29 | ] 30 | 31 | [lint.extend-per-file-ignores] 32 | "docs/conf.py" = [ 33 | "A001", # builtin-variable-shadowing 34 | "D100", # Missing docstring in public module 35 | "E402", # Module level import not at top of file 36 | "E501", # Line too long 37 | "ERA001", # Found commented-out code 38 | "ERA001", # Found commented-out code 39 | "EXE001", # Shebang is present but file is not executable 40 | "INP001" # File `docs/conf.py` is part of an implicit namespace package. Add an `__init__.py`. 41 | ] 42 | "test_*.py" = [ 43 | "ANN001", # Missing type annotation for function argument 44 | "ANN201", # Missing return type annotation for public function 45 | "ANN202", # Missing return type annotation for private function 46 | "INP001", # File is part of an implicit namespace package 47 | "PD901", # Avoid using the generic variable name `df` for DataFrames 48 | "S101", # Use of assert detected 49 | ] 50 | "sw_test.py" = [ 51 | "INP001", # File `seawater/test/sw_test.py` is part of an implicit namespace package. Add an `__init__.py`. 52 | "C901", # `test` is too complex (20 > 10) 53 | "PLR0912", # Too many branches (19 > 12) 54 | "PLR0915", # Too many statements (242 > 50) 55 | "SIM115", # Use context handler for opening files 56 | "PTH123", # `open()` should be replaced by `Path.open()` 57 | "TD002", # Missing author in TODO; try: `# TODO(): ...` or `# TODO @: ...` 58 | "TD003", # Missing issue link on the line following this TODO 59 | "FIX002", # Line contains TODO, consider resolving the issue 60 | ] 61 | # nbqa-ruff acts on converted .py so we cannot glob .ipynb :-/ 62 | # https://github.com/nbQA-dev/nbQA/issues/823 63 | "notebooks/*" = [ 64 | "ANN001", # Missing type annotation for function argument 65 | "ANN201", # Missing return type annotation for public function 66 | "B018", # Found useless expression. Either assign it to a variable or remove it 67 | "D100", # Missing docstring in public module 68 | "D103", # Missing docstring in public function 69 | "E402", # Module level import not at top of file 70 | "FBT003", # Boolean positional value in function call 71 | "INP001", # File is part of an implicit namespace package 72 | "PD901", # Avoid using the generic variable name `df` for DataFrames 73 | "T201", # `print` found" 74 | ] 75 | [lint.pycodestyle] 76 | max-doc-length = 180 77 | -------------------------------------------------------------------------------- /seawater/__init__.py: -------------------------------------------------------------------------------- 1 | """Seawater: EOS-80 equation of state.""" 2 | 3 | import warnings 4 | 5 | try: 6 | from ._version import __version__ 7 | except ImportError: 8 | __version__ = "unknown" 9 | 10 | from .eos80 import ( 11 | adtg, 12 | alpha, 13 | aonb, 14 | beta, 15 | cp, 16 | dens, 17 | dens0, 18 | dpth, 19 | fp, 20 | g, 21 | pden, 22 | pres, 23 | ptmp, 24 | salt, 25 | svel, 26 | temp, 27 | ) 28 | from .extras import dist, f, satAr, satN2, satO2, swvel 29 | from .geostrophic import bfrq, gpan, gvel, svan 30 | from .library import cndr, salds, salrp, salrt, sals, seck, smow 31 | 32 | __all__ = [ 33 | "adtg", 34 | "alpha", 35 | "aonb", 36 | "beta", 37 | "bfrq", 38 | "cndr", 39 | "cp", 40 | "dens", 41 | "dens0", 42 | "dist", 43 | "dpth", 44 | "f", 45 | "fp", 46 | "g", 47 | "gpan", 48 | "gvel", 49 | "pden", 50 | "pres", 51 | "ptmp", 52 | "salds", 53 | "salrp", 54 | "salrt", 55 | "sals", 56 | "salt", 57 | "satAr", 58 | "satN2", 59 | "satO2", 60 | "seck", 61 | "smow", 62 | "svan", 63 | "svel", 64 | "swvel", 65 | "temp", 66 | ] 67 | 68 | warnings.warn( 69 | "The seawater library is deprecated! Please use gsw instead.", 70 | stacklevel=2, 71 | ) 72 | -------------------------------------------------------------------------------- /seawater/constants.py: -------------------------------------------------------------------------------- 1 | """Constants. 2 | ========= 3 | 4 | """ 5 | 6 | from numpy import pi 7 | 8 | # dbar to pascal. 9 | db2Pascal = 1e4 10 | 11 | # The Celsius zero point. 12 | Kelvin = 273.15 13 | 14 | # Acceleration of gravity [m/s**2] 15 | gdef = 9.8 16 | 17 | # 1 nm = 1.8520 km 18 | DEG2NM, NM2KM = 60.0, 1.8520 19 | 20 | # Sidereal day = 23.9344696 hours. 21 | OMEGA = 7.292e-5 # 7.292115e-5 22 | 23 | # Mean radius of earth [m] A.E. Gill. 24 | earth_radius = 6371000.0 25 | 26 | # Angle conversions. 27 | deg2rad, rad2deg = pi / 180.0, 180.0 / pi 28 | 29 | # Conductivity at S=35 psu , T=15 C [ITPS 68] and P=0 dbar. 30 | c3515 = 42.914 31 | -------------------------------------------------------------------------------- /seawater/extras.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from .constants import DEG2NM, NM2KM, OMEGA, Kelvin, deg2rad, gdef, rad2deg 4 | from .library import T68conv 5 | 6 | __all__ = [ 7 | "dist", 8 | "f", 9 | "satAr", 10 | "satN2", 11 | "satO2", 12 | "swvel", 13 | ] 14 | 15 | 16 | def dist(lat, lon, units="km"): 17 | """Calculate distance between two positions on globe using the "Plane 18 | Sailing" method. Also uses simple geometry to calculate the bearing of 19 | the path between position pairs. 20 | 21 | Parameters 22 | ---------- 23 | lat : array_like 24 | decimal degrees (+ve N, -ve S) [- 90.. +90] 25 | lon : array_like 26 | decimal degrees (+ve E, -ve W) [-180..+180] 27 | units : string, optional 28 | default kilometers 29 | 30 | Returns 31 | ------- 32 | dist : array_like 33 | distance between positions in units 34 | phaseangle : array_like 35 | angle of line between stations with x axis (East). 36 | Range of values are -180..+180. (E=0, N=90, S=-90) 37 | 38 | Examples 39 | -------- 40 | >>> import seawater as sw 41 | >>> sw.dist(0, [-179, 180]) 42 | (array([111.12]), array([180.])) 43 | >>> lon = [35, 35] 44 | >>> lat = [41, 40] 45 | >>> sw.dist(lat, lon) 46 | (array([111.12]), array([-90.])) 47 | >>> # Create a distance vector. 48 | >>> lon = np.arange(30, 40, 1) 49 | >>> lat = 35 50 | >>> np.cumsum(np.append(0, sw.dist(lat, lon, units="km")[0])) 51 | array([ 0. , 91.02417516, 182.04835032, 273.07252548, 52 | 364.09670065, 455.12087581, 546.14505097, 637.16922613, 53 | 728.19340129, 819.21757645]) 54 | 55 | References 56 | ---------- 57 | .. [1] The PLANE SAILING method as described in "CELESTIAL NAVIGATION" 1989 58 | by Dr. P. Gormley. The Australian Antarctic Division. 59 | 60 | """ 61 | lon, lat = list(map(np.asanyarray, (lon, lat))) 62 | lon, lat = np.broadcast_arrays(lon, lat) 63 | 64 | npositions = max(lon.shape) 65 | 66 | ind = np.arange(0, npositions - 1, 1) # Index to first of position pairs. 67 | 68 | dlon = np.diff(lon, axis=0) 69 | lon180, lon360 = 180, 360 70 | if np.any(np.abs(dlon) > lon180): 71 | flag = abs(dlon) > lon180 72 | dlon[flag] = -np.sign(dlon[flag]) * (lon360 - np.abs(dlon[flag])) 73 | 74 | latrad = np.abs(lat * deg2rad) 75 | dep = np.cos((latrad[ind + 1] + latrad[ind]) / 2) * dlon 76 | dlat = np.diff(lat, axis=0) 77 | dist = DEG2NM * (dlat**2 + dep**2) ** 0.5 78 | 79 | if units == "km": 80 | dist = dist * NM2KM 81 | 82 | # Calculate angle to x axis. 83 | phaseangle = np.angle(dep + dlat * 1j) * rad2deg 84 | return dist, phaseangle 85 | 86 | 87 | def f(lat): 88 | r"""Calculates the Coriolis factor :math:`f` defined by: 89 | 90 | .. math:: 91 | f = 2 \\Omega \\sin(lat) 92 | 93 | where: 94 | 95 | .. math:: 96 | \\Omega = \\frac{2 \\pi}{\\textrm{sidereal day}} = 7.2921150e^{-5} 97 | \\textrm{ radians sec}^{-1} 98 | 99 | 100 | Parameters 101 | ---------- 102 | lat : array_like 103 | latitude in decimal degrees north [-90..+90]. 104 | 105 | Returns 106 | ------- 107 | f : array_like 108 | Coriolis factor [s :sup:`-1`] 109 | 110 | Examples 111 | -------- 112 | >>> import seawater as sw 113 | >>> sw.f(45) 114 | 0.00010312445296824608 115 | 116 | References 117 | ---------- 118 | .. [1] S. Pond & G.Pickard 2nd Edition 1986 Introductory Dynamical 119 | Oceanography Pergamon Press Sydney. ISBN 0-08-028728-X 120 | 121 | .. [2] A.E. Gill 1982. p.54 Eqn. 3.7.15 "Atmosphere-Ocean Dynamics" 122 | Academic Press: New York. ISBN: 0-12-283522-0 123 | 124 | .. [3] Groten, E., 2004: Fundamental Parameters and Current (2004) Best 125 | Estimates of the Parameters of Common Relevance to Astronomy, Geodesy, 126 | and Geodynamics. Journal of Geodesy, 77, pp. 724-797. 127 | 128 | """ 129 | lat = np.asanyarray(lat) 130 | # Eqn p27. UNESCO 1983. 131 | return 2 * OMEGA * np.sin(lat * deg2rad) 132 | 133 | 134 | def satAr(s, t): 135 | """Solubility (saturation) of Argon (Ar) in sea water. 136 | 137 | Parameters 138 | ---------- 139 | s : array_like 140 | salinity [psu (PSS-78)] 141 | t : array_like 142 | temperature [℃ (ITS-90)] 143 | 144 | Returns 145 | ------- 146 | satAr : array_like 147 | solubility of Ar [ml l :sup:`-1`] 148 | 149 | Examples 150 | -------- 151 | >>> # Data from Weiss 1970. 152 | >>> import seawater as sw 153 | >>> from seawater.library import T90conv 154 | >>> t = T90conv([[-1, -1], [10, 10], [20, 20], [40, 40]]) 155 | >>> s = [[20, 40], [20, 40], [20, 40], [20, 40]] 156 | >>> sw.satAr(s, t) 157 | array([[0.4455784 , 0.38766011], 158 | [0.33970659, 0.29887756], 159 | [0.27660227, 0.24566428], 160 | [0.19861429, 0.17937698]]) 161 | 162 | References 163 | ---------- 164 | .. [1] Weiss, R. F. 1970. The Solubility of Nitrogen, Oxygen and Argon in 165 | Water and Seawater Deep-Sea Research Vol. 17, p. 721-735. 166 | doi:10.1016/0011-7471(70)90037-9 167 | 168 | """ 169 | s, t = list(map(np.asanyarray, (s, t))) 170 | 171 | # Convert T to Kelvin. 172 | t = Kelvin + T68conv(t) 173 | 174 | # Constants for Eqn (4) of Weiss 1970. 175 | a = [-173.5146, 245.4510, 141.8222, -21.8020] 176 | b = [-0.034474, 0.014934, -0.0017729] 177 | 178 | # Eqn (4) of Weiss 1970. 179 | lnC = ( 180 | a[0] 181 | + a[1] * (100 / t) 182 | + a[2] * np.log(t / 100) 183 | + a[3] * (t / 100) 184 | + s * (b[0] + b[1] * (t / 100) + b[2] * ((t / 100) ** 2)) 185 | ) 186 | 187 | return np.exp(lnC) 188 | 189 | 190 | def satN2(s, t): 191 | """Solubility (saturation) of Nitrogen (N2) in sea water. 192 | 193 | Parameters 194 | ---------- 195 | s : array_like 196 | salinity [psu (PSS-78)] 197 | t : array_like 198 | temperature [℃ (ITS-90)] 199 | 200 | Returns 201 | ------- 202 | satN2 : array_like 203 | solubility of N2 [ml l :sup:`-1`] 204 | 205 | Examples 206 | -------- 207 | >>> # Data from Weiss 1970. 208 | >>> import seawater as sw 209 | >>> from seawater.library import T90conv 210 | >>> t = T90conv([[-1, -1], [10, 10], [20, 20], [40, 40]]) 211 | >>> s = [[20, 40], [20, 40], [20, 40], [20, 40]] 212 | >>> sw.satN2(s, t) 213 | array([[16.27952432, 14.00784526], 214 | [12.64036196, 11.01277257], 215 | [10.46892822, 9.21126859], 216 | [ 7.78163876, 6.95395099]]) 217 | 218 | References 219 | ---------- 220 | .. [1] Weiss, R. F. 1970. The Solubility of Nitrogen, Oxygen and Argon in 221 | Water and Seawater Deep-Sea Research Vol. 17, p. 721-735. 222 | doi:10.1016/0011-7471(70)90037-9 223 | 224 | """ 225 | s, t = list(map(np.asanyarray, (s, t))) 226 | 227 | # Convert T to Kelvin. 228 | t = Kelvin + T68conv(t) 229 | 230 | # Constants for Eqn (4) of Weiss 1970. 231 | a = (-172.4965, 248.4262, 143.0738, -21.7120) 232 | b = (-0.049781, 0.025018, -0.0034861) 233 | 234 | # Eqn (4) of Weiss 1970. 235 | lnC = ( 236 | a[0] 237 | + a[1] * (100 / t) 238 | + a[2] * np.log(t / 100) 239 | + a[3] * (t / 100) 240 | + s * (b[0] + b[1] * (t / 100) + b[2] * ((t / 100) ** 2)) 241 | ) 242 | 243 | return np.exp(lnC) 244 | 245 | 246 | def satO2(s, t): 247 | """Solubility (saturation) of Oxygen (O2) in sea water. 248 | 249 | Parameters 250 | ---------- 251 | s : array_like 252 | salinity [psu (PSS-78)] 253 | t : array_like 254 | temperature [℃ (ITS-68)] 255 | 256 | Returns 257 | ------- 258 | satO2 : array_like 259 | solubility of O2 [ml l :sup:`-1` ] 260 | 261 | Examples 262 | -------- 263 | >>> # Data from Weiss 1970. 264 | >>> import seawater as sw 265 | >>> from seawater.library import T90conv 266 | >>> t = T90conv([[-1, -1], [10, 10], [20, 20], [40, 40]]) 267 | >>> s = [[20, 40], [20, 40], [20, 40], [20, 40]] 268 | >>> sw.satO2(s, t) 269 | array([[9.162056 , 7.98404249], 270 | [6.95007741, 6.12101928], 271 | [5.64401453, 5.01531004], 272 | [4.0495115 , 3.65575811]]) 273 | 274 | References 275 | ---------- 276 | .. [1] Weiss, R. F. 1970. The Solubility of Nitrogen, Oxygen and Argon in 277 | Water and Seawater Deep-Sea Research Vol. 17, p. 721-735. 278 | doi:10.1016/0011-7471(70)90037-9 279 | 280 | """ 281 | s, t = list(map(np.asanyarray, (s, t))) 282 | 283 | # Convert T to Kelvin. 284 | t = Kelvin + T68conv(t) 285 | 286 | # Constants for Eqn (4) of Weiss 1970. 287 | a = (-173.4292, 249.6339, 143.3483, -21.8492) 288 | b = (-0.033096, 0.014259, -0.0017000) 289 | 290 | # Eqn (4) of Weiss 1970. 291 | lnC = ( 292 | a[0] 293 | + a[1] * (100 / t) 294 | + a[2] * np.log(t / 100) 295 | + a[3] * (t / 100) 296 | + s * (b[0] + b[1] * (t / 100) + b[2] * ((t / 100) ** 2)) 297 | ) 298 | 299 | return np.exp(lnC) 300 | 301 | 302 | def swvel(length, depth): 303 | """Calculates surface wave velocity. 304 | 305 | length : array_like 306 | wave length 307 | depth : array_like 308 | water depth [meters] 309 | 310 | Returns 311 | ------- 312 | speed : array_like 313 | surface wave speed [m s :sup:`-1`] 314 | 315 | Examples 316 | -------- 317 | >>> import seawater as sw 318 | >>> sw.swvel(10, 100) 319 | 3.949327084834294 320 | 321 | """ 322 | length, depth = list(map(np.asanyarray, (length, depth))) 323 | k = 2.0 * np.pi / length 324 | return np.sqrt(gdef * np.tanh(k * depth) / k) 325 | -------------------------------------------------------------------------------- /seawater/geostrophic.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from .constants import db2Pascal, gdef 4 | from .eos80 import dens, dpth, g, pden 5 | from .extras import dist, f 6 | from .library import atleast_2d 7 | 8 | __all__ = [ 9 | "bfrq", 10 | "svan", 11 | "gpan", 12 | "gvel", 13 | ] 14 | 15 | 16 | def bfrq(s, t, p, lat=None): 17 | r"""Calculates Brünt-Väisälä Frequency squared (N :sup:`2`) at the mid 18 | depths from the equation: 19 | 20 | .. math:: 21 | N^{2} = \\frac{-g}{\\sigma_{\\theta}} \\frac{d\\sigma_{\\theta}}{dz} 22 | 23 | Also calculates Potential Vorticity from: 24 | 25 | .. math:: 26 | q = f \\frac{N^2}{g} 27 | 28 | Parameters 29 | ---------- 30 | s(p) : array_like 31 | salinity [psu (PSS-78)] 32 | t(p) : array_like 33 | temperature or potential temperature [℃ (ITS-90)] 34 | p : array_like 35 | pressure [db]. 36 | lat : number or array_like, optional 37 | latitude in decimal degrees north [-90..+90]. 38 | Will grav instead of the default g = 9.8 m :sup:`2` s :sup:`-1`) and 39 | d(z) instead of d(p) 40 | 41 | Returns 42 | ------- 43 | n2 : array_like 44 | Brünt-Väisälä Frequency squared (M-1xN) [rad s :sup:`-2`] 45 | q : array_like 46 | planetary potential vorticity (M-1xN) [ m s :sup:`-1`] 47 | p_ave : array_like 48 | mid pressure between P grid (M-1xN) [db] 49 | 50 | Examples 51 | -------- 52 | >>> import seawater as sw 53 | >>> s = [[0, 0, 0], [15, 15, 15], [30, 30, 30], [35, 35, 35]] 54 | >>> t = [[15] * 3] * 4 55 | >>> p = [[0], [250], [500], [1000]] 56 | >>> lat = [30, 32, 35] 57 | >>> sw.bfrq(s, t, p, lat)[0] 58 | array([[4.51543648e-04, 4.51690708e-04, 4.51920753e-04], 59 | [4.45598092e-04, 4.45743207e-04, 4.45970207e-04], 60 | [7.40996788e-05, 7.41238078e-05, 7.41615525e-05]]) 61 | 62 | References 63 | ---------- 64 | .. [1] A.E. Gill 1982. p.54 Eqn. 3.7.15 "Atmosphere-Ocean Dynamics" 65 | Academic Press: New York. ISBN: 0-12-283522-0 66 | 67 | .. [2] Jackett, David R., Trevor J. Mcdougall, 1995: Minimal Adjustment of 68 | Hydrographic Profiles to Achieve Static Stability. J. Atmos. Oceanic 69 | Technol., 12, 381-389. 70 | doi: 10.1175/1520-0426(1995)012<0381:MAOHPT>2.0.CO;2 71 | 72 | """ 73 | s, t, p = list(map(np.asanyarray, (s, t, p))) 74 | s, t, p = np.broadcast_arrays(s, t, p) 75 | s, t, p = list(map(atleast_2d, (s, t, p))) 76 | 77 | if lat is None: 78 | z, cor, grav = p, np.nan, np.ones(p.shape) * gdef 79 | else: 80 | lat = np.asanyarray(lat) 81 | z = dpth(p, lat) 82 | grav = g(lat, -z) # -z because `grav` expects height as argument. 83 | cor = f(lat) 84 | 85 | p_ave = (p[0:-1, ...] + p[1:, ...]) / 2.0 86 | 87 | pden_up = pden(s[0:-1, ...], t[0:-1, ...], p[0:-1, ...], p_ave) 88 | pden_lo = pden(s[1:, ...], t[1:, ...], p[1:, ...], p_ave) 89 | 90 | mid_pden = (pden_up + pden_lo) / 2.0 91 | dif_pden = pden_up - pden_lo 92 | 93 | mid_g = (grav[0:-1, ...] + grav[1:, ...]) / 2.0 94 | 95 | dif_z = np.diff(z, axis=0) 96 | 97 | n2 = -mid_g * dif_pden / (dif_z * mid_pden) 98 | 99 | q = -cor * dif_pden / (dif_z * mid_pden) 100 | 101 | return n2, q, p_ave 102 | 103 | 104 | def svan(s, t, p=0): 105 | """Specific Volume Anomaly calculated as 106 | svan = 1 / dens(s, t, p) - 1 / dens(35, 0, p). 107 | 108 | Note that it is often quoted in literature as 1e8 * units. 109 | 110 | Parameters 111 | ---------- 112 | s(p) : array_like 113 | salinity [psu (PSS-78)] 114 | t(p) : array_like 115 | temperature [℃ (ITS-90)] 116 | p : array_like 117 | pressure [db]. 118 | 119 | Returns 120 | ------- 121 | svan : array_like 122 | specific volume anomaly [m :sup:`3` kg :sup:`-1`] 123 | 124 | Examples 125 | -------- 126 | >>> # Data from Unesco Tech. Paper in Marine Sci. No. 44, p22. 127 | >>> import seawater as sw 128 | >>> from seawater.library import T90conv 129 | >>> s = [[0, 1, 2], [15, 16, 17], [30, 31, 32], [35, 35, 35]] 130 | >>> t = T90conv([[15] * 3] * 4) 131 | >>> p = [[0], [250], [500], [1000]] 132 | >>> sw.svan(s, t, p) 133 | array([[2.82371949e-05, 2.74626498e-05, 2.66921126e-05], 134 | [1.68453274e-05, 1.60993333e-05, 1.53543515e-05], 135 | [5.80768118e-06, 5.07784980e-06, 4.34876387e-06], 136 | [2.30490099e-06, 2.30490099e-06, 2.30490099e-06]]) 137 | 138 | References 139 | ---------- 140 | .. [1] Fofonoff, P. and Millard, R.C. Jr UNESCO 1983. Algorithms for 141 | computation of fundamental properties of seawater. UNESCO Tech. Pap. in 142 | Mar. Sci., No. 44, 53 pp. Eqn.(31) p.39. 143 | https://unesdoc.unesco.org/ark:/48223/pf0000059832_eng 144 | 145 | .. [2] S. Pond & G.Pickard 2nd Edition 1986 Introductory Dynamical 146 | Oceanography Pergamon Press Sydney. ISBN 0-08-028728-X 147 | 148 | """ 149 | s, t, p = list(map(np.asanyarray, (s, t, p))) 150 | return 1 / dens(s, t, p) - 1 / dens(35, 0, p) 151 | 152 | 153 | def gpan(s, t, p): 154 | """Geopotential Anomaly calculated as the integral of svan from the 155 | the sea surface to the bottom. THUS RELATIVE TO SEA SURFACE. 156 | 157 | Adapted method from Pond and Pickard (p76) to calculate gpan relative to 158 | sea surface whereas Pond and Pickard calculated relative to the deepest 159 | common depth. Note that older literature may use units of "dynamic 160 | decimeter" for above. 161 | 162 | 163 | Parameters 164 | ---------- 165 | s(p) : array_like 166 | salinity [psu (PSS-78)] 167 | t(p) : array_like 168 | temperature [℃ (ITS-90)] 169 | p : array_like 170 | pressure [db]. 171 | 172 | Returns 173 | ------- 174 | gpan : array_like 175 | geopotential anomaly 176 | [m :sup:`3` kg :sup:`-1` 177 | Pa = m :sup:`2` s :sup:`-2` = J kg :sup:`-1`] 178 | 179 | Examples 180 | -------- 181 | >>> # Data from Unesco Tech. Paper in Marine Sci. No. 44, p22. 182 | >>> import seawater as sw 183 | >>> s = [[0, 1, 2], [15, 16, 17], [30, 31, 32], [35, 35, 35]] 184 | >>> t = [[15] * 3] * 4 185 | >>> p = [[0], [250], [500], [1000]] 186 | >>> sw.gpan(s, t, p) 187 | array([[ 0. , 0. , 0. ], 188 | [ 56.35465209, 54.45399428, 52.55961152], 189 | [ 84.67266947, 80.92724333, 77.19028933], 190 | [104.95799186, 99.38799979, 93.82834339]]) 191 | 192 | References 193 | ---------- 194 | .. [1] S. Pond & G.Pickard 2nd Edition 1986 Introductory Dynamical 195 | Oceanography Pergamon Press Sydney. ISBN 0-08-028728-X 196 | 197 | """ 198 | s, t, p = list(map(np.asanyarray, (s, t, p))) 199 | s, t, p = np.broadcast_arrays(s, t, p) 200 | s, t, p = list(map(atleast_2d, (s, t, p))) 201 | 202 | svn = svan(s, t, p) 203 | 204 | # NOTE: Assumes that pressure is the first dimension! 205 | mean_svan = (svn[1:, ...] + svn[0:-1, ...]) / 2.0 206 | top = svn[0, ...] * p[0, ...] * db2Pascal 207 | bottom = (mean_svan * np.diff(p, axis=0)) * db2Pascal 208 | ga = np.concatenate((top[None, ...], bottom), axis=0) 209 | return np.cumsum(ga, axis=0).squeeze() 210 | 211 | 212 | def gvel(ga, lat, lon): 213 | """Calculates geostrophic velocity given the geopotential anomaly and 214 | position of each station. 215 | 216 | Parameters 217 | ---------- 218 | ga : array_like 219 | geopotential anomaly relative to the sea surface. 220 | lat : array_like 221 | latitude of each station (+ve = N, -ve = S) [ -90.. +90] 222 | lon : array_like 223 | longitude of each station (+ve = E, -ve = W) [-180..+180] 224 | 225 | Returns 226 | ------- 227 | vel : array_like 228 | geostrophic velocity relative to the sea surface. 229 | Dimension will be MxN-1 (N: stations) 230 | 231 | Examples 232 | -------- 233 | >>> import numpy as np 234 | >>> import seawater as sw 235 | >>> lon = np.array([-30, -30, -30, -30, -30]) 236 | >>> lat = np.linspace(-22, -21, 5) 237 | >>> t = np.array( 238 | ... [ 239 | ... [0, 0, 0, 0, 0], 240 | ... [10, 10, 10, 10, 10], 241 | ... [20, 20, 20, 20, 20], 242 | ... [30, 30, 30, 30, 30], 243 | ... [40, 40, 40, 40, 40], 244 | ... ] 245 | ... ) 246 | >>> s = np.array( 247 | ... [ 248 | ... [25, 25, 25, 35, 35], 249 | ... [25, 25, 25, 35, 35], 250 | ... [25, 25, 25, 35, 35], 251 | ... [25, 25, 25, 35, 35], 252 | ... [25, 25, 25, 35, 35], 253 | ... ] 254 | ... ) 255 | >>> p = np.array( 256 | ... [ 257 | ... [0, 5000, 10000, 0, 5000], 258 | ... [0, 5000, 10000, 0, 5000], 259 | ... [0, 5000, 10000, 0, 5000], 260 | ... [0, 5000, 10000, 0, 5000], 261 | ... [0, 5000, 10000, 0, 5000], 262 | ... ] 263 | ... ) 264 | >>> ga = sw.gpan(s, t, p) 265 | >>> sw.gvel(ga, lat, lon) 266 | array([[ 231.74785186, 197.54291221, -436.64938045, 0. ], 267 | [ 231.74785186, 197.54291221, -436.64938045, 0. ], 268 | [ 231.74785186, 197.54291221, -436.64938045, 0. ], 269 | [ 231.74785186, 197.54291221, -436.64938045, 0. ], 270 | [ 231.74785186, 197.54291221, -436.64938045, 0. ]]) 271 | 272 | References 273 | ---------- 274 | .. [1] S. Pond & G.Pickard 2nd Edition 1986 Introductory Dynamical 275 | Oceanography Pergamon Press Sydney. ISBN 0-08-028728-X 276 | 277 | """ 278 | ga, lon, lat = list(map(np.asanyarray, (ga, lon, lat))) 279 | distm = dist(lat, lon, units="km")[0] * 1e3 280 | lf = f((lat[0:-1] + lat[1:]) / 2) * distm 281 | return -np.diff(ga, axis=1) / lf 282 | -------------------------------------------------------------------------------- /seawater/tests/data/Endeavor_Cruise-88_Station-61-64-gvel.csv: -------------------------------------------------------------------------------- 1 | # Table 10.4 Computation of Relative Geostrophic Currents. 2 | # Data from Endeavor Cruise 88, Station 61 and 64 3 | "decibar","m^2/s^2","m^2/s^2","m^2/s^2","m^2/s^2","m/s" 4 | "Pressure","10e-5 ΔΦ_61","ΣΔΦ at 61","10e-5 ΔΦ at 64","ΣΔΦ at 64","V" 5 | 0,NaN,2.1872,NaN,1.2583,0.95 6 | 1,0.046,2.1826,0.0510,1.2532,0.95 7 | 10,0.396,2.1430,0.4610,1.2070,0.96 8 | 20,0.423,2.1006,0.5130,1.1557,0.97 9 | 30,0.424,2.0583,0.0466,1.1091,0.97 10 | 50,0.757,1.9830,0.6450,1.0446,0.96 11 | 75,0.755,1.9075,0.4640,0.9982,0.93 12 | 100,0.644,1.8431,0.3400,0.9642,0.90 13 | 125,0.574,1.7857,0.3020,0.9340,0.87 14 | 150,0.522,1.7335,0.2800,0.9060,0.85 15 | 200,0.948,1.6387,0.5010,0.8559,0.80 16 | 250,0.894,1.5493,0.4370,0.8122,0.75 17 | 300,0.871,1.4623,0.3970,0.7725,0.71 18 | 400,1.704,1.2919,0.6670,0.7058,0.60 19 | 500,1.668,1.1252,0.5270,0.6531,0.48 20 | 600,1.588,0.9664,0.4680,0.6063,0.37 21 | 700,1.432,0.8232,0.4470,0.5617,0.27 22 | 800,1.242,0.6990,0.4370,0.5180,0.19 23 | 900,1.045,0.5945,0.4320,0.4748,0.12 24 | 1000,0.808,0.5137,0.4310,0.4317,0.08 25 | 1100,0.619,0.4518,0.4310,0.3886,0.06 26 | 1200,0.546,0.3972,0.4310,0.3454,0.05 27 | 1300,0.517,0.3454,0.4330,0.3022,0.04 28 | 1400,0.504,0.2950,0.4340,0.2588,0.04 29 | 1500,0.497,0.2453,0.4330,0.2155,0.03 30 | 1750,1.232,0.1221,1.0800,0.1075,0.01 31 | 2000,1.221,0.0000,1.0750,0.0000,0.00 32 | 2500,2.389,-0.2389,2.1060,-0.2106,-0.03 33 | 3000,2.297,-0.4686,2.0160,-0.4123,-0.06 34 | 3500,2.170,-0.6856,1.9610,-0.6083,-0.08 35 | 4000,2.097,-0.8952,2.0040,-0.8087,-0.09 36 | -------------------------------------------------------------------------------- /seawater/tests/data/Endeavor_Cruise-88_Station-61.csv: -------------------------------------------------------------------------------- 1 | # http://oceanworld.tamu.edu/resources/ocng_textbook/chapter10/Images/table10-2.htm 2 | # Table 10.2 Computation of Relative Geostrophic Currents. 3 | # Data from Endeavor Cruise 88, Station 61 4 | # (36°40.03’N, 70°59.59’W; 23 August 1982; 1102Z) 5 | "decibar","°C","psu","Kg/m^3","m^3/Kg","m^3/Kg","m^2/s^2" 6 | "Pressure","t","S","σ(θ)","δ(S,t,p)","<δ>","10e-5 ΔΦ" 7 | 0,25.698,35.221,23.296,457.24,NaN,NaN 8 | 1,25.698,35.221,23.296,457.28,457.26,0.046 9 | 10,26.763,36.106,23.658,423.15,440.22,0.396 10 | 20,26.678,36.106,23.658,423.66,423.41,0.423 11 | 30,26.676,36.107,23.659,423.98,423.82,0.424 12 | 50,24.528,36.561,24.670,328.48,376.23,0.752 13 | 75,22.753,36.614,25.236,275.66,302.07,0.755 14 | 100,21.427,36.637,25.630,239.15,257.41,0.644 15 | 125,20.633,36.627,25.841,220.06,229.61,0.574 16 | 150,19.522,36.558,26.086,197.62,208.84,0.522 17 | 200,18.798,36.555,26.273,181.67,189.65,0.948 18 | 250,18.431,36.537,26.354,175.77,178.72,0.894 19 | 300,18.189,36.526,26.408,172.46,174.12,0.871 20 | 400,17.726,36.477,26.489,168.30,170.38,1.704 21 | 500,17.165,36.381,26.557,165.22,166.76,1.668 22 | 600,15.952,36.105,26.714,152.33,158.78,1.588 23 | 700,13.458,35.776,26.914,134.03,143.18,1.432 24 | 800,11.109,35.437,27.115,114.36,124.20,1.242 25 | 900,8.798,35.178,27.306,94.60,104.48,1.045 26 | 1000,6.292,35.044,27.562,67.07,80.84,0.808 27 | 1100,5.249,35.004,27.660,56.70,61.89,0.619 28 | 1200,4.813,34.995,27.705,52.58,54.64,0.546 29 | 1300,4.554,34.986,27.727,50.90,51.74,0.517 30 | 1400,4.357,34.977,27.743,49.89,50.40,0.504 31 | 1500,4.245,34.975,27.753,49.56,49.73,0.497 32 | 1750,4.028,34.973,27.777,49.03,49.30,1.232 33 | 2000,3.852,34.975,27.799,48.62,48.83,1.221 34 | 2500,3.424,34.968,27.839,46.92,47.77,2.389 35 | 3000,2.963,34.946,27.868,44.96,45.94,2.297 36 | 3500,2.462,34.920,27.894,41.84,43.40,2.170 37 | 4000,2.259,34.904,27.001,42.02,41.93,2.097 38 | -------------------------------------------------------------------------------- /seawater/tests/data/Endeavor_Cruise-88_Station-64.csv: -------------------------------------------------------------------------------- 1 | # http://oceanworld.tamu.edu/resources/ocng_textbook/chapter10/Images/table10-3.htm 2 | # Table 10.3 Computation of Relative Geostrophic Currents. 3 | # Data from Endeavor Cruise 88, Station 64 4 | # (37°39.93’N, 71°0.00’W; 24 August 1982; 0203Z) 5 | "decibar","°C","psu","Kg/m^3","m^3/Kg","m^3/Kg","m^2/s^2" 6 | "Pressure","t","S","σ(θ)","δ(S,t,p)","<δ>","10e-5 ΔΦ" 7 | 0,26.148,34.646,22.722,512.09,NaN,NaN 8 | 1,26.148,34.646,22.722,512.21,512.15,0.051 9 | 10,26.163,34.645,22.717,513.01,512.61,0.461 10 | 20,26.167,34.655,22.724,512.76,512.89,0.513 11 | 30,25.640,35.733,23.703,419.82,466.29,0.466 12 | 50,18.967,35.944,25.755,224.93,322.38,0.645 13 | 75,15.371,35.904,26.590,146.19,185.56,0.464 14 | 100,14.356,35.897,26.809,126.16,136.18,0.340 15 | 125,13.059,35.696,26.925,115.66,120.91,0.302 16 | 150,12.134,35.567,27.008,108.20,111.93,0.280 17 | 200,10.307,35.360,27.185,92.17,100.19,0.501 18 | 250,8.783,35.168,27.290,82.64,87.41,0.437 19 | 300,8.046,35.117,27.364,76.16,79.40,0.397 20 | 400,6.235,35.052,27.568,57.19,66.68,0.667 21 | 500,5.230,35.018,27.667,48.23,52.71,0.527 22 | 600,5.005,35.044,27.710,45.29,46.76,0.468 23 | 700,4.756,35.027,27.731,44.04,44.67,0.447 24 | 800,4.399,34.992,27.744,43.33,43.69,0.437 25 | 900,4.291,34.991,27.756,43.11,43.22,0.432 26 | 1000,4.179,34.986,27.764,43.12,43.12,0.431 27 | 1100,4.077,34.982,27.773,43.07,43.10,0.431 28 | 1200,3.969,34.975,27.779,43.17,43.12,0.431 29 | 1300,3.909,34.974,27.786,43.39,43.28,0.433 30 | 1400,3.831,34.973,27.793,43.36,43.38,0.434 31 | 1500,3.767,34.975,27.802,43.26,43.31,0.433 32 | 1750,3.600,34.975,27.821,43.13,43.20,1.080 33 | 2000,3.401,34.968,27.837,42.86,43.00,1.075 34 | 2500,2.942,34.948,27.867,41.39,42.13,2.106 35 | 3000,2.475,34.923,27.891,39.26,40.33,2.016 36 | 3500,2.219,34.904,27.000,39.17,39.22,1.961 37 | 4000,2.177,34.896,27.901,40.98,40.08,2.004 38 | -------------------------------------------------------------------------------- /seawater/tests/data/shapes.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pyoceans/python-seawater/a9e687c51d557b847cf9165d05ffa0093722f202/seawater/tests/data/shapes.npz -------------------------------------------------------------------------------- /seawater/tests/matlab_test.txt: -------------------------------------------------------------------------------- 1 | *********************** 2 | TEST REPORT 3 | 4 | SEA WATER LIBRARY 5 | 6 | SEAWATER Version 3.3 7 | 8 | Matlab Version 8.1.0.604 (R2013a) 9 | 10 | 04-Aug-2013 11 | *********************** 12 | 13 | ************************************* 14 | ** TESTING MODULE: sw_ptmp 15 | ** and SUB-MODULE: sw_adtg.m 16 | ************************************* 17 | 18 | ******************************************************** 19 | Comparison of accepted values from UNESCO 1983 20 | (Unesco Tech. Paper in Marine Sci. No. 44, p45) 21 | with computed results from sw_ptmp on GLNXA64 computer 22 | ******************************************************** 23 | 24 | Sal Temp Press PTMP sw_ptmp 25 | (psu) (C) (db) (C) (C) 26 | 25 0 0 0.0000 0.00000 27 | 25 10 0 10.0000 10.00000 28 | 25 20 0 20.0000 20.00000 29 | 25 30 0 30.0000 30.00000 30 | 25 40 0 40.0000 40.00000 31 | 32 | Sal Temp Press PTMP sw_ptmp 33 | (psu) (C) (db) (C) (C) 34 | 25 0 5000 -0.3061 -0.30614 35 | 25 10 5000 9.3531 9.35306 36 | 25 20 5000 19.0438 19.04376 37 | 25 30 5000 28.7512 28.75125 38 | 25 40 5000 38.4607 38.46068 39 | 40 | Sal Temp Press PTMP sw_ptmp 41 | (psu) (C) (db) (C) (C) 42 | 25 0 10000 -0.9667 -0.96669 43 | 25 10 10000 8.4684 8.46841 44 | 25 20 10000 17.9426 17.94265 45 | 25 30 10000 27.4353 27.43530 46 | 25 40 10000 36.9254 36.92545 47 | 48 | Sal Temp Press PTMP sw_ptmp 49 | (psu) (C) (db) (C) (C) 50 | 35 0 0 0.0000 0.00000 51 | 35 10 0 10.0000 10.00000 52 | 35 20 0 20.0000 20.00000 53 | 35 30 0 30.0000 30.00000 54 | 35 40 0 40.0000 40.00000 55 | 56 | Sal Temp Press PTMP sw_ptmp 57 | (psu) (C) (db) (C) (C) 58 | 35 0 5000 -0.3856 -0.38556 59 | 35 10 5000 9.2906 9.29063 60 | 35 20 5000 18.9985 18.99845 61 | 35 30 5000 28.7231 28.72313 62 | 35 40 5000 38.4498 38.44980 63 | 64 | Sal Temp Press PTMP sw_ptmp 65 | (psu) (C) (db) (C) (C) 66 | 35 0 10000 -1.0974 -1.09741 67 | 35 10 10000 8.3643 8.36426 68 | 35 20 10000 17.8654 17.86536 69 | 35 30 10000 27.3851 27.38506 70 | 35 40 10000 36.9023 36.90232 71 | 72 | ************************************************************************ 73 | ** TESTING MODULE: sw_svan.m 74 | ** and SUB-MODULE: sw_dens.m sw_dens0.m sw_smow.m sw_seck.m sw_pden.m sw_ptmp.m 75 | ************************************************************************ 76 | 77 | ******************************************************** 78 | Comparison of accepted values from UNESCO 1983 79 | (Unesco Tech. Paper in Marine Sci. No. 44, p22) 80 | with computed results from sw_svan.m on GLNXA64 computer 81 | ******************************************************** 82 | 83 | Sal Temp Press SVAN sw_svan 84 | (psu) (C) (db) (1e-8*m3/kg) (1e-8*m3/kg) 85 | 0 0 0 2749.54 2749.539 86 | 0 0 10000 2288.61 2288.610 87 | 0 30 0 3170.58 3170.582 88 | 0 30 10000 3147.85 3147.853 89 | 35 0 0 0.00 0.000 90 | 35 0 10000 0.00 0.000 91 | 35 30 0 607.14 607.142 92 | 35 30 10000 916.34 916.336 93 | 94 | ************************************************************************ 95 | ** TESTING MODULE: sw_salt.m 96 | ** and SUB-MODULE: sw_salrt.m sw_salrp.m sw_sals.m 97 | ************************************************************************ 98 | 99 | ******************************************************** 100 | Comparison of accepted values from UNESCO 1983 101 | (Unesco Tech. Paper in Marine Sci. No. 44, p9) 102 | with computed results from sw_salt.m on GLNXA64 computer 103 | ******************************************************** 104 | 105 | Temp Press R S sw_salt 106 | (C) (db) (no units) (psu) (psu) 107 | 15 0 1.00 35.000000 34.9999999 108 | 20 2000 1.20 37.245628 37.2456276 109 | 5 1500 0.65 27.995347 27.9953469 110 | 111 | ************************************************************************ 112 | ** TESTING MODULE: sw_cndr.m 113 | ** and SUB-MODULE: sw_salds.m 114 | ************************************************************************ 115 | 116 | ******************************************************** 117 | Comparison of accepted values from UNESCO 1983 118 | (Unesco Tech. Paper in Marine Sci. No. 44, p14) 119 | with computed results from sw_cndr.m on GLNXA64 computer 120 | ******************************************************** 121 | 122 | Temp Press S cndr sw_cndr 123 | (C) (db) (psu) (no units) (no units) 124 | 0 0 25.000000 0.498088 0.49800825 125 | 10 0 25.000000 0.654990 0.65499015 126 | 0 1000 25.000000 0.506244 0.50624434 127 | 10 1000 25.000000 0.662975 0.66297496 128 | 10 0 40.000000 1.000073 1.00007311 129 | 30 0 40.000000 1.529967 1.52996697 130 | 131 | ************************************************************************ 132 | ** TESTING MODULE: sw_dpth.m 133 | ************************************************************************ 134 | 135 | ******************************************************** 136 | Comparison of accepted values from Unesco 1983 137 | (Unesco Tech. Paper in Marine Sci. No. 44, p28) 138 | with computed results from sw_dpth.m on GLNXA64 computer 139 | ******************************************************** 140 | 141 | Lat Press DPTH sw_dpth 142 | (degree) (db) (meter) (meter) 143 | 0.000 500 496.65 496.653 144 | 30.000 500 496.00 495.998 145 | 45.000 500 495.34 495.343 146 | 90.000 500 494.03 494.034 147 | 148 | Lat Press DPTH sw_dpth 149 | (degree) (db) (meter) (meter) 150 | 0.000 5000 4915.04 4915.041 151 | 30.000 5000 4908.56 4908.560 152 | 45.000 5000 4902.08 4902.081 153 | 90.000 5000 4889.13 4889.131 154 | 155 | Lat Press DPTH sw_dpth 156 | (degree) (db) (meter) (meter) 157 | 0.000 10000 9725.47 9725.471 158 | 30.000 10000 9712.65 9712.653 159 | 45.000 10000 9699.84 9699.841 160 | 90.000 10000 9674.23 9674.231 161 | 162 | ************************************************************************ 163 | ** TESTING MODULE: sw_fp.m 164 | ************************************************************************ 165 | 166 | ******************************************************** 167 | Comparison of accepted values from UNESCO 1983 168 | (Unesco Tech. Paper in Marine Sci. No. 44, p30) 169 | with computed results from sw_fp.m on GLNXA64 computer 170 | ******************************************************** 171 | 172 | Sal Press fp sw_fp 173 | (psu) (db) (C) (C) 174 | 5 0 -0.274 -0.2737 175 | 10 0 -0.542 -0.5423 176 | 15 0 -0.812 -0.8114 177 | 20 0 -1.083 -1.0829 178 | 25 0 -1.358 -1.3580 179 | 30 0 -1.638 -1.6375 180 | 35 0 -1.922 -1.9218 181 | 40 0 -2.212 -2.2115 182 | 183 | Sal Press fp sw_fp 184 | (psu) (db) (C) (C) 185 | 5 500 -0.650 -0.6501 186 | 10 500 -0.919 -0.9187 187 | 15 500 -1.188 -1.1878 188 | 20 500 -1.460 -1.4594 189 | 25 500 -1.735 -1.7345 190 | 30 500 -2.014 -2.0139 191 | 35 500 -2.299 -2.2982 192 | 40 500 -2.589 -2.5879 193 | 194 | ************************************************************************ 195 | ** TESTING MODULE: sw_cp.m 196 | ************************************************************************ 197 | 198 | ******************************************************** 199 | Comparison of accepted values from UNESCO 1983 200 | (Unesco Tech. Paper in Marine Sci. No. 44, p37) 201 | with computed results from sw_cp.m on GLNXA64 computer 202 | ******************************************************** 203 | 204 | Sal Temp Press Cp sw_cp 205 | (psu) (C) (db) (J/kg.C) (J/kg.C) 206 | 25 0 0 4048.4 4048.44 207 | 25 10 0 4041.8 4041.83 208 | 25 20 0 4044.8 4044.84 209 | 25 30 0 4049.1 4049.10 210 | 25 40 0 4051.2 4051.22 211 | 212 | Sal Temp Press Cp sw_cp 213 | (psu) (C) (db) (J/kg.C) (J/kg.C) 214 | 25 0 5000 3896.3 3896.26 215 | 25 10 5000 3919.6 3919.56 216 | 25 20 5000 3938.6 3938.60 217 | 25 30 5000 3952.0 3952.04 218 | 25 40 5000 3966.1 3966.11 219 | 220 | Sal Temp Press Cp sw_cp 221 | (psu) (C) (db) (J/kg.C) (J/kg.C) 222 | 25 0 10000 3807.7 3807.73 223 | 25 10 10000 3842.3 3842.31 224 | 25 20 10000 3866.7 3866.74 225 | 25 30 10000 3883.0 3882.99 226 | 25 40 10000 3905.9 3905.92 227 | 228 | Sal Temp Press Cp sw_cp 229 | (psu) (C) (db) (J/kg.C) (J/kg.C) 230 | 35 0 0 3986.5 3986.53 231 | 35 10 0 3986.3 3986.34 232 | 35 20 0 3993.9 3993.85 233 | 35 30 0 4000.7 4000.68 234 | 35 40 0 4003.5 4003.46 235 | 236 | Sal Temp Press Cp sw_cp 237 | (psu) (C) (db) (J/kg.C) (J/kg.C) 238 | 35 0 5000 3849.3 3849.26 239 | 35 10 5000 3874.7 3874.73 240 | 35 20 5000 3895.0 3894.99 241 | 35 30 5000 3909.2 3909.24 242 | 35 40 5000 3923.9 3923.89 243 | 244 | Sal Temp Press Cp sw_cp 245 | (psu) (C) (db) (J/kg.C) (J/kg.C) 246 | 35 0 10000 3769.1 3769.12 247 | 35 10 10000 3804.4 3804.42 248 | 35 20 10000 3828.3 3828.29 249 | 35 30 10000 3844.3 3844.32 250 | 35 40 10000 3868.3 3868.29 251 | 252 | ************************************************************************ 253 | ** TESTING MODULE: sw_svel.m 254 | ************************************************************************ 255 | 256 | ******************************************************** 257 | Comparison of accepted values from UNESCO 1983 258 | (Unesco Tech. Paper in Marine Sci. No. 44, p50) 259 | with computed results from sw_svel.m on GLNXA64 computer 260 | ******************************************************** 261 | 262 | Sal Temp Press SVEL sw_svel 263 | (psu) (C) (db) (m/s) (m/s) 264 | 25 0 0 1435.8 1435.790 265 | 25 10 0 1477.7 1477.683 266 | 25 20 0 1510.3 1510.314 267 | 25 30 0 1535.2 1535.214 268 | 25 40 0 1553.4 1553.445 269 | 270 | Sal Temp Press SVEL sw_svel 271 | (psu) (C) (db) (m/s) (m/s) 272 | 25 0 5000 1520.4 1520.359 273 | 25 10 5000 1561.3 1561.306 274 | 25 20 5000 1593.6 1593.597 275 | 25 30 5000 1619.0 1618.956 276 | 25 40 5000 1638.0 1638.025 277 | 278 | Sal Temp Press SVEL sw_svel 279 | (psu) (C) (db) (m/s) (m/s) 280 | 25 0 10000 1610.4 1610.407 281 | 25 10 10000 1647.4 1647.393 282 | 25 20 10000 1676.8 1676.810 283 | 25 30 10000 1700.6 1700.605 284 | 25 40 10000 1719.2 1719.151 285 | 286 | Sal Temp Press SVEL sw_svel 287 | (psu) (C) (db) (m/s) (m/s) 288 | 35 0 0 1449.1 1449.139 289 | 35 10 0 1489.8 1489.822 290 | 35 20 0 1521.5 1521.462 291 | 35 30 0 1545.6 1545.595 292 | 35 40 0 1563.2 1563.209 293 | 294 | Sal Temp Press SVEL sw_svel 295 | (psu) (C) (db) (m/s) (m/s) 296 | 35 0 5000 1534.0 1533.969 297 | 35 10 5000 1573.4 1573.409 298 | 35 20 5000 1604.5 1604.476 299 | 35 30 5000 1629.0 1628.973 300 | 35 40 5000 1647.3 1647.299 301 | 302 | Sal Temp Press SVEL sw_svel 303 | (psu) (C) (db) (m/s) (m/s) 304 | 35 0 10000 1623.2 1623.150 305 | 35 10 10000 1659.0 1658.991 306 | 35 20 10000 1687.2 1687.183 307 | 35 30 10000 1710.1 1710.063 308 | 35 40 10000 1727.8 1727.832 309 | 310 | ********************************************************************** 311 | ** TESTING MODULE: sw_alpha.m sw_beta.m sw_aonb.m 312 | ********************************************************************** 313 | 314 | ******************************************************** 315 | Comparison of accepted values from MCDOUGALL 1987 316 | with computed results on GLNXA64 computer 317 | ******************************************************** 318 | 319 | Sal Temp Press BETA sw_beta 320 | (psu) (C) (db) (psu^-1) (psu^-1) 321 | 40 10 4000 7.2088e-04 7.20877e-04 322 | 323 | Sal Temp Press AONB sw_aonb 324 | (psu) (C) (db) (psu C^-1) (psu C^-1) 325 | 40 10 4000 0.34763 0.347651 326 | 327 | Sal Temp Press ALPHA sw_alpha 328 | (psu) (C) (db) (psu^-1) (psu^-1) 329 | 40 10 4000 2.5060e-04 2.5061e-04 330 | 331 | ************************************* 332 | ** TESTING MODULE: sw_satO2 sw_satN2 sw_satAr 333 | ** and SUB-MODULE: sw_alpha.m sw_beta.m sw_aonb.m 334 | ************************************* 335 | 336 | ******************************************************** 337 | Comparison of accepted values from Weiss, R.F. 1979 338 | "The solubility of nitrogen, oxygen and argon in water and seawater." 339 | Deap-Sea Research., 1970, Vol 17, pp721-735. 340 | with computed results from sw_satO2 sw_satN2 sw_satAr on GLNXA64 computer 341 | ******************************************************** 342 | 343 | Sal Temp O2 sw_satO2 344 | (psu) (C) (ml/l) (ml/l) 345 | 20 -1 9.16 9.162 346 | 20 10 6.95 6.950 347 | 20 20 5.64 5.644 348 | 20 40 4.05 4.050 349 | 350 | Sal Temp O2 sw_satO2 351 | (psu) (C) (ml/l) (ml/l) 352 | 40 -1 7.98 7.984 353 | 40 10 6.12 6.121 354 | 40 20 5.01 5.015 355 | 40 40 3.66 3.656 356 | 357 | Sal Temp N2 sw_satN2 358 | (psu) (C) (ml/l) (ml/l) 359 | 20 -1 16.28 16.280 360 | 20 10 12.64 12.640 361 | 20 20 10.47 10.469 362 | 20 40 7.78 7.782 363 | 364 | Sal Temp N2 sw_satN2 365 | (psu) (C) (ml/l) (ml/l) 366 | 40 -1 14.01 14.008 367 | 40 10 11.01 11.013 368 | 40 20 9.21 9.211 369 | 40 40 6.95 6.954 370 | 371 | Sal Temp Ar sw_satAr 372 | (psu) (C) (ml/l) (ml/l) 373 | 20 -1 0.4456 0.4456 374 | 20 10 0.3397 0.3397 375 | 20 20 0.2766 0.2766 376 | 20 40 0.1986 0.1986 377 | 378 | Sal Temp Ar sw_satAr 379 | (psu) (C) (ml/l) (ml/l) 380 | 40 -1 0.3877 0.3877 381 | 40 10 0.2989 0.2989 382 | 40 20 0.2457 0.2457 383 | 40 40 0.1794 0.1794 384 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/Contents.m: -------------------------------------------------------------------------------- 1 | % SEAWATER Library 2 | % Version 3.3 22-Sep-2010 3 | % 4 | % ******************************* 5 | % * SEAWATER Library * 6 | % * * 7 | % * Version 3.3 * 8 | % * (for Matlab 5.x onwards) * 9 | % * * 10 | % * * 11 | % * Phillip P. Morgan * 12 | % * CSIRO * 13 | % * * 14 | % * Maintained by * 15 | % * Lindsay Pender * 16 | % * CSIRO * 17 | % * * 18 | % * Lindsay.Pender@csiro.au * 19 | % ******************************* 20 | % 21 | % LIST OF ROUTINES: 22 | % 23 | % SW_NEW What's new in this version of seawater. 24 | % 25 | % SW_ADTG Adiabatic temperature gradient 26 | % SW_ALPHA Thermal expansion coefficient (alpha) 27 | % SW_AONB Calculate alpha/beta (a on b) 28 | % SW_BETA Saline contraction coefficient (beta) 29 | % SW_BFRQ Brunt-Vaisala Frequency Squared (N^2) 30 | % SW_COPY Copyright and Licence file 31 | % SW_CP Heat Capacity (Cp) of Sea Water 32 | % SW_DENS Density of sea water 33 | % SW_DENS0 Denisty of sea water at atmospheric pressure 34 | % SW_DIST Distance between two lat, lon coordinates 35 | % SW_DPTH Depth from pressure 36 | % SW_F Coriolis factor "f" 37 | % SW_FP Freezing Point of sea water 38 | % SW_G Gravitational acceleration 39 | % SW_GPAN Geopotential anomaly 40 | % SW_GVEL Geostrophic velocity 41 | % SW_INFO Information on the SEAWATER library. 42 | % SW_PDEN Potential Density 43 | % SW_PRES Pressure from depth 44 | % SW_PTMP Potential temperature 45 | % SW_SALS Salinity of sea water 46 | % SW_SALT Salinity from cndr, T, P 47 | % SW_SATAr Solubility (saturation) of Ar in seawater 48 | % SW_SATN2 Solubility (saturation) of N2 in seawater 49 | % SW_SATO2 Solubility (saturation) of O2 in seawater 50 | % SW_SVAN Specific volume anomaly 51 | % SW_SVEL Sound velocity of sea water 52 | % SW_SWVEL Surface wave velocity 53 | % SW_SMOW Denisty of standard mean ocean water (pure water) 54 | % SW_TEMP Temperature from potential temperature 55 | % SW_TEST Run test suite on library 56 | % SW_VER Version number of SEAWATER library 57 | % 58 | % LOW LEVEL ROUTINES CALLED BY ABOVE: (also available for you to use) 59 | % 60 | % SW_C3515 Conductivity at (35,15,0) 61 | % SW_CNDR Conductivity ratio R = C(S,T,P)/C(35,15,0) 62 | % SW_SALDS Differiential dS/d(sqrt(Rt)) at constant T. 63 | % SW_SALRP Conductivity ratio Rp(S,T,P) = C(S,T,P)/C(S,T,0) 64 | % SW_SALRT Conductivity ratio rt(T) = C(35,T,0)/C(35,15,0) 65 | % SW_SECK Secant bulk modulus (K) of sea water 66 | %======================================================================= 67 | 68 | % Contents.m $Id$ 69 | 70 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_adtg.m: -------------------------------------------------------------------------------- 1 | 2 | function ADTG = sw_adtg(S,T,P) 3 | 4 | % SW_ADTG Adiabatic temperature gradient 5 | %=========================================================================== 6 | % SW_ADTG $Id: sw_adtg.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % adtg = sw_adtg(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Calculates adiabatic temperature gradient as per UNESCO 1983 routines. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % S = salinity [psu (PSS-78) ] 16 | % T = temperature [degree C (ITS-90)] 17 | % P = pressure [db] 18 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 19 | % 20 | % OUTPUT: 21 | % ADTG = adiabatic temperature gradient [degree_C/db] 22 | % 23 | % AUTHOR: Phil Morgan, Lindsay Pender (Lindsay.Pender@csiro.au) 24 | % 25 | % DISCLAIMER: 26 | % This software is provided "as is" without warranty of any kind. 27 | % See the file sw_copy.m for conditions of use and licence. 28 | % 29 | % REFERENCES: 30 | % Fofonoff, P. and Millard, R.C. Jr 31 | % Unesco 1983. Algorithms for computation of fundamental properties of 32 | % seawater. Unesco Tech. Pap. in Mar. Sci., No. 44, 53 pp. Eqn.(31) p.39 33 | % 34 | % Bryden, H. 1973. 35 | % "New Polynomials for thermal expansion, adiabatic temperature gradient 36 | % and potential temperature of sea water." 37 | % DEEP-SEA RES., 1973, Vol20,401-408. 38 | %========================================================================= 39 | 40 | % Modifications 41 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 42 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 43 | 44 | %------------- 45 | % CHECK INPUTS 46 | %------------- 47 | if nargin ~= 3 48 | error('sw_adtg.m: Must pass 3 parameters ') 49 | end %if 50 | 51 | % CHECK S,T,P dimensions and verify consistent 52 | [ms,ns] = size(S); 53 | [mt,nt] = size(T); 54 | [mp,np] = size(P); 55 | 56 | 57 | % CHECK THAT S & T HAVE SAME SHAPE 58 | if (ms~=mt) | (ns~=nt) 59 | error('check_stp: S & T must have same dimensions') 60 | end %if 61 | 62 | % CHECK OPTIONAL SHAPES FOR P 63 | if mp==1 & np==1 % P is a scalar. Fill to size of S 64 | P = P(1)*ones(ms,ns); 65 | elseif np==ns & mp==1 % P is row vector with same cols as S 66 | P = P( ones(1,ms), : ); % Copy down each column. 67 | elseif mp==ms & np==1 % P is column vector 68 | P = P( :, ones(1,ns) ); % Copy across each row 69 | elseif mp==ms & np==ns % PR is a matrix size(S) 70 | % shape ok 71 | else 72 | error('check_stp: P has wrong dimensions') 73 | end %if 74 | 75 | %***check_stp 76 | 77 | %------------- 78 | % BEGIN 79 | %------------- 80 | 81 | T68 = 1.00024 * T; 82 | 83 | a0 = 3.5803E-5; 84 | a1 = +8.5258E-6; 85 | a2 = -6.836E-8; 86 | a3 = 6.6228E-10; 87 | 88 | b0 = +1.8932E-6; 89 | b1 = -4.2393E-8; 90 | 91 | c0 = +1.8741E-8; 92 | c1 = -6.7795E-10; 93 | c2 = +8.733E-12; 94 | c3 = -5.4481E-14; 95 | 96 | d0 = -1.1351E-10; 97 | d1 = 2.7759E-12; 98 | 99 | e0 = -4.6206E-13; 100 | e1 = +1.8676E-14; 101 | e2 = -2.1687E-16; 102 | 103 | ADTG = a0 + (a1 + (a2 + a3.*T68).*T68).*T68 ... 104 | + (b0 + b1.*T68).*(S-35) ... 105 | + ( (c0 + (c1 + (c2 + c3.*T68).*T68).*T68) ... 106 | + (d0 + d1.*T68).*(S-35) ).*P ... 107 | + ( e0 + (e1 + e2.*T68).*T68 ).*P.*P; 108 | 109 | return 110 | %========================================================================== 111 | 112 | 113 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_alpha.m: -------------------------------------------------------------------------------- 1 | 2 | function [ALPHA] = sw_alpha(S, T, P, keyword) 3 | 4 | % SW_ALPHA Thermal expansion coefficient (alpha) 5 | %================================================================ 6 | % SW_ALPHA $Id: sw_alpha.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Nathan Bindoff 1993. 8 | % 9 | % USAGE: [ALPHA] = alpha(S, T, P, keyword) 10 | % 11 | % [ALPHA] = alpha(S, T, P, 'temp') %default 12 | % [ALPHA] = alpha(S, PTMP, P, 'ptmp') 13 | % 14 | % DESCRIPTION: 15 | % A function to calculate the thermal expansion coefficient. 16 | % 17 | % INPUT: 18 | % S = salinity [psu (PSS-78) ] 19 | % * PTMP = potential temperature [degree C (ITS-90)] 20 | % * T = temperature [degree C (ITS-90)] 21 | % P = pressure [db] 22 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 23 | % 24 | % keyword = optional string to identify if temp or ptmp passed. 25 | % = No argument defaults to 'temp' 26 | % = 'temp' assumes (S,T,P) passed. Will execute slower 27 | % as ptmp will be calculated internally. 28 | % = 'ptmp' assumes (S,PTMP,P) passed. Will execute faster. 29 | % 30 | % OUTPUT: 31 | % ALPHA = Thermal expansion coeff (alpha) [degree_C.^-1] 32 | % 33 | % AUTHOR: N.L. Bindoff 1993, Lindsay Pender (Lindsay.Pender@csiro.au) 34 | % 35 | % DISCLAIMER: 36 | % This software is provided "as is" without warranty of any kind. 37 | % See the file sw_copy.m for conditions of use and licence. 38 | % 39 | % REFERENCE: 40 | % McDougall, T.J. 1987. "Neutral Surfaces" 41 | % Journal of Physical Oceanography vol 17 pages 1950-1964, 42 | % 43 | % CHECK VALUE: 44 | % See sw_beta.m amd sw_aonb.m 45 | %================================================================ 46 | 47 | % Modifications 48 | % 93-04-22. Phil Morgan, Help display modified to suit library 49 | % 93-04-23. Phil Morgan, Input argument checking 50 | % 94-10-15. Phil Morgan, Pass S,T,P and keyword for 'ptmp' 51 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 52 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 53 | 54 | % CHECK INPUT ARGUMENTS 55 | if ~(nargin==3 | nargin==4) 56 | error('sw_alpha.m: requires 3 or 4 input arguments') 57 | end %if 58 | if nargin == 3 59 | keyword = 'temp'; 60 | end %if 61 | 62 | % CHECK S,T,P dimensions and verify consistent 63 | [ms,ns] = size(S); 64 | [mt,nt] = size(T); 65 | [mp,np] = size(P); 66 | 67 | 68 | % CHECK THAT S & T HAVE SAME SHAPE 69 | if (ms~=mt) | (ns~=nt) 70 | error('check_stp: S & T must have same dimensions') 71 | end %if 72 | 73 | % CHECK OPTIONAL SHAPES FOR P 74 | if mp==1 & np==1 % P is a scalar. Fill to size of S 75 | P = P(1)*ones(ms,ns); 76 | elseif np==ns & mp==1 % P is row vector with same cols as S 77 | P = P( ones(1,ms), : ); % Copy down each column. 78 | elseif mp==ms & np==1 % P is column vector 79 | P = P( :, ones(1,ns) ); % Copy across each row 80 | elseif mp==ms & np==ns % PR is a matrix size(S) 81 | % shape ok 82 | else 83 | error('check_stp: P has wrong dimensions') 84 | end %if 85 | 86 | %***check_stp 87 | 88 | % BEGIN 89 | 90 | ALPHA = sw_aonb(S,T,P,keyword).*sw_beta(S,T,P,keyword); 91 | 92 | return 93 | %------------------------------------------------------------------------ 94 | 95 | 96 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_aonb.m: -------------------------------------------------------------------------------- 1 | 2 | function [AONB]= aonb(S, T, P, keyword) 3 | 4 | % SW_AONB Calculate alpha/beta (a on b) 5 | %================================================================ 6 | % SW_AONB $Revision: 1.1 $ $Date: 2003/12/12 04:23:22 $ 7 | % Copyright (C) CSIRO, Nathan Bindoff 1993 8 | % 9 | % USAGE: [AONB] = aonb(S, T, P, {keyword} ) 10 | % 11 | % [AONB] = aonb(S, T, P, 'temp' ) %default 12 | % [AONB] = aonb(S, PTMP, P, 'ptmp' ) 13 | % 14 | % DESCRIPTION 15 | % Calculate alpha/beta. See sw_alpha.m and sw_beta.m 16 | % 17 | % INPUT: (all must have same dimensions) 18 | % S = salinity [psu (PSS-78) ] 19 | % * PTMP = potential temperature [degree C (ITS-90)] 20 | % * T = temperature [degree C (ITS-90)] 21 | % P = pressure [db] 22 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 23 | % 24 | % keyword = optional string to identify if temp or ptmp passed. 25 | % = No argument defaults to 'temp' 26 | % = 'temp' assumes (S,T,P) passed. Will execute slower 27 | % as ptmp will be calculated internally. 28 | % = 'ptmp' assumes (S,PTMP,P) passed. Will execute faster. 29 | % 30 | % OUTPUT 31 | % AONB = alpha/beta [psu/degree_C] 32 | % 33 | % AUTHOR: N.L. Bindoff 1993, Lindsay Pender (Lindsay.Pender@csiro.au) 34 | % 35 | % DISCLAIMER: 36 | % This software is provided "as is" without warranty of any kind. 37 | % See the file sw_copy.m for conditions of use and licence. 38 | % 39 | % REFERENCE: 40 | % McDougall, T.J. 1987. "Neutral Surfaces" 41 | % Journal of Physical Oceanography vol 17 pages 1950-1964, 42 | % 43 | % CHECK VALUE: 44 | % aonb=0.34763 psu C^-1 at S=40.0 psu, ptmp=10.0 C, p=4000 db 45 | %================================================================ 46 | 47 | % Modifications 48 | % 93-04-22. Phil Morgan, Help display modified to suit library 49 | % 93-04-23. Phil Morgan, Input argument checking 50 | % 94-10-15. Phil Morgan, Pass S,T,P and keyword for 'ptmp' 51 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 52 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 53 | 54 | % CHECK INPUT ARGUMENTS 55 | if ~(nargin==3 | nargin==4) 56 | error('sw_aonb.m: requires 3 input arguments') 57 | end %if 58 | if nargin == 3 59 | keyword = 'temp'; 60 | end %if 61 | 62 | % CHECK S,T,P dimensions and verify consistent 63 | [ms,ns] = size(S); 64 | [mt,nt] = size(T); 65 | [mp,np] = size(P); 66 | 67 | 68 | % CHECK THAT S & T HAVE SAME SHAPE 69 | if (ms~=mt) | (ns~=nt) 70 | error('check_stp: S & T must have same dimensions') 71 | end %if 72 | 73 | % CHECK OPTIONAL SHAPES FOR P 74 | if mp==1 & np==1 % P is a scalar. Fill to size of S 75 | P = P(1)*ones(ms,ns); 76 | elseif np==ns & mp==1 % P is row vector with same cols as S 77 | P = P( ones(1,ms), : ); % Copy down each column. 78 | elseif mp==ms & np==1 % P is column vector 79 | P = P( :, ones(1,ns) ); % Copy across each row 80 | elseif mp==ms & np==ns % PR is a matrix size(S) 81 | % shape ok 82 | else 83 | error('check_stp: P has wrong dimensions') 84 | end %if 85 | 86 | %***check_stp 87 | 88 | % ENSURE WE USE PTMP IN CALCULATIONS 89 | if ~strcmp(lower(keyword),'ptmp') 90 | T = sw_ptmp(S,T,P,0); % now have ptmp 91 | end %if 92 | 93 | T = T * 1.00024; 94 | 95 | % BEGIN 96 | c1=fliplr([ 0.665157e-1, 0.170907e-1, ... 97 | -0.203814e-3, 0.298357e-5, ... 98 | -0.255019e-7]); 99 | c2=fliplr([ 0.378110e-2, ... 100 | -0.846960e-4]); 101 | c2a=fliplr([0.0 -0.164759e-6, ... 102 | -0.251520e-11]); 103 | c3=[-0.678662e-5]; 104 | c4=fliplr([+0.380374e-4, -0.933746e-6, ... 105 | +0.791325e-8]); 106 | c5=[0.512857e-12]; 107 | c6=[-0.302285e-13]; 108 | % 109 | % Now calaculate the thermal expansion saline contraction ratio adb 110 | % 111 | [m,n] = size(S); 112 | sm35 = S-35.0*ones(m,n); 113 | AONB = polyval(c1,T) + sm35.*(polyval(c2,T)... 114 | + polyval(c2a,P)) ... 115 | + sm35.^2*c3 + P.*polyval(c4,T) ... 116 | + c5*(P.^2).*(T.^2) + c6*P.^3; 117 | 118 | return 119 | %---------------------------------------------------------------------- 120 | 121 | 122 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_beta.m: -------------------------------------------------------------------------------- 1 | 2 | function [BETA] = sw_beta(S, T, P, keyword) 3 | 4 | % SW_BETA Saline contraction coefficient (beta) 5 | %======================================================================== 6 | % SW_BETA $Id: sw_beta.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % % Copyright (C) CSIRO, Nathan Bindoff 1993. 8 | % 9 | % USAGE: [BETA] = sw_beta(S, T, P, {keyword} ) 10 | % 11 | % [BETA] = sw_beta(S, T, P, 'temp') %default 12 | % [BETA] = sw_beta(S, PTMP, P, 'ptmp') 13 | % 14 | % DESCRIPTION 15 | % The saline contraction coefficient as defined by T.J. McDougall. 16 | % 17 | % INPUT: (all must have same dimensions) 18 | % S = salinity [psu (PSS-78) ] 19 | % * PTMP = potential temperature [degree C (ITS-90)] 20 | % * T = temperature [degree C (ITS-90)] 21 | % P = pressure [db] 22 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 23 | % 24 | % keyword = optional string to identify if temp or ptmp passed. 25 | % = No argument defaults to 'temp' 26 | % = 'temp' assumes (S,T,P) passed. Will execute slower 27 | % as ptmp will be calculated internally. 28 | % = 'ptmp' assumes (S,PTMP,P) passed. Will execute faster. 29 | % 30 | % OUTPUT 31 | % BETA = Saline Contraction Coefficient [psu.^-1] 32 | % 33 | % AUTHOR: N.L. Bindoff 1993, Lindsay Pender (Lindsay.pender@csiro.au) 34 | % 35 | % DISCLAIMER: 36 | % This software is provided "as is" without warranty of any kind. 37 | % See the file sw_copy.m for conditions of use and licence. 38 | % 39 | % REFERENCE: 40 | % McDougall, T.J. 1987. "Neutral Surfaces" 41 | % Journal of Physical Oceanography vol 17 pages 1950-1964, 42 | % 43 | % CHECK VALUE: 44 | % beta=0.72088e-3 psu.^-1 at S=40.0 psu, ptmp = 10.0 C (ITS-68), p=4000 db 45 | %======================================================================== 46 | 47 | % Modifications 48 | % 93-04-22. Phil Morgan, Help display modified to suit library 49 | % 93-04-23. Phil Morgan, Input argument checking 50 | % 94-10-15. Phil Morgan, Pass S,T,P and keyword for 'ptmp' 51 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 52 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 53 | 54 | % CHECK INPUT ARGUMENTS 55 | if ~(nargin==3 | nargin==4) 56 | error('sw_beta.m: requires 3 or 4 input arguments') 57 | end %if 58 | if nargin == 3 59 | keyword = 'temp'; 60 | end %if 61 | 62 | % CHECK S,T,P dimensions and verify consistent 63 | [ms,ns] = size(S); 64 | [mt,nt] = size(T); 65 | [mp,np] = size(P); 66 | 67 | 68 | % CHECK THAT S & T HAVE SAME SHAPE 69 | if (ms~=mt) | (ns~=nt) 70 | error('check_stp: S & T must have same dimensions') 71 | end %if 72 | 73 | % CHECK OPTIONAL SHAPES FOR P 74 | if mp==1 & np==1 % P is a scalar. Fill to size of S 75 | P = P(1)*ones(ms,ns); 76 | elseif np==ns & mp==1 % P is row vector with same cols as S 77 | P = P( ones(1,ms), : ); % Copy down each column. 78 | elseif mp==ms & np==1 % P is column vector 79 | P = P( :, ones(1,ns) ); % Copy across each row 80 | elseif mp==ms & np==ns % PR is a matrix size(S) 81 | % shape ok 82 | else 83 | error('check_stp: P has wrong dimensions') 84 | end %if 85 | 86 | %***check_stp 87 | 88 | % ENSURE WE USE PTMP IN CALCULATIONS 89 | if ~strcmp(lower(keyword),'ptmp') 90 | T = sw_ptmp(S,T,P,0); % now have ptmp 91 | end %if 92 | 93 | T = T * 1.00024; 94 | 95 | % BEGIN 96 | 97 | c1=fliplr([ 0.785567e-3, -0.301985e-5 ... 98 | 0.555579e-7, -0.415613e-9]); 99 | c2=fliplr([ -0.356603e-6, 0.788212e-8]); 100 | c3=fliplr([0.0 0.408195e-10, -0.602281e-15]); 101 | c4=[0.515032e-8]; 102 | c5=fliplr([-0.121555e-7, 0.192867e-9, -0.213127e-11]); 103 | c6=fliplr([0.176621e-12 -0.175379e-14]); 104 | c7=[0.121551e-17]; 105 | % 106 | % Now calaculate the thermal expansion saline contraction ratio adb 107 | % 108 | [m,n] = size(S); 109 | sm35 = S-35*ones(m,n); 110 | BETA = polyval(c1,T) + sm35.*(polyval(c2,T) + ... 111 | polyval(c3,P)) + c4*(sm35.^2) + ... 112 | P.*polyval(c5,T) + (P.^2).*polyval(c6,T) ... 113 | +c7*( P.^3); 114 | 115 | return 116 | %------------------------------------------------------------------------ 117 | 118 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_bfrq.m: -------------------------------------------------------------------------------- 1 | 2 | function [n2,q,p_ave] = sw_bfrq(S,T,P,LAT) 3 | 4 | % SW_BFRQ Brunt-Vaisala Frequency Squared (N^2) 5 | %=========================================================================== 6 | % SW_BFRQ $Id: sw_bfrq.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: [bfrq,vort,p_ave] = sw_bfrq(S,T,P,{LAT}) 10 | % 11 | % DESCRIPTION: 12 | % Calculates Brunt-Vaisala Frequency squared (N^2) at the mid depths 13 | % from the equation, 14 | % 15 | % -g d(pdens) 16 | % N2 = ----- x -------- 17 | % pdens d(z) 18 | % 19 | % Also returns Potential Vorticity from q = f*N2/g. 20 | % 21 | % INPUT: (all must have same dimensions MxN) 22 | % S = salinity [psu (PSS-78) ] 23 | % T = temperature [degree C (ITS-90)] 24 | % P = pressure [db] 25 | % 26 | % OPTIONAL: 27 | % LAT = Latitude in decimal degrees north [-90..+90] 28 | % May have dimensions 1x1 or 1xN where S(MxN). 29 | % (Will use sw_g instead of the default g=9.8 m^2/s) 30 | % (Will also calc d(z) instead of d(p) in numerator) 31 | % OUTPUT: 32 | % bfrq = Brunt-Vaisala Frequency squared (M-1xN) [s^-2] 33 | % vort = Planetary Potential Vorticity (M-1xN) [(ms)^-1] 34 | % (if isempty(LAT) vort=NaN ) 35 | % p_ave = Mid pressure between P grid (M-1xN) [db] 36 | % 37 | % AUTHOR: Phil Morgan 93-06-24, Lindsay Pender (Lindsay.Pender@csiro.au) 38 | % 39 | % DISCLAIMER: 40 | % This software is provided "as is" without warranty of any kind. 41 | % See the file sw_copy.m for conditions of use and licence. 42 | % 43 | % REFERENCES: 44 | % A.E. Gill 1982. p.54 eqn 3.7.15 45 | % "Atmosphere-Ocean Dynamics" 46 | % Academic Press: New York. ISBN: 0-12-283522-0 47 | % 48 | % Jackett, D.R. and McDougall, T.J. 1994. 49 | % Minimal adjustment of hydrographic properties to achieve static 50 | % stability. submitted J.Atmos.Ocean.Tech. 51 | % 52 | % Greg Johnson (gjohnson@pmel.noaa.gov) 53 | % added potential vorticity calcuation 54 | %========================================================================= 55 | 56 | % Modifications 57 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 58 | % 06-04-19. Lindsay Pender, Corrected sign of PV. 59 | 60 | % CALLER: general purpose 61 | % CALLEE: sw_dens.m sw_pden.m 62 | 63 | %$Id: sw_bfrq.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 64 | 65 | %------------- 66 | % Check Inputs 67 | %------------- 68 | 69 | error(nargchk(3, 4, nargin)); 70 | 71 | if nargin == 3 72 | LAT = []; 73 | end 74 | 75 | % Get S,T,P dimensions and check consistency 76 | 77 | [ms,ns] = size(S); 78 | [mt,nt] = size(T); 79 | [mp,np] = size(P); 80 | 81 | % Check S, T P and have the same shape 82 | 83 | if (ms~=mt) | (ns~=nt) | (np~=np) 84 | error('S, T & P must have same dimensions') 85 | end 86 | 87 | % Check S and T have length at least of 2 88 | 89 | if (ms * ns == 1) 90 | error('Length of T, S and P must be at least 2') 91 | end 92 | 93 | % If S, T and P are row vectors - transpose 94 | 95 | if ms == 1 96 | S = S'; 97 | T = T'; 98 | P = P'; 99 | transpose = 1; 100 | else 101 | transpose = 0; 102 | end 103 | 104 | % If lat passed then verify dimensions 105 | 106 | if ~isempty(LAT) 107 | [mL,nL] = size(LAT); 108 | if mL==1 & nL==1 109 | LAT = LAT*ones(size(S)); 110 | else 111 | if (ms~=mL) | (ns~=nL) % S & LAT are not the same shape 112 | if (ns==nL) & (mL==1) % copy LATS down each column 113 | LAT = LAT( ones(1,ms), : ); % s.t. dim(S)==dim(LAT) 114 | else 115 | error('Inputs arguments have wrong dimensions') 116 | end 117 | end 118 | end 119 | end 120 | 121 | %------ 122 | % Begin 123 | %------ 124 | 125 | if ~isempty(LAT) 126 | % note that sw_g expects height as argument 127 | Z = sw_dpth(P,LAT); 128 | g = sw_g(LAT,-Z); 129 | f = sw_f(LAT); 130 | else 131 | Z = P; 132 | g = 9.8*ones(size(P)); 133 | f = NaN*ones(size(P)); 134 | end %if 135 | 136 | [m,n] = size(P); 137 | iup = 1:m-1; 138 | ilo = 2:m; 139 | p_ave = (P(iup,:)+P(ilo,:) )/2; 140 | pden_up = sw_pden(S(iup,:),T(iup,:),P(iup,:),p_ave); 141 | pden_lo = sw_pden(S(ilo,:),T(ilo,:),P(ilo,:),p_ave); 142 | 143 | mid_pden = (pden_up + pden_lo )/2; 144 | dif_pden = pden_up - pden_lo; 145 | mid_g = (g(iup,:)+g(ilo,:))/2; 146 | dif_z = diff(Z); 147 | n2 = -mid_g .* dif_pden ./ (dif_z .* mid_pden); 148 | 149 | mid_f = f(iup,:); 150 | q = -mid_f .* dif_pden ./ (dif_z .* mid_pden); 151 | 152 | if transpose 153 | n2 = n2'; 154 | q = q'; 155 | p_ave = p_ave'; 156 | end 157 | 158 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_c3515.m: -------------------------------------------------------------------------------- 1 | 2 | function c3515 = sw_c3515() 3 | 4 | % SW_C3515 Conductivity at (35,15,0) 5 | %========================================================================= 6 | % SW_c3515 $Id: sw_c3515.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: c3515 = sw_c3515 10 | % 11 | % DESCRIPTION: 12 | % Returns conductivity at S=35 psu , T=15 C [ITPS 68] and P=0 db). 13 | % 14 | % INPUT: (none) 15 | % 16 | % OUTPUT: 17 | % c3515 = Conductivity [mmho/cm == mS/cm] 18 | % 19 | % AUTHOR: Phil Morgan 93-04-17 (morgan@ml.csiro.au) 20 | % 21 | % DISCLAIMER: 22 | % This software is provided "as is" without warranty of any kind. 23 | % See the file sw_copy.m for conditions of use and licence. 24 | % 25 | % REFERENCES: 26 | % R.C. Millard and K. Yang 1992. 27 | % "CTD Calibration and Processing Methods used by Woods Hole 28 | % Oceanographic Institution" Draft April 14, 1992 29 | % (Personal communication) 30 | %========================================================================= 31 | 32 | % CALLER: none 33 | % CALLEE: none 34 | % 35 | 36 | c3515 = 42.914; 37 | 38 | return 39 | %------------------------------------------------------------------------- 40 | 41 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_cndr.m: -------------------------------------------------------------------------------- 1 | 2 | function R = sw_cndr(S,T,P) 3 | 4 | % SW_CNDR Conductivity ratio R = C(S,T,P)/C(35,15(IPTS-68),0) 5 | %========================================================================= 6 | % SW_CNDR $Id: sw_cndr.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: cndr = sw_cndr(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Calculates conductivity ratio from S,T,P. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % S = salinity [psu (PSS-78) ] 16 | % T = temperature [degree C (ITS-90)] 17 | % P = pressure [db] 18 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 19 | % 20 | % OUTPUT: 21 | % cndr = Conductivity ratio R = C(S,T,P)/C(35,15(IPTS-68),0) [no units] 22 | % 23 | % AUTHOR: Phil Morgan 93-04-21, Lindsay Pender (Lindsay.Pender@csiro.au) 24 | % 25 | % DISCLAIMER: 26 | % This software is provided "as is" without warranty of any kind. 27 | % See the file sw_copy.m for conditions of use and licence. 28 | % 29 | % REFERENCES: 30 | % Fofonoff, P. and Millard, R.C. Jr 31 | % Unesco 1983. Algorithms for computation of fundamental properties of 32 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 33 | %========================================================================= 34 | 35 | % Modifications 36 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 37 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 38 | % 20-09-20. Lindsay Pender, Fixed inconsistency in use of ITS-90 and 39 | % increase convergence precision from 1e-4 to 1e-10. 40 | 41 | % CALLER: general purpose 42 | % CALLEE: sw_salds.m sw_sals.m sw_salrt.m 43 | 44 | %-------------- 45 | % check inputs 46 | %------------- 47 | if nargin~=3 48 | error('sw_cndr.m: must have 3 input arguments') 49 | end %if 50 | 51 | % CHECK S,T,P dimensions and verify consistent 52 | [ms,ns] = size(S); 53 | [mt,nt] = size(T); 54 | [mp,np] = size(P); 55 | 56 | 57 | % CHECK THAT S & T HAVE SAME SHAPE 58 | if (ms~=mt) | (ns~=nt) 59 | error('check_stp: S & T must have same dimensions') 60 | end %if 61 | 62 | % CHECK OPTIONAL SHAPES FOR P 63 | if mp==1 & np==1 % P is a scalar. Fill to size of S 64 | P = P(1)*ones(ms,ns); 65 | elseif np==ns & mp==1 % P is row vector with same cols as S 66 | P = P( ones(1,ms), : ); % Copy down each column. 67 | elseif mp==ms & np==1 % P is column vector 68 | P = P( :, ones(1,ns) ); % Copy across each row 69 | elseif mp==ms & np==ns % PR is a matrix size(S) 70 | % shape ok 71 | else 72 | error('check_stp: P has wrong dimensions') 73 | end %if 74 | 75 | %***check_stp 76 | 77 | %------- 78 | % BEGIN 79 | %------- 80 | 81 | T68 = T * 1.00024; 82 | 83 | for i = 1:ms 84 | for j = 1:ns 85 | %--------------------------------------------------------------------- 86 | % DO A NEWTON-RAPHSON ITERATION FOR INVERSE INTERPOLATION OF Rt FROM S. 87 | %--------------------------------------------------------------------- 88 | S_loop = S(i,j); % S in the loop 89 | T_loop = T(i,j); % T in the loop 90 | Rx_loop = sqrt(S_loop/35.0); % first guess at Rx = sqrt(Rt) 91 | SInc = sw_sals(Rx_loop.*Rx_loop,T_loop); % S INCrement (guess) from Rx 92 | iloop = 0; 93 | end_loop = 0; 94 | while ~end_loop 95 | Rx_loop = Rx_loop + (S_loop - SInc)./... 96 | sw_salds(Rx_loop,T_loop/1.00024 - 15); 97 | 98 | SInc = sw_sals(Rx_loop.*Rx_loop,T_loop); 99 | iloop = iloop + 1; 100 | dels = abs(SInc-S_loop); 101 | if (dels>1.0e-10 & iloop<100) 102 | end_loop = 0; 103 | else 104 | end_loop = 1; 105 | end %if 106 | end %while 107 | 108 | Rx(i,j) = Rx_loop; 109 | 110 | end %for j 111 | end %for i 112 | 113 | %------------------------------------------------------ 114 | % ONCE Rt FOUND, CORRESPONDING TO EACH (S,T) EVALUATE R 115 | %------------------------------------------------------ 116 | % eqn(4) p.8 Unesco 1983 117 | 118 | d1 = 3.426e-2; 119 | d2 = 4.464e-4; 120 | d3 = 4.215e-1; 121 | d4 = -3.107e-3; 122 | 123 | e1 = 2.070e-5; 124 | e2 = -6.370e-10; 125 | e3 = 3.989e-15; 126 | 127 | A = (d3 + d4.*T68); 128 | B = 1 + d1.*T68 + d2.*T68.^2; 129 | C = P.*(e1 + e2.*P + e3.*P.^2); 130 | 131 | % eqn(6) p.9 UNESCO 1983. 132 | Rt = Rx.*Rx; 133 | rt = sw_salrt(T); 134 | Rtrt = rt.*Rt; 135 | D = B - A.*rt.*Rt; 136 | E = rt.*Rt.*A.*(B+C); 137 | R = sqrt(abs(D.^2+4*E)) - D; 138 | R = 0.5*R./A; 139 | 140 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_copy.m: -------------------------------------------------------------------------------- 1 | % SW_COPY Copyright and licence information on SEAWATER library. 2 | % ================================================================= 3 | % SW_COPY $Id: sw_copy.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 4 | % Copyright (C) Phil Morgan 1993 5 | % 6 | % SOFTWARE LICENCE AGREEMENT 7 | % 8 | % 1.0 Grant of Licence 9 | % 10 | % 1.1 The CSIRO Division of Oceanography (herein referred to as 11 | % "CSIRO") hereby grants you (hereinafter referred to as 12 | % the "Licencee"), subject to the Licencee agreeing to 13 | % comply with the terms and conditions of this Agreement, a 14 | % non-transferable, non-exclusive licence to use the 15 | % computer programs described in this document (hereinafter 16 | % referred to as the "Software") for the purpose of 17 | % the Licencee's computing activity. 18 | % 19 | % 1.2 CSIRO hereby grants the Licencee the right to make copies 20 | % of the Software for the purpose of the Licencee's 21 | % computing activity only. 22 | % 23 | % 1.3 The benefit of the rights granted to the Licencee by the 24 | % Licence and this Agreement generally shall be personal to 25 | % the Licencee and the Licencee shall not mortgage, charge, 26 | % assign, rent, lease, sell or otherwise dispose of or 27 | % transfer the same or any part to any third party. 28 | % 29 | % 1.4 Unless otherwise agreed in writing or provided for in 30 | % this Agreement, CSIRO shall be under no obligation or 31 | % responsibility to provide the Licencee with any training, 32 | % maintenance services, enhancements or updates of the 33 | % Software or any services whatsoever. 34 | % 35 | % 2.0 Acknowledgment by the Licencee 36 | % 37 | % 2.1 The Licencee acknowledges and agrees that it shall not: 38 | % 39 | % (i) sell, let for hire or by way of trade, offer or 40 | % exhibit or expose for sale or hire or otherwise 41 | % distribute the Software for the purposes of trade or 42 | % any other purpose; 43 | % 44 | % (ii) authorise or assist any third person to do any 45 | % of the acts set out in (i) above; 46 | % 47 | % (iii) modify the Software source code without advising 48 | % CSIRO. 49 | % 50 | % 2.2 The Licencee agrees that: 51 | % 52 | % (a) CSIRO is the owner of all copyright and other 53 | % Intellectual Property Rights subsisting in the 54 | % Software; 55 | % 56 | % (b) this document must be properly cited in any 57 | % publication reporting results derived from this 58 | % document or obtained from application and use of this 59 | % software. Any of the Licencee's documentation 60 | % describing results generated by the Licencee's 61 | % use of the Software will contain an acknowledgement 62 | % of CSIRO's ownership of the Software; 63 | % 64 | % (c) CSIRO reserves all rights in the Software other than 65 | % the rights granted to the Licencee by this 66 | % Agreement; 67 | % 68 | % (d) each item of the Software will display a banner 69 | % summarising the terms of this Agreement and 70 | % acknowledging the source of the Software, and the 71 | % contents of a banner will not be modified and its 72 | % display will not be inactivated by the Licencee 73 | % without the approval of CSIRO. 74 | % 75 | % 3.0 Indemnity 76 | % 77 | % 3.1 To the full extent permitted by law, CSIRO excludes any 78 | % and all liability in respect of any loss or damage, 79 | % whether personal (includes death or illness) or of 80 | % property and whether direct, consequential or special 81 | % (including consequential financial loss or damage) of 82 | % the Licencee, its officers, agents and employees or any 83 | % third party howsoever caused, which may be suffered or 84 | % incurred or which may arise directly or indirectly in 85 | % respect of or arising out of the Licencee's use or 86 | % inability to use the Software or the failure or omission 87 | % on the part of CSIRO to comply with the conditions and 88 | % warranties under this Licence Agreement. Insofar as 89 | % liability for loss or damages under or pursuant to such 90 | % legislation cannot be excluded, CSIRO's liability for 91 | % loss or damages shall be limited to the amount of One 92 | % Dollar ($1.00). 93 | % 94 | % 3.2 CSIRO make no warranties, expressed or implied, and 95 | % excludes all other warranties representations, terms or 96 | % conditions, whether express or implied, oral or written, 97 | % statutory or otherwise, relating in any way to the 98 | % Software, or to this Agreement, including any implied 99 | % warranty of merchantability or of fitness for particular 100 | % purpose. To the full extent permitted by the law of the 101 | % Commonwealth of Australia or the laws of any State or 102 | % Territory of Australia, any conditions or warranties 103 | % imposed by such legislation are hereby excluded. In so 104 | % far as liability under or pursuant to such legislation 105 | % may not be excluded, CSIRO's liability to the Licencee 106 | % pursuant to this Agreement shall be limited as set out in 107 | % clause 3.1 hereof. 108 | % 109 | % 3.3 The Licencee acknowledges and agrees that the Software 110 | % was developed for CSIRO research purposes and may have 111 | % inherent defects, errors or deficiencies, and that it is 112 | % the responsibility of the Licencee to make its own 113 | % assessment of the suitability of the Software for the 114 | % purpose of the Licencee's computing activity. The 115 | % Licencee will use the Software, and advice, opinions or 116 | % information supplied by CSIRO, its officers, employees or 117 | % agents concerning the Software at the Licencee's own 118 | % risk. 119 | % 120 | % 3.4 The Licencee hereby releases and indemnifies and shall 121 | % continue to release and indemnify CSIRO, its officers, 122 | % employees and agents from and against all actions, 123 | % claims, proceedings or demands (including those brought 124 | % by third parties) which may be bought against it or them, 125 | % whether on their own or jointly with the Licencee and 126 | % whether at common law, in equity or pursuant to statute or 127 | % otherwise, in respect of any loss, death, injury, illness 128 | % or damage (whether personal or property, and whether 129 | % direct or consequential, including consequential 130 | % financial loss) and any infringement of copyright, 131 | % patents, trade marks, designs or other Intellectual 132 | % Property Rights, howsoever arising out of the Licencee's 133 | % exercise of its rights under this Agreement and from and 134 | % against all damages, costs and expenses incurred in 135 | % defending or settling any such claim, proceeding or 136 | % demand. 137 | % 138 | % 3.5 The Licencee's obligation to indemnify CSIRO and its 139 | % officers, employees and agents set out in clause 3.4 140 | % hereof is a continuing obligation separate from 141 | % and independent of the Licencee's other obligations under 142 | % this Agreement, and shall survive all expiration or 143 | % termination of this Agreement. 144 | % 145 | % 4.0 Termination 146 | % 147 | % 4.1 The Licence shall terminate immediately upon the Licencee 148 | % breaching any term or condition of this Agreement whether 149 | % or not CSIRO is aware of the occurrence of the breach at 150 | % the time that it happens. 151 | % 152 | % 4.2 CSIRO may terminate the Licence on reasonable grounds by 153 | % notice in writing to the Licencee, and such notice of 154 | % termination shall be effective immediately upon receipt 155 | % by the Licencee. 156 | % 157 | %========================================================================= 158 | 159 | more on 160 | help sw_copy 161 | more off 162 | return 163 | %-------------------------------------------------------------------- 164 | 165 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_cp.m: -------------------------------------------------------------------------------- 1 | 2 | function cp = sw_cp(S,T,P) 3 | 4 | % SW_CP Heat Capacity (Cp) of sea water 5 | %========================================================================= 6 | % SW_CP $Id: sw_cp.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: cp = sw_cp(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Heat Capacity of Sea Water using UNESCO 1983 polynomial. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % S = salinity [psu (PSS-78)] 16 | % T = temperature [degree C (ITS-90)] 17 | % P = pressure [db] 18 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 19 | % 20 | % OUTPUT: 21 | % cp = Specific Heat Capacity [J kg^-1 C^-1] 22 | % 23 | % AUTHOR: Phil Morgan, Lindsay Pender (Lindsay.Pender@csiro.au) 24 | % 25 | % DISCLAIMER: 26 | % This software is provided "as is" without warranty of any kind. 27 | % See the file sw_copy.m for conditions of use and licence. 28 | % 29 | % REFERENCES: 30 | % Fofonff, P. and Millard, R.C. Jr 31 | % Unesco 1983. Algorithms for computation of fundamental properties of 32 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 33 | %========================================================================= 34 | 35 | % Modifications 36 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 37 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 38 | 39 | % CALLER: general purpose 40 | % CALLEE: none 41 | 42 | %---------------------- 43 | % CHECK INPUT ARGUMENTS 44 | %---------------------- 45 | if nargin ~=3 46 | error('Must pass 3 parameters') 47 | end %if 48 | 49 | % CHECK S,T,P dimensions and verify consistent 50 | [ms,ns] = size(S); 51 | [mt,nt] = size(T); 52 | [mp,np] = size(P); 53 | 54 | 55 | % CHECK THAT S & T HAVE SAME SHAPE 56 | if (ms~=mt) | (ns~=nt) 57 | error('S & T must have same dimensions') 58 | end %if 59 | 60 | % CHECK OPTIONAL SHAPES FOR P 61 | if mp==1 & np==1 % P is a scalar. Fill to size of S 62 | P = P(1)*ones(ms,ns); 63 | elseif np==ns & mp==1 % P is row vector with same cols as S 64 | P = P( ones(1,ms), : ); % Copy down each column. 65 | elseif mp==ms & np==1 % P is column vector 66 | P = P( :, ones(1,ns) ); % Copy across each row 67 | elseif mp==ms & np==ns % PR is a matrix size(S) 68 | % shape ok 69 | else 70 | error('P has wrong dimensions') 71 | end %if 72 | 73 | %***check_stp 74 | 75 | %------ 76 | % BEGIN 77 | %------ 78 | P = P/10; % to convert db to Bar as used in Unesco routines 79 | T68 = T * 1.00024; 80 | 81 | %------------ 82 | % eqn 26 p.32 83 | %------------ 84 | c0 = 4217.4; 85 | c1 = -3.720283; 86 | c2 = 0.1412855; 87 | c3 = -2.654387e-3; 88 | c4 = 2.093236e-5; 89 | 90 | a0 = -7.64357; 91 | a1 = 0.1072763; 92 | a2 = -1.38385e-3; 93 | 94 | b0 = 0.1770383; 95 | b1 = -4.07718e-3; 96 | b2 = 5.148e-5; 97 | 98 | Cpst0 = (((c4.*T68 + c3).*T68 + c2).*T68 + c1).*T68 + c0 + ... 99 | (a0 + a1.*T68 + a2.*T68.^2).*S + ... 100 | (b0 + b1.*T68 + b2.*T68.^2).*S.*sqrt(S); 101 | 102 | %------------ 103 | % eqn 28 p.33 104 | %------------ 105 | a0 = -4.9592e-1; 106 | a1 = 1.45747e-2; 107 | a2 = -3.13885e-4; 108 | a3 = 2.0357e-6; 109 | a4 = 1.7168e-8; 110 | 111 | b0 = 2.4931e-4; 112 | b1 = -1.08645e-5; 113 | b2 = 2.87533e-7; 114 | b3 = -4.0027e-9; 115 | b4 = 2.2956e-11; 116 | 117 | c0 = -5.422e-8; 118 | c1 = 2.6380e-9; 119 | c2 = -6.5637e-11; 120 | c3 = 6.136e-13; 121 | 122 | del_Cp0t0 = (((((c3.*T68 + c2).*T68 + c1).*T68 + c0).*P + ... 123 | ((((b4.*T68 + b3).*T68 + b2).*T68 + b1).*T68 + b0)).*P + ... 124 | ((((a4.*T68 + a3).*T68 + a2).*T68 + a1).*T68 + a0)).*P; 125 | 126 | %------------ 127 | % eqn 29 p.34 128 | %------------ 129 | d0 = 4.9247e-3; 130 | d1 = -1.28315e-4; 131 | d2 = 9.802e-7; 132 | d3 = 2.5941e-8; 133 | d4 = -2.9179e-10; 134 | 135 | e0 = -1.2331e-4; 136 | e1 = -1.517e-6; 137 | e2 = 3.122e-8; 138 | 139 | f0 = -2.9558e-6; 140 | f1 = 1.17054e-7; 141 | f2 = -2.3905e-9; 142 | f3 = 1.8448e-11; 143 | 144 | g0 = 9.971e-8; 145 | 146 | h0 = 5.540e-10; 147 | h1 = -1.7682e-11; 148 | h2 = 3.513e-13; 149 | 150 | j1 = -1.4300e-12; 151 | S3_2 = S.*sqrt(S); 152 | 153 | del_Cpstp = [((((d4.*T68 + d3).*T68 + d2).*T68 + d1).*T68 + d0).*S + ... 154 | ((e2.*T68 + e1).*T68 + e0).*S3_2].*P + ... 155 | [(((f3.*T68 + f2).*T68 + f1).*T68 + f0).*S + ... 156 | g0.*S3_2].*P.^2 + ... 157 | [((h2.*T68 + h1).*T68 + h0).*S + ... 158 | j1.*T68.*S3_2].*P.^3; 159 | 160 | 161 | cp = Cpst0 + del_Cp0t0 + del_Cpstp; 162 | 163 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_dens.m: -------------------------------------------------------------------------------- 1 | 2 | function dens = sw_dens(S,T,P) 3 | 4 | % SW_DENS Density of sea water 5 | %========================================================================= 6 | % SW_DENS $Id: sw_dens.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: dens = sw_dens(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Density of Sea Water using UNESCO 1983 (EOS 80) polynomial. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % S = salinity [psu (PSS-78)] 16 | % T = temperature [degree C (ITS-90)] 17 | % P = pressure [db] 18 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 19 | % 20 | % OUTPUT: 21 | % dens = density [kg/m^3] 22 | % 23 | % AUTHOR: Phil Morgan 92-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 24 | % 25 | % DISCLAIMER: 26 | % This software is provided "as is" without warranty of any kind. 27 | % See the file sw_copy.m for conditions of use and licence. 28 | % 29 | % REFERENCES: 30 | % Fofonoff, P. and Millard, R.C. Jr 31 | % Unesco 1983. Algorithms for computation of fundamental properties of 32 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 33 | % 34 | % Millero, F.J., Chen, C.T., Bradshaw, A., and Schleicher, K. 35 | % " A new high pressure equation of state for seawater" 36 | % Deap-Sea Research., 1980, Vol27A, pp255-264. 37 | %========================================================================= 38 | 39 | % Modifications 40 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 41 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 42 | 43 | % CALLER: general purpose 44 | % CALLEE: sw_dens0.m sw_seck.m 45 | 46 | % UNESCO 1983. eqn.7 p.15 47 | 48 | %---------------------- 49 | % CHECK INPUT ARGUMENTS 50 | %---------------------- 51 | if nargin ~=3 52 | error('sw_dens.m: Must pass 3 parameters') 53 | end %if 54 | 55 | % CHECK S,T,P dimensions and verify consistent 56 | [ms,ns] = size(S); 57 | [mt,nt] = size(T); 58 | [mp,np] = size(P); 59 | 60 | 61 | % CHECK THAT S & T HAVE SAME SHAPE 62 | if (ms~=mt) | (ns~=nt) 63 | error('check_stp: S & T must have same dimensions') 64 | end %if 65 | 66 | % CHECK OPTIONAL SHAPES FOR P 67 | if mp==1 & np==1 % P is a scalar. Fill to size of S 68 | P = P(1)*ones(ms,ns); 69 | elseif np==ns & mp==1 % P is row vector with same cols as S 70 | P = P( ones(1,ms), : ); % Copy down each column. 71 | elseif mp==ms & np==1 % P is column vector 72 | P = P( :, ones(1,ns) ); % Copy across each row 73 | elseif mp==ms & np==ns % PR is a matrix size(S) 74 | % shape ok 75 | else 76 | error('check_stp: P has wrong dimensions') 77 | end %if 78 | 79 | %***check_stp 80 | 81 | %------ 82 | % BEGIN 83 | %------ 84 | densP0 = sw_dens0(S,T); 85 | K = sw_seck(S,T,P); 86 | P = P/10; % convert from db to atm pressure units 87 | dens = densP0./(1-P./K); 88 | return 89 | %-------------------------------------------------------------------- 90 | 91 | 92 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_dens0.m: -------------------------------------------------------------------------------- 1 | 2 | function dens = sw_dens0(S,T) 3 | 4 | % SW_DENS0 Denisty of sea water at atmospheric pressure 5 | %========================================================================= 6 | % SW_DENS0 $Id: sw_dens0.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992 8 | % 9 | % USAGE: dens0 = sw_dens0(S,T) 10 | % 11 | % DESCRIPTION: 12 | % Density of Sea Water at atmospheric pressure using 13 | % UNESCO 1983 (EOS 1980) polynomial. 14 | % 15 | % INPUT: (all must have same dimensions) 16 | % S = salinity [psu (PSS-78)] 17 | % T = temperature [degree C (ITS-90)] 18 | % 19 | % OUTPUT: 20 | % dens0 = density [kg/m^3] of salt water with properties S,T, 21 | % P=0 (0 db gauge pressure) 22 | % 23 | % AUTHOR: Phil Morgan 92-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 24 | % 25 | % DISCLAIMER: 26 | % This software is provided "as is" without warranty of any kind. 27 | % See the file sw_copy.m for conditions of use and licence. 28 | % 29 | % REFERENCES: 30 | % Unesco 1983. Algorithms for computation of fundamental properties of 31 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 32 | % 33 | % Millero, F.J. and Poisson, A. 34 | % International one-atmosphere equation of state of seawater. 35 | % Deep-Sea Res. 1981. Vol28A(6) pp625-629. 36 | %========================================================================= 37 | 38 | % Modifications 39 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 40 | 41 | % CALLER: general purpose, sw_dens.m 42 | % CALLEE: sw_smow.m 43 | 44 | %---------------------- 45 | % CHECK INPUT ARGUMENTS 46 | %---------------------- 47 | if nargin ~=2 48 | error('sw_dens0.m: Must pass 2 parameters') 49 | end %if 50 | 51 | [mS,nS] = size(S); 52 | [mT,nT] = size(T); 53 | 54 | if (mS~=mT) | (nS~=nT) 55 | error('sw_dens0.m: S,T inputs must have the same dimensions') 56 | end %if 57 | 58 | %---------------------- 59 | % DEFINE CONSTANTS 60 | %---------------------- 61 | 62 | T68 = T * 1.00024; 63 | 64 | % UNESCO 1983 eqn(13) p17. 65 | 66 | b0 = 8.24493e-1; 67 | b1 = -4.0899e-3; 68 | b2 = 7.6438e-5; 69 | b3 = -8.2467e-7; 70 | b4 = 5.3875e-9; 71 | 72 | c0 = -5.72466e-3; 73 | c1 = +1.0227e-4; 74 | c2 = -1.6546e-6; 75 | 76 | d0 = 4.8314e-4; 77 | dens = sw_smow(T) + (b0 + (b1 + (b2 + (b3 + b4*T68).*T68).*T68).*T68).*S ... 78 | + (c0 + (c1 + c2*T68).*T68).*S.*sqrt(S) + d0*S.^2; 79 | return 80 | %-------------------------------------------------------------------- 81 | 82 | 83 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_dist.m: -------------------------------------------------------------------------------- 1 | 2 | function [dist,phaseangle] = sw_dist(lat,lon,units) 3 | 4 | % SW_DIST Distance between two lat,lon coordinates 5 | %=================================================================== 6 | % SW_DIST $Id: sw_dist.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan & Steve Rintoul 1992. 8 | % 9 | % USAGE: [dist,phaseangle] = sw_dist(lat,lon {,units} ) 10 | % 11 | % DESCRIPTION: 12 | % Calculate distance between two positions on glode using the "Plane 13 | % Sailing" method. Also uses simple geometry to calculate the bearing of 14 | % the path between position pairs. 15 | % 16 | % INPUT: 17 | % lat = decimal degrees (+ve N, -ve S) [- 90.. +90] 18 | % lon = decimal degrees (+ve E, -ve W) [-180..+180] 19 | % units = optional string specifing units of distance 20 | % 'nm' = nautical miles (default) 21 | % 'km' = kilometres 22 | % 23 | % OUTPUT: 24 | % dist = distance between positions in units 25 | % phaseangle = angle of line between stations with x axis (East). 26 | % Range of values are -180..+180. (E=0, N=90, S=-90) 27 | % 28 | % AUTHOR: Phil Morgan and Steve Rintoul 92-02-10 29 | % 30 | % DISCLAIMER: 31 | % This software is provided "as is" without warranty of any kind. 32 | % See the file sw_copy.m for conditions of use and licence. 33 | % 34 | % REFERENCE: 35 | % The PLANE SAILING method as descriibed in "CELESTIAL NAVIGATION" 1989 by 36 | % Dr. P. Gormley. The Australian Antartic Division. 37 | %================================================================== 38 | 39 | % Modifications 40 | % 99-06-25. Lindsay Pender, Function name change from distance to sw_dist. 41 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 42 | 43 | % CALLER: general purpose 44 | % CALLEE: none 45 | 46 | %---------------------- 47 | % CHECK INPUT ARGUMENTS 48 | %---------------------- 49 | if nargin > 3 50 | error('sw_dist.m: No more than 3 arguments allowed') 51 | elseif nargin==3 52 | if ~isstr(units) 53 | error('sw_dist.m: units argument must be string') 54 | end %if 55 | elseif nargin==2 56 | units = 'nm'; % default units 57 | else 58 | error('sw_dist.m: wrong number of arguments') 59 | end%if 60 | 61 | [mlat,nlat] = size(lat); 62 | if mlat~=1 & nlat~=1 63 | error('sw_dist.m: lat, lon must be vectors. No matrices allowed') 64 | end%if 65 | 66 | if length(lat)~=length(lon) 67 | error('sw_dist.m: lat and lon must have same number of elements') 68 | end%if 69 | 70 | %----------------- 71 | % DEFINE CONSTANTS 72 | %----------------- 73 | DEG2RAD = (2*pi/360); 74 | RAD2DEG = 1/DEG2RAD; 75 | DEG2MIN = 60; 76 | DEG2NM = 60; 77 | NM2KM = 1.8520; % Defined in Pond & Pickard p303. 78 | 79 | % BEGIN 80 | npositions = length(lat); 81 | ind=1:npositions-1; % index to first of position pairs 82 | 83 | dlon = diff(lon); 84 | if any(abs(dlon)>180) 85 | flag = find(abs(dlon)>180); 86 | for ii=1:length(flag) 87 | dlon(flag(ii))= -sign(dlon(flag(ii))) * (360 - abs(dlon(flag(ii))) ); 88 | end %for 89 | end %if 90 | latrad = abs(lat*DEG2RAD); 91 | dep = cos( (latrad(ind+1)+latrad(ind))./2 ) .* dlon; 92 | dlat = diff(lat); 93 | dist = DEG2NM*sqrt(dlat.^2 + dep.^2); % in n.miles 94 | 95 | if strcmp(units,'km') % defaults to n.miles 96 | dist = dist * NM2KM; 97 | end %if 98 | 99 | % CALCUALTE ANGLE TO X AXIS 100 | phaseangle = angle(dep+dlat*sqrt(-1))*RAD2DEG; 101 | return 102 | %-------------------------------------------------------------------- 103 | 104 | 105 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_dpth.m: -------------------------------------------------------------------------------- 1 | 2 | function DEPTHM = sw_dpth(P,LAT) 3 | 4 | % SW_DPTH Depth from pressure 5 | %=========================================================================== 6 | % SW_DPTH $Id: sw_dpth.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: dpth = sw_dpth(P,LAT) 10 | % 11 | % DESCRIPTION: 12 | % Calculates depth in metres from pressure in dbars. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % P = Pressure [db] 16 | % LAT = Latitude in decimal degress north [-90..+90] 17 | % (lat may have dimensions 1x1 or 1xn where P(mxn). 18 | % 19 | % OUTPUT: 20 | % dpth = depth [metres] 21 | % 22 | % AUTHOR: Phil Morgan 92-04-06 (morgan@ml.csiro.au) 23 | % 24 | % DISCLAIMER: 25 | % This software is provided "as is" without warranty of any kind. 26 | % See the file sw_copy.m for conditions of use and licence. 27 | % 28 | % REFERENCES: 29 | % Unesco 1983. Algorithms for computation of fundamental properties of 30 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 31 | %========================================================================= 32 | 33 | % Modifications 34 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 35 | 36 | % CALLER: general purpose 37 | % CALLEE: none 38 | 39 | %------------- 40 | % CHECK INPUTS 41 | %------------- 42 | [mP,nP] = size(P); 43 | [mL,nL] = size(LAT); 44 | if mL==1 & nL==1 % LAT scalar - fill to size of P 45 | LAT = LAT*ones(size(P)); 46 | 47 | elseif nP == nL & mL == 1 % LAT is row vector 48 | LAT = LAT(ones(1, mP), :); % Coppy down each column 49 | 50 | elseif mP == mL & nL == 1 % LAT is column vector 51 | LAT = LAT(:, ones(1, nP)); % Copy across each row 52 | 53 | elseif mP == mL & nP == nL 54 | % Ok 55 | 56 | else 57 | error('sw_depth.m: Inputs arguments have wrong dimensions') 58 | end %if 59 | 60 | %------------- 61 | % BEGIN 62 | %------------- 63 | % Eqn 25, p26. Unesco 1983. 64 | 65 | DEG2RAD = pi/180; 66 | c1 = +9.72659; 67 | c2 = -2.2512E-5; 68 | c3 = +2.279E-10; 69 | c4 = -1.82E-15; 70 | gam_dash = 2.184e-6; 71 | 72 | LAT = abs(LAT); 73 | X = sin(LAT*DEG2RAD); % convert to radians 74 | X = X.*X; 75 | bot_line = 9.780318*(1.0+(5.2788E-3+2.36E-5*X).*X) + gam_dash*0.5*P; 76 | top_line = (((c4*P+c3).*P+c2).*P+c1).*P; 77 | DEPTHM = top_line./bot_line; 78 | return 79 | %=========================================================================== 80 | % 81 | 82 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_f.m: -------------------------------------------------------------------------------- 1 | 2 | function f = sw_f(lat) 3 | 4 | % SW_F Coriolis factor "f" 5 | %=========================================================================== 6 | % SW_F $Id: sw_f.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: f = sw_f(lat) 10 | % 11 | % DESCRIPTION: 12 | % Calculates the Coriolis factor "f" defined by 13 | % f = 2*Omega*Sin(lat) where Omega = 7.292e-5 radians/sec 14 | % 15 | % INPUT: 16 | % lat = Latitude in decimal degress north [-90..+90] 17 | % 18 | % OUTPUT: 19 | % f = Coriolis Factor "f" [s-1] 20 | % 21 | % AUTHOR: Phil Morgan 93-04-20 (morgan@ml.csiro.au) 22 | % 23 | % DISCLAIMER: 24 | % This software is provided "as is" without warranty of any kind. 25 | % See the file sw_copy.m for conditions of use and licence. 26 | % 27 | % REFERENCE: 28 | % S. Pond & G.Pickard 2nd Edition 1986 29 | % Introductory Dynamical Oceanogrpahy 30 | % Pergamon Press Sydney. ISBN 0-08-028728-X 31 | % 32 | % A.E. Gill 1982. p.597 33 | % "Atmosphere-Ocean Dynamics" 34 | % Academic Press: New York. ISBN: 0-12-283522-0 35 | %========================================================================= 36 | 37 | % CALLER: general purpose 38 | % CALLEE: none 39 | 40 | %------------- 41 | % CHECK INPUTS 42 | %------------- 43 | if nargin ~= 1 44 | error('sw_f.m: Requires one input argument') 45 | end %if 46 | 47 | %------------- 48 | % BEGIN 49 | %------------- 50 | % Eqn p27. Unesco 1983. 51 | DEG2RAD = pi/180; 52 | OMEGA = 7.292e-5; %s-1 A.E.Gill p.597 53 | f = 2*OMEGA*sin(lat*DEG2RAD); 54 | 55 | return 56 | %=========================================================================== 57 | 58 | 59 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_fp.m: -------------------------------------------------------------------------------- 1 | 2 | function fp = sw_fp(S,P) 3 | 4 | % SW_FP Freezing point of sea water 5 | %========================================================================= 6 | % SW_FP % $Id: sw_fp.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: fp = sw_fp(S,P) 10 | % 11 | % DESCRIPTION: 12 | % Freezing point of Sea Water using UNESCO 1983 polynomial. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % S = salinity [psu (PSS-78)] 16 | % P = pressure [db] 17 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 18 | % 19 | % OUTPUT: 20 | % fp = Freezing Point temperature [degree C (ITS-90)] 21 | % 22 | % AUTHOR: Phil Morgan 93-04-20, Lindsay Pender (Lindsay.Pender@csiro.au) 23 | % 24 | % DISCLAIMER: 25 | % This software is provided "as is" without warranty of any kind. 26 | % See the file sw_copy.m for conditions of use and licence. 27 | % 28 | % REFERENCES: 29 | % Fofonff, P. and Millard, R.C. Jr 30 | % Unesco 1983. Algorithms for computation of fundamental properties of 31 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 32 | %========================================================================= 33 | 34 | % Modifications 35 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 36 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 37 | 38 | % CALLER: general purpose 39 | % CALLEE: none 40 | 41 | %---------------------- 42 | % CHECK INPUT ARGUMENTS 43 | %---------------------- 44 | if nargin ~=2 45 | error('Must pass 2 parameters') 46 | end %if 47 | 48 | [ms,ns] = size(S); 49 | [mp,np] = size(P); 50 | 51 | % CHECK OPTIONAL SHAPES FOR P 52 | if mp==1 & np==1 % P is a scalar. Fill to size of S 53 | P = P(1)*ones(ms,ns); 54 | elseif np==ns & mp==1 % P is row vector with same cols as S 55 | P = P( ones(1,ms), : ); % Copy down each column. 56 | elseif mp==ms & np==1 % P is column vector 57 | P = P( :, ones(1,ns) ); % Copy across each row 58 | elseif mp==ms & np==ns % PR is a matrix size(S) 59 | % shape ok 60 | else 61 | error('P has wrong dimensions') 62 | end %if 63 | 64 | %------ 65 | % BEGIN 66 | %------ 67 | %P = P/10; % to convert db to Bar as used in Unesco routines 68 | 69 | %------------ 70 | % eqn p.29 71 | %------------ 72 | a0 = -0.0575; 73 | a1 = 1.710523e-3; 74 | a2 = -2.154996e-4; 75 | b = -7.53e-4; 76 | 77 | fp = (a0.*S + a1.*S.*sqrt(S) + a2.*S.^2 + b.*P) / 1.00024; 78 | 79 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_g.m: -------------------------------------------------------------------------------- 1 | 2 | function g = sw_g(LAT,z) 3 | 4 | % SW_G Gravitational acceleration 5 | %=========================================================================== 6 | % SW_G $Id: sw_g.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: g = sw_g(lat,z) 10 | % 11 | % DESCRIPTION: 12 | % Calculates acceleration due to gravity as function of latitude. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % lat = Latitude in decimal degress north [-90..+90] 16 | % z = height in metres (+ve above sea surface, -ve below) 17 | % 18 | % OUTPUT: 19 | % g = gravity [m/s^2] 20 | % 21 | % AUTHOR: Phil Morgan 93-04-20 (morgan@ml.csiro.au) 22 | % 23 | % DISCLAIMER: 24 | % This software is provided "as is" without warranty of any kind. 25 | % See the file sw_copy.m for conditions of use and licence. 26 | % 27 | % REFERENCES: 28 | % Unesco 1983. Algorithms for computation of fundamental properties of 29 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 30 | % 31 | % A.E. Gill 1982. p.597 32 | % "Atmosphere-Ocean Dynamics" 33 | % Academic Press: New York. ISBN: 0-12-283522-0 34 | %========================================================================= 35 | 36 | % CALLER: general purpose 37 | % CALLEE: none 38 | 39 | %------------- 40 | % CHECK INPUTS 41 | %------------- 42 | if ~(nargin==1 | nargin==2) 43 | error('sw_g.m: Requires one or two input arguments') 44 | end %if 45 | if nargin == 1 46 | z = zeros(size(LAT)); 47 | end %if 48 | 49 | [mL,nL] = size(LAT); 50 | [mz,nz] = size(z); 51 | if ~(mL==mz | nL==nz) 52 | error('sw_g.m: Input arguments should have same dimensions') 53 | end %if 54 | 55 | %------------- 56 | % BEGIN 57 | %------------- 58 | % Eqn p27. Unesco 1983. 59 | a = 6371000; % mean radius of earth A.E.Gill 60 | DEG2RAD = pi/180; 61 | LAT = abs(LAT); 62 | X = sin(LAT*DEG2RAD); % convert to radians 63 | sin2 = X.*X; 64 | g = 9.780318*(1.0+(5.2788E-3+2.36E-5*sin2).*sin2); 65 | if any(any(z)) 66 | g = g./((1+z/a).^2); % from A.E.Gill p.597 67 | end %if 68 | return 69 | %=========================================================================== 70 | 71 | 72 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_gpan.m: -------------------------------------------------------------------------------- 1 | 2 | function [ga] = sw_gpan(S,T,P) 3 | 4 | % SW_GPAN Geopotential anomaly 5 | %========================================================================= 6 | % SW_GPAN $Id: sw_gpan.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: [gpan]= sw_gpan(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Geopotential Anomaly calculated as the integral of svan from the 13 | % the sea surface to the bottom. Thus RELATIVE TO SEA SURFACE. 14 | % 15 | % INPUT: (all must have same dimensions) 16 | % S = salinity [psu (PSS-78)] 17 | % T = temperature [degree C (ITS-90)] 18 | % P = Pressure [db] 19 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 20 | % 21 | % OUTPUT: 22 | % gpan = Geopotential Anomaly [m^3 kg^-1 Pa == m^2 s^-2 == J kg^-1] 23 | % 24 | % AUTHOR: Phil Morgan 92-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 25 | % 26 | % DISCLAIMER: 27 | % This software is provided "as is" without warranty of any kind. 28 | % See the file sw_copy.m for conditions of use and licence. 29 | % 30 | % REFERENCE: S. Pond & G.Pickard 2nd Edition 1986 31 | % Introductory Dynamical Oceanogrpahy 32 | % Pergamon Press Sydney. ISBN 0-08-028728-X 33 | % 34 | % Note that older literature may use units of "dynamic decimeter' for above. 35 | % 36 | % Adapted method from Pond and Pickard (p76) to calc gpan rel to sea 37 | % surface whereas P&P calculated relative to the deepest common depth. 38 | %========================================================================= 39 | 40 | % Modifications 41 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 42 | 43 | % 44 | % CALLER: general purpose 45 | % CALLEE: sw_svan.m 46 | 47 | %---------------------- 48 | % CHECK INPUT ARGUMENTS 49 | %---------------------- 50 | if nargin ~=3 51 | error('Must pass 3 parameters') 52 | end %if 53 | 54 | % CHECK S,T,P dimensions and verify consistent 55 | [ms,ns] = size(S); 56 | [mt,nt] = size(T); 57 | [mp,np] = size(P); 58 | 59 | 60 | % CHECK THAT S & T HAVE SAME SHAPE 61 | if (ms~=mt) | (ns~=nt) 62 | error('S & T must have same dimensions') 63 | end %if 64 | 65 | % CHECK OPTIONAL SHAPES FOR P 66 | if mp==1 & np==1 % P is a scalar. Fill to size of S 67 | P = P(1)*ones(ms,ns); 68 | elseif np==ns & mp==1 % P is row vector with same cols as S 69 | P = P( ones(1,ms), : ); % Copy down each column. 70 | elseif mp==ms & np==1 % P is column vector 71 | P = P( :, ones(1,ns) ); % Copy across each row 72 | elseif mp==ms & np==ns % PR is a matrix size(S) 73 | % shape ok 74 | else 75 | error('P has wrong dimensions') 76 | end %if 77 | [mp,np] = size(P); 78 | 79 | 80 | 81 | % IF ALL ROW VECTORS ARE PASSED THEN LET US PRESERVE SHAPE ON RETURN. 82 | Transpose = 0; 83 | if mp == 1 % row vector 84 | P = P(:); 85 | T = T(:); 86 | S = S(:); 87 | 88 | Transpose = 1; 89 | end %if 90 | %***check_stp 91 | 92 | %------ 93 | % BEGIN 94 | %------ 95 | db2Pascal = 1e4; 96 | [m,n] = size(P); 97 | svan = sw_svan(S,T,P); 98 | mean_svan = 0.5*(svan(2:m,:) + svan(1:m-1,:) ); 99 | 100 | if n==1 101 | top = svan(1,1).*P(1,1)*db2Pascal; 102 | else 103 | top = svan(1,:).*P(1,:)*db2Pascal; 104 | end %if 105 | 106 | %press_diff = diff(P); 107 | 108 | delta_ga = (mean_svan.*diff(P))*db2Pascal; 109 | ga = cumsum([ top; delta_ga]); 110 | 111 | if Transpose 112 | ga = ga'; 113 | end %if 114 | 115 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_gvel.m: -------------------------------------------------------------------------------- 1 | 2 | function vel = sw_gvel(ga,lat,lon) 3 | 4 | % SW_GVEL Geostrophic velocity 5 | %=================================================================== 6 | % GEOVEL $Id: sw_gvel.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992 8 | % 9 | % USAGE: vel = sw_gvel(ga,lat,lon) 10 | % 11 | % DESCRIPTION: 12 | % Calculates geostrophic velocity given the geopotential anomaly 13 | % and position of each station. 14 | % 15 | % INPUT: 16 | % ga = geopotential anomoly relative to the sea surface. 17 | % dim(mxnstations) 18 | % lat = latitude of each station (+ve = N, -ve = S) [ -90.. +90] 19 | % lon = longitude of each station (+ve = E, -ve = W) [-180..+180] 20 | % 21 | % OUTPUT: 22 | % vel = geostrophic velocity RELATIVE to the sea surface. 23 | % dim(m,nstations-1) 24 | % 25 | % AUTHOR: Phil Morgan 1992/03/26 (morgan@ml.csiro.au) 26 | % 27 | % DISCLAIMER: 28 | % This software is provided "as is" without warranty of any kind. 29 | % See the file sw_copy.m for conditions of use and licence. 30 | % 31 | % REFERENCE: S. Pond & G.Pickard 2nd Edition 1986 32 | % Introductory Dynamical Oceanogrpahy 33 | % Pergamon Press Sydney. ISBN 0-08-028728-X 34 | % Equation 8.9A p73 Pond & Pickard 35 | % 36 | % NOTE: This calls sw_dist.m. You can replace the call to this 37 | % routine if you have a more appropraite distance routine. 38 | %================================================================== 39 | 40 | % CALLER: general purpose 41 | % CALLEE: sw_dist.m 42 | % 43 | 44 | 45 | DEG2RAD = pi/180; 46 | RAD2DEG = 180/pi; 47 | OMEGA = 7.292e-5; % Angular velocity of Earth [radians/sec] 48 | 49 | % You may replace the call to sw_dist if you have 50 | % a more appropriate distance routine. 51 | distm = 1000*sw_dist(lat,lon,'km'); 52 | [m,n] = size(ga); 53 | f = 2*OMEGA*sin( (lat(1:n-1)+lat(2:n))*DEG2RAD/2 ); 54 | lf = f.*distm; 55 | 56 | LF = lf(ones(m,1),:); 57 | 58 | vel = -( ga(:,2:n)-ga(:,1:n-1) ) ./ LF; 59 | 60 | return 61 | %-------------------------------------------------------------------- 62 | 63 | 64 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_info.m: -------------------------------------------------------------------------------- 1 | 2 | % SW_INFO Computational routines for the properties of sea water 3 | % 4 | % SEAWATER - developed by Phil Morgan, CSIRO 5 | % 6 | % DESCRIPTION: 7 | % SEAWATER is a toolkit of MATLAB routines for calculating the 8 | % properties of sea water. They are a self contained library and 9 | % are extremely easy to use and will run on all computers that 10 | % support MATLAB. 11 | % 12 | % MATLAB: 13 | % For information on MATLAB contact info@mathworks.com 14 | % 15 | % DISCLAIMER 16 | % This software is provided "as is" without warranty of any kind. 17 | % See the file sw_copy.m for conditions of use and licence. 18 | % 19 | % MORE INFORMATION: 20 | % http://www.marine.csiro.au/~morgan/seawater 21 | % 22 | % $Id: sw_info.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 23 | % Copyright (C) CSIRO, Phil Morgan 1993. 24 | %========================================================================= 25 | 26 | more on 27 | help sw_info 28 | more off 29 | return 30 | %-------------------------------------------------------------------- 31 | 32 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_new.m: -------------------------------------------------------------------------------- 1 | 2 | % SW_NEW What's new in this version of seawater. 3 | % 4 | % 19 April 2006 release 3.2 (For version 5.x and onwards of Matlab) 5 | % ******************************************************** 6 | % Corrected sign of potential vorticity in sw_bfrq. 7 | % 8 | % 24 November 2005 release 3.1 (For version 5.x and onwards of Matlab) 9 | % ******************************************************** 10 | % Added sw_swvel to compute surface wave velocity. 11 | % 12 | % 12 December 2003 release 3.0 (For version 5.x and onwards of Matlab) 13 | % ******************************************************** 14 | % Coverted code so that temperature is now ITS-90 throughout. 15 | % 16 | % 25 June 1999 release 2.0.2 (For version 5.x of Matlab) 17 | % ******************************************************** 18 | % Coding changes to enable functions to return the same shape vector as 19 | % the input arguments. In previous releases, some functions returned 20 | % column vectors for row vector input. Also some other tidying up. 21 | % 22 | % 22 April 1998 release 2.0.1 (For version 5.x of Matlab) 23 | % ******************************************************** 24 | % This version is not optimised but will run under Matlab 5.x 25 | % sw_satAr New routine. Solubility of Ar in seawater 26 | % sw_satN2 New routine. Solubility of N2 in seawater 27 | % sw_satO2 New routine. Solubility of O2 in seawater 28 | % sw_test Updated to include tests for above 29 | % 30 | % April 1998 release 1.2e (For version 4.x of Matlab) 31 | % ************************ 32 | % sw_alpha Fixed bug where temp used in calculations regardless of 33 | % whether 'temp' or 'pmpt' was passed as keyword. 34 | % 35 | % sw_info Shorter version. Refer users to web pages 36 | % http://www.marine.csiro.au 37 | % 38 | % sw_ver New routine. Returns version number of SEAWATER 39 | % 40 | % sw_test New Routine. Run a test on the SEAWATER routines 41 | % and compare results with literature values 42 | % 43 | % 94/11/15 release 1.2d 44 | % ********************** 45 | % sw_bfrq.m Now also returns potential vorticity. 46 | % Thanks to Greg Johnson (gjohnson@pmel.noaa.gov) 47 | % 48 | % sw_gvel.m OMEGA=7.29e-5 changed to OMEGA=7.292e-5 to be 49 | % consistent with sw_f.m 50 | % 51 | % IMPORTANT CHANGE: The usage of the following 52 | % routines has changed! 53 | % 54 | % sw_alpha.m | All these routines expect (S,T,P) to 55 | % sw_beta.m |-- be passed instead of (S,PTMP,P) as in 56 | % sw_aonb.m | previous releases of seawater. 57 | % Fast execution can still be obtained by passing 58 | % ptmp with a string flag 'ptmp' see help. 59 | % 60 | % 94/10/19 release 1.2c 61 | % ********************** 62 | % Added routine sw_new.m to inform of updates and new features. 63 | % sw_bfrq.m Fixed bug where LAT = [] was needed as argument when 64 | % no latitude values are being passed. 65 | % Now pass PRESSURE instead of DEPTH -> more consistent 66 | % though only a negligible change is answers. 67 | % 68 | % sw_info.m Updated to include a registration section. 69 | % Noted that software is FREE. 70 | % Noted best email address is seawater@ml.csiro.au 71 | % Requests for Report also via email to library@ml.csiro.au 72 | % 73 | % 94/10/12 release 1.2b 74 | % ******************** 75 | % First official release and announcement on the networks. 76 | % 77 | 78 | more on 79 | help sw_new 80 | more off 81 | 82 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_pden.m: -------------------------------------------------------------------------------- 1 | 2 | function pden = sw_pden(S,T,P,PR) 3 | 4 | % SW_PDEN Potential density 5 | %=========================================================================== 6 | % SW_PDEN $Id: sw_pden.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: pden = sw_pden(S,T,P,PR) 10 | % 11 | % DESCRIPTION: 12 | % Calculates potential density of water mass relative to the specified 13 | % reference pressure by pden = sw_dens(S,ptmp,PR). 14 | % 15 | % INPUT: (all must have same dimensions) 16 | % S = salinity [psu (PSS-78) ] 17 | % T = temperature [degree C (ITS-90)] 18 | % P = pressure [db] 19 | % PR = Reference pressure [db] 20 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 21 | % 22 | % OUTPUT: 23 | % pden = Potential denisty relative to the ref. pressure [kg/m^3] 24 | % 25 | % AUTHOR: Phil Morgan 1992/04/06, Lindsay Pender (Lindsay.Pender@csiro.au) 26 | % 27 | % DISCLAIMER: 28 | % This software is provided "as is" without warranty of any kind. 29 | % See the file sw_copy.m for conditions of use and licence. 30 | % 31 | % REFERENCES: 32 | % A.E. Gill 1982. p.54 33 | % "Atmosphere-Ocean Dynamics" 34 | % Academic Press: New York. ISBN: 0-12-283522-0 35 | %========================================================================= 36 | 37 | % Modifications 38 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 39 | 40 | % CALLER: general purpose 41 | % CALLEE: sw_ptmp.m sw_dens.m 42 | 43 | %------------- 44 | % CHECK INPUTS 45 | %------------- 46 | if nargin ~= 4 47 | error('sw_pden.m: Must pass 4 parameters ') 48 | end %if 49 | 50 | % LET sw_ptmp.m DO DIMENSION CHECKING 51 | 52 | %------ 53 | % BEGIN 54 | %------ 55 | ptmp = sw_ptmp(S,T,P,PR); 56 | pden = sw_dens(S,ptmp,PR); 57 | 58 | return 59 | %========================================================================= 60 | 61 | 62 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_pres.m: -------------------------------------------------------------------------------- 1 | 2 | function pres = sw_pres(DEPTH,LAT) 3 | 4 | % SW_PRES Pressure from depth 5 | %=========================================================================== 6 | % SW_PRES $Id: sw_pres.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: pres = sw_pres(depth,lat) 10 | % 11 | % DESCRIPTION: 12 | % Calculates pressure in dbars from depth in meters. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % depth = depth [metres] 16 | % lat = Latitude in decimal degress north [-90..+90] 17 | % (LAT may have dimensions 1x1 or 1xn where depth(mxn) ) 18 | % 19 | % OUTPUT: 20 | % pres = Pressure [db] 21 | % 22 | % AUTHOR: Phil Morgan 93-06-25 (morgan@ml.csiro.au) 23 | % 24 | % DISCLAIMER: 25 | % This software is provided "as is" without warranty of any kind. 26 | % See the file sw_copy.m for conditions of use and licence. 27 | % 28 | % REFERENCES: 29 | % Saunders, P.M. 1981 30 | % "Practical conversion of Pressure to Depth" 31 | % Journal of Physical Oceanography, 11, 573-574 32 | % 33 | % CHECK VALUE: 34 | % P=7500.00 db for LAT=30 deg, depth=7321.45 meters 35 | %========================================================================= 36 | 37 | % Modifications 38 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 39 | 40 | % CALLER: general purpose 41 | % CALLEE: none 42 | 43 | %------------- 44 | % CHECK INPUTS 45 | %------------- 46 | [mD,nD] = size(DEPTH); 47 | [mL,nL] = size(LAT); 48 | if mL==1 & nL==1 % LAT scalar - fill to size of P 49 | LAT = LAT*ones(size(DEPTH)); 50 | 51 | elseif nD == nL & mL == 1 % LAT is row vector 52 | LAT = LAT(ones(1, mD), :); % Coppy down each column 53 | 54 | elseif mD == mL & nL == 1 % LAT is column vector 55 | LAT = LAT(:, ones(1, nD)); % Copy across each row 56 | 57 | elseif mD == mL & nD == nL 58 | % Ok 59 | 60 | else 61 | error('sw_pres.m: Inputs arguments have wrong dimensions') 62 | end %if 63 | 64 | %------------- 65 | % BEGIN 66 | %------------- 67 | 68 | DEG2RAD = pi/180; 69 | X = sin(abs(LAT)*DEG2RAD); % convert to radians 70 | C1 = 5.92E-3+X.^2*5.25E-3; 71 | pres = ((1-C1)-sqrt(((1-C1).^2)-(8.84E-6*DEPTH)))/4.42E-6; 72 | return 73 | %=========================================================================== 74 | 75 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_ptmp.m: -------------------------------------------------------------------------------- 1 | 2 | function PT = sw_ptmp(S,T,P,PR) 3 | 4 | % SW_PTMP Potential temperature 5 | %=========================================================================== 6 | % SW_PTMP $Id: sw_ptmp.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: ptmp = sw_ptmp(S,T,P,PR) 10 | % 11 | % DESCRIPTION: 12 | % Calculates potential temperature as per UNESCO 1983 report. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % S = salinity [psu (PSS-78) ] 16 | % T = temperature [degree C (ITS-90)] 17 | % P = pressure [db] 18 | % PR = Reference pressure [db] 19 | % (P & PR may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 20 | % 21 | % OUTPUT: 22 | % ptmp = Potential temperature relative to PR [degree C (ITS-90)] 23 | % 24 | % AUTHOR: Phil Morgan 92-04-06, Lindsay Pender (Lindsay.Pender@csiro.au) 25 | % 26 | % DISCLAIMER: 27 | % This software is provided "as is" without warranty of any kind. 28 | % See the file sw_copy.m for conditions of use and licence. 29 | % 30 | % REFERENCES: 31 | % Fofonoff, P. and Millard, R.C. Jr 32 | % Unesco 1983. Algorithms for computation of fundamental properties of 33 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 34 | % Eqn.(31) p.39 35 | % 36 | % Bryden, H. 1973. 37 | % "New Polynomials for thermal expansion, adiabatic temperature gradient 38 | % and potential temperature of sea water." 39 | % DEEP-SEA RES., 1973, Vol20,401-408. 40 | %========================================================================= 41 | 42 | % Modifications 43 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 44 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 45 | 46 | % CALLER: general purpose 47 | % CALLEE: sw_adtg.m 48 | 49 | %------------- 50 | % CHECK INPUTS 51 | %------------- 52 | if nargin ~= 4 53 | error('sw_ptmp.m: Must pass 4 parameters ') 54 | end %if 55 | 56 | % CHECK S,T,P dimensions and verify consistent 57 | [ms,ns] = size(S); 58 | [mt,nt] = size(T); 59 | [mp,np] = size(P); 60 | 61 | [mpr,npr] = size(PR); 62 | 63 | 64 | % CHECK THAT S & T HAVE SAME SHAPE 65 | if (ms~=mt) | (ns~=nt) 66 | error('check_stp: S & T must have same dimensions') 67 | end %if 68 | 69 | % CHECK OPTIONAL SHAPES FOR P 70 | if mp==1 & np==1 % P is a scalar. Fill to size of S 71 | P = P(1)*ones(ms,ns); 72 | elseif np==ns & mp==1 % P is row vector with same cols as S 73 | P = P( ones(1,ms), : ); % Copy down each column. 74 | elseif mp==ms & np==1 % P is column vector 75 | P = P( :, ones(1,ns) ); % Copy across each row 76 | elseif mp==ms & np==ns % PR is a matrix size(S) 77 | % shape ok 78 | else 79 | error('check_stp: P has wrong dimensions') 80 | end %if 81 | [mp,np] = size(P); 82 | 83 | 84 | % CHECK OPTIONAL SHAPES FOR PR 85 | if mpr==1 & npr==1 % PR is a scalar. Fill to size of S 86 | PR = PR(1)*ones(ms,ns); 87 | elseif npr==ns & mpr==1 % PR is row vector with same cols as S 88 | PR = PR( ones(1,ms), : ); % Copy down each column. 89 | elseif mpr==ms & npr==1 % P is column vector 90 | PR = PR( :, ones(1,ns) ); % Copy across each row 91 | elseif mpr==ms & npr==ns % PR is a matrix size(S) 92 | % shape ok 93 | else 94 | error('check_stp: PR has wrong dimensions') 95 | end %if 96 | 97 | %***check_stp 98 | 99 | %------ 100 | % BEGIN 101 | %------ 102 | 103 | % theta1 104 | del_P = PR - P; 105 | del_th = del_P.*sw_adtg(S,T,P); 106 | th = T * 1.00024 + 0.5*del_th; 107 | q = del_th; 108 | 109 | % theta2 110 | del_th = del_P.*sw_adtg(S,th/1.00024,P+0.5*del_P); 111 | th = th + (1 - 1/sqrt(2))*(del_th - q); 112 | q = (2-sqrt(2))*del_th + (-2+3/sqrt(2))*q; 113 | 114 | % theta3 115 | del_th = del_P.*sw_adtg(S,th/1.00024,P+0.5*del_P); 116 | th = th + (1 + 1/sqrt(2))*(del_th - q); 117 | q = (2 + sqrt(2))*del_th + (-2-3/sqrt(2))*q; 118 | 119 | % theta4 120 | del_th = del_P.*sw_adtg(S,th/1.00024,P+del_P); 121 | PT = (th + (del_th - 2*q)/6)/1.00024; 122 | return 123 | %========================================================================= 124 | 125 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_salds.m: -------------------------------------------------------------------------------- 1 | 2 | function dS = sw_salds(Rtx,delT) 3 | 4 | % SW_SALDS Differiential dS/d(sqrt(Rt)) at constant T. 5 | %========================================================================= 6 | % SW_SALDS $Id: sw_salds.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: dS = sw_salds(Rtx,delT) 10 | % 11 | % DESCRIPTION: 12 | % Calculates Salinity differential dS/d(sqrt(Rt)) at constant T. 13 | % UNESCO 1983 polynomial. 14 | % 15 | % INPUT: (all must have same dimensions) 16 | % Rtx = sqrt(Rt) where Rt defined in sw_salt.m 17 | % delT = T-15 [degree C (IPTS-68)] 18 | % 19 | % OUTPUT: 20 | % dS = S differential dS/d(sqrt(Rt)) at constant T. 21 | % 22 | % AUTHOR: Phil Morgan 93-04-21, Lindsay Pender (Lindsay.Pender@csiro.au) 23 | % 24 | % DISCLAIMER: 25 | % This software is provided "as is" without warranty of any kind. 26 | % See the file sw_copy.m for conditions of use and licence. 27 | % 28 | % REFERENCES: 29 | % Fofonoff, P. and Millard, R.C. Jr 30 | % Unesco 1983. Algorithms for computation of fundamental properties of 31 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 32 | %========================================================================= 33 | 34 | % CALLER: sw_cndr.m 35 | % CALLEE: none 36 | 37 | %------------- 38 | % CHECK INPUTS 39 | %------------- 40 | if nargin~=2 41 | error('sw_salds.m: must have 2 input arguments') 42 | end %if 43 | 44 | [m1,n1] = size(Rtx); 45 | [m2,n2] = size(delT); 46 | if ~(m1==m2 | n1==n2) 47 | error('sw_salds.m: Rtx and delT must have the same shape') 48 | end %if 49 | 50 | %------- 51 | % BEGIN 52 | %------- 53 | 54 | a0 = 0.0080; 55 | a1 = -0.1692; 56 | a2 = 25.3851; 57 | a3 = 14.0941; 58 | a4 = -7.0261; 59 | a5 = 2.7081; 60 | 61 | b0 = 0.0005; 62 | b1 = -0.0056; 63 | b2 = -0.0066; 64 | b3 = -0.0375; 65 | b4 = 0.0636; 66 | b5 = -0.0144; 67 | 68 | k = 0.0162; 69 | 70 | dS = a1 + (2*a2 + (3*a3 + (4*a4 + 5*a5.*Rtx).*Rtx).*Rtx).*Rtx + ... 71 | (delT./(1+k*delT))* ... 72 | (b1 + (2*b2 + (3*b3 + (4*b4 + 5*b5.*Rtx).*Rtx).*Rtx).*Rtx); 73 | 74 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_salrp.m: -------------------------------------------------------------------------------- 1 | 2 | function Rp = sw_salrp(R,T,P) 3 | 4 | % SW_SALRP Conductivity ratio Rp(S,T,P) = C(S,T,P)/C(S,T,0) 5 | %========================================================================= 6 | % SW_SALRP $Id: sw_salrp.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: Rp = sw_salrp(R,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Equation Rp(S,T,P) = C(S,T,P)/C(S,T,0) used in calculating salinity. 13 | % UNESCO 1983 polynomial. 14 | % 15 | % INPUT: (All must have same shape) 16 | % R = Conductivity ratio R = C(S,T,P)/C(35,15(IPTS-68),0) [no units] 17 | % T = temperature [degree C (ITS-90)] 18 | % P = pressure [db] 19 | % 20 | % OUTPUT: 21 | % Rp = conductivity ratio Rp(S,T,P) = C(S,T,P)/C(S,T,0) [no units] 22 | % 23 | % AUTHOR: Phil Morgan 93-04-17, Lindsay Pender (Lindsay.Pender@csiro.au) 24 | % 25 | % DISCLAIMER: 26 | % This software is provided "as is" without warranty of any kind. 27 | % See the file sw_copy.m for conditions of use and licence. 28 | % 29 | % REFERENCES: 30 | % Fofonoff, P. and Millard, R.C. Jr 31 | % Unesco 1983. Algorithms for computation of fundamental properties of 32 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 33 | %========================================================================= 34 | 35 | % Modifications 36 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 37 | 38 | % CALLER: sw_salt 39 | % CALLEE: none 40 | 41 | %------------------- 42 | % CHECK INPUTS 43 | %------------------- 44 | if nargin~=3 45 | error('sw_salrp.m: requires 3 input arguments') 46 | end %if 47 | 48 | [mr,nr] = size(R); 49 | [mp,np] = size(P); 50 | [mt,nt] = size(T); 51 | if ~(mr==mp | mr==mt | nr==np | nr==nt) 52 | error('sw_salrp.m: R,T,P must all have the same shape') 53 | end %if 54 | 55 | %------------------- 56 | % eqn (4) p.8 unesco. 57 | %------------------- 58 | 59 | T68 = T * 1.00024; 60 | 61 | d1 = 3.426e-2; 62 | d2 = 4.464e-4; 63 | d3 = 4.215e-1; 64 | d4 = -3.107e-3; 65 | 66 | e1 = 2.070e-5; 67 | e2 = -6.370e-10; 68 | e3 = 3.989e-15; 69 | 70 | Rp = 1 + ( P.*(e1 + e2.*P + e3.*P.^2) ) ... 71 | ./ (1 + d1.*T68 + d2.*T68.^2 +(d3 + d4.*T68).*R); 72 | 73 | 74 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_salrt.m: -------------------------------------------------------------------------------- 1 | 2 | function rt = sw_salrt(T) 3 | 4 | % SW_SALRT Conductivity ratio rt(T) = C(35,T,0)/C(35,15,0) 5 | %========================================================================= 6 | % SW_SALRT $Id: sw_salrt.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: rt = sw_salrt(T) 10 | % 11 | % DESCRIPTION: 12 | % Equation rt(T) = C(35,T,0)/C(35,15(IPTS-68),0) used in calculating 13 | % salinity. 14 | % UNESCO 1983 polynomial. 15 | % 16 | % INPUT: 17 | % T = temperature [degree C (ITS-90)] 18 | % 19 | % OUTPUT: 20 | % rt = conductivity ratio [no units] 21 | % 22 | % AUTHOR: Phil Morgan 93-04-17, Lindsay Pender (Lindsay.Pender@csiro.au) 23 | % 24 | % DISCLAIMER: 25 | % This software is provided "as is" without warranty of any kind. 26 | % See the file sw_copy.m for conditions of use and licence. 27 | % 28 | % REFERENCES: 29 | % Fofonoff, P. and Millard, R.C. Jr 30 | % Unesco 1983. Algorithms for computation of fundamental properties of 31 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 32 | %========================================================================= 33 | 34 | % Modifications 35 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 36 | 37 | % CALLER: sw_salt 38 | % CALLEE: none 39 | 40 | % rt = rt(T) = C(35,T,0)/C(35,15,0) 41 | % Eqn (3) p.7 Unesco. 42 | 43 | T68 = T * 1.00024; 44 | 45 | c0 = 0.6766097; 46 | c1 = 2.00564e-2; 47 | c2 = 1.104259e-4; 48 | c3 = -6.9698e-7; 49 | c4 = 1.0031e-9; 50 | 51 | rt = c0 + (c1 + (c2 + (c3 + c4.*T68).*T68).*T68).*T68; 52 | 53 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_sals.m: -------------------------------------------------------------------------------- 1 | 2 | function S = sw_sals(Rt,T) 3 | 4 | % SW_SALS Salinity of sea water 5 | %========================================================================= 6 | % SW_SALS $Id: sw_sals.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: S = sw_sals(Rt,T) 10 | % 11 | % DESCRIPTION: 12 | % Salinity of sea water as a function of Rt and T. 13 | % UNESCO 1983 polynomial. 14 | % 15 | % INPUT: 16 | % Rt = Rt(S,T) = C(S,T,0)/C(35,T(IPTS-68),0) 17 | % T = temperature [degree C (ITS-90)] 18 | % 19 | % OUTPUT: 20 | % S = salinity [psu (PSS-78)] 21 | % 22 | % AUTHOR: Phil Morgan 93-04-17, Lindsay Pender (Lindsay.Pender@csiro.au) 23 | % 24 | % DISCLAIMER: 25 | % This software is provided "as is" without warranty of any kind. 26 | % See the file sw_copy.m for conditions of use and licence. 27 | % 28 | % REFERENCES: 29 | % Fofonoff, P. and Millard, R.C. Jr 30 | % Unesco 1983. Algorithms for computation of fundamental properties of 31 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 32 | %========================================================================= 33 | 34 | % Modifications 35 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 36 | 37 | % CALLER: sw_salt 38 | % CALLEE: none 39 | 40 | %-------------------------- 41 | % CHECK INPUTS 42 | %-------------------------- 43 | if nargin~=2 44 | error('sw_sals.m: requires 2 input arguments') 45 | end %if 46 | 47 | [mrt,nrt] = size(Rt); 48 | [mT,nT] = size(T); 49 | if ~(mrt==mT | nrt==nT) 50 | error('sw_sals.m: Rt and T must have the same shape') 51 | end %if 52 | 53 | %-------------------------- 54 | % eqn (1) & (2) p6,7 unesco 55 | %-------------------------- 56 | 57 | del_T68 = T * 1.00024 - 15; 58 | 59 | a0 = 0.0080; 60 | a1 = -0.1692; 61 | a2 = 25.3851; 62 | a3 = 14.0941; 63 | a4 = -7.0261; 64 | a5 = 2.7081; 65 | 66 | b0 = 0.0005; 67 | b1 = -0.0056; 68 | b2 = -0.0066; 69 | b3 = -0.0375; 70 | b4 = 0.0636; 71 | b5 = -0.0144; 72 | 73 | k = 0.0162; 74 | 75 | Rtx = sqrt(Rt); 76 | del_S = (del_T68 ./ (1+k*del_T68) ) .* ... 77 | ( b0 + (b1 + (b2+ (b3 + (b4 + b5.*Rtx).*Rtx).*Rtx).*Rtx).*Rtx); 78 | 79 | S = a0 + (a1 + (a2 + (a3 + (a4 + a5.*Rtx).*Rtx).*Rtx).*Rtx).*Rtx; 80 | 81 | S = S + del_S; 82 | 83 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_salt.m: -------------------------------------------------------------------------------- 1 | 2 | function S = sw_salt(cndr,T,P) 3 | 4 | % SW_SALT Salinity from cndr, T, P 5 | %========================================================================= 6 | % SW_SALT $Id: sw_salt.m,v 1.2 2004/03/18 20:27:03 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: S = sw_salt(cndr,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Calculates Salinity from conductivity ratio. UNESCO 1983 polynomial. 13 | % 14 | % INPUT: 15 | % cndr = Conductivity ratio R = C(S,T,P)/C(35,15(IPTS-68),0) [no units] 16 | % T = temperature [degree C (ITS-90)] 17 | % P = pressure [db] 18 | % 19 | % OUTPUT: 20 | % S = salinity [psu (PSS-78)] 21 | % 22 | % AUTHOR: Phil Morgan 93-04-17, Lindsay Pender (Lindsay.Pender@csiro.au) 23 | % 24 | % DISCLAIMER: 25 | % This software is provided "as is" without warranty of any kind. 26 | % See the file sw_copy.m for conditions of use and licence. 27 | % 28 | % REFERENCES: 29 | % Fofonoff, P. and Millard, R.C. Jr 30 | % Unesco 1983. Algorithms for computation of fundamental properties of 31 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 32 | %========================================================================= 33 | 34 | % Modifications 35 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 36 | 37 | % CALLER: general purpose 38 | % CALLEE: sw_sals.m sw_salrt.m sw_salrp.m 39 | 40 | 41 | %---------------------------------- 42 | % CHECK INPUTS ARE SAME DIMENSIONS 43 | %---------------------------------- 44 | [mc,nc] = size(cndr); 45 | [mt,nt] = size(T); 46 | [mp,np] = size(P); 47 | 48 | if ~(mc==mt | mc==mp | nc==nt | nc==np) 49 | error('sw_salt.m: cndr,T,P must all have the same dimensions') 50 | end %if 51 | 52 | %------- 53 | % BEGIN 54 | %------- 55 | R = cndr; 56 | rt = sw_salrt(T); 57 | Rp = sw_salrp(R,T,P); 58 | Rt = R./(Rp.*rt); 59 | S = sw_sals(Rt,T); 60 | 61 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_satAr.m: -------------------------------------------------------------------------------- 1 | %$$$ 2 | %$$$ #undef __PR 3 | %$$$ #include "VARIANT.h" 4 | 5 | function c = sw_satAr(S,T) 6 | 7 | % SW_SATAr Satuaration of Ar in sea water 8 | %========================================================================= 9 | % sw_satAr $Id: sw_satAr.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 10 | % Copyright (C) CSIRO, Phil Morgan 1998. 11 | % 12 | % USAGE: satAr = sw_satAr(S,T) 13 | % 14 | % DESCRIPTION: 15 | % Solubility (satuaration) of Argon (Ar) in sea water 16 | % 17 | % INPUT: (all must have same dimensions) 18 | % S = salinity [psu (PSS-78)] 19 | % T = temperature [degree C (ITS-90)] 20 | % 21 | % OUTPUT: 22 | % satAr = solubility of Ar [ml/l] 23 | % 24 | % AUTHOR: Phil Morgan 97-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 25 | % 26 | %$$$ #include "disclaimer_in_code.inc" 27 | % 28 | % REFERENCES: 29 | % Weiss, R. F. 1970 30 | % "The solubility of nitrogen, oxygen and argon in water and seawater." 31 | % Deap-Sea Research., 1970, Vol 17, pp721-735. 32 | %========================================================================= 33 | 34 | % Modifications 35 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 36 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 37 | 38 | % CALLER: general purpose 39 | % CALLEE: 40 | 41 | %$$$ #ifdef VARIANT_PRIVATE 42 | %$$$ %*********************************************************** 43 | %$$$ % 44 | %$$$ %$Log: sw_satAr.m,v $ 45 | %$$$ %Revision 1.1 2003/12/12 04:23:22 pen078 46 | %$$$ %*** empty log message *** 47 | %$$$ % 48 | 49 | %$$$ % 50 | %$$$ %*********************************************************** 51 | %$$$ #endif 52 | 53 | %---------------------- 54 | % CHECK INPUT ARGUMENTS 55 | %---------------------- 56 | if nargin ~=2 57 | error('Must pass 2 parameters') 58 | end %if 59 | 60 | % CHECK S,T dimensions and verify consistent 61 | [ms,ns] = size(S); 62 | [mt,nt] = size(T); 63 | 64 | 65 | % CHECK THAT S & T HAVE SAME SHAPE 66 | if (ms~=mt) | (ns~=nt) 67 | error('S & T must have same dimensions') 68 | end %if 69 | 70 | %------ 71 | % BEGIN 72 | %------ 73 | 74 | % convert T to Kelvin 75 | T = 273.15 + T * 1.00024; 76 | 77 | % constants for Eqn (4) of Weiss 1970 78 | a1 = -173.5146; 79 | a2 = 245.4510; 80 | a3 = 141.8222; 81 | a4 = -21.8020; 82 | b1 = -0.034474; 83 | b2 = 0.014934; 84 | b3 = -0.0017729; 85 | 86 | % Eqn (4) of Weiss 1970 87 | lnC = a1 + a2.*(100./T) + a3.*log(T./100) + a4.*(T./100) + ... 88 | S.*( b1 + b2.*(T./100) + b3.*((T./100).^2) ); 89 | 90 | c = exp(lnC); 91 | 92 | return 93 | 94 | 95 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_satN2.m: -------------------------------------------------------------------------------- 1 | %$$$ 2 | %$$$ #undef __PR 3 | %$$$ #include "VARIANT.h" 4 | 5 | function c = sw_satN2(S,T) 6 | 7 | % SW_SATN2 Satuaration of N2 in sea water 8 | %========================================================================= 9 | % sw_satN2 $Id: sw_satN2.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 10 | % Copyright (C) CSIRO, Phil Morgan 1998. 11 | % 12 | % USAGE: satN2 = sw_satN2(S,T) 13 | % 14 | % DESCRIPTION: 15 | % Solubility (satuaration) of Nitrogen (N2) in sea water 16 | % 17 | % INPUT: (all must have same dimensions) 18 | % S = salinity [psu (PSS-78)] 19 | % T = temperature [degree C (ITS-90)] 20 | % 21 | % OUTPUT: 22 | % satN2 = solubility of N2 [ml/l] 23 | % 24 | % AUTHOR: Phil Morgan 97-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 25 | % 26 | %$$$ #include "disclaimer_in_code.inc" 27 | % 28 | % REFERENCES: 29 | % Weiss, R. F. 1970 30 | % "The solubility of nitrogen, oxygen and argon in water and seawater." 31 | % Deap-Sea Research., 1970, Vol 17, pp721-735. 32 | %========================================================================= 33 | 34 | % Modifications 35 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 36 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 37 | 38 | % CALLER: general purpose 39 | % CALLEE: 40 | 41 | %$$$ #ifdef VARIANT_PRIVATE 42 | %$$$ %*********************************************************** 43 | %$$$ %$Id: sw_satN2.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 44 | %$$$ % 45 | %$$$ %$Log: sw_satN2.m,v $ 46 | %$$$ %Revision 1.1 2003/12/12 04:23:22 pen078 47 | %$$$ %*** empty log message *** 48 | %$$$ % 49 | 50 | %$$$ % 51 | %$$$ %*********************************************************** 52 | %$$$ #endif 53 | 54 | %---------------------- 55 | % CHECK INPUT ARGUMENTS 56 | %---------------------- 57 | if nargin ~=2 58 | error('sw_satN2.m: Must pass 2 parameters') 59 | end %if 60 | 61 | % CHECK S,T dimensions and verify consistent 62 | [ms,ns] = size(S); 63 | [mt,nt] = size(T); 64 | 65 | 66 | % CHECK THAT S & T HAVE SAME SHAPE 67 | if (ms~=mt) | (ns~=nt) 68 | error('sw_satN2: S & T must have same dimensions') 69 | end %if 70 | 71 | %------ 72 | % BEGIN 73 | %------ 74 | 75 | % convert T to Kelvin 76 | T = 273.15 + T * 1.00024; 77 | 78 | % constants for Eqn (4) of Weiss 1970 79 | a1 = -172.4965; 80 | a2 = 248.4262; 81 | a3 = 143.0738; 82 | a4 = -21.7120; 83 | b1 = -0.049781; 84 | b2 = 0.025018; 85 | b3 = -0.0034861; 86 | 87 | % Eqn (4) of Weiss 1970 88 | lnC = a1 + a2.*(100./T) + a3.*log(T./100) + a4.*(T./100) + ... 89 | S.*( b1 + b2.*(T./100) + b3.*((T./100).^2) ); 90 | 91 | c = exp(lnC); 92 | 93 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_satO2.m: -------------------------------------------------------------------------------- 1 | %$$$ 2 | %$$$ #undef __PR 3 | %$$$ #include "VARIANT.h" 4 | 5 | function c = sw_satO2(S,T) 6 | 7 | % SW_SATO2 Satuaration of O2 in sea water 8 | %========================================================================= 9 | % sw_satO2 $Id: sw_satO2.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 10 | % Copyright (C) CSIRO, Phil Morgan 1998. 11 | % 12 | % USAGE: satO2 = sw_satO2(S,T) 13 | % 14 | % DESCRIPTION: 15 | % Solubility (satuaration) of Oxygen (O2) in sea water 16 | % 17 | % INPUT: (all must have same dimensions) 18 | % S = salinity [psu (PSS-78)] 19 | % T = temperature [degree C (ITS-68)] 20 | % 21 | % OUTPUT: 22 | % satO2 = solubility of O2 [ml/l] 23 | % 24 | % AUTHOR: Phil Morgan 97-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 25 | % 26 | %$$$ #include "disclaimer_in_code.inc" 27 | % 28 | % REFERENCES: 29 | % Weiss, R. F. 1970 30 | % "The solubility of nitrogen, oxygen and argon in water and seawater." 31 | % Deap-Sea Research., 1970, Vol 17, pp721-735. 32 | %========================================================================= 33 | 34 | % Modifications 35 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 36 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 37 | 38 | % CALLER: general purpose 39 | % CALLEE: 40 | 41 | %$$$ #ifdef VARIANT_PRIVATE 42 | %$$$ %*********************************************************** 43 | %$$$ %$Id: sw_satO2.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 44 | %$$$ % 45 | %$$$ %$Log: sw_satO2.m,v $ 46 | %$$$ %Revision 1.1 2003/12/12 04:23:22 pen078 47 | %$$$ %*** empty log message *** 48 | %$$$ % 49 | 50 | %$$$ % 51 | %$$$ %*********************************************************** 52 | %$$$ #endif 53 | 54 | %---------------------- 55 | % CHECK INPUT ARGUMENTS 56 | %---------------------- 57 | if nargin ~=2 58 | error('sw_satO2.m: Must pass 2 parameters') 59 | end %if 60 | 61 | % CHECK S,T dimensions and verify consistent 62 | [ms,ns] = size(S); 63 | [mt,nt] = size(T); 64 | 65 | 66 | % CHECK THAT S & T HAVE SAME SHAPE 67 | if (ms~=mt) | (ns~=nt) 68 | error('sw_satO2: S & T must have same dimensions') 69 | end %if 70 | 71 | %------ 72 | % BEGIN 73 | %------ 74 | 75 | % convert T to Kelvin 76 | T = 273.15 + T * 1.00024; 77 | 78 | % constants for Eqn (4) of Weiss 1970 79 | a1 = -173.4292; 80 | a2 = 249.6339; 81 | a3 = 143.3483; 82 | a4 = -21.8492; 83 | b1 = -0.033096; 84 | b2 = 0.014259; 85 | b3 = -0.0017000; 86 | 87 | % Eqn (4) of Weiss 1970 88 | lnC = a1 + a2.*(100./T) + a3.*log(T./100) + a4.*(T./100) + ... 89 | S.*( b1 + b2.*(T./100) + b3.*((T./100).^2) ); 90 | 91 | c = exp(lnC); 92 | 93 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_seck.m: -------------------------------------------------------------------------------- 1 | 2 | function K = sw_seck(S,T,P) 3 | 4 | % SW_SECK Secant bulk modulus (K) of sea water 5 | %========================================================================= 6 | % SW_SECK $Id: sw_seck.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: dens = sw_seck(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Secant Bulk Modulus (K) of Sea Water using Equation of state 1980. 13 | % UNESCO polynomial implementation. 14 | % 15 | % INPUT: (all must have same dimensions) 16 | % S = salinity [psu (PSS-78) ] 17 | % T = temperature [degree C (ITS-90)] 18 | % P = pressure [db] 19 | % (alternatively, may have dimensions 1*1 or 1*n where n is columns in S) 20 | % 21 | % OUTPUT: 22 | % K = Secant Bulk Modulus [bars] 23 | % 24 | % AUTHOR: Phil Morgan 92-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 25 | % 26 | % DISCLAIMER: 27 | % This software is provided "as is" without warranty of any kind. 28 | % See the file sw_copy.m for conditions of use and licence. 29 | % 30 | % REFERENCES: 31 | % Fofonoff, P. and Millard, R.C. Jr 32 | % Unesco 1983. Algorithms for computation of fundamental properties of 33 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 34 | % Eqn.(15) p.18 35 | % 36 | % Millero, F.J. and Poisson, A. 37 | % International one-atmosphere equation of state of seawater. 38 | % Deep-Sea Res. 1981. Vol28A(6) pp625-629. 39 | %========================================================================= 40 | 41 | % Modifications 42 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 43 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 44 | 45 | % CALLER: sw_dens.m 46 | % CALLEE: none 47 | 48 | %---------------------- 49 | % CHECK INPUT ARGUMENTS 50 | %---------------------- 51 | if nargin ~=3 52 | error('sw_seck.m: Must pass 3 parameters') 53 | end %if 54 | 55 | % CHECK S,T,P dimensions and verify consistent 56 | [ms,ns] = size(S); 57 | [mt,nt] = size(T); 58 | [mp,np] = size(P); 59 | 60 | 61 | % CHECK THAT S & T HAVE SAME SHAPE 62 | if (ms~=mt) | (ns~=nt) 63 | error('check_stp: S & T must have same dimensions') 64 | end %if 65 | 66 | % CHECK OPTIONAL SHAPES FOR P 67 | if mp==1 & np==1 % P is a scalar. Fill to size of S 68 | P = P(1)*ones(ms,ns); 69 | elseif np==ns & mp==1 % P is row vector with same cols as S 70 | P = P( ones(1,ms), : ); % Copy down each column. 71 | elseif mp==ms & np==1 % P is column vector 72 | P = P( :, ones(1,ns) ); % Copy across each row 73 | elseif mp==ms & np==ns % PR is a matrix size(S) 74 | % shape ok 75 | else 76 | error('check_stp: P has wrong dimensions') 77 | end %if 78 | 79 | %***check_stp 80 | 81 | %-------------------------------------------------------------------- 82 | % COMPUTE COMPRESSION TERMS 83 | %-------------------------------------------------------------------- 84 | P = P/10; %convert from db to atmospheric pressure units 85 | T68 = T * 1.00024; 86 | 87 | % Pure water terms of the secant bulk modulus at atmos pressure. 88 | % UNESCO eqn 19 p 18 89 | 90 | h3 = -5.77905E-7; 91 | h2 = +1.16092E-4; 92 | h1 = +1.43713E-3; 93 | h0 = +3.239908; %[-0.1194975]; 94 | 95 | AW = h0 + (h1 + (h2 + h3.*T68).*T68).*T68; 96 | 97 | k2 = 5.2787E-8; 98 | k1 = -6.12293E-6; 99 | k0 = +8.50935E-5; %[+3.47718E-5]; 100 | 101 | BW = k0 + (k1 + k2*T68).*T68; 102 | 103 | e4 = -5.155288E-5; 104 | e3 = +1.360477E-2; 105 | e2 = -2.327105; 106 | e1 = +148.4206; 107 | e0 = 19652.21; %[-1930.06]; 108 | 109 | KW = e0 + (e1 + (e2 + (e3 + e4*T68).*T68).*T68).*T68; % eqn 19 110 | 111 | %-------------------------------------------------------------------- 112 | % SEA WATER TERMS OF SECANT BULK MODULUS AT ATMOS PRESSURE. 113 | %-------------------------------------------------------------------- 114 | j0 = 1.91075E-4; 115 | 116 | i2 = -1.6078E-6; 117 | i1 = -1.0981E-5; 118 | i0 = 2.2838E-3; 119 | 120 | SR = sqrt(S); 121 | 122 | A = AW + (i0 + (i1 + i2*T68).*T68 + j0*SR).*S; 123 | 124 | 125 | m2 = 9.1697E-10; 126 | m1 = +2.0816E-8; 127 | m0 = -9.9348E-7; 128 | 129 | B = BW + (m0 + (m1 + m2*T68).*T68).*S; % eqn 18 130 | 131 | f3 = -6.1670E-5; 132 | f2 = +1.09987E-2; 133 | f1 = -0.603459; 134 | f0 = +54.6746; 135 | 136 | g2 = -5.3009E-4; 137 | g1 = +1.6483E-2; 138 | g0 = +7.944E-2; 139 | 140 | K0 = KW + ( f0 + (f1 + (f2 + f3*T68).*T68).*T68 ... 141 | + (g0 + (g1 + g2*T68).*T68).*SR ).*S; % eqn 16 142 | 143 | K = K0 + (A + B.*P).*P; % eqn 15 144 | return 145 | %---------------------------------------------------------------------------- 146 | 147 | 148 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_smow.m: -------------------------------------------------------------------------------- 1 | 2 | function dens = sw_smow(T) 3 | 4 | % SW_SMOW Denisty of standard mean ocean water (pure water) 5 | %========================================================================= 6 | % SW_SMOW $Id: sw_smow.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: dens = sw_smow(T) 10 | % 11 | % DESCRIPTION: 12 | % Denisty of Standard Mean Ocean Water (Pure Water) using EOS 1980. 13 | % 14 | % INPUT: 15 | % T = temperature [degree C (ITS-90)] 16 | % 17 | % OUTPUT: 18 | % dens = density [kg/m^3] 19 | % 20 | % AUTHOR: Phil Morgan 92-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 21 | % 22 | % DISCLAIMER: 23 | % This software is provided "as is" without warranty of any kind. 24 | % See the file sw_copy.m for conditions of use and licence. 25 | % 26 | % REFERENCES: 27 | % Unesco 1983. Algorithms for computation of fundamental properties of 28 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 29 | % UNESCO 1983 p17 Eqn(14) 30 | % 31 | % Millero, F.J & Poisson, A. 32 | % INternational one-atmosphere equation of state for seawater. 33 | % Deep-Sea Research Vol28A No.6. 1981 625-629. Eqn (6) 34 | %========================================================================= 35 | 36 | % Modifications 37 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 38 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 39 | 40 | %---------------------- 41 | % CHECK INPUT ARGUMENTS 42 | %---------------------- 43 | % TEST INPUTS 44 | if nargin ~= 1 45 | error('sw_smow.m: Only one input argument allowed') 46 | end %if 47 | 48 | %---------------------- 49 | % DEFINE CONSTANTS 50 | %---------------------- 51 | a0 = 999.842594; 52 | a1 = 6.793952e-2; 53 | a2 = -9.095290e-3; 54 | a3 = 1.001685e-4; 55 | a4 = -1.120083e-6; 56 | a5 = 6.536332e-9; 57 | 58 | T68 = T * 1.00024; 59 | dens = a0 + (a1 + (a2 + (a3 + (a4 + a5*T68).*T68).*T68).*T68).*T68; 60 | return 61 | %-------------------------------------------------------------------- 62 | 63 | 64 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_svan.m: -------------------------------------------------------------------------------- 1 | 2 | function svan = sw_svan(S,T,P) 3 | 4 | % SW_SVAN Specific volume anomaly 5 | %========================================================================= 6 | % SW_SVAN $Id: sw_svan.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: svan = sw_svan(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Specific Volume Anomaly calculated as 13 | % svan = 1/sw_dens(s,t,p) - 1/sw_dens(35,0,p) 14 | % Note that it is often quoted in literature as 1e8*units 15 | % 16 | % INPUT: (all must have same dimensions) 17 | % S = salinity [psu (PSS-78) ] 18 | % T = temperature [degree C (ITS-90)] 19 | % P = Pressure [db] 20 | % (alternatively, may have dimensions 1*1 or 1*n where n is columns in S) 21 | % 22 | % OUTPUT: 23 | % svan = Specific Volume Anomaly [m^3 kg^-1] 24 | % 25 | % AUTHOR: Phil Morgan 92-11-05, Lindsay Pender (Lindsay.Pender@csiro.au) 26 | % 27 | % DISCLAIMER: 28 | % This software is provided "as is" without warranty of any kind. 29 | % See the file sw_copy.m for conditions of use and licence. 30 | % 31 | % REFERENCE: 32 | % Fofonoff, N.P. and Millard, R.C. Jr 33 | % Unesco 1983. Algorithms for computation of fundamental properties of 34 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 35 | % Eqn (9) p.15. 36 | % 37 | % S. Pond & G.Pickard 2nd Edition 1986 38 | % Introductory Dynamical Oceanogrpahy 39 | % Pergamon Press Sydney. ISBN 0-08-028728-X 40 | %========================================================================= 41 | 42 | % Modifications 43 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 44 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 45 | 46 | % CALLER: general purpose 47 | % CALLEE: sw_dens.m 48 | 49 | %---------------------- 50 | % CHECK INPUT ARGUMENTS 51 | %---------------------- 52 | if nargin ~=3 53 | error('sw_svan.m: Must pass 3 parameters') 54 | end %if 55 | 56 | % CHECK S,T,P dimensions and verify consistent 57 | [ms,ns] = size(S); 58 | [mt,nt] = size(T); 59 | [mp,np] = size(P); 60 | 61 | 62 | % CHECK THAT S & T HAVE SAME SHAPE 63 | if (ms~=mt) | (ns~=nt) 64 | error('check_stp: S & T must have same dimensions') 65 | end %if 66 | 67 | % CHECK OPTIONAL SHAPES FOR P 68 | if mp==1 & np==1 % P is a scalar. Fill to size of S 69 | P = P(1)*ones(ms,ns); 70 | elseif np==ns & mp==1 % P is row vector with same cols as S 71 | P = P( ones(1,ms), : ); % Copy down each column. 72 | elseif mp==ms & np==1 % P is column vector 73 | P = P( :, ones(1,ns) ); % Copy across each row 74 | elseif mp==ms & np==ns % PR is a matrix size(S) 75 | % shape ok 76 | else 77 | error('check_stp: P has wrong dimensions') 78 | end %if 79 | 80 | %***check_stp 81 | 82 | 83 | % ----- 84 | % BEGIN 85 | % ----- 86 | svan = ( ones(size(S)) ./ sw_dens(S,T,P)) - ... 87 | (ones(size(S)) ./ sw_dens(35*ones(size(S)),zeros(size(S)),P) ); 88 | 89 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_svel.m: -------------------------------------------------------------------------------- 1 | 2 | function svel = sw_svel(S,T,P) 3 | 4 | % SW_SVEL Sound velocity of sea water 5 | %========================================================================= 6 | % SW_SVEL $Id: sw_svel.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: svel = sw_svel(S,T,P) 10 | % 11 | % DESCRIPTION: 12 | % Sound Velocity in sea water using UNESCO 1983 polynomial. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % S = salinity [psu (PSS-78)] 16 | % T = temperature [degree C (ITS-90)] 17 | % P = pressure [db] 18 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 19 | % 20 | % OUTPUT: 21 | % svel = sound velocity [m/s] 22 | % 23 | % AUTHOR: Phil Morgan 93-04-20, Lindsay Pender (Lindsay.Pender@csiro.au) 24 | % 25 | % DISCLAIMER: 26 | % This software is provided "as is" without warranty of any kind. 27 | % See the file sw_copy.m for conditions of use and licence. 28 | % 29 | % REFERENCES: 30 | % Fofonoff, P. and Millard, R.C. Jr 31 | % Unesco 1983. Algorithms for computation of fundamental properties of 32 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 33 | %========================================================================= 34 | 35 | % Modifications 36 | % 99-06-25. Lindsay Pender, Fixed transpose of row vectors. 37 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 38 | 39 | % CALLER: general purpose 40 | % CALLEE: none 41 | 42 | % UNESCO 1983. eqn.33 p.46 43 | 44 | %---------------------- 45 | % CHECK INPUT ARGUMENTS 46 | %---------------------- 47 | if nargin ~=3 48 | error('sw_svel.m: Must pass 3 parameters') 49 | end %if 50 | 51 | % CHECK S,T,P dimensions and verify consistent 52 | [ms,ns] = size(S); 53 | [mt,nt] = size(T); 54 | [mp,np] = size(P); 55 | 56 | 57 | % CHECK THAT S & T HAVE SAME SHAPE 58 | if (ms~=mt) | (ns~=nt) 59 | error('check_stp: S & T must have same dimensions') 60 | end %if 61 | 62 | % CHECK OPTIONAL SHAPES FOR P 63 | if mp==1 & np==1 % P is a scalar. Fill to size of S 64 | P = P(1)*ones(ms,ns); 65 | elseif np==ns & mp==1 % P is row vector with same cols as S 66 | P = P( ones(1,ms), : ); % Copy down each column. 67 | elseif mp==ms & np==1 % P is column vector 68 | P = P( :, ones(1,ns) ); % Copy across each row 69 | elseif mp==ms & np==ns % PR is a matrix size(S) 70 | % shape ok 71 | else 72 | error('check_stp: P has wrong dimensions') 73 | end %if 74 | 75 | %***check_stp 76 | 77 | %--------- 78 | % BEGIN 79 | %-------- 80 | 81 | P = P/10; % convert db to bars as used in UNESCO routines 82 | T68 = T * 1.00024; 83 | 84 | %------------ 85 | % eqn 34 p.46 86 | %------------ 87 | c00 = 1402.388; 88 | c01 = 5.03711; 89 | c02 = -5.80852e-2; 90 | c03 = 3.3420e-4; 91 | c04 = -1.47800e-6; 92 | c05 = 3.1464e-9; 93 | 94 | c10 = 0.153563; 95 | c11 = 6.8982e-4; 96 | c12 = -8.1788e-6; 97 | c13 = 1.3621e-7; 98 | c14 = -6.1185e-10; 99 | 100 | c20 = 3.1260e-5; 101 | c21 = -1.7107e-6; 102 | c22 = 2.5974e-8; 103 | c23 = -2.5335e-10; 104 | c24 = 1.0405e-12; 105 | 106 | c30 = -9.7729e-9; 107 | c31 = 3.8504e-10; 108 | c32 = -2.3643e-12; 109 | 110 | Cw = ((((c32.*T68 + c31).*T68 + c30).*P + ... 111 | ((((c24.*T68 + c23).*T68 + c22).*T68 + c21).*T68 + c20)).*P + ... 112 | ((((c14.*T68 + c13).*T68 + c12).*T68 + c11).*T68 + c10)).*P + ... 113 | ((((c05.*T68 + c04).*T68 + c03).*T68 + c02).*T68 + c01).*T68 + c00; 114 | 115 | %------------- 116 | % eqn 35. p.47 117 | %------------- 118 | a00 = 1.389; 119 | a01 = -1.262e-2; 120 | a02 = 7.164e-5; 121 | a03 = 2.006e-6; 122 | a04 = -3.21e-8; 123 | 124 | a10 = 9.4742e-5; 125 | a11 = -1.2580e-5; 126 | a12 = -6.4885e-8; 127 | a13 = 1.0507e-8; 128 | a14 = -2.0122e-10; 129 | 130 | a20 = -3.9064e-7; 131 | a21 = 9.1041e-9; 132 | a22 = -1.6002e-10; 133 | a23 = 7.988e-12; 134 | 135 | a30 = 1.100e-10; 136 | a31 = 6.649e-12; 137 | a32 = -3.389e-13; 138 | 139 | A = ((((a32.*T68 + a31).*T68 + a30).*P + ... 140 | (((a23.*T68 + a22).*T68 + a21).*T68 + a20)).*P + ... 141 | ((((a14.*T68 + a13).*T68 + a12).*T68 + a11).*T68 + a10)).*P + ... 142 | (((a04.*T68 + a03).*T68 + a02).*T68 + a01).*T68 + a00; 143 | 144 | %------------ 145 | % eqn 36 p.47 146 | %------------ 147 | b00 = -1.922e-2; 148 | b01 = -4.42e-5; 149 | b10 = 7.3637e-5; 150 | b11 = 1.7945e-7; 151 | 152 | B = b00 + b01.*T68 + (b10 + b11.*T68).*P; 153 | 154 | %------------ 155 | % eqn 37 p.47 156 | %------------ 157 | d00 = 1.727e-3; 158 | d10 = -7.9836e-6; 159 | 160 | D = d00 + d10.*P; 161 | 162 | %------------ 163 | % eqn 33 p.46 164 | %------------ 165 | svel = Cw + A.*S + B.*S.*sqrt(S) + D.*S.^2; 166 | 167 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_swvel.m: -------------------------------------------------------------------------------- 1 | 2 | function speed = sw_swvel(len, depth) 3 | 4 | % SW_SWVEL Surface wave velocity 5 | %=========================================================================== 6 | % SW_SWVEL $Id$ 7 | % Copyright (C) CSIRO, Phil Morgan 1993. 8 | % 9 | % USAGE: speed = sw_swvel(len, depth) 10 | % 11 | % DESCRIPTION: 12 | % Calculates surface wave velocity. 13 | % 14 | % INPUT: (all must have same dimensions) 15 | % len = wave length 16 | % depth = water depth [metres] 17 | % 18 | % OUTPUT: 19 | % speed = Surface wave speed (m/s) 20 | % 21 | % AUTHOR: Lindsay Pender 2005 22 | % 23 | % DISCLAIMER: 24 | % This software is provided "as is" without warranty of any kind. 25 | % See the file sw_copy.m for conditions of use and licence. 26 | %========================================================================= 27 | 28 | % CALLER: general purpose 29 | % CALLEE: none 30 | 31 | %------------- 32 | % CHECK INPUTS 33 | %------------- 34 | [mD,nD] = size(depth); 35 | [mL,nL] = size(len); 36 | if mD==1 & nD==1 % depth scalar - fill to size of len 37 | depth = depth*ones(size(len)); 38 | 39 | elseif nL == nD & mD == 1 % depth is row vector 40 | depth = depth(ones(1, mL), :); % Copy down each column 41 | 42 | elseif mL == mD & nD == 1 % depth is column vector 43 | depth = depth(:, ones(1, nL)); % Copy across each row 44 | 45 | elseif mD == mL & nD == nL 46 | % Ok 47 | 48 | else 49 | error('sw_swvel.m: Inputs arguments have wrong dimensions') 50 | end %if 51 | 52 | %------------- 53 | % BEGIN 54 | %------------- 55 | 56 | g = 9.8; 57 | k = 2.0 * pi ./ len; 58 | speed = sqrt(g * tanh(k .* depth) ./ k); 59 | return 60 | %=========================================================================== 61 | 62 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_temp.m: -------------------------------------------------------------------------------- 1 | 2 | function PT = sw_temp(S,T,P,PR) 3 | 4 | % SW_TEMP Temperature from potential temperature 5 | %=========================================================================== 6 | % TEMP $Id: sw_temp.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 7 | % Copyright (C) CSIRO, Phil Morgan 1992. 8 | % 9 | % USAGE: temp = sw_temp(S,PTMP,P,PR) 10 | % 11 | % DESCRIPTION: 12 | % Calculates temperature from potential temperature at the reference 13 | % pressure PR and in-situ pressure P. 14 | % 15 | % INPUT: (all must have same dimensions) 16 | % S = salinity [psu (PSS-78) ] 17 | % PTMP = potential temperature [degree C (ITS-90)] 18 | % P = pressure [db] 19 | % PR = Reference pressure [db] 20 | % (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) ) 21 | % 22 | % OUTPUT: 23 | % temp = temperature [degree C (ITS-90)] 24 | % 25 | % AUTHOR: Phil Morgan 92-04-06, Lindsay Pender (Lindsay.Pender@csiro.au) 26 | % 27 | % DISCLAIMER: 28 | % This software is provided "as is" without warranty of any kind. 29 | % See the file sw_copy.m for conditions of use and licence. 30 | % 31 | % REFERENCES: 32 | % Fofonoff, P. and Millard, R.C. Jr 33 | % Unesco 1983. Algorithms for computation of fundamental properties of 34 | % seawater, 1983. _Unesco Tech. Pap. in Mar. Sci._, No. 44, 53 pp. 35 | % Eqn.(31) p.39 36 | % 37 | % Bryden, H. 1973. 38 | % "New Polynomials for thermal expansion, adiabatic temperature gradient 39 | % and potential temperature of sea water." 40 | % DEEP-SEA RES., 1973, Vol20,401-408. 41 | %========================================================================= 42 | 43 | % Modifications 44 | % 03-12-12. Lindsay Pender, Converted to ITS-90. 45 | 46 | % CALLER: general purpose 47 | % CALLEE: sw_ptmp.m 48 | 49 | %------------- 50 | % CHECK INPUTS 51 | %------------- 52 | if nargin ~= 4 53 | error('sw_temp.m: Must pass 4 parameters ') 54 | end %if 55 | % LET sw_ptmp.m DO DIMENSION CHECKING 56 | 57 | % CARRY OUT INVERSE CALCULATION BY SWAPPING P0 & PR. 58 | PT = sw_ptmp(S,T,PR,P); 59 | 60 | -------------------------------------------------------------------------------- /seawater/tests/seawater_v3_3/sw_ver.m: -------------------------------------------------------------------------------- 1 | % SW_VER Version number of SEAWATER library 2 | %========================================================================= 3 | % SW_VER $Id: sw_ver.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $ 4 | % Copyright (C) CSIRO, Phil Morgan 1994 5 | % 6 | % sw_ver 7 | % 8 | % DESCRIPTION: 9 | % Returns version number of the SEAWATER library 10 | % 11 | % AUTHOR: Phil Morgan, Lindsay Pender (Lindsay.Pender@csiro.au) 12 | % 13 | % DISCLAIMER: 14 | % This software is provided "as is" without warranty of any kind. 15 | % See the file sw_copy.m for conditions of use and licence. 16 | % 17 | %========================================================================= 18 | disp('SEAWATER Version 3.3') 19 | 20 | -------------------------------------------------------------------------------- /seawater/tests/test_input_shapes.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from pathlib import Path 3 | 4 | import numpy as np 5 | 6 | import seawater as sw 7 | 8 | rootpath = Path(__file__).parent 9 | fname = rootpath.joinpath("data", "shapes.npz") 10 | 11 | 12 | class InputShapes(unittest.TestCase): 13 | def setUp(self): 14 | with np.load(fname) as shapes: 15 | self.cp = shapes["cp"] 16 | self.lon = shapes["lon"] 17 | self.lat = shapes["lat"] 18 | self.dens = shapes["dens"] 19 | self.depth = shapes["depth"] 20 | self.s_mean = shapes["s_mean"] 21 | self.t_mean = shapes["t_mean"] 22 | self.pt_mean = shapes["pt_mean"] 23 | self.steric_height = shapes["steric_height"] 24 | 25 | def tearDown(self): 26 | unittest.TestCase.tearDown(self) 27 | 28 | def test_1D(self): 29 | steric_height_new = sw.gpan( 30 | self.s_mean[:, 0, 0], 31 | self.t_mean[:, 0, 0], 32 | self.depth, 33 | ) 34 | np.testing.assert_array_almost_equal( 35 | self.steric_height[:, 0, 0], 36 | steric_height_new, 37 | ) 38 | 39 | def test_2D(self): 40 | steric_height_new = sw.gpan( 41 | self.s_mean[..., 1], 42 | self.t_mean[..., 1], 43 | self.depth[..., None], 44 | ) 45 | np.testing.assert_array_almost_equal( 46 | self.steric_height[..., 1], 47 | steric_height_new, 48 | ) 49 | 50 | def test_3D(self): 51 | steric_height_new = sw.gpan( 52 | self.s_mean, 53 | self.t_mean, 54 | self.depth[..., None, None], 55 | ) 56 | np.testing.assert_array_almost_equal( 57 | self.steric_height, 58 | steric_height_new, 59 | ) 60 | -------------------------------------------------------------------------------- /seawater/tests/test_result_comparison.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from pathlib import Path 3 | 4 | import numpy as np 5 | import pytest 6 | from oct2py import Oct2Py 7 | 8 | import seawater as sw 9 | from seawater.constants import c3515 10 | from seawater.library import T68conv, T90conv, atleast_2d 11 | 12 | rootpath = Path(__file__).parent 13 | octave = Oct2Py(timeout=3) 14 | path = rootpath.joinpath("seawater_v3_3") 15 | _ = octave.addpath(octave.genpath(str(path))) 16 | 17 | 18 | functions = { 19 | "adtg": octave.sw_adtg, 20 | "alpha": octave.sw_alpha, 21 | "aonb": octave.sw_aonb, 22 | "beta": octave.sw_beta, 23 | "bfrq": octave.sw_bfrq, 24 | "c3515": octave.sw_c3515, 25 | "cndr": octave.sw_cndr, 26 | "cp": octave.sw_cp, 27 | "dens0": octave.sw_dens0, 28 | "dens": octave.sw_dens, 29 | "dist": octave.sw_dist, 30 | "dpth": octave.sw_dpth, 31 | "f": octave.sw_f, 32 | "fp": octave.sw_fp, 33 | "g": octave.sw_g, 34 | "gpan": octave.sw_gpan, 35 | "gvel": octave.sw_gvel, 36 | "pden": octave.sw_pden, 37 | "pres": octave.sw_pres, 38 | "ptmp": octave.sw_ptmp, 39 | "salds": octave.sw_salds, 40 | "salrp": octave.sw_salrp, 41 | "salrpP": octave.sw_salrp, 42 | "salrt": octave.sw_salrt, 43 | "sals": octave.sw_sals, 44 | "salt": octave.sw_salt, 45 | "satAr": octave.sw_satAr, 46 | "satN2": octave.sw_satN2, 47 | "satO2": octave.sw_satO2, 48 | "seck": octave.sw_seck, 49 | "smow": octave.sw_smow, 50 | "svan": octave.sw_svan, 51 | "svel": octave.sw_svel, 52 | "swvel": octave.sw_swvel, 53 | "temp": octave.sw_temp, 54 | "test": octave.sw_test, 55 | } 56 | 57 | 58 | def compare_results(name, function, args, values): 59 | """Compare Python and Matlab results.""" 60 | args = [values.get(arg) for arg in args] 61 | res = function(*args) # Python call. 62 | # NOTE: Test only the first output when multiple outputs are present. 63 | if isinstance(res, tuple): 64 | res = res[0] 65 | val = functions[name](*args) # Octave call. 66 | if isinstance(val, np.ndarray): 67 | val, res = val.squeeze(), res.squeeze() 68 | np.testing.assert_allclose(val, res) 69 | 70 | 71 | class OctaveResultComparison(unittest.TestCase): 72 | def setUp(self): 73 | kw = {"comments": "#", "skiprows": 6, "delimiter": ","} 74 | station_61 = "Endeavor_Cruise-88_Station-61.csv" 75 | station_64 = "Endeavor_Cruise-88_Station-64.csv" 76 | st61 = np.loadtxt(rootpath.joinpath("data", station_61), **kw) 77 | st64 = np.loadtxt(rootpath.joinpath("data", station_64), **kw) 78 | 79 | latst = 36.0 + 40.03 / 60.0, 37.0 + 39.93 / 60.0 80 | lonst = -(70.0 + 59.59 / 60.0), -71.0 81 | Sal = np.c_[st61[:, 2], st64[:, 2]] 82 | Temp = np.c_[st61[:, 1], st64[:, 1]] 83 | Pres = np.c_[st61[:, 0], st61[:, 0]] 84 | Gpan = sw.gpan(Sal, Temp, Pres) 85 | 86 | self.values = { 87 | "r": np.array( 88 | [ 89 | 56.4125, 90 | 56.3161, 91 | 50.6703, 92 | 38.1345, 93 | 35.0565, 94 | 32.9865, 95 | ], 96 | ) 97 | / c3515, 98 | "s": np.array( 99 | [ 100 | 34.5487, 101 | 34.7275, 102 | 34.8605, 103 | 34.6810, 104 | 34.5680, 105 | 34.5600, 106 | ], 107 | ), 108 | "t": np.array( 109 | [ 110 | 28.7856, 111 | 28.4329, 112 | 22.8103, 113 | 10.2600, 114 | 6.8863, 115 | 4.4036, 116 | ], 117 | ), 118 | "p": np.array([10.0, 50.0, 125.0, 250.0, 600.0, 1000.0]), 119 | "pref": np.array([0.0]), 120 | "pt": np.array( 121 | [ 122 | 28.8099, 123 | 28.4392, 124 | 22.7862, 125 | 10.2262, 126 | 6.8272, 127 | 4.3236, 128 | ], 129 | ), 130 | "rtx": np.array([0.99353194]), 131 | "delt": np.array([13.7856]), 132 | "rt": np.array( 133 | [ 134 | 1.32968079, 135 | 1.32094651, 136 | 1.18368907, 137 | 0.89332541, 138 | 0.81977076, 139 | 0.76703445, 140 | ], 141 | ), 142 | "units": "km", 143 | "lon": np.array([-30.0] * 6), 144 | "lat": np.linspace(-22, -21.0, 6), 145 | "length": np.array([100.0] * 6), 146 | "latst": np.array(latst), 147 | "lonst": np.array(lonst), 148 | "Sal": Sal, 149 | "Temp": Temp, 150 | "Pres": Pres, 151 | "Gpan": Gpan, 152 | } 153 | 154 | def tearDown(self): 155 | unittest.TestCase.tearDown(self) 156 | 157 | # `library.py` 158 | def test_cndr(self): 159 | name = "cndr" 160 | function, args = (sw.cndr, ("s", "t", "p")) 161 | compare_results( 162 | name=name, 163 | function=function, 164 | args=args, 165 | values=self.values, 166 | ) 167 | 168 | def test_salds(self): 169 | name = "salds" 170 | function, args = (sw.salds, ("rtx", "delt")) 171 | compare_results( 172 | name=name, 173 | function=function, 174 | args=args, 175 | values=self.values, 176 | ) 177 | 178 | def test_salrp(self): 179 | name = "salrp" 180 | function, args = (sw.salrp, ("r", "t", "p")) 181 | compare_results( 182 | name=name, 183 | function=function, 184 | args=args, 185 | values=self.values, 186 | ) 187 | 188 | def test_salrt(self): 189 | name = "salrt" 190 | function, args = (sw.salrt, ("t",)) 191 | compare_results( 192 | name=name, 193 | function=function, 194 | args=args, 195 | values=self.values, 196 | ) 197 | 198 | def test_seck(self): 199 | name = "seck" 200 | function, args = (sw.seck, ("s", "t", "pref")) 201 | compare_results( 202 | name=name, 203 | function=function, 204 | args=args, 205 | values=self.values, 206 | ) 207 | 208 | def test_sals(self): 209 | name = "sals" 210 | function, args = (sw.sals, ("rt", "t")) 211 | compare_results( 212 | name=name, 213 | function=function, 214 | args=args, 215 | values=self.values, 216 | ) 217 | 218 | # `extras.py` 219 | def test_dist(self): 220 | name = "dist" 221 | function, args = (sw.dist, ("lat", "lon", "units")) 222 | compare_results( 223 | name=name, 224 | function=function, 225 | args=args, 226 | values=self.values, 227 | ) 228 | 229 | def test_f(self): 230 | name = "f" 231 | function, args = (sw.f, ("lat",)) 232 | compare_results( 233 | name=name, 234 | function=function, 235 | args=args, 236 | values=self.values, 237 | ) 238 | 239 | def test_satAr(self): 240 | name = "satAr" 241 | function, args = (sw.satAr, ("s", "t")) 242 | compare_results( 243 | name=name, 244 | function=function, 245 | args=args, 246 | values=self.values, 247 | ) 248 | 249 | def test_satN2(self): 250 | name = "satN2" 251 | function, args = (sw.satN2, ("s", "t")) 252 | compare_results( 253 | name=name, 254 | function=function, 255 | args=args, 256 | values=self.values, 257 | ) 258 | 259 | def test_satO2(self): 260 | name = "satO2" 261 | function, args = (sw.satO2, ("s", "t")) 262 | compare_results( 263 | name=name, 264 | function=function, 265 | args=args, 266 | values=self.values, 267 | ) 268 | 269 | def test_swvel(self): 270 | name = "swvel" 271 | function, args = (sw.swvel, ("length", "p")) 272 | compare_results( 273 | name=name, 274 | function=function, 275 | args=args, 276 | values=self.values, 277 | ) 278 | 279 | # `eos80.py` 280 | def test_adtg(self): 281 | name = "adtg" 282 | function, args = (sw.adtg, ("s", "t", "p")) 283 | compare_results( 284 | name=name, 285 | function=function, 286 | args=args, 287 | values=self.values, 288 | ) 289 | 290 | def test_alpha(self): 291 | name = "alpha" 292 | function, args = (sw.alpha, ("s", "t", "p")) 293 | compare_results( 294 | name=name, 295 | function=function, 296 | args=args, 297 | values=self.values, 298 | ) 299 | 300 | def test_aonb(self): 301 | name = "aonb" 302 | function, args = (sw.aonb, ("s", "t", "p")) 303 | compare_results( 304 | name=name, 305 | function=function, 306 | args=args, 307 | values=self.values, 308 | ) 309 | 310 | def test_beta(self): 311 | name = "beta" 312 | function, args = (sw.beta, ("s", "t", "p")) 313 | compare_results( 314 | name=name, 315 | function=function, 316 | args=args, 317 | values=self.values, 318 | ) 319 | 320 | def test_bfrq1d(self): 321 | name = "bfrq" 322 | function, args = (sw.bfrq, ("s", "t", "p")) 323 | compare_results( 324 | name=name, 325 | function=function, 326 | args=args, 327 | values=self.values, 328 | ) 329 | 330 | def test_dpth(self): 331 | name = "dpth" 332 | function, args = (sw.dpth, ("p", "lat")) 333 | compare_results( 334 | name=name, 335 | function=function, 336 | args=args, 337 | values=self.values, 338 | ) 339 | 340 | def test_g(self): 341 | name = "g" 342 | function, args = (sw.g, ("lat",)) 343 | compare_results( 344 | name=name, 345 | function=function, 346 | args=args, 347 | values=self.values, 348 | ) 349 | 350 | def test_salt(self): 351 | name = "salt" 352 | function, args = (sw.salt, ("r", "t", "p")) 353 | compare_results( 354 | name=name, 355 | function=function, 356 | args=args, 357 | values=self.values, 358 | ) 359 | 360 | def test_fp(self): 361 | name = "fp" 362 | function, args = (sw.fp, ("s", "p")) 363 | compare_results( 364 | name=name, 365 | function=function, 366 | args=args, 367 | values=self.values, 368 | ) 369 | 370 | def test_svel(self): 371 | name = "svel" 372 | function, args = (sw.svel, ("s", "t", "p")) 373 | compare_results( 374 | name=name, 375 | function=function, 376 | args=args, 377 | values=self.values, 378 | ) 379 | 380 | def test_pres(self): 381 | name = "pres" 382 | function, args = (sw.pres, ("p", "lat")) 383 | compare_results( 384 | name=name, 385 | function=function, 386 | args=args, 387 | values=self.values, 388 | ) 389 | 390 | def test_dens0(self): 391 | name = "dens0" 392 | function, args = (sw.dens0, ("s", "t")) 393 | compare_results( 394 | name=name, 395 | function=function, 396 | args=args, 397 | values=self.values, 398 | ) 399 | 400 | def test_smow(self): 401 | name = "smow" 402 | function, args = (sw.smow, ("t")) 403 | compare_results( 404 | name=name, 405 | function=function, 406 | args=args, 407 | values=self.values, 408 | ) 409 | 410 | def test_dens(self): 411 | name = "dens" 412 | function, args = (sw.dens, ("s", "t", "p")) 413 | compare_results( 414 | name=name, 415 | function=function, 416 | args=args, 417 | values=self.values, 418 | ) 419 | 420 | def test_pden(self): 421 | name = "pden" 422 | function, args = (sw.pden, ("s", "t", "p", "pref")) 423 | compare_results( 424 | name=name, 425 | function=function, 426 | args=args, 427 | values=self.values, 428 | ) 429 | 430 | def test_cp(self): 431 | name = "cp" 432 | function, args = (sw.cp, ("s", "t", "p")) 433 | compare_results( 434 | name=name, 435 | function=function, 436 | args=args, 437 | values=self.values, 438 | ) 439 | 440 | def test_ptmp(self): 441 | name = "ptmp" 442 | function, args = (sw.ptmp, ("s", "t", "p", "pref")) 443 | compare_results( 444 | name=name, 445 | function=function, 446 | args=args, 447 | values=self.values, 448 | ) 449 | 450 | def test_temp(self): 451 | name = "temp" 452 | function, args = (sw.temp, ("s", "pt", "p", "pref")) 453 | compare_results( 454 | name=name, 455 | function=function, 456 | args=args, 457 | values=self.values, 458 | ) 459 | 460 | # `geostrophic.py` 461 | def test_svan(self): 462 | name = "svan" 463 | function, args = (sw.svan, ("s", "t", "pref")) 464 | compare_results( 465 | name=name, 466 | function=function, 467 | args=args, 468 | values=self.values, 469 | ) 470 | 471 | def test_bfrq(self): 472 | name = "bfrq" 473 | function, args = (sw.bfrq, ("Sal", "Temp", "Pres")) 474 | compare_results( 475 | name=name, 476 | function=function, 477 | args=args, 478 | values=self.values, 479 | ) 480 | 481 | def test_gpan(self): 482 | name = "gpan" 483 | function, args = (sw.gpan, ("Sal", "Temp", "Pres")) 484 | compare_results( 485 | name=name, 486 | function=function, 487 | args=args, 488 | values=self.values, 489 | ) 490 | 491 | def test_gvel(self): 492 | name = "gvel" 493 | function, args = (sw.gvel, ("Gpan", "latst", "lonst")) 494 | compare_results( 495 | name=name, 496 | function=function, 497 | args=args, 498 | values=self.values, 499 | ) 500 | 501 | 502 | class TConv(unittest.TestCase): 503 | def setUp(self): 504 | self.temp = np.arange(-4.0, 45.0) 505 | 506 | def tearDown(self): 507 | unittest.TestCase.tearDown(self) 508 | 509 | def test_roundtrip(self): 510 | T68 = T68conv(self.temp) 511 | T90 = T90conv(T68, t_type="T68") 512 | np.testing.assert_array_almost_equal(T90, self.temp) 513 | 514 | def test_raise(self): 515 | with pytest.raises(NameError): 516 | T90conv(self.temp, t_type="T10") 517 | 518 | 519 | class Arrays(unittest.TestCase): 520 | def setUp(self): 521 | self.res = np.array( 522 | [ 523 | [1], 524 | [2], 525 | [3], 526 | ], 527 | ) 528 | 529 | def tearDown(self): 530 | unittest.TestCase.tearDown(self) 531 | 532 | def test_atleast_0d(self): 533 | np.testing.assert_equal( 534 | atleast_2d(1), 535 | np.array([[1]]), 536 | ) 537 | 538 | def test_atleast_1d(self): 539 | np.testing.assert_equal( 540 | atleast_2d([1, 2, 3]), 541 | self.res, 542 | ) 543 | 544 | def test_atleast_2d(self): 545 | np.testing.assert_equal( 546 | atleast_2d([[1], [2], [3]]), 547 | self.res, 548 | ) 549 | 550 | atleast_2d([[1], [2], [3]]) 551 | 552 | 553 | if __name__ == "__main__": 554 | unittest.main() 555 | --------------------------------------------------------------------------------