# Dynlib

## Contents

- 1 Documentation
- 2 Obtaining dynlib
- 3 Quick start to developing with dynlib
- 4 Dynlib functions
- 4.1
*ddx*: partial x derivative - 4.2
*ddy*: partial y derivative - 4.3
*grad*: gradient of a scalar - 4.4
*lap2*: 2-D laplacian of a scalar - 4.5
*vor*: 2-D vorticity - 4.6
*div*: 2-D divergence - 4.7
*def_shear*: shear deformation - 4.8
*def_stretch*: stretch deformation - 4.9
*def_total*: total deformation - 4.10
*def_angle*: deformation angle - 4.11
*isopv_angle*: iso-PV line angle - 4.12
*beta*: angle between dilatation axis and iso-PV lines

- 4.1

## Documentation

The steps necessary to obtain dynlib are described below. A more thorough documentation is compiled in the main documentation page.

## Obtaining dynlib

- Copying the source code repository
`git clone /Data/gfi/users/tsp065/lib/dynlib.git`

- Change into the dynlib folder
`cd dynlib`

- Compile the library
`./compile`

## Quick start to developing with dynlib

### Editing the Fortran code

The fortran code lives in the main source code directory. At the moment there are six source code files

`$ ls *.f95`

`dynlib_config.f95 dynlib_const.f95 dynlib_conv.f95 dynlib_diag.f95 dynlib_kind.f95 dynlib_stat.f95`

```
```

The most important are `dynlib_diag.f95`

which contains subroutines that calculate various diagnostics, and `dynlib_stat.f95`

which contains statistical functions. Changed Fortran sources need to be recompiled, again using

`./compile`

### Version control

The changes you made to the source code files can be listed by

`git status`

or viewed in detailed diff-comparisons by

`git diff`

or for one file only

`git diff [filename]`

Commit your changes from time to time and give a sensible and brief description of your changes in the editor that is opened (automatically)

`git commit -a`

The commit is then stored in your copy of the source code repository, but not yet available for others, which allows you to also commit work-in-progress.

A more thorough introduction to the version control system is given here or on the official documentation.

### Using the Fortran functions

An example python script which calculates deformation using the Fortran function is provided with `deformation.py`

.

## Dynlib functions

The functions operate on real arrays with dimension (nz,ny,nx) where nz is number of times or levels, and ny and nx are number of latitudes and longitudes, respectively. Typically, the results for each level or time are computed individually as a 2-D slice of the 3-D data.

*ddx*: partial x derivative

res=ddx(dat,dx,dy)

Calculates the partial x derivative of dat, using centred differences. For a non-EW-cyclic grid, 0 is returned on the edges of the x domain.

*ddy*: partial y derivative

res=ddy(dat,dx,dy)

Calculates the partial y derivative of dat, using centred differences. For a non-EW-cyclic grid, 0 is returned on all edges of the x,y domain. For an EW-cyclic grid, 0 is returned on the first and last latitudes.

*grad*: gradient of a scalar

(resx,resy)=grad(dat,dx,dy)

Calculates the gradient of dat, using centred differences. For a non-EW-cyclic grid, 0 is returned on all edges of the x,y domain. For an EW-cyclic grid, 0 is returned on the first and last latitudes.

*lap2*: 2-D laplacian of a scalar

(res)=lap2(dat,dx,dy)

Calculates the 2-D laplacian of dat, using centred differences. For a non-EW-cyclic grid, 0 is returned on all edges of the x,y domain. For an EW-cyclic grid, 0 is returned on the first and last latitudes.

*vor*: 2-D vorticity

(res)=vor(u,v,dx,dy)

Calculates the z component of vorticity of (u,v), using centred differences.

*div*: 2-D divergence

(res)=div(u,v,dx,dy)

Calculates the 2-D divergence of (u,v), using centred differences.

*def_shear*: shear deformation

(res)=def_shear(u,v,dx,dy)

Calculates the shear (antisymmetric) deformation of (u,v), using centred differences.

*def_stretch*: stretch deformation

(res)=def_stretch(u,v,dx,dy)

Calculates the stretch (symmetric) deformation of (u,v), using centred differences.

*def_total*: total deformation

(res)=def_total(u,v,dx,dy)

Calculates the total (rotation-independent) deformation of (u,v), using centred differences.

*def_angle*: deformation angle

(res)=def_angle(u,v,dx,dy)

Calculates the angle between the x-axis and the dilatation axis of the deformation of (u,v).

*isopv_angle*: iso-PV line angle

(res)=isopv_angle(pv,dx,dy)

Calculates the angle between the x-axis and the iso-lines of PV.

*beta*: angle between dilatation axis and iso-PV lines

(res)=beta(u,v,pv,dx,dy)

Calculates the angle between the dilatation axis and the iso-lines of PV.