Blame | Last modification | View Log | Download | RSS feed
\documentclass[12pt]{article}\renewcommand{\topfraction}{0.93}\renewcommand{\bottomfraction}{0.93}\renewcommand{\textfraction}{.07}\input BoxedEPS\SetRokickiEPSFSpecial\ForceOn\SetEPSFDirectory{M:/Weiterbildung/Allgemeine_Informatik/Diplomarbeit/fig/}\HideDisplacementBoxes\textwidth16.0cm\textheight26.0cm\oddsidemargin0.5cm\topmargin-1.5cm\headsep0cm\topskip0cm\renewcommand{\baselinestretch}{1.2}\begin{document}\pagenumbering{Roman}% ----------------------------------------------------------------------------------------------% Title page% ----------------------------------------------------------------------------------------------\thispagestyle{empty}\vspace{0.7cm}\begin{center}{\Large\bf Numerical Piecewise Potential Vorticity Inversion \\[2mm]A user guide for real-case experiments}\vspace{1cm}\begin{center}\begin{minipage}[t]{10cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{Fig05_pv_320K.eps}\end{minipage}\end{center}\vspace{1cm}Michael Sprenger, Ph.\,D.$^{1}$ \\\vspace{0.3cm}{\sl Institute for Atmospheric and Climate Science, ETH Z\"urich, Switzerland}\\\vspace{1.8cm}\today \\{Diploma Thesis for the Postgraduate Course in Computer Science, FHSS Schweiz,\\under the supervision of Lars Kruse, Ph.\,D.}\end{center}\vspace{2cm}\noindent{\sl $^1$Corresponding author and his address:}\\[1mm]Michael Sprenger\\Institute for Climate and Atmospheric Science, {\it IAC}ETH \\ETH Zurich \\CH-8092 Zurich, Switzerland \\e-mail: michael.sprenger@env.ethz.ch\newpage\vspace{20cm}\noindent{\bf Title figure:} Ertel's potential vorticity at 320\,K.% ----------------------------------------------------------------------------------------------% Abstract% ----------------------------------------------------------------------------------------------\newpage\begin{center}{\large \bf Abstract}\end{center}\noindentPotential vorticity (PV) is a key quantity in atmospheric dynamics. Its value is based upon severalpoints: (a) PV is conserved in purely adiabatic flows, i.e. if radiative and condensational heating and otherdiabatic processes can be neglected; (b) under suitable balance conditions the specification of PVin the interior of a domain and with boundary values for potential temperature completely determinesthe flow field, in particular horizontal wind and temperature can be derived; (c) in many respectsthe atmosphere can be partitioned into several distinct PV features, which then interact and allowthe dynamics to be interpreted as the interaction of these PV elements. Points (b) and (c) are knownas the invertibility and partitioning principle, respectively.\\\noindentIn this thesis, a program package is presented which allows to isolate PV elements and then tostudy their impact on the atmospheric flow field and on the temperature distribution. Technically,this is done with a so-called PV inversion, which in turn comprises several different steps, as forexample transformation into suitable co-ordinate systems and numerical solution of a poisson equation. With PV inversion, two major problems arise: Firstly, a suitable balance condition mustbe formulated, secondly the inversion problem for Ertel's PV is nonlinear, and therefore poses a significant challenge. The program presented in this thesis is based upon the so-calledquasi-geostrophic balance condition. More specifically, the linear quasi-geostrophic PV equation issolved. Since quasi-geostrophic and Ertel's PV do not exactly coincide, an iterative techniqueis adopted to approach the nonlinear Ertel-PV inversion by means of successively quasi-geostrophicinversions.\\\noindentThe aim of this work is to present an in-depth discussion of all steps which are needed for a PV inversion.Special focus was given to a clear and user-friendly program package, where all steps arewell documented and hence are attractive for further development. In this respect, the completeinversion is controlled by one single Linux Shell script.The new user needs only to adjust some few paths in this script. Themain parameters for the inversion itself are specified in a separate parameter file.\newpage\begin{center}{\large \bf Zusammenfassung}\end{center}\noindentDie potentielle Vortizit\"at (PV) ist eine Kerngr\"osse der dynamischen Meteorologie. Ihre Bedeutung basiert auf mehreren Eigenschaften: (a) In einer adiabatischen Str\"omung, dh. wenn Strahlung,die Freisetzung von latenter W\"arme und andere diabatische Prozesse vernachl\"assigt werdenk\"onnen, ist PV eine lagrange'sche Erhaltungsgr\"osse; (b) unter geeigneten Balancebedingungen bestimmt die Verteilung der PV im Innern und der potentiellen Temperatur am Rand eines Gebietesvollst\"andig den Zustand der Atmosph\"are, insbesondere die horizontalen Windfelder und dasTemperaturfeld; (c) h\"aufig l\"asst sich die Atmosph\"are in mehrere, klar voneinander getrennte PV-Elemente unterteilen, die dann die Dynamik der Atmosph\"are durch ihre Wechselwirkung bestimmen.Die Eigenschaften (b) und (c) sind in der Literatur bekannt als das Invertibilit\"atsprinzip undPartitionierungsprinzip.\\\noindentIn dieser Arbeit wird ein Programmpaket vorgestellt, mit dessen Hilfe sich einzelne PV-Elementeisolieren und ihr Einfluss auf die atmosph\"arischen Windfelder und Temperaturen studierenlassen. Programmtechnisch besteht diese sogenannte PV-Inversion aus mehreren Schritten. So musszum Beispiel eine Koordinatentransformation durchgef\"uhrt werden und eine Poisson-Gleichungnumerisch gel\"ost werden. Damit die PV-Inversion sinnvoll ist, m\"ussen zwei Probleme gel\"ostwerden. Zun\"achst muss eine geeignete Balancebedingung vorgegegeben sein. Ausserdem handelt essich bei der Inversion um einen nichtlinearen Prozess, der numerisch einige Herausforderungenstellt. In dem Programmpaket dieser Arbeit wird die sogenannte quasi-geostrophische Balanceverwendet, dh. der mathematische/numerische Inversionsprozess besteht in der L\"osung derlinearen quasi-geostrophischen PV-Gleichung. Das Problem der Nichtlinearit\"at wird dadurch gel\"ost, dassdie Berechnung des genannten linearen Inversionsproblems mehrmals wiederholt wird. Iterativergibt sich somit eine L\"osung des nichtlinearen Problems.\\\noindentZiel dieser Arbeit ist eine detailierte Darstellung aller Schritte, die bei einer PV-Inversionn\"otig sind. Besonderes Augenmerk wurde bei der Entwicklung des Programmpakets auf die klareStrukturierung und Anwenderfreundlichkeit gelegt. Dadurch kann das Paket einerseits als Black-Boxverwendet werden, zugleich erlaubt es erfahrenen Benutzern eine leichte Einarbeitung in dieProgramme und damit die M\"oglichkeit zu deren Erweiterung. Die ganze Inversion wird von einem einzigenLinux Shell Skript kontrolliert, in dem lediglich einige wenige Pfade angepasst werden m\"ussen. Diemeisten Parameter, welche das gestellte Problem der PV-Inversion beschreiben, sind in einerseparaten Parameterdatei eingetragen.% ----------------------------------------------------------------------------------------------% Inhalt% ----------------------------------------------------------------------------------------------\newpage\section*{Contents}\vspace{0.5cm}\renewcommand{\contentsname}{}\contentsline{section}{\hspace{0.5cm} Abstract}{III}\contentsline{section}{\hspace{0.5cm} Zusammenfassung}{IV}\contentsline{section}{\hspace{0.5cm} Abbreviations}{VII}\contentsline{section}{\hspace{0.5cm} List of Figures}{VIII}\vspace{-1.5cm}\tableofcontents% ----------------------------------------------------------------------------------------------% Abkürzungen% ----------------------------------------------------------------------------------------------\newpage\section*{Abbreviations}\vspace{0.5cm}\begin{tabular}{rll}{\bf [1]} & {\bf DWD} & Deutscher Wetterdienst (German weather service)\\[2mm]{\bf [2]} & {\bf ECMWF} & European Centre for Medium Range Weather Forecasts\\[2mm]{\bf [3]} & {\bf ERA-40} & Re-analysis of the ECMWF for the periods 1958-2001\\[2mm]{\bf [4]} & {\bf ERA-15} & Re-analysis of the ECMWF for the periods 1979-1993\\[2mm]{\bf [5]} & {\bf ETH} & Eidgen\"ossische Technische Hochschule\\[2mm]{\bf [6]} & {\bf f} & Coriolis parameter (in $s^{-1}$)\\[2mm]{\bf [7]} & {\bf IACETH} & Institute for Atmospheric and Climate Science at ETH Zurich\\[2mm]{\bf [8]} & {\bf METEOSAT} & European geostationary weather satellite\\[2mm]{\bf [9]} & {\bf MeteoSwiss} & Swiss weather service\\[2mm]{\bf [10]} & {\bf NaN } & Not a Number (missing data flag)\\[2mm]{\bf [11]} & {\bf netcdf } & Compact and random-access file format\\[2mm]{\bf [12]} & {\bf NWP } & Numerical weather prediction\\[2mm]{\bf [13]} & {\bf $N^2$ } & Squared Brunt-Vais\"al\"a frequency (in $s^-2$)\\[2mm]{\bf [14]} & {\bf PV} & Potential vorticity (if not otherwise stated Ertel's potential vorticity)\\[2mm]{\bf [15]} & {\bf pvu} & Potential vorticity unit\\[2mm]{\bf [16]} & {\bf PDE} & Partial differential equation\\[2mm]{\bf [17]} & {\bf SOR} & Successive over-relaxation\\[2mm]{\bf [18]} & {\bf T} & Temperature (in $^\circ$C)\\[2mm]{\bf [19]} & {\bf $T_v$} & Virtual temperature (in $^\circ$C)\\[2mm]{\bf [20]} & {\bf U} & Zonal velocity component (in west/east direction)\\[2mm]{\bf [21]} & {\bf V} & Meridional velocity component (in south/north direction)\\[2mm]{\bf [22]} & {\bf $\omega$} & Vertical velocity component (in Pa/s)\\[2mm]{\bf [23]} & {\bf q} & Specific humidity (in kg/kg)\\[2mm]{\bf [24]} & {\bf $\theta$} & Potential temperature (in K)\\[2mm]{\bf [25]} & {\bf $\rho$} & Air density (in kg/m$^3$)\\[2mm]{\bf [26]} & {\bf R$_d$} & Gas constant for dry air (in kg/m$^3$)\\[2mm]{\bf [27]} & {\bf $\epsilon$} & Ratio of gas constants for dry air and water vapour\\[2mm]{\bf [28]} & {\bf g} & Earth's gravity (in kg m/s$^2)$\\\end{tabular}\newpage\listoffigures% ----------------------------------------------------------------------------------------------% Introduction and Motivation% ----------------------------------------------------------------------------------------------\newpage\clearpage\pagenumbering{arabic}\section{Introduction and Motivation}\begin{figure}[t]\begin{center}\begin{minipage}[t]{16cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{sat_wv.ps}\end{minipage}\\\caption{\it Water vapour satellite imagery (in gray shading) and isolines of Ertel's potential vorticity (PV)at 350\,hPa and for 3 May 1998, 12\,UTC. Dark regions indicate a dry upper troposphere, whereas bright and white regions areindicative for a lot of moisture in the upper troposphere. Note that high-PV regions are coincident withdry regions. }\label{satwv}\end{center}\end{figure}There are different ways how the state of the atmosphere can be described. Traditionally this is done by specification of temperature, horizontal and vertical wind components and of either pressure, if geometrical height is used as the vertical co-ordinate, or geopotential height, if pressure is used as the vertical co-ordinate. This traditional approach has its main advantage in its simplicity. On the other hand, theoretical physics has often experienced the case that new insight can be gained if abstract, but physically more fundamental quantities were introduced. Consider for example the introduction of action and its primary physical parameter, the Planck constant. Similarly, geophysical fluid dynamics and hence atmospheric dynamics made some transitions away from the simple traditional meteorological fields toward more abstract ones.\\\noindentA long existing concept of engineering fluid dynamics is the concept of vorticity, which mathematically is defined as the curl of the wind vector field. Vorticity is treated in nearly every text book on fluid dynamics, for instance in Acheson (1990). Vorticity is a scalar quantity, but nevertheless, in a divergent-free and two-dimensional flow its specification is sufficient to deduce the complete velocity field. We could call this the invertibility principle for vorticity in such a non-divergent and two-dimensional flow. Moreover, an interesting conservation law hold for vorticity under these assumptions: Following the fluid motion, vorticity is conserved, i.e. its lagrangian derivative with respect to time is zero. Probably, in its most elegant way this conservation principle is expressed in Kelvin's circulation theorem (Acheson, 1990). These concepts of barotropic flow and of conservation of vorticity were indeed the basis for the first numerical weather predictions by Charney in 1950 (for an interestinghistory of numerical weather prediction, consult either Lynch, 2006, or Nebeker, 1995).\\\noindentOf course, the atmosphere cannot be treated in an exact way as a barotropic fluid. It constitutes astratified fluid where density and pressure decreases with increasing height. Therefore, a suitablegeneralisation of the barotropic-vorticity equation for the real atmosphere is by far not trivial, but would be highly desirable.Potential vorticity goes into this direction. The fundamental work by Rossby (1940) and Ertel (1942)showed that potential vorticity is conserved in adiabatic (no latent heat release, no radiative heatingor cooling) and frictionless flow. The generalisation of the "invertibility principle for vorticity"in two-dimensional flow was first stated in a rough way by Kleinschmidt (1950). He was able to attributesome low-level flow features to an upper-level PV anomaly, in his words to a "Zyklonenk\"orper". Figure\,1is a nice illustration of an upper-level PV anomaly. It shows some isolines of Ertel's PV on 350\,hPa,which form an elongated and narrow filament of high PV extending from Scandinavia south to the north-westernedge of Spain. Remarkably, this anomaly of high PV is also discernible as a dark band in the water vapourimagery of the geostationary METEOSAT weather satellite. Hence, the high PV band is associated with a very dry upper troposphere. \\\begin{figure}[t]\begin{center}\begin{minipage}[t]{16cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{Fig11_PVInv_tropo1.ps}\end{minipage}\\\caption{\it Section across the circularly symmetric structure induced by an isolated, circularly symmetric, cyclonic potential vorticity anomaly near the model tropopause across which the Rossby-Ertel potential vorticity has a strong discontinuity, by a factor of 6. The bold line is the tropopause, the horizontalthin lines are potential temperature, plotted at 5\,K intervals, and the circular/elliptical lines denote tangential velocity, at 3\,m/s intervals. The structure is typical for middle latitudes; the Coriolis parameter is $10^{-4}s^{-1}$ (as at geographical latitude $43.3^\circ$N). The domain shown has a radius of 2500\,km (taken from McIntyre,1997).}\label{inversion}\end{center}\end{figure}\noindentA very influential set of equations was introduced by Charney by means of a scale analysis of the dynamical equations (1948). These so called quasi-geostrophic equations are well suitable to describe synoptic and planetary-scaleprocesses, whilst neglecting smaller-scale features. Although these equations nowadays are considered nolonger of sufficient accuracy for numerical weather prediction, they nevertheless still are of great importance intheoretical dynamic meteorology due to their simplicity and elegance (Holton, 1992).Along with this set of equations came a new version of potential vorticity. This quasi-geostrophicpotential vorticity is linearly "linked" to the flow and temperature field, and -particularly interesting forthis study- an invertibility principle can be formulated. Indeed, the linear relationship between quasi-geostrophic potential vorticity and the flow field makes it very interesting since sophisticatednumerical techniques exist for the solution of this kind of problem. An example of such an inversion is shown in Fig.\,\ref{inversion} wherea cyclonic potential-vorticity anomaly near a model tropopause is shown. The potential vorticity is highin the stratosphere and low in the troposphere. Therefore, the downward excursion of the tropopause isassociated locally with anomalously high potential vorticity. This anomaly is marked in the figure withstippling. The "horizontal" lines correspond to the potential temperature, the "circular/elliptical" contours to the tangential velocity. Note that the isolines of potential temperature (the so-called isentropes) arepulled upwards below the PV anomaly, and pulled downward within the PV anomaly. An interesting aspect ofthe upward pulling of the isentropes is the associated reduction in atmospheric stability. Due to the reducedvertical gradient of potential temperature, the atmosphere is more prone to convective instability. In fact,in a recent study Martius et al. (2006) showed that many heavy precipitation events in the south of the Alps areassociated with such upper-level distortions of the tropopause, and hence with a PV anomaly. Moreover, notethat the upper-level PV anomaly is not only associated with a deformation of the isentropes, but isalso linked with a wind field. The induced wind field in this idealised setting reaches 21\,m/s at its maximum andis cyclonically (anti-clockwise) oriented. The wind field is strongest at the tropopause level, but is even discernible atthe surface far below the anomaly. In this respect, the PV field exhibits a far-field effect, and this in turnis the basic idea behind the invertibility principle. If this principle is taken together with the partitioningprinciple, its explaining power becomes particularly attractive. This latter principles states that the atmospheric state canbe expressed as the interaction of isolated PV elements. This immediately invokes a research strategy, which is: toenter, modify or remove some of these PV elements, and to see how the flow evolves in the thuschanged state. A very influential review article on PV and PV thinking was presented by Hoskins et al. (1985).Here the key elements of PV thinking are discussed and applied to many atmospheric dynamical problems. \\\begin{figure}[t]\begin{center}\begin{minipage}[t]{16cm}\vspace{-2cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{streamer.eps}\end{minipage}\\[-2cm]\caption{\it Stratospheric PV streamer and positions with stratosphere-troposphere mass exchange. The section isfor 1 January 1986, 06\,UTC and on the 320\,K isentrope. It is taken from the ERA-15 data set of the ECMWF. In color Ertel's potential vorticity is shown in pvu. Mass exchange from the stratosphere to the troposphere ismarked with stars, transport in the opposite direction by open circles (taken from Sprenger et al., 2007)}\label{streamer}\end{center}\end{figure}\noindentMany studies relate to this PV thinking perspective. For instance, Davis and Emanuel (1991) looked at thepotential vorticity diagnostics of cyclogenesis; Fehlmann and Davies (1997) investigated the impact of PVstructures on precipitation events over Europe. In addition to this methodology, PV has gained a lot ofinterest in recent years as a diagnostic tool. Indeed, from a dynamicist's point of view it is highlyattractive to use potential vorticity as the defining component of the extra-tropical tropopause (Stohl et al. 2003). Typically,this value is set to 2\,pvu, and every air parcel with larger PV is treated as stratospheric andevery air parcel with lower PV as tropospheric. This definition allows to discuss the dynamics of the extra-tropical tropopause, as it would not be feasible with the more common thermal (or lapse-rate) definition of the tropopause. In Fig.\,\ref{streamer} a prominent feature of the extra-tropical tropopause is shown: a stratosphericPV streamer. It corresponds to a pronounced excursion of stratospheric (high-PV) air towards the south. Thesefeatures are quite common in the extra-tropics and are important for the mass exchange between the stratosphereand the troposphere, amongst other impacts (for example they are often related to cyclogenesis). The positions where stratospheric mass (and chemical constituents, as for example ozone) crosses the tropopause are marked in the figure by stars. They are predominantly found on the upstream(western) side of the streamer. Crossing in the opposite direction, i.e. from the troposphere to the stratosphere,on the other hand occurs on the downstream (eastern) side of the streamer. Interesting questions emerge from theinspection of a such a figure: If the intensity, or the southward excursion of the PV streamer was reduced, would there still be a significant mass flux across the tropopause? These, and similar questions are at the heart ofthe PV inversion, which is introduced in this study.\\\noindentThe study is organised in the following way: In chapter 2 the mathematical problem of PV inversion isformulated and some essential aspects of the numerical algorithm are discussed. Chapter~3 introduces somekey aspects for the re-structuring of the program package.Then, in chapter 4 a detailedexample of PV inversion is discussed. This part is intended to be a practical user guide for PV inversion,and therefore rather detailed technical aspects are presented. Chapter 5 follows with some helpfuldiagnostic tools which allow to quality and impact of the PV inversion. Finally, chapter 6 concludeswith some general remarks and wishes regarding the PV inversion tool.\newpage\section{Mathematical Framework and Numerical Aspects}In this study we use the quasi-geostrophic approximation for the real-caseinversion problem. In this limit the relative (quasi-geostrophic) potential vorticity$q$ is given by:\\[-2mm]\[q = \frac{\partial^2\psi}{\partial x^2} + \frac{\partial^2\psi}{\partial y^2} +\frac{f^2}{\rho_0} \cdot \frac{\partial}{\partial z} ( \frac{\rho_0}{N_0^2}\cdot \frac{\partial \psi}{\partial z})\]\vspace{0.3cm}\noindentwith the boundary values of potential temperature at the upper and lower lid andof zonal and meridional wind components at the lateral boundaries:\\[-2mm]\[g \cdot \frac{\theta^*}{\theta_0} = f \cdot \frac{\partial \psi}{\partial z}\quad \quadu = -\frac{\partial \psi}{\partial y}\quad \quadv = -\frac{\partial \psi}{\partial x}\]\vspace{0.3cm}\noindentHere $N_0^2$, $\rho_0$ and $\theta_0$ denote the squared Brunt-V\"as\"ala frequency, the density and thepotential temperature of a reference state depending only on the vertical co-ordinate $z$. $\psi$ is thestreamfunction from which the horizontal wind components can be derived. Finally, $f$ is the Coriolis parameterwhich measures the Earth's rotation rate (typically $10^{-4}s^{-1}$ in the mid-latitudes and 0 at the equator),and $g$ is the Earth's gravity.\\\noindentThe above equations constitute a so-called von Neumann boundary problem for the ellipticdifferential equation relating the potential vorticity $q$ to the streamfunction $\psi$. Hence,the elliptic partial differential equation (PDE) can be transformed into the general form:\\[-2mm]\[\frac{\partial}{\partial x}(\alpha \cdot \frac{\partial \psi}{\partial x}) +\frac{\partial}{\partial y}(\beta \cdot \frac{\partial \psi}{\partial y}) +\frac{\partial}{\partial z}(\gamma \cdot \frac{\partial \psi}{\partial z}) +\sigma = 0\]\vspace{0.3cm}\noindentwhere the coefficients $\alpha$, $\beta$, $\gamma$ and $\sigma$ are easily expressed in terms ofthe density $\rho_0$, the Coriolis parameter $f$ and the squared Brunt-Vais\"al\"a frequency $N^2$:\\[-2mm]\[\alpha = \rho_0(z) \quad \quad\beta = \rho_0(z) \quad \quad\gamma = \frac{f^2(y) \cdot \rho_0(z)}{N_0^2(z)} \quad \quad\sigma = - \rho_0(z) \cdot q(x,y,z)\]\vspace{0.3cm}\noindentThe next step is to discretise the above PDE by means of finite differences. We assume that allfields (quasi-geostrophic PV $q$, streamfunction $\psi$,...) are defined on a three-dimensional grid, whosegrid points can be addressed by the three indices $i$, $j$, and $k$ in the x-, y- and z-direction (see Fig.\,ref{grid}). With thisconvention, the discretised PDE can be written as:\\[-2mm]\[\Delta_x(A \cdot \Delta_x \psi) +\Delta_y(B \cdot \Delta_y \psi) +\Delta_z(C \cdot \Delta_z \psi) +S = 0\]\vspace{0.3cm}\noindentHere the operators $\Delta_x(A \cdot \Delta_x\psi)$, $\Delta_y(B \cdot \Delta_y\psi)$ and$\Delta_z(C \cdot \Delta_z\psi)$ at the grid position $i,j,k$ are defined by:\begin{eqnarray*}\Delta_x(A \cdot \Delta_x\psi)_{i,j,k} & = &A_{i+1/2,j,k} \cdot (\psi_{i+1,j,k}-\psi_{i,j,k}) -A_{i-1/2,j,k} \cdot (\psi_{i,j,k}-\psi_{i-1,j,k}) \\[0.2cm]\Delta_y(B \cdot \Delta_y\psi)_{i,j,k} & = &B_{i,j+1/2,k} \cdot (\psi_{i,j+1,k}-\psi_{i,j,k}) -B_{i,j-1/2,k} \cdot (\psi_{i,j,k}-\psi_{i,j-1,k}) \\[0.2cm]\Delta_z(C \cdot \Delta_z\psi)_{i,j,k} & = &C_{i,j,k+1/2} \cdot (\psi_{i,j,k+1}-\psi_{i,j,k}) -C_{i,j,k-1/2} \cdot (\psi_{i,j,k}-\psi_{i,j,k-1})\end{eqnarray*}\vspace{0.3cm}\noindentSome simple algebra yields the following expressions for $A$, $B$ and $C$:\begin{eqnarray*}A_{i,j,k} & = & \frac{\Delta y \cdot \Delta z}{\Delta x} \cdot \alpha_{i,j,k}\\[0.2cm]B_{i,j,k} & = & \frac{\Delta y \cdot \Delta z}{\Delta x} \cdot \beta_{i,j,k}\\[0.2cm]C_{i,j,k} & = & \frac{\Delta y \cdot \Delta z}{\Delta x} \cdot \gamma_{i,j,k}\end{eqnarray*}\begin{figure}[t]\begin{center}\begin{minipage}[t]{16cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{numericalgrid.eps}\end{minipage}\\\caption{\it The numerical grid for the PV inversion in an xz cross-section. The horizontal grid spacing is $\Delta x$in the x-direction (and correspondingly $\Delta y$ in the y-direction), the vertical grid spacing $\Delta z$. Note that in the vertical, a staggered grid at half-levels is also needed (taken from Fehlmann, 1997).}\label{grid}\end{center}\end{figure}\vspace{0.3cm}\noindentFinally, the additive operator $S$ is expressed as:\[S_{i,j,k} = \Delta x \cdot \Delta y \cdot \Delta z \cdot \sigma_{i,j,k}\]\vspace{0.3cm}\noindentIt turns out to be advantageous to have the coefficients $\alpha$, $\beta$, $\gamma$ and $\sigma$not only on the 3d grid where the quasi-geostrophic PV and the streamfunction are defined, but tohave them also on intermediate points. These leads to the grid structure which is shown in Fig.\,\ref{grid}.On the left side the indices for the $\psi$-grid is shown, i.e. for the grid where thequasi-geostrophic PV and the streamfunction is defined. The right side gives the indices for thecoefficients $\alpha$, $\beta$, $\gamma$ and $\sigma$, i.e. for the intermediate layers.\\\noindentLet $\rho(k) = \rho_{k/2}$ and $N^2(k)=N^2_{k/2}$, hence expressing the vertical grid with intermediate layers. With these definitions the coefficients $A$, $B$ and $C$ for the inversion problem are readily obtained (note that these coefficients are dependent only on the vertical index z):\begin{eqnarray*}A_k & = & \frac{\Delta y \cdot \Delta z}{\Delta x} \cdot \rho(2k) \quad (k=0,...,nz)\\[0.2cm]B_k & = & \frac{\Delta y \cdot \Delta z}{\Delta x} \cdot \rho(2k) \quad (k=0,...,nz)\\[0.2cm]C_k & = & \frac{\Delta y \cdot \Delta z}{\Delta x} \cdot \frac{\rho(k) \cdot f^2}{N^2(k)} \quad (k=0,...2\cdot nz)\end{eqnarray*}\vspace{0.3cm}\noindentThe additive operator $S$ depends on all three grid indices. In its discretised form it is:\[S_{i,j,k} = - \Delta x \cdot \Delta y \cdot \Delta z \cdot \rho(2k) \cdot q_{i,j,k}\quad (i=0,...,nx, j=0,...,ny, k=0,...,nz)\]\vspace{0.3cm}\noindentIt is convenient to additionally define the coefficients $C_{-1}=C_0$ and $C_{2nz+1}=C_{2nz}$. Withall these definitions the fully discretised quasi-geostrophic PV equation can be written as:\begin{eqnarray*}S_{i,j,k} & = &\quad \quad (\psi_{i-1,j,k}-2\psi_{i,j,k}+\psi_{i+1,j,k}) \cdot A_k \\[0.2cm]& & + \quad (\psi_{i,j-1,k}-2\psi_{i,j,k}+\psi_{i,j+1,k}) \cdot B_k \\[0.2cm]& & + \quad (\psi_{i,j,k-1} - \psi_{i,j,k}) \cdot C_{2k-1} \\[0.2cm]& & + \quad (\psi_{i,j,k+1} - \psi_{i,j,k}) \cdot C_{2k+1}\end{eqnarray*}\vspace{0.3cm}\noindentwith the indices ranges as follows: $i=0, ... nx$ and $k=0, ... nz$. In addition to this discretisedPV equation, additional equations must be specified for terms like $\psi_{-1,j,k}$. These discretisedvon Neumann boundary conditions are:\begin{eqnarray*}A_k \cdot (\psi_{0,j,k} - \psi_{-1,j,k}) & = & {\Delta y} \cdot {\Delta z} \cdot \rho(2k) \cdot v_a(j,k)\\[0.2cm]A_k \cdot (\psi_{nx+1,j,k} - \psi_{nx,j,k}) & = & {\Delta y} \cdot {\Delta z} \cdot \rho(2k) \cdot v_b(j,k)\\[0.2cm]B_k \cdot (\psi_{i,0,k} - \psi_{i,-1,k}) & = & -{\Delta x} \cdot {\Delta z} \cdot \rho(2k) \cdot u_a(i,k)\\[0.2cm]B_k \cdot (\psi_{i,ny+1,k} - \psi_{i,ny,k}) & = & -{\Delta x} \cdot {\Delta z} \cdot \rho(2k) \cdot u_b(i,k)\end{eqnarray*}\vspace{0.3cm}\noindentwhere $u_a,u_b$ denote the velocity components in x direction at the left (western) and right (eastern) lateral boundary, andcorrespondingly $v_a,v_b$ denote the velocity components in y direction at the front (southern) and back (northern) lateral boundary. Additional boundary values are specified at the lower and upper lid of the domain:\begin{eqnarray*}C_{-1} \cdot (\psi_{i,j,0} - \psi_{i,j,-1}) & = & {\Delta x} \cdot {\Delta z} \cdot\frac{f \cdot g \cdot \rho(0) \cdot \theta_{bot}(i,j)}{N^2(0) \cdot \theta_0(0)}\\[0.2cm]C_{2 nz + 1} \cdot (\psi_{i,j,nz+1} - \psi_{i,j,nz}) & = & {\Delta x} \cdot {\Delta z} \cdot\frac{f \cdot g \cdot \rho(2 nz) \cdot \theta_{top}(i,j)}{N^2(2 nz) \cdot \theta_0(2 nz)}\end{eqnarray*}\vspace{0.3cm}\noindentHere, $\theta_{bot}$ and $\theta_{top}$ denote the boundary conditions for potential temperature at thelower and upper lid of the domain.\\\noindentThis is a system of linear equations which can be expressed as\\[-2mm]\[B\psi = b\]\vspace{0.3cm}\noindentwhere $B$ is a $m \times m$ matrix with in total $m=(nx+1) \cdot (ny+1) \cdot (nz+1)$ elements (not to beconfused with the above coefficients $B_k$). This linearsystem has a solution if the following condition is fulfilled:\[\sum_{i,j,k} b_{i,j,k} = 0\]\vspace{0.3cm}\noindentThis is exactly the discrete version of the compatibility condition in section~5.1. The derivation of thecondition starts with the observation that the null space, i.e. the kernel of the system is at leastone-dimensional because the non-trivial vector $\psi_{i,j,k}=1 \forall i,j,k$ is element of this kernel. Physically, this expresses the fact that the streamfunction is determined only up to an additive constant. Since the kernel of the linear system is at least one-dimensional, the image of the operator $B$ isat most (m-1) dimensional. Moreover, the operator $B$ is normal, and therefore the image is orthogonal to thekernel. Because $b$ is in the image of the operator $B$ and $\psi_{i,j,k}=1$ is in the kernel, the two vectorsare orthogonal. This leads immediately to the necessary consistency condition $\sum_{i,j,k} b_{i,j,k} = 0$.Note that this expresses a complicated relationship which must be fulfilled by the interior PV distribution and the boundary values of potential temperature and horizontal wind components, because $b$ includes all theseforcing terms.\\\noindentThe consistency condition is not met if vanishing boundary values are specified. This automaticallyleads to an inconsistency in the numerical solution of the equation. In practice, the fulfillmentof the consistency condition can be enforced if a potential temperature "correction" is added at thelower and upper lid, this correction being uniform and of opposite sign on the two boundaries. Forreasonable PV and temperature distributions this additive temperature shift remains smaller than about 2\,K.\\\noindentThere exist several techniques how to solve linear systems of equations. Here we adopt the successiveover-relaxation (SOR) method: Let $A$ be a linear operator which is represented by an $m \times m$ matrix, andlet $\omega$ be a real number (the relaxation parameter) such that $|1-\omega (1+A)|< 1$. Then a solutionof the equation can be obtained iteratively, starting with an arbitrary first guess $\psi_i^{(0)}$. The iterations\[\psi_i^{(n+1)} = \omega \cdot (b_i - \sum_{j=1}^{i-1} A_{i,j} \cdot \psi_j^{(n+1)}- \sum_{j=i}^{m} A_{i,j} \cdot \psi_j^{(n)})+ (1-\omega) \cdot \psi_i^{(n)}\]\vspace{0.3cm}\noindentconverge toward the solution of the system $A\psi + \psi =b$. If we choose $A=B-1$, the iterations converge toward a solution of the quasi-geostrophic PV equation. \\\noindentNote that the above outlined algorithm allows to overwrite the variable $\psi_i^{(n)}$ with the updatedvariable $\psi_i^{(n+1)}$, and therefore needs a minimum of computational memory. In the Fortran program{\em inv\-cart.f} the number of iterations and the SOR parameter $\omega$ are specified. The are set to 500 iterations and 1.81, respectively.% ----------------------------------------------------------------------------------------------% Program philosophy% ----------------------------------------------------------------------------------------------\newpage\section{Re-Structuring of the Code}In this section some key concepts of the program package are described. In fact, an earlier version of the package already existed (developed originally by Rene Fehlmann and later modified by Sebastien Dirren) and the present work is based upon this pre-existing package. So, the question arises what added value this re-development and re-structuring of the code is associated with. The basicidea is to provide a code which fulfills the following three requirements:\begin{center}\begin{minipage}[t]{10cm}\begin{itemize}\item[a)] {\bf Transparency and Modularity}\\[-3mm]\item[b)] {\bf Universality and Model Independence}\\[-3mm]\item[c)] {\bf User friendliness}\end{itemize}\end{minipage}\end{center}\vspace{0.3cm}\noindentIn the following parts, a detailed discussion is intended to illustrate how this requirements were missing in the existing codeand how they could be incorporated into the new version. Before doing so, it is worthwhile to consider why the original code was lacking these requirements. A short review of the relevant literatureillustrates that the situation is actually quite common. Any software which is really used has to be adapted to the changing demands. It must be maintained. Unfortunately this maintenance often leadsto a degeneration of the code. The changes introduced into the code then make necessary some furtheradaptions, and so on. Finally, in the end the code becomes so "distorted" and "chaotic" that oftena complete re-coding is easier to be done than a re-structuring of the existing version. Theremedy against this code degeneration is a continuous re-structuring. Hence, if changes in the codeare obligatory due to new user demands, it is important not only to introduce the needed changesshort-sightedly. The overall structure of the program should be kept in mind, and if possiblelong-term perspectives in code maintenance should be allowed, although such a long-term perspectivemomentarily leads to an additional effort. \\\noindentComputer science, in particular software engineering, has defined the term "re-structuring" (or"re-factoring" for object-oriented programming languages) for the process how code should bemaintained in order to avoid severe degeneration. Fowler defines the term re-factoring in thefollowing way (taken from URL {\em www.refactoring.com}):\\\begin{center}\parbox{14cm}{"Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a 'refactoring') does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it's less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring."}\end{center}\vspace{0.6cm}\noindentHence, the key aspect of re-structuring is to continuously maintain the code, not only inits performance, but also in its readability, documentation and adaptabilty to neededchanges.\\\vspace{0.3cm}\noindentScientific programming in particular is very prone to code degeneration. This is certainly dueto the fact that cutting-edge science is, by "definition", investigating what is not known.Therefore, if for instance a computer program is written to numerically simulate a physicalprocess, it might well turn out during the development of the code that complete new aspectsmust be included. This naturally leads to chaotically structured code. In the present case, i.e.for the PV inversion program, this certainly explains to a large part why the code becameso un-organised. Several works have been done with the program, several researchers includedinto the code what they needed for their specific task, without considering that other users might have no use of their changes. The results was a program package which, in principle, was stillworking, but the knowledge of how to apply it went lost.\\\noindentA first rough inspection immediately madeclear that major changes were necessary to make the code available to a broader community again.Would it have been possible to only re-organise the code and write a new user guide? In a firsttry, this was in fact considered. But then the advantages of a more or less completere-coding turned out to be more suitable. Hence, the original software package joined thesad fate of so many degenerated codes: a complete re-coding. On the other hand, such a re-codingmust be seen as a great chance. It allows to improve the code in such a way, as it would never bepossible if only "slight" changes at the existing code were made.\\\noindentIn the following threesubsections, some key aspects of this re-coding will be presented. They are by no meansexhausting, but should give an impression of the new "philosophy". Hopefully, they also motivatefuture users of the program package to "successfully" maintain it.\subsection{Transparency and Modularity}What makes a computer program readable? Probably one of the most important points is "modularity".The problem to be solved numerically can and should be split into several distinct steps. For instance,for the PV inversion a classic three step splitting is appropriate: pre-processing, PV inversion, and post-processing. Moreover, each of these three primary steps can further be split into several secondary sub-steps.In the existing code, the splitting of the problem into distinct sub-problems was not clearly discernible. Indeed, the main Fortran program included not only the numerical inversion of the quasi-geostrophic PV equation, but also some of thepreparatory steps and some of the post-processing steps. \\\noindentA major improvement was gained by a very strict separation of the distinct primary steps. So, pre-processing, inversion and post-processing are done by three completely separated program packages. This strictseparation is supported by the fact that three separated directories are used: There is one directory where pre-processing is done, on directory where inversion is done, and finally one directory where post-processing is done. A flow of data between the three directories is allowed only at well-definedsteps within the whole process. At the end of pre-processing the relevant files, and only those, are moved to the inversion (or run) directory. Similarly, at the end of the inversion, the relevant filesare moved from the run directory to the post-processing directory.\\\noindentAdditional improvement resulted from a very clear separation of the sub-processes in the three main-processes (pre-processing, inversion, post-processing). In fact, it was not tried to incorporateall preparatory steps into one large Fortran program, but instead each well-defined task (as for example transformation into a new co-ordinate system) constitutes a separate Fortran program. Thismodularity is very similar to the "philosophy" of the Linux operating system: Keep flexibility andclarity by offering not one program which handles everything (and thereby becomes a "monstrosity"), but offer many flexible and simple tools which the user only has to combine in order to perform complex tasks.\\\noindentWhat else except for modularity can be done to improve the readability of computer programs? It is obvious, and probably the most neglected aspect of good computer code generation: in-code documentation. Everysmall sub-section of a computer program should be documented. It should be possible to gaininsight into an algorithm only by looking at the in-code documentation. It is definitely notsufficient only to document for every subroutine what its aim is and what its interface is, althoughquite often even this most basic principle is not fulfilled. Hence, in the re-coding of thePV inversion focus was led to good documentation: Where are files opened, where variables initialised, what is a subroutine call meaning? \\\noindentFinally a remark concerning the used programming language. A complete re-coding of a software package might also bea chance to switch to a "better" programming language. In the present case, the original code was written inFortran 77, and this language was also used for the re-coding. Fortran, and in particular its older versionFortran 77, is by far not a modern language. Comparing its vocabulary and its structural elements to languages like C++ or Java, its power is very limited. Moreover, Fortran includes jump statements like {\em Goto} which could easily makeany code un-readable. So why do so many research codes still rely on Fortran? In fact, most numericalweather prediction models are written in Fortran. There are two reasons why the PV inversion was written in Fortran: Firstly, the small vocabulary and the intuitive naming of the inherent Fortran commandsmakes it quite easy to read a code. Many researches never had a profound introduction into programming. Nevertheless they should be able to implement algorithms for their daily work. This is easily done with Fortran, and certainly much easier done than using object-oriented concepts offered by C++ and other modern languages. The PV inversion should be availableto a research community which has excellent algorithmic thinking, but only a "weak" background in computer languages. Fortran is an optimal choice in this respect. The second reason why the re-coding was done in Fortran is its high performance. In fact, PV inversion is very resource demanding, and compilers must create fast-running codes in orderthe PV inversion tool to be helpful.\\\noindentRegarding the "unholy" {\em Goto} statements, it can be immediately said that good programming style is not restricted to languages which do not offer a {\em Goto} statement. A well-structured and carefully developed Fortran program iscertainly preferable to a "bad" algorithm in a "good" computer language, "good" meaning that this language offers manycontrolling structures. Probably, a key concept of well-written computer code is a good balance between the "power" of a (Fortran)subroutine and its length (expressed in the number of code lines). Two extreme examples might illustrate this point: If no subroutines at all are used, i.e. if the program consists only in one single main program, the algorithm might get"lost" in two many "technical" details. On the other hand, if every single and minor step is a separate subroutine, thecode lacks clarity due to the large number of subroutines. In the present re-coding of the PV inversion, focus was givento a good balance of functionality (power) of a subroutine and its length.\subsection{Universality and Model Independence}Universality was another aspect which was important in re-coding the PV inversion. In the presentexample universality might be better named "model independence". Model in this respect refers either to different numerical weather prediction (NWP) models or to idealised experiments. In the former case,the variety of NWP models is very large. The PV inversion tool was originally written for the Europamodel (EM) of the German weather service (DWD). Later it was applied to the higher-resolutionmodel (HRM and CHRM) which was run by the DWD and the Swiss weather service (MeteoSwiss). In recent years, thenon-hydrostatic local model (LM) developed by the DWD replaced the HRM in regionalweather forecasting. So, an adaption of the existing PV inversion code would have been necessary.Moreover, PV inversion is particularly attractive for global-scale data sets. So, the method and theprograms were adapted to conform with the global model of the European Centre for Medium Range Forecasts (ECMWF). To make things worse, idealised experiments should also be performed. What actuallymakes the situation so difficult is that each model has its own horizontal grid structure and its own vertical grid structure. For instance, ECMWF uses a terrain-following co-ordinate system which in higher levels becomes a pressure-level co-ordinate system, quite in contrast what is used by the regional LM model (a variant of geometrical height). \\\noindentModel independence cannot completely avoided. It is a fact which has to be adopted and cleverlydealt with. In the re-coding, model aspects were removed in the first two preparatory steps (out ofeight different steps, see section~4.4) and the way back to the model is done in the last post-processing steps.Essentially the preparatory steps interpolate the needed meteorological fields onto a stack of height levels andtransforms the fields into a local quasi-cartesian co-ordinate system. After completing these steps, the other preparatory steps and the PV inversion itself is completely independent of the model from which the input data is retrieved. As a particular example consider the PV inversion of a structure over the North Pole. In the existing code such an inversion would not have been feasible due to the convergence of thelongitude circles at the North Pole. The new code, on the other hand, elegantly circumvents thisproblem by introducing a new quasi-cartesian co-ordinate system centered over the North Pole. In thisrespect the North Pole is not different from any other region on the globe.\\\noindentWith respect to idealised experiments, the following strategy was adopted. This kind of experimentsis generally so different from what is needed for real-case studies that a complete separationis preferable. So, in contrast to the existing code, this type of experiments is now handled bya completely separated program package. Of course, many programs "overlap" or are even identical, but it nevertheless makes sense to treat the two kind of experiments (real-case versus idealised) separately.\subsection{User Friendliness}Computer programs are not written for a computer's joy, but because they should solve a problemwhich cannot be solved analytically by any person. So, computer programs are tools which shouldmake "life" easier for their users, or at least they should make some problems tractable. If theuser-interface of a computer program is chaotic and badly structured, the computer does not complain.The user, on the other hand, might give up using the tool simply because it needs too much effort to understand how the program must be handled. Scientific programs are especially in danger ofhaving bad user-interfaces because these kind of programs are always "in the flow". This in turnmeans that often it is not worthwhile to develop a graphical user-interface, as it is an absolutemust for commercial software. \\\noindentIn the existing code for the PV inversion the user-interface was highly "chaotic". It consisted ofseveral hundred lines of Linux Shell scripts which were difficult to read -partly due to lack of documentation, partly due to the unnecessarily complex structure. The behaviour of the inversionwas controlled by many variables set in the beginning of the Linux Shell script, set withoutknowing exactly where and when these variables are used. This gave the user a "bad feeling" abouthis experiments, simply because it was not always clear what changing parameters really meant.\\\noindentAlthough a graphical user-interface is not provided for the new version, an attractive command-basedinterface is now available. This interface essentially consists of two parts. Firstly, a Linux Shell scriptis provided which handles all calls to the computing Fortran programs. For instance, {\em inversion.sh prep} runs through all preparatory steps. User friendliness is reached by the fact the the user needs to make no changes to this Linux Shell script, although its limited size and documentation would make it quite simple.Probably the best user-interface is provided by a parameter file. Such a file is provided in the newversion, and all parameters describing the inversion problem can be entered into this file. In fact,this kind of user-interface was motivated by sophisticated numerical weather prediction (NWP) models. There too,the specifications characterising a model run are passed to the NWP model by means of a parameterfile.\\\noindentWhat else made the existing user-interface chaotic? A close inspection revealed that the flow of data and information was absolutely non-transparent. Meteorological fields were moved from one file toanother, only to be renamed there and subsequently being moved again to another file. For a part-time user it would have been impossible to keep track of the flow of information. In the new code the flow of information is very strictly controlled (see also the above subsection~3.1). In fact, there are many different files involved in the PV inversion:input files, several intermediate files and finally the output files. It is not the number of files which makes aprocess difficult to understand. If the flow of information is well controlled, it remains tractable. For the case ofthe PV inversion, this information flow can be kept clear, and this was indeed an important aspect of the re-coding.% ----------------------------------------------------------------------------------------------% PV Inversion for Real Cases% ----------------------------------------------------------------------------------------------\newpage\section{Inversion of an Extra-tropical PV Streamer}\subsection{Scientific question}The PV inversion starts with the selection of a distinct PV anomaly which should beremoved or added to the original PV distribution. It is then the aim to analyseand compare the meteorological fields of horizontal wind and potential temperatureassociated with the modified PV distribution with the corresponding fields associated withthe original PV distribution.\\\begin{figure}[t]\begin{center}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_20060114_18_315K.eps}\end{minipage}\hspace{0.5cm}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_20060115_18_315K.eps}\end{minipage}\\\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_20060116_18_315K.eps}\end{minipage}\hspace{0.5cm}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_20060117_18_315K.eps}\end{minipage}\\\begin{minipage}[t]{11cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_colorbar.eps}\end{minipage}\\\caption{\it Time evolution of Ertel's potential vorticity (PV) on the 315\,K isentropic surface. The fourplots are for 14, 15, 16 and 17 January 2006, 18\,UTC. The PV inversion will be exemplified in this user guide for 16 January 2006, 18\,UTC.}\label{question}\end{center}\end{figure}\noindentThe time evolution of potential vorticity (PV) on the 315\,K isentropic surface shows a distinct feature over the Eastern United States (Fig.\,\ref{question}). This so-called stratospheric PV streamer is indicative fora deep intrusion of stratospheric air towards the equator. In the course of the four days shown, thePV streamer moves towards the east, and in the later stages exhibits an cyclonic rolling-up. An eminentquestion is how this stratospheric PV streamer influences the atmospheric flow in its neighbourhood. From theoreticalconsiderations, it can be expected that the impact on the horizontal velocity and on the static stabilityis quite large (see introduction, Fig.\,2). By means of the so-called quasi-geostrophic omega equation (Holton, 1992), it is also expected that pronouncedvertical motions are directly associated with the passage of the PV streamer. It is the aim of this study -and of PV inversion in general- to surmount the qualitative argumentation, and toquantitatively assess the impact of such a structure on the atmospheric flow. \\\noindentIn the following chapters, all steps are discussed which are needed to quantify this impact. Here, weexemplarily consider the date of 16 January 2006, 18\,UTC, and determine explicitly for this datethe atmospheric response the upper-level (near tropopause level) PV structure.\subsection{Necessary input files}\begin{figure}[t]\vspace{-2cm}\begin{center}\begin{minipage}[t]{8.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{q_20060116_18_500hPa.eps}\end{minipage}\hspace{-0.6cm}\begin{minipage}[t]{8.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{t_20060116_18_500hPa.eps}\end{minipage}\\[-3cm]\begin{minipage}[t]{8.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{uv_20060116_18_500hPa.eps}\end{minipage}\hspace{-0.6cm}\begin{minipage}[t]{8.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{ps_20060116_18_500hPa.eps}\end{minipage}\\[-2cm]\caption{\it Specific humidity (g/kg), temperature (in $^\circ$C), wind vectorsat 500\,hPa and surface pressure for 16 January 2006, 18\,UTC. These field are neededas input for the PV inversion, and are available on the so-called P file.}\label{inpp}\end{center}\end{figure}Several preparatory steps are necessary before the PV inversion itself can beperformed. Here each of these steps is described in detail and -where possible-illustrated with suitable figures. Starting point of the analysis is the P andZ file of the ECMWF (re-)analysis:\begin{itemize}\item {\bf P20060116\_18} with temperature T (in $^\circ$C), horizontal wind components U,V (in m/s) inzonal and meridional direction, respectively,specific humidity Q (in kg/kg) and surface pressure PS (in hPa).\item {\bf Z20060116\_18} with geopotential height Z (in m) on a stack of pressurelevels (for instance on 850, 500 and 250\,hPa).\end{itemize}\begin{figure}[t]\vspace{-2cm}\begin{center}\begin{minipage}[t]{8.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{z_20060116_18_250hPa.eps}\end{minipage}\hspace{-0.6cm}\begin{minipage}[t]{8.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{z_20060116_18_500hPa.eps}\end{minipage}\\[-3.5cm]\begin{minipage}[t]{8.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{z_20060116_18_850hPa.eps}\end{minipage}\\[-1.5cm]\caption{\it Geopotential height (in m) on 250, 500 and 850\,hPa for 16 January 2006, 18\,UTC. These field are neededas input for the PV inversion, and are available on the Z file.}\label{inpz}\end{center}\end{figure}\noindentFigure\,\ref{inpp} shows temperature T, specific humidity Q and wind vectors (U,V) at 500\,hPa and the surface pressure for 16 January 2006, 18\,UTC. A narrow band of high specific humidity is discernible on the downstreamside (to the east) of the PV streamer (upper-left panel). Most probably, this extended band is directly associated withthe southerly winds which prevail to the east of the PV streamer, and which are able to transport moistair from the warm subtropics to the north. In the temperature field (upper-right panel), the PV streamer's impact is also discernible. It is associated -at this level- by a local warm anomaly. On theoretical grounds, we would expect a local cold anomaly below the streamer and a local warm anomaly within and above the streamer (see introduction, Fig.\,2). The present signal indicates that the streamer reaches far down into the troposphere, and enforces a local warm anomaly at the low level of 500\,hPa. As already mentioned before, and explicitly shown by the wind vectors (lower-left panel), the PV streamer is also associated with a cyclonic flow. Besides the impact on the temperature field, this PV induced flow field is the most eminent impact of a PV streamer. Indeed, it is the wind field where the far-field effect of a PV streamer becomes most evident, because the streamer's impact on temperature and stratification is essentially confined to theregions just below or above.Finally, the P file contains the surface pressure PS (lower-right panel), which of course to the largest extent simply reflects the surface topography. So for instance,the high topography of the Rocky Mountains or of the Greenland ice shield, is associated with lowsurface pressure, 700\,hPa corresponding to about 3\,km height above sea level.\\\noindentIn addition to the P file, a so-called Z file must be provided as input for the PV inversion. This file contains the geopotential height on a distinct set of pressure levels. Typically, these levels are850, 500 and 250\,hPa. A plot of these levels is shown in Fig.\,\ref{inpz}. The need for this reference levelswill become evident in a subsequent section. In short: They are needed to integrate the hydrostatic equation and thereby to transform from pressure to geometrical height as vertical co-ordinate.Note how the PV streamer over the west Atlantic is discernible in the geopotential as a deep trough.\subsection{An overview of the inversion}\begin{figure}[t]\begin{center}\begin{minipage}[t]{6cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{threesteps.eps}\end{minipage}\\\caption{\it Data flow diagram for the three steps of the PV inversion. The preparatory steps areessentially performed in the input directory, the inversion in the run directory and the output isfinally written to the output directory.}\label{threesteps}\end{center}\end{figure}The PV inversion can be split into three well-separated steps. The first step is associated withpreparations, in particular with the definition of the modified Ertel-PV field. In addition, somepreparatory steps have to be performed in order to adapt the ECMWF grid to the cartesian grid which isassumed in the inversion algorithm. In the second step the atmospheric state is iteratively adjusted tothe modified PV field, as it was specified in the previous preparatory step. This second part comprises the "core" of the algorithm, i.e. the numerical inversion of the quasi-geostrophic potentialvorticity equation by means of a successive over-relaxation (SOR) technique. Finally, in the third stepthe modified atmospheric state is brought back from the cartesian grid of the inversion to theoriginal latitude/longitude grid of the ECMWF, including its hybrid vertical co-ordinate. After thisstep a direct comparison between input and output fields is feasible due to the equivalentgrid structure of input and output fields. The basic three steps are shown in Fig.\,\ref{threesteps}, and will subsequently be described in greater detail in the following sections. Before doing so, a note has to be made on the user-interface for the PV inversion.\\\noindentThe inversion is controlled by one master Linux Shell script (inversion.sh), which calls the performing Fortran programs(for a complete listing of the Linux Shell script consider Appendix~9.2).A major aim of this work was to make theapplication of the inversion as easy as possible. Therefore, the typical user is not forced to studythe master script itself, but can provide all needed parameters by means of a so-called "parameter file"(inversion.param).The contents of this file is parsed by a Perl script, which extracts all needed information. In thedescription of the subsequent steps, the relevant parts of this parameter file will be reproduced anddescribed. A complete listing of the parameter file can be found in Appendix~9.3.\\\noindentNevertheless, it will be necessary for an advanced usage of the inversion package to go intosome greater details. For instance, if particular PV structures should be removed or added, theimplemented simple filtering approach (to be discussed in section~4.4.4) might not be sufficient.In this case, the advanced user is encouraged to modify the Fortran code in order to fulfill his particulartasks.\\\noindentIn a first step some directories must be specified. This is done in the parameter file {\em inversion.param} in the section DATA. For the example of this study this section looks like:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\ForceWidth{1.0\textwidth}\begin{verbatim}BEGIN DATADATE = 20060116_18;INP_DIR = /lhome/sprenger/PV_Inversion_Tool/real/inp;RUN_DIR = /lhome/sprenger/PV_Inversion_Tool/real/run;OUT_DIR = /lhome/sprenger/PV_Inversion_Tool/real/out;END DATA\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe first argument (DATE) gives the date of the case. Then the following three entries specify the input (INP\_DIR), the run (RUN\_DIR) and the output (OUT\_DIR) directory, respectively. These directories can be created by the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\ForceWidth{1.0\textwidth}\begin{verbatim}inversion.sh inst\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentFor test reasons a set of sample files is provided. These sample P20060115\_18 and Z20060115\_18 files can be copied to the input directory with the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\ForceWidth{1.0\textwidth}\begin{verbatim}inversion.sh sample\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe fields available on the two files are:\begin{center}\begin{tabular}{|l|l|l|}\hlineQ & Specific humidity ($kg/kg$) & P20060116\_18 \\U & Zonal velocity ($m/s$) & P20060116\_18 \\V & Meridional velocity ($m/s$) & P20060116\_18 \\T & Temperature ($^\circ C$) & P20060116\_18 \\OMEGA & Vertical velocity ($Pa/s$) & P20060116\_18 \\PS & Surface pressure ($hPa$) & P20060116\_18 \\\hlineZ & Geopotential height ($m$) on 850, 500 and 250\,hPa & Z20060115\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\noindentWith these preparatory steps, the inversion can be performed. The following sections discuss the three basic step, i.e. the preparation of the input files for the inversion, the inversion itself and the post processing of the output files.\subsection{Pre-processing: Defining the inversion problem [prep]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{12cm}\vspace{2.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{preparation.eps}\end{minipage}\\\caption{\it Flowchart of preparatory steps. Additionally, to the left of the single steps theessential flow of information is shown. For instance, H $\rightarrow$ R means that the input is taken fromthe file with prefix H and the output is then written to the file with prefix R.}\label{preparation}\end{center}\end{figure}Firstly, the vertical co-ordinatehas to be changed from pressure to geometrical height (section~4.4.1) and the fields have to betransformed from the geographical latitude/longitude grid to a cartesian grid (section~4.4.2). Then additional meteorologicalfields have to be computed on this new cartesian grid (section~4.4.3). With these two preparations theErtel-PV anomaly can be defined (section~4.4.4), and the input files for the quasi-geostrophic PV inversion be written(section~4.4.5). Some additional steps are then: definition of a reference profile (in section~4.4.6) andthe transformation of the coastlines into the cartesian grid (section~4.4.6).\\\noindentThese single steps have to be done once for every inversion problem. A complete flowchart ofthe preparatory steps is shown in Fig.\,\ref{preparation}. In the following description every single step willbe launched and discussed individually. If desired, the call\\[0.0cm]\begin{center}\begin{minipage}[t]{13cm}\ForceWidth{1.0\textwidth}\begin{verbatim}inversion.sh prep\end{verbatim}\end{minipage}\end{center}\vspace{0.6cm}\noindentwill run through all steps without waiting for intermediate check. This is particularly practical if allsettings remain essentially unchanged, and therefore a detailed check after each step is not necessary.\subsubsection{Transformation to height levels [prep1]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{10cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{sigma_level.eps}\end{minipage}\\\caption{\it Illustration of the terrain-following hybrid co-ordinate system of the ECMWF grid.Here it is shown with 15 levels, recent versions of the ECMWF model contain 60 hybrid levels for the ERA-40 re-analysis and 91 levels for the operational analysis and deterministic 10\,day forecast [illustration takenfrom "An Introduction to dynamic meteorology" by Holton, 1992].}\label{sigma}\end{center}\end{figure}The input data are available on a latitude/longitude gridin the horizontal and on a so-called hybrid $\sigma$-grid on the vertical. Whereas the former iswell known, the latter needs some explanation. The basic idea is illustrated in Fig.\,\ref{sigma}. Themodel levels are terrain-following, and the pressure p(i,j,k) at a specific grid point (with grid indices i,j,k) is given by the expression:\[p(i,j,k) = ak(k) + bk(k)*ps(i,j)\]\vspace{0.3cm}\noindentwhere $ps(i,j)$ is the pressure at the surface at the specified grid position. The two one-dimensionalarrays $ak$ and $bk$ are part of the P file, more specifically of the constants file associated with the P file. The main advantage of this hybrid grid is its non-intersection with the ground, whichfacilitates many numerical calculations.\\\noindentThe ECMWF fields are easily plotted on pressure surfaces since the vertical co-ordinate of theunderlying data set is essentially based upon pressure. On the other hand, the inversion programassumes a cartesian grid with geometrical height (in m) as vertical co-ordinate. Therefore, all needed fields from theoriginal P file must be interpolated onto a stack of height levels. This transformation is easilydone by means of the hydrostatic equation:\[\frac{\partial p}{\partial z} = - \rho \cdot g\]\vspace{0.3cm}\noindentwhere $\rho$ denotes the density of moist air and $g$ is the Earth's gravity. Note that thisequation can be re-formulated to one including temperature if the ideal gas equation\[p = \rho \cdot R_d \cdot T_v\]is used and $\rho$ replaced. Here $R_d$ is the ideal gas constant of dry air and $T_v$ is the virtual temperature,i.e. the temperature corrected for the water vapour contents of the air. The definition ofvirtual temperature takes into account the specific humidity of an air parcel and its (sensible)temperature (see for instance Wallace and Hobbs, 1977):\\\[T_v = T \cdot \{ 1 - \frac{q}{\epsilon} \cdot (1 - \epsilon) \}^{-1} \approxT \cdot ( 1 + \epsilon \cdot q )\]\vspace{0.3cm}\noindentwhere $T$ is the temperature (in K), $q$ the specific humidity (in kg/kg), $\epsilon=R_d/R_v$ is the ratio of the gas constant for dry ($R_d$) air and water vapour ($R_v$). \\\noindentWith the previous definitions, the hydrostatic equation can be integrated vertically to getthe height as a function of the pressure p:\[z(p) = z_{ref} - \frac{R_d}{g} \cdot \int_{\log(p_{ref})}^{\log(p)} T_v \cdot d\log(p)\]\vspace{0.3cm}\noindentwhere $z_{ref}$ and $p_{ref}$ denote the reference level. If several reference levels are given(for example at 850, 500 and 250\,hPa, see Fig.\,7) the integration can be performed from the nearestreference level to the specified pressure level. Note that at least one reference levelmust be given, i.e. at one pressure level the geometrical height must be known.Typically, this correspondence is known for the 500\,hPa level (see Fig.\,\ref{hydro}). As a resultof the integration, the geometrical height is given as a function of the pressure at all pointsof the model grid.\\\begin{figure}[t]\begin{center}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pro_t_70w40n_20060115_18.eps}\end{minipage}\hspace{0.5cm}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pro_q_70w40n_20060115_18.eps}\end{minipage}\\\caption{\it Left: Vertical profile of temperature (in $^\circ$C) in dependence of pressure at 70$^\circ$Wand 40$^\circ$ for 15 January 2006, 18\,UTC. Additionally the reference pressure levels are included withthe corresponding geopotential height (in m). Right: Vertical profile of specific humidity (in g/kg).}\label{hydro}\end{center}\end{figure}\noindentIn addition to the geometrical height at each grid point, the hydrostatic equation can be integrateddownward to obtain a consistent estimate of topography height. In fact, if the surface pressure$p_s$ is given, the height of the topography is readily determined by\\\[z(p_s) = z_{ref} - \frac{R_d}{g} \cdot \int_{\log(p_{ref})}^{\log(p_s)} T_v \cdot d\log(p)\]\vspace{0.3cm}\noindentThe advantage of the thus determined topography (instead of using the ECMWF topography) is itsconsistency.\\\noindentHaving determined the geometrical height $z(i,j,k)$ at each grid point $i,j,k$ in addition to the already knownpressure $p(i,j,k)$, it is straightforward to interpolate a field (temperature, velocity,...) onto an arbitrary height level.The method adopted here is to lie a natural cubic spline through the grid points along a verticalprofile and then to evaluate the spline at the pre-specified height levels. In detail: The cubic spline at a horizontal grid position $i,j$ is based upon the values $[x_k=z(i,j,k),y_k=T(i,j,k)]$ if temperature $T$ is to be interpolated ontoa stack of height levels. Having determined the associated cubic spline $T_{sp}$, temperature at an arbitrary height $z$can be calculated by evaluating the cubic spline at this level: $T_{sp}(z)$. The algorithm for the cubic spline is taken from Press et al. (1992).\\\noindentThe interpolation onto height levels is done with the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh prep1\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentwhich numericallyintegrates the hydrostatic equation and therefore attributes to each grid point not only itspressure (in hPa) but also its geometrical height (in m). The relevant numerical parameters are taken from theparameter file {\em inversion.param}, where the following section is essential:\\\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}BEGIN GRIDGEO_ZMIN = 0.;GEO_NZ = 125 ;GEO_DZ = 200.;END GRID\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe three parameters describe the new vertical co-ordinate. The lowest levels is assumed to be at ground(GEO\_ZMIN), the number of vertical levels is 125 (GEO\_NZ) and the vertical resolution is equidistantly200\,m (GEO\_DZ). Hence, the new vertical grid spans the range from ground up to 25\,km.\\\noindentThe output file H20060115\_18 is a new netcdf file which has now geometrical height as vertical co-ordinateand the variables ({U,V,T,Q}) interpolated onto the height levels from surface up to 25\,km. Note that the height of the topography ({ORO}) is alsodetermined. If a model level is below the topography, all field values are set to missing data. The following table gives all the variables which are available on the new H file:\\\begin{center}\begin{tabular}{|l|l|l|}\hlineQ & Specific humidity ($kg/kg$) & H20060116\_18 \\U & Zonal velocity ($m/s$) & H20060116\_18 \\V & Meridional velocity ($m/s$) & H20060116\_18 \\T & Temperature ($^\circ C$) & H20060116\_18 \\P & Pressure ($hPa$) & H20060116\_18 \\ORO & Height of topography ($m$) & H20060116\_18 \\\hline\end{tabular}\end{center}\begin{figure}[t]\begin{center}\begin{minipage}[t]{14cm}\vspace{-1cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{latlon_nh.eps}\end{minipage}\\[-0.5cm]\caption{\it Latitude/longitude grid of the ECMWF P and Z files. For clarity, the grid spacing was reduced to 5 degrees, instead of the 1 degree in the files. Meteorological fields -as for instancetemperature, wind vectors, pressure and geopotential- are given at the intersection of the latitude andlongitude circles. Note how this grid becomes singular toward the north pole.}\label{latlon}\end{center}\end{figure}\subsubsection{Rotating to a quasi-cartesian co-ordinate system [prep2]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{13cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{local_cart_grid.eps}\end{minipage}\\\caption{\it Local cartesian grid which is centered at the PV streamer's position and whichshows much less distortion due to the sphericity of the Earth. The center of the new gridcorresponds to the rotated latitude and longitude (0,0). The boundaries are at $-31^\circ$ and$+31^\circ$ rotated longitude, and at $-31^\circ$ and $+31^\circ$ rotated latitude.}\label{localcart}\end{center}\end{figure}The input fields are given on a latitude/longitude grid, with -after the previous step- the fieldson an equi-distant grid of height levels. The inversion itself assumes a cartesian grid, hence auniform grid spacing is also assumed in the horizontal directions. This is clearly not the case for thelatitude/longitude grid, as illustrated in Fig.\,\ref{latlon}.Due to the sphericity of the Earth, the zonalgrid spacing decreases with increasing geographical latitude. As a remedy to this singularity, allinput fields are transformed to a "quasi-cartesian" grid with its center on the PV structure ofinterest. The transformation between the two grids is illustrated in Fig.\,\ref{localcart}. It becomes evidentthat the grid distortion is significantly reduced by this step. The formula which relates the twogrids is based upon the co-ordinate transformation given in the Appendix~A (Fortran subroutines {\em lmstolm} and{\em phstoph}). The geographical latitude/longitude corresponding to a grid point in the rotated (quasi-cartesian) co-ordinate system is obtained in the following way. Firstly, the rotated latitude/longitude $\phi_{rot},\lambda_{rot}$ is transformed into\begin{eqnarray*}\lambda'_{rot} & = & 90+lmstolm(\phi_{rot},\lambda_{rot}-90,90+\alpha,-180) \\[0.2cm]\phi'_{rot} & = & phstoph(\phi_{rot},\lambda_{rot}-90,90+\alpha,-180)\end{eqnarray*}\vspace{0.3cm}\noindentwhere $\alpha$ is the rotation angle given in the parameter file (CROT, see below). These twovalues are then, in a second rotation, transformed into geographical latitude and longitude:\begin{eqnarray*}\lambda_{geo} & = & lmstolm(\phi'_{rot},\lambda'_{rot},90-\phi_{cen},\lambda_{cen}-180) \\[0.2cm]\phi_{geo} & = & phstoph(\phi'_{rot},\lambda'_{rot},90-\phi_{cen},\lambda_{cen}-180))\end{eqnarray*}\vspace{0.3cm}\noindentwhere the centre of the PV anomaly (the centre of the quasi-cartesian co-ordinate system in geogrpahicallatitude/longitude co-ordinates) is given by $\phi_{cen}$ and $\lambda_{cen}$ (CLAT and CLON in theparameter file, see below).\\\begin{figure}[t]\begin{center}\begin{minipage}[t]{8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{latlon_grid.eps}\end{minipage}\hspace{-0.5cm}\begin{minipage}[t]{8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{xy_grid.eps}\end{minipage}\\\caption{\it Quasi-cartesian grid which is centered at the PV streamer's position and whichshows much less distortion due to the sphericity of the Earth. On the left panel the latitude andlongitude on the Earth surface is shown, on the right panel the x and y co-ordinates in the newco-ordinate system. Note how the distortion is considerably reduced with the new x,y co-ordinates (right), as compared with the original latitude/longitude co-ordinates (left). Additionally, the topography (in m above sea level) is shownin color: Clearly discernible is Greenland and the east coast of North America.}\label{xylatlon}\end{center}\end{figure}\noindentThe transformation looks quite complicated, but has an easy geometrical interpretation. In fact, we create a newlatitude/longitude grid, but now longitude and latitude are defined not relative to the Earth's northpole, but relative to a rotated imaginary "north pole". Therefore, we call the new latitudes/longitudes rotated co-ordinates. The link between the geographical latitude/longitude andthe rotated ones is shown in Fig.\,\ref{xylatlon} for the case study. Here, the left panel gives the latitude and longitude at the grid positions of the quasi-cartesian grid. The right panel gives the quasi-cartesian co-ordinates x and y, which correspond to the grand-circle distance on the Earth surface.While the transformation of a scalar quantity (like for instance temperature, pressure, wind speed) is straightforward with the above formulas, the transformation of a vector field is much morecomplicated. This is easily illustrated with the following example: Consider a perfectly zonal flowin the geographical grid, i.e. there is only a wind component along the geographical latitude circles, but none along the geographical longitude circles (hence, in the left panel of Fig.\,14 the velocity vector is parallel to the latitudecircles). In the rotated grid -the quasi-cartesian grid- thispure zonal velocity is transformed into a wind vector which has components both along the rotatedlongitude and latitude circles (i.e. in Fig.\,14 the vector has a component along the horizontal and thevertical axis).In principle, a complicated formula could be derived which gives an explicit expression how theindividual velocity components transform. Here, we adopt a more pragmatic approach: We numericallydetermine the local rotation angle between the two orthogonal co-ordinate systems, and subsequentlyuse these angles to get the transformed velocity components. \\\begin{figure}[t]\begin{center}\begin{minipage}[t]{10cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{coriol_grid.eps}\end{minipage}\\\caption{\it Coriolis parameter (in $10^{-4}s^{-1}$) in the quasi-cartesian co-ordinate frame.The Coriolis parameter is a local measure for the Earth's rotation. It is constant alonglatitude circles. Note that $f$ becomes maximal at the pole and vanishes at the equator. NoPV inversion can be performed if the cartesian grid crosses the equator and hence crosses thezero isoline of the Coriolis parameter.}\label{coriol}\end{center}\end{figure}\noindentOf course, the Coriolis parameter must be kept in the transformation to the quasi-cartesianco-ordinate frame. Tis parameter is given by:\[f = 2 \cdot \Omega \cdot sin(\phi)\]\vspace{0.3cm}\noindentwhere $\Omega$ is the angular velocity of the Earth rotation and $\phi$ is the geographical latitude.From the definition it is clear that the Coriolis parameter is constant along latitude circles. Furthermore,it takes its maximum value at the pole and vanishes at the equator. A typical value for the mid-latitudesis $f=10^{-4}s^{-1}$. For the case study the Coriolis parameter is shown in Fig.\,\ref{coriol}.\\\noindentNumerically, the rotation of the fields to the quasi-cartesian co-ordinate frame is done with thecall\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh prep2\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe program needs some information from the parameter file. The relevant section is:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}BEGIN GRIDROT_NX = 250 ;ROT_NY = 250 ;ROT_DX = 0.25;ROT_DY = 0.25;CLON = -65.;CLAT = 45.;CROT = 0.;END GRID\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe first two parameters (ROT\_NX and ROT\_NY) give the number of grid points in the horizontal directions forthe rotated co-ordinate system. Here it is assumed that the grid has 250 grid points in x and in y direction. Notethat the number of grid points in the z direction needs not to be specified because this information isalready available on the file H20060115\_18. The new horizontal resolution of the rotated grid is given by thenext two values. They give the resolution in x (ROT\_DX) and in y (ROT\_DY) direction. In the present case theseresolutions are 0.25 degrees, which corresponds to approximately 28\,km, according to the formula\\\[0.25 \cdot \frac{2\pi}{360} \cdot R_E \quad \quad \mbox{with the Earth's radius} \quad R_E=6370\,km\]\vspace{0.3cm}\noindentNote that the resolution of the rotated grid is higher than the resolution of the input grid, where a value of1\,degree is given. Finally, the last three parameters specify where the new co-ordinate system is centered on theglobe. Here, this position is at 65\,W (CLON) and 45\,N (CLAT), i.e. approximately in the centre of the PV streamershown in Fig.\,\ref{question}. The last parameter (CROT) allows the new grid to be rotated. At the end of this step, the following fields are available on the R20060115\_18 file:\\[0.2cm]\begin{center}\begin{tabular}{|l|l|l|}\hlineQ & Specific humidity ($kg/kg$) & R20060116\_18 \\U & (Rotated) Zonal velocity ($m/s$) & R20060116\_18 \\V & (Rotated) Meridional velocity ($m/s$) & R20060116\_18 \\T & Temperature ($^\circ C$) & R20060116\_18 \\P & Pressure ($hPa$) & R20060116\_18 \\ORO & Height of topography ($m$) & R20060116\_18 \\LAT & Geographical latitude & R20060116\_18 \\LON & Geographical longitude & R20060116\_18 \\CORIOL & Coriolis parameter ($1/s$) & R20060116\_18 \\X & Cartesian distance from centre along x axis ($km$) & R20060116\_18 \\Y & Cartesian distance from centre along x axis ($km$) & R20060116\_18 \\\hline\end{tabular}\end{center}\subsubsection{Calculating secondary fields [prep3]}Several additional fields are needed for the PV inversion, the most prominent of course being Ertel's PV itself.This field can easily derived from the horizontal wind components, the potential temperature andthe density. Firstly, the potential temperature $\theta$ is calculated from pressure $p$ (in hPa) andtemperature $T$ (in K) according to its definition:\[\theta = T \cdot (\frac{p_0}{p})^\kappa\]where the reference pressure is fixed as 1000\,hPa and $\kappa=R/C_p$ is the ratio of the gas constantfor dry air ($R$) and the specific heat at constant pressure ($c_p$). Numerically, this valueis in good approximation: $\kappa=0.286$.Note that an inherent property of the atmosphere is its stability. This is expressed physically bya potential temperature which increases with height. Regions where potential temperature decreaseswith height are hydrostatically unstable and the pre-requisites for a PV inversion are not fulfilledthere. \\\noindentThe density $\rho$ (in kg/m$^3$) of the air is determined by the ideal gas equation for air.\\[-0.3cm]\[\rho = \frac{p}{R_D \cdot T}\]\vspace{0.3cm}\noindentwhere $R_d$ is the gas constant for dry air and p and T are the pressure (in Pa) and temperature(in K), respectively.\\\noindentWith this definition of potential temperature and density, Ertel's PV is readily calculated according to:\[PV = -\frac{1}{\rho} \cdot ( \vec{\xi} + f \cdot \hat{k} ) \cdot \vec{\nabla}{\theta}\]\vspace{0.3cm}\noindentHere, $\hat{k}$ is a unit vector pointing in the vertical direction, $f$ is the planetary vorticity(typically $10^{-4} s^{-1}$ in the extra-tropics),i.e. the vorticity due to the Earth's rotation, and $\vec{\xi}$ is the curl $\vec{\nabla} \times \vec{u}$of the wind vector $\vec{u}$. In large-scale dynamics vertical wind components can be neglected in theabove formula. The final expression for Ertel's PV then reduces to:\[PV = -\frac{1}{\rho} \cdot [ ( \frac{\partial v}{\partial x} - \frac{\partial u}{\partial y} + f )\cdot \frac{\partial \theta}{\partial z}+ \frac{\partial u}{\partial z} \cdot \frac{\partial \theta}{\partial y}- \frac{\partial v}{\partial z} \cdot \frac{\partial \theta}{\partial x}]\]\vspace{0.3cm}\noindentIn many cases the latter two terms (involving vertical derivatives of horizontal velocity) canalso be neglected. Here, we keep these terms in order to have a higher-order approximation to Ertel'sPV. Note that the first term on the right side includes the aforementioned verticalderivative of potential temperature. The stability criterion forces this derivative to be positive.The theory of atmospheric turbulence leads to a still stronger constraint. Indeed, the whole PVmust be positive (on the northern hemisphere), since otherwise symmetric instability will set in andturbulently adjust the atmosphere to a state where PV is non-negative.\\\begin{figure}[t]\begin{center}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{zus_pv_k40.eps}\end{minipage}\hspace{0cm}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{zus_th_k40.eps}\end{minipage}\\[0cm]\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{zus_nsq_k40.eps}\end{minipage}\hspace{0cm}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{zus_rho_k40.eps}\end{minipage}\\[0cm]\caption{\it Secondary fields:Ertel's potential vorticity (upper-left, in $pvu$), potential temperature (upper-right, in K),squared Brunt-V\"ais\"al\"a frequency (lower-left, in $10^{-4} s^{-2}$) and density (lower-right,in $kg m^{-3}$). The stratification is a measure of the vertical stratification of the atmosphere.High values correspondto strong stratification and suppression of vertical motions. Note how the stratospheric PV streamer isassociated with enhanced stratification. The density, on the other hand, is slightly decreased within thestreamer's region. Allfields are plotted on model level 40, corresponding to a geometrical height of approximately 8\,km.}\label{secfield}\end{center}\end{figure}\noindentThe last field which is needed for the PV inversion is strongly related to the vertical derivativeof potential temperature. It is the so-called squared Brunt-V\"as\"ala frequency (or stratification),defined by\[N^2 = \frac{g}{\theta} \cdot \frac{\partial \theta}{\partial z}\]\vspace{0.3cm}\noindentwhere $g$ is the Earth's gravity. Following the above discussion, a necessary condition foratmospheric stability is that $N^2$ is non-negative. Note that strong stratifications counteractvertical motions. Particularly strong stratifications are typically found in the stratosphere,($N^2 \approx 10^{-4} s^{-2}$) whereas the troposphere is considerably weaker stratified($N^2 \approx 10^{-4} s^{-2}$).\\\noindentAll these secondary fields are calculated with the call to \\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh prep3\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentAfter this step, four additional variables are available on the file R20060116\_18. They are listed in the following table and are shown in Fig.\,\ref{secfield}:\\\begin{center}\begin{tabular}{|l|l|l|}\hlineTH & Potential temperature ($K$) & R20060116\_18 \\PV & Ertel's potential vorticity ($pvu$) & R20060116\_18 \\NSQ & Squared Brunt-Vai\"al\"a frequency ($1/s^2$) & R20060116\_18 \\RHO & Air density ($kg/m^3$) & R20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\subsubsection{Identification of a PV anomaly [prep4]}Having calculated Ertel's PV on height levels, it is now time to specify the modified PV distributionwhich should be obtained by the PV inversion. In short, a PV anomaly has to be identified from the originalPV field and then the effect of this anomaly on the potential temperature and velocity has to be determined.\\\noindentThere is no unique and fool-proof method how to specify an anomaly. Indeed, this step strongly depends onthe features which should be studied. In the present example, we look at a so-called stratospheric PV streamer and the aimis to remove this streamer from the PV field and thereby to quantify its influence on the stability and windfields in the middle and lower troposphere. Figure\,ref{box} shows the PV in a horizontal cross-section at 8\,kmheight. The PV streamer is clearly discernible as asouthward intrusion of high-PV, i.e. stratospheric air toward the south. In the vertical the streamer reachesdown to levels of 6\,km (not shown).\\\noindentThe extraction of the streamer is performed by filtering the original PV field. This filtering is doneby the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh prep4\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentEssentially, the program performsthe following two steps: Choose a grid point within the filtering box (see Fig\,ref{box}), andreplace the PV value at this grid point by the zonal mean of all PV values. Formally this might bewritten as:\[PV \quad \rightarrow \quad <PV>\]\vspace{0.3cm}\noindentwhere $<>$ denotes the filtering operator which applies only within the filtering box.The anomaly could now be determined as the difference of the original and filtered PV:It turns out that this simple difference $AN=PV-<PV>$ would produce not only the desired positive anomaly associatedwith the streamer, but also surrounding negative PV anomalies. We neglect all these negative anomaliesby simply setting them to zero. \\[-0.2cm]\[AN = PV - <PV> \quad \mbox{and} \quad AN \rightarrow AN^+.\]\begin{figure}[t]\begin{center}\begin{minipage}[t]{13cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{box.eps}\end{minipage}\\\caption{\it Ertel's PV on level $k=40$ (corresponding to a height of 8\,km). Additionally the horizontalgrid is shown, and the filtering box is marked with the bold black lines.}\label{box}\end{center}\end{figure}\vspace{0.3cm}\noindentThe outcome $AN^+$ is a "well-behaved" PV anomaly, which in turn is used to finally define the modified $PV^M$, i.e.the PV field which should be obtained by the inversion:\\\[PV^M = PV - AN^+\]\vspace{0.3cm}\noindentThe original $PV$, modified $PV^M$ and the anomaly $AN^+$ is shown in Fig.\,\ref{ano} at several model levels. Note how the PV streamer of Fig.\,\ref{question} is well captured by the PV anomaly\begin{figure}[t]\begin{center}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_org_k20.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_mod_k20.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_ano_k20.eps}\end{minipage}\\\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_org_k30.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_mod_k30.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_ano_k30.eps}\end{minipage}\\\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_org_k40.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_mod_k40.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_ano_k40.eps}\end{minipage}\\\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_org_k50.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_mod_k50.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_ano_k50.eps}\end{minipage}\\\caption{\it Original (left), modified (middle) and anomaly (right) Ertel's PV for 16 January 2006, 18\,UTC. The different rows correspond to the levels (from top to bottom) 20, 30 40 50 corresponding to the heights 4, 6, 8 and 10\,km.}\label{ano}\end{center}\end{figure}\noindentThe filteringis characterised by the values in six lines of the parameter file. \\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}BEGIN ANOMALYBOX_XMIN = -1200.;BOX_XMAX = 1200.;BOX_YMIN = -1200.;BOX_YMAX = 1200.;BOX_ZMIN = 2000.;BOX_ZMAX = 10000.;NFILTER = 5 ;BOUND_XY = 500.;BOUND_Z = 500.;END ANOMALY\end{verbatim}\end{minipage}\end{center}\vspace{0.6cm}\noindentThe lines specify the filtering box in the west-east direction (from -1200\,km to1200\,km, from BOX\_XMIN to BOX\_XMAX), in the south-north direction (from -1200\,km to 1200\,km, from BOX\_YMIN to BOX\_YMAX), and in the vertical(from 2000\,m to 10000\,m, from BOX\_ZMIN to BOX\_ZMAX). The filtering is not only applied once, but(as given by NFILTER) $n=5$ times.Finally the last two parameters describe the handling at the boundaries of the filtering box. In fact,it is advantageous to force the anomaly PV to zero at the boundaries of the box. This is accomplishedby multiplying the PV anomaly with a function f$_{\partial F}$ which is 0 without the box, then monotonically increasesto 1 within a boundary zone, and then is constant 1 in the interior of the box. The width of the boundaryzone is given as 500\,km in the horizontal direction (BOUND\_XY) and 500\,m in the vertical direction (BOUND\_Z).\\\noindentThe modified PV field and the anomaly are written to the R20060116\_18 file.Additionally the boundary values are written. The velocity fields must be specified on the lateralboundaries, whereas the potential temperature anomaly must be specified on the lower and upper boundary. Inthe present settings, all boundary values are zero. The following table lists all fields which are additionallywritten to the R file.\begin{center}\begin{tabular}{|l|l|l|}\hlinePV\_FILT & Modified Ertel's PV ($pvu$) & R20060116\_18 \\PV\_ANOM & Anomaly in Ertel' PV ($pvu$) & R20060116\_18 \\UU\_ANOM & Lateral boundary condition of zonal wind($m/s$) & R20060116\_18 \\VV\_ANOM & Lateral boundary condition of meridional wind ($m/s$) & R20060116\_18 \\TH\_ANOM & Upper and lower boundary of potential temperature ($K$) & R20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\subsubsection{Splitting into different files [prep5]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{11.5cm}\hspace{-2.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{splitting.eps}\end{minipage}\\\caption{\it Splitting of the initial R20060116\_18 file into four different files withprefix ORG, MOD, ANO and REF. }\label{split}\end{center}\end{figure}\noindentSo far, all new fields are written to the R20060116\_18 file. In the further steps it isadvantageous to split this file into several files. One file should get all originalfields, one only the modified fields and one only anomaly fields. Additionally, some"static" fields, such as orography and Coriolis parameter, should be written to a specialfile, from here on called the reference file.\\\noindentThe splitting is done with the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{15cm}\begin{verbatim}inversion.sh prep4\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe result of this step is a set of new netcdf files with prefix ORG, MOD, ANO and REF. The following table(and Fig.\,\ref{split}) illustrates which variables are written to which file. Note that some variables are renamed in this process.\\\begin{center}\begin{tabular}{|r|r|r|r|}\hlineOld variable name & New variable name & Source file & Destination file \\\hlinePV & PV & R20060115\_18 & ORG\_20060116\_18 \\U & U & R20060115\_18 & ORG\_20060116\_18 \\V & V & R20060115\_18 & ORG\_20060116\_18 \\TH & TH & R20060115\_18 & ORG\_20060116\_18 \\Q & Q & R20060115\_18 & ORG\_20060116\_18 \\P & P & R20060115\_18 & ORG\_20060116\_18 \\T & T & R20060115\_18 & ORG\_20060116\_18 \\\hlinePV\_FILT & PV\_AIM & R20060115\_18 & MOD\_20060116\_18 \\U & U & R20060115\_18 & MOD\_20060116\_18 \\V & V & R20060115\_18 & MOD\_20060116\_18 \\Q & Q & R20060115\_18 & MOD\_20060116\_18 \\P & P & R20060115\_18 & MOD\_20060116\_18 \\T & T & R20060115\_18 & MOD\_20060116\_18 \\NSQ & NSQ & R20060115\_18 & MOD\_20060116\_18 \\RHO & RHO & R20060115\_18 & MOD\_20060116\_18 \\TH & TH & R20060115\_18 & MOD\_20060116\_18 \\\hline\end{tabular}\begin{tabular}{|r|r|r|r|}\hlineOld variable name & New variable name & Source file & Destination file \\\hlinePV\_ANOM & PV & R20060115\_18 & ANO\_20060115\_18 \\TH\_ANOM & TH & R20060115\_18 & ANO\_20060115\_18 \\UU\_ANOM & U & R20060115\_18 & ANO\_20060115\_18 \\VV\_ANOM & V & R20060115\_18 & ANO\_20060115\_18 \\\hlineORO & ORO & R20060115\_18 & REF\_20060115\_18 \\X & X & R20060115\_18 & REF\_20060115\_18 \\Y & Y & R20060115\_18 & REF\_20060115\_18 \\LAT & LAT & R20060115\_18 & REF\_20060115\_18 \\LON & LON & R20060115\_18 & REF\_20060115\_18 \\CORIOL & CORIOL & R20060115\_18 & REF\_20060115\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\subsubsection{Specifying the reference profile [prep6]}A reference vertical profile must bedefined for the PV inversion. The profile should be as near as possible to the real profile. Any quantity is defined inthe inversion as a deviation from this profile. Hence if the profile is well chosen only smalldeviations can be expected and the assumed linearisation (see later) is better. Physically we determinea good reference profile by taking the area mean over the subdomain, i.e at every model level themean over potential temperature $\theta$, squared Brunt Vais\"al\"a frequency $N^2$ and density $\rho$is calculated. The resulting profiles are shown in Fig.\,\ref{reference} as a function of height, and additionallyas a function of pressure.\\\noindentNote how the density of the reference profile exponentially decreasesdecreases with increasing height. If pressure is used as vertical co-ordinate, the decrease in densityis essentially linear with decreasing pressure. The profile of potential temperature increases withincreasing height: This is a necessary condition for the convective stability of the air column. In fact,any region where potential temperature decreases with increasing height is unstable and characterised by high levelsof turbulence. The stability expressed by this potential temperature increase with height is numericallydetermined by the so-called (squared) Brunt-Vais\"al\"a frequency, shown in the left panels. Since thisfield directly goes into the solution of the quasi-geostrophic PV equation (see section~3.5), it mustbe guaranteed that it always remains positive.\\\begin{figure}[t]\begin{center}\begin{minipage}[t]{16cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{reference.eps}\end{minipage}\\\caption{\it Reference profiles of potential temperature $\theta$, squared Brunt Vais\"al\"a frequency $N^2$ and density $\rho$ as a function of height (upper panels) and pressure (lower panels). Thereference profiles correspond to the area-averaged values over the inversion subdomain. }\label{reference}\end{center}\end{figure}\noindentThe reference profile is calculated with the call to \\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh prep5\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentAfter his step some additional variables are available on the REF file. These are:\\\begin{center}\begin{tabular}{|l|l|l|}\hlineNSQREF & Reference squared Brunt-Vais\"al\"a frequency ($1/s^2$) & MOD\_20060116\_18 \\RHOREF & Reference air density ($kg/m^3$) & MOD\_20060116\_18 \\PREREF & Reference pressure ($hPa$) & MOD\_20060115\_18 \\THETAREF & Reference potential temperature ($K$) & MOD\_20060116\_18 \\ZREF & Reference geopotential height ($m$) & MOD\_20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\subsubsection{Adding the coastlines [prep7]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{coast1.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{coast2.eps}\end{minipage}\\\caption{\it Coastlines transformed into the quasi-cartesian co-ordinate system. In the left panel, thecoastlines are shown in a system with rotated longitude and latitude as axes, in the right panel theyare shown in a x/y co-ordinate system.}\label{coastline}\end{center}\end{figure}At this stage it is not possible to plot the continental coastlines in the quasi-cartesian co-ordinate frame.In fact, this becomes only feasible if the geographical coastlines (as given in latitude/longitude co-ordinates) are transformed into the new quasi-cartesian co-ordinate system. This is donewith the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh prep7\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentIn Fig.\,\ref{coastline} the transformed co-ordinates are shown. On the left panel, the co-ordinate axis are the rotated longitude and latitude and on the left panel they are given by the distance (in km) from the co-ordinate's center (see Fig.\,14).In this step the following additional fields are written to the REF\_20060116\_18 file:\begin{center}\begin{tabular}{|l|l|l|}\hlineCOAST\_LON & Longitude of coastline & REF\_20060115\_18 \\COAST\_LAT & Latitude of coastline & REF\_20060115\_18 \\COAST\_RLON & Rotated longitude of coastline & REF\_20060115\_18 \\COAST\_RLAT & Rotated latitude of coastline & REF\_20060115\_18 \\COAST\_X & X co-ordinate of coastline & REF\_20060115\_18 \\COAST\_Y & Y co-ordinate of coastline & REF\_20060115\_18 \\\hline\end{tabular}\end{center}\vspace{0.3cm}\noindentThe coastline in geographical co-ordinates is taken from a global data set which can be retrieved fromthe National Geophysical Data Center(rimmer.ngdc.noaa.gov/coast/). Only, the part of the coastlines inside the rotated co-ordinate system are specified. This allowsan efficient plotting of the coastlines. If Matlab is used as a visualisation tool, the plotting can bedone with the following few lines, depending whether rotated longitude/latitude or X/Y is used as co-ordinateaxes.\\[0.0cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}%Read input fileinp = ncget('REF_20060116_18');% Plot continental boundaries (rotated latitude/longitude)figure;plot(inp.COAST_RLON.data,inp.COAST_RLAT.data,'k');% Plot continental boundaries (x/y)figure;plot(inp.COAST_X.data,inp.COAST_Y.data,'k');\end{verbatim}\end{minipage}\end{center}\vspace{0.6cm}\noindentThe first command reads the reference file. All variables and parameters are then available in the Matlab structure inp. The COAST subfields of this structure can then immediately be plotted. Sometimes it turnsout to be better to set all co-ordinates outside the plotting domain to NaN.\subsubsection{Moving the files to the run directory [prep8]}At this stage, all essential preparatory steps for the PV inversion are done: The modified PV field is defined, theboundary conditions are written and the reference profile is available. In this last step, the files are moved from theinput directory to the run directory, where all iterations of the PV inversions are performed. The moving of thefiles is done with\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh prep8\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe ORG, MOD, ANO and REF files are now available in the run directory (see Fig.\,8). No further processes arerun in the input directory.\subsection{Inversion - Iterative steps toward modified PV field [pvin]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{14cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{iterations.eps}\end{minipage}\\\caption{\it Flowchart of the different inversion steps. Additionally, to the right of the different blocks, the"flow" of information is illustrated. For instance, MOD $\rightarrow$ ANO means that the input informationis taken from the MOD file and then written to the ANO file. }\label{iterations}\end{center}\end{figure}The following steps build the core of the PV inversion. An interior anomaly of Ertel's PVand the boundary values for the inversion were specified in the previous preparatory steps.Now the flow anomalies (wind vectors, temperature, pressure and potential temperature) associatedwith this PV anomaly has to be determined. This is the aim of the inversion. More specificallythe process must be split again into several distinct steps. These different steps are shown as a flowchart inFig.\,\ref{iterations}.\subsubsection{Calculation of secondary fields [pvin1]}Secondary fields have to be calculated. These fields are potential temperature, potential vorticitydensity and squared Brunt-Vais\"al\"a frequency. The details of these calculations were already presentedin section~4.4.3, and are not repeated here. All the secondary fields are calculated with the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh pvin1\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe call subsequently calculates potential temperature, squared Brunt-V\"as\"ala frequency, density and Ertel's PV. Where the height levels are below topography,missing data values are written. The following table lists the new fields which are written to the MOD file:\begin{center}\begin{tabular}{|l|l|l|}\hlineTH & Potential temperature ($K$) & MOD\_20060116\_18 \\PV & Ertel's potential vorticity ($pvu$) & MOD\_20060116\_18 \\NSQ & Squared Brunt-Vai\"al\"a frequency ($1/s^2$) & MOD\_20060116\_18 \\RHO & Air density ($kg/m^3$) & MOD\_20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\subsubsection{Transforming Ertel's PV to quasi-geostrophic PV [pvin2]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{14.0cm}\hspace{-1.0cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{pv_to_qgpv.eps}\end{minipage}\\\caption{\it Determination of Ertel's PV anomaly and its transformation intoan anomaly of quasi-geostrophic PV. The calculated Ertel's PV is subtracted fromErtel's PV which should be reached, and then this difference is transformed intoan approximate quasi-geostrophic PV. The input is taken from the MOD file, and theoutput is written to the ANO file.}\label{pvtoqg}\end{center}\end{figure}So far only Ertel's PV was used. On the other hand, the inverson problem is formulated for thequasi-geostrophic PV. Therefore a conversion between the two has to be done. In a first approximationErtels's PV is given by (for clarity it is denoted as EPV in this section):\\[-0.2cm]\[EPV = \frac{1}{\rho} \cdot ( \xi + f ) \cdot \frac{\partial \theta}{\partial z}\]\vspace{0.3cm}\noindentwhere $\rho$ is the density, $\xi$ the relative vorticity, $f$ the Coriolis parameter and $\theta$ the potential temperature.Ertel's PV can be expressed in terms of the reference profile and deviation thereof. If we set$\theta=\theta_0 + \theta^*$ and $\rho=\rho_0 + \rho^*$, consider the definitionof the reference stratification $N^2_0=g/\theta_0 \cdot \partial {\theta_0}/{\partial z}$ and furthermoreapply the quasi-geostrophic assumption $\xi \ll f$, the following approximateexpression hold in first order (we have neglected the density perturbation $\rho^*$ in the denominator):\\[-2mm]\[EPV = \frac{\theta_0 N_0^2}{g \rho_0} \cdot (\xi + \frac{f g}{\theta_0 N_0^2} \cdot \frac{\partial \theta^*}{\partial z})\]\vspace{0.3cm}\noindentOn the other hand, the quasi-geostrophic PV (denoted by qgPV in this section) is defined by the streamfunction $\psi$\\[-0.2cm]\[qgPV = \frac{\partial^2\psi}{\partial x^2} + \frac{\partial^2\psi}{\partial y^2} +\frac{f^2}{\rho_0} \cdot \frac{\partial}{\partial z} (\frac{\rho_0}{N_0^2}\cdot \frac{\partial \psi}{\partial z} )\]\vspace{0.3cm}\noindentwhere $\rho_0$ and $N_0^2$ denotes a reference profile of density and stratification (as defined in thepreparatory steps and written to the REF file). The following relationship between the streamfunction and the meteorological fields persists:\\[-2mm]\[g \cdot \frac{\theta^*}{\theta_0} = f \cdot \frac{\partial \psi}{\partial z}\quad \quadu = -\frac{\partial \psi}{\partial y}\quad \quadv = -\frac{\partial \psi}{\partial x}\]\vspace{0.3cm}\noindentIf these expressions are inserted into the above equation for $q$, one gets:\\[-2mm]\[qgPV = \xi + \frac{f^2}{\rho_0} \cdot \frac{\partial}{\partial z}(\frac{\rho_0 g}{N_0^2 f \theta_0} \cdot \theta^* )\]\vspace{0.3cm}\noindentIn a first approximation, we treat the reference profile and the Coriolis parameter as constant. Then,this last expression is further simplified to:\\[-2mm]\[qgPV = \xi + \frac{f g}{N_0^2 \theta_0} \cdot \frac{\partial \theta^*}{\partial z}\]\vspace{0.3cm}\noindentWith this form, it is easy to see that the following approximate relationship between Ertel's and thequasi-geostrophic PV holds. \\[-2mm]\[qgPV \approx \frac{\rho_0 g}{\theta_0 N_0^2} \cdot EPV - f\]\vspace{0.3cm}\noindentNote that according to the previous derivation, this equation does not hold exactly. It is based uponan assumption of linearisation and on approximate forms of Ertel's PV. Nevertheless, we can expect itto be a good first-order approximation. In the PV inversion tool, use is made of this relationship,but since it is only approximate, an iterative technique has to be applied. Finally note that thisformula can be easily applied to PV anomalies. Indeed, if $\Delta PV$ refers to a anomaly in Ertel'sPV, the corresponding anomaly in quasi-geostrophic PV is given by:\\[-2mm]\[\Delta(qgPV) \approx \frac{\rho_0 g}{\theta_0 N_0^2} \cdot \Delta(EPV)\]\vspace{0.3cm}\noindentIt is in this latter form that the program call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh pvin2\end{verbatim}\end{minipage}\end{center}\begin{figure}[t]\begin{center}\begin{minipage}[t]{8.1cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{qgpv_ano_ew.eps}\end{minipage}\hspace{-0.5cm}\begin{minipage}[t]{8.1cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{qgpv_ano_ns.eps}\end{minipage}\\\caption{\it Quasi-geostrophic PV anomaly in an east/west (left) and an north/south (right)vertical cross-section for 16 January 2006, 18\,UTC. }\label{qgano}\end{center}\end{figure}\vspace{0.3cm}\noindentmakes the conversion. It takes the Ertel-PV from the MOD file, and subtracts it from the PV\_AIM which is alsoavailable on the MOD file. The difference between the two PV is the new anomaly in Ertel's PV which has tobe inverted in this iterative step. The approximate relationship between quasi-geostrophic PV and Ertel'sPV is then used to get a corresponding anomaly of the former one (see Fig.\,ref{pvtoqg}).Note that this program handles also missing data values. If at some grid point Ertel's PV is not defined,i.e. the missing data flag is set, the corresponding value of quasi-geostrophic PV is set to zero. It is notset to the missing data value since no check will be done by the PV inversion program. Therefore, it isbest to treat every missing value as a vanishing anomaly of quasi-geostrophic PV. A vertical cross-sectionof the anomaly in quasi-geostrophic PV is shown in Fig.\,\ref{qgano}.The additional or changed fields on the file ANO\_20060116\_18 are given in the following table:\\\begin{center}\begin{tabular}{|l|l|l|}\hlinePV & Ertel's PV anomaly ($pvu$) & ANO\_20060116\_18 \\QGPV & Anomaly in quasi-geostrophic PV ($s^{-1}$) & ANO\_20060116\_18 \\\hline\end{tabular}\end{center}\subsubsection{Inversion of the quasi-geostrophic PV [pvin3]}At this stage the interior distribution of quasi-geostrophic PV and the boundary valuesare given, and therefore the inversion can be performed in order to get the streamfunction.Numerical aspects of the inversion were already presented in section~2. Here, we focus on thepractical aspects. The numerical problem solved in this step is expressed in the followingboundary value problem: \\[-0.3cm]\[q = \frac{\partial^2\psi}{\partial x^2} + \frac{\partial^2\psi}{\partial y^2} +\frac{f^2}{\rho_0} \cdot \frac{\partial}{\partial z} ( \frac{\rho_0}{N_0^2}\cdot \frac{\partial \psi}{\partial z})\]\vspace{0.3cm}\noindentwith the pre-described values\\[-0.3cm]\[g \cdot \frac{\theta^*}{\theta_0} = f \cdot \frac{\partial \psi}{\partial z}\quad \quadu = -\frac{\partial \psi}{\partial y}\quad \quadv = -\frac{\partial \psi}{\partial x}\]\vspace{0.3cm}\noindenton the upper and lower boundaries (for $\theta^*$) and on the lateral boundaries (for $u$ and $v$). The inversion program is called by\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh pvin3\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentNote that the inversion affects only the file ANO\_20060116\_18 because the inversion isperformed for an anomaly of quasi-geostrophic PV.The final aim of this step is to calculate the wind, temperature, pressure and potential temperatureperturbations which are associated with the specified anomaly of quasi-geostrophic PV.The call to the program yields some information about the ongoing iterative steps. First of all,the spectral width in the x-, y- and z-direction is written to screen. In the present example thisis:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{small}\begin{verbatim}Spectrum of the matrix in each directionSpectrum = 1.028528 0.9136161 1.231250\end{verbatim}\end{small}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe spectral widths $\lambda_x,\lambda_y, \lambda_z$ (in the same order as in the above program output) are important to decide whether the inversion can be reasonably be performed. Thecriterion is based upon the matrix elements defining the inversion problem. For a reasonable settingthe following inequalities should be fulfilled:\[\lambda_x > 1/2 \cdot \lambda_y \quad \quad \mbox{and} \quad \quad \lambda_x > 1/2 \cdot \lambda_z\]\[\lambda_y > 1/2 \cdot \lambda_x \quad \quad \mbox{and} \quad \quad \lambda_y > 1/2 \cdot \lambda_z\]\[\lambda_z > 1/2 \cdot \lambda_x \quad \quad \mbox{and} \quad \quad \lambda_z > 1/2 \cdot \lambda_y\]\vspace{0.3cm}\noindentwhich is evidently fulfilled in our case study (otherwise the program would abort with the errormessage that the grid dimensions are not large enough). Then some run-time statistics is provided for theiterative solution of the elliptical partial differential equation. As described in section~2 thesolution of the quasi-geostrophic PV equation is found by means of an successive over-relaxation (SOR)technique. Starting from an initial estimate of the streamfunction $\psi$ several hundred iterations of\[\psi_i^{(n+1)} = \omega \cdot (b_i - \sum_{j=1}^{i-1} A_{i,j} \cdot \psi_j^{(n+1)}- \sum_{j=i}^{m} A_{i,j} \cdot \psi_j^{(n)})+ (1-\omega) \cdot \psi_i^{(n)}\]\vspace{0.3cm}\noindentare performed (see section~2 for details). Essentially two statistical measures are provided: The first one $\psi_{gauge}$measures the amplitude of the streamfunction which is produced in the course of the iteration,the second one is a direct check whether the iteration solution converges. In fact, after several iterations the so-farreached streamfunction is used to calculate the quasi-geostrophic $PV^{c}$ according to the formula:\\[-0.3cm]\[PV^c = \frac{\partial^2\psi}{\partial x^2} + \frac{\partial^2\psi}{\partial y^2} +\frac{f^2}{\rho_0} \cdot \frac{\partial}{\partial z} ( \frac{\rho_0}{N_0^2}\cdot \frac{\partial \psi}{\partial z})\]\vspace{0.3cm}\noindentThis value can then be compared to the quasi-geostrophic$PV^{i}$ distribution which was given as input to the inversion algorithm. The following norm $\Delta^2$ is thencalculated as a measure of the convergence:\\[-0.3cm]\[\Delta^2 = \sum_{i,j,k} (\psi^{i}_{i,j,k}-\psi^{c}_{i,j,k})^2\]\vspace{0.3cm}\noindentSome sample output is reproduced below for the case study, the first column corresponding to $\psi_{gauge}$ and thesecond one to $\Delta^2$:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}psigauge = 0.000E+00 deltasq = 0.850E-09psigauge = 0.000E+00 deltasq = 0.112E-09psigauge = -0.681E+03 deltasq = 0.643E-10psigauge = -0.681E+03 deltasq = 0.466E-10psigauge = -0.806E+03 deltasq = 0.367E-10psigauge = -0.806E+03 deltasq = 0.303E-10psigauge = -0.547E+03 deltasq = 0.259E-10psigauge = -0.547E+03 deltasq = 0.228E-10psigauge = -0.398E+03 deltasq = 0.206E-10psigauge = -0.398E+03 deltasq = 0.191E-10psigauge = -0.309E+03 deltasq = 0.180E-10\end{verbatim}\end{minipage}\end{center}\vspace{0.6cm}\noindentNote that the gauge streamfunction reaches a value of order -3000 (corresponding to a substantial anomaly of windand temperature), and that the convergence measure $\Delta^2$ decreasesby an order of magnitude from the beginning to the end. At the end of this step, the streamfunction associated with the quasi-geostrophic PV anomaly is determined. It is shown in Fig.\,\ref{stream} at three horizontal cross-sections. Theminimum of the streamfunction is found in the interior of the domain, in agreement with the cyclonic flow around thepositive anomaly of quasi-geostrophic PV. \\\begin{figure}[t]\begin{center}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{psi_ano_k01.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{psi_ano_k20.eps}\end{minipage}\hspace{0.0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{psi_ano_k40.eps}\end{minipage}\\\caption{\it Streamfunction associated with the quasi-geostrophic PV anomaly shown in Fig.\,ref{qgano}. The three panels show horizontal cross-sections at 0, 4\,km and 8\,km above ground.}\label{stream}\end{center}\end{figure}\noindentNow, additional perturbation fields can be computed from this streamfunction: Potential temperature,wind components in x and y direction, pressure, and temperature. The corresponding formula are:\\[-0.5cm]\begin{eqnarray*}\theta^* & = & \frac{f}{g} \cdot \theta_0 \cdot \frac{\partial \psi}{\partial z}\\[0.2cm]u & = & - \frac{\partial \psi}{\partial y}\\\end{eqnarray*}\begin{eqnarray*}v & = & \frac{\partial \psi}{\partial x}\\\end{eqnarray*}\vspace{0.3cm}\noindentThe anomaly of potential temperature $\theta^*$ and the two horizontal wind components $u$ and $v$ can directly determined from thestreamfunction. Moreover, the pressure anomaly is directly proportional to the streamfunction, which is onlydetermined up to an additive constant. In order to obtain a vanishing pressure at the boundary of theinversion domain, we firstly calculate such a constant $\psi_0$ (essentially the average over the domain boundary) and then set the pressure to:\\[-0.2cm]\[p^* = \rho_0 \cdot f \cdot (\psi - \psi_0)\]\vspace{0.3cm}\noindentThe temperature anomaly is now easily calculated from pressure and potential temperature according the relationship$\theta = T \cdot (p_ref/p)^\kappa$, where $T$ is the temperature in Kelvin, $p_ref$ is the reference pressure level (1000\,hPa) and $\kappa$ is the ratio between the gas constant for dry air ($R_d$) and the specific heat at constant pressure ($c_p$). Consistent with previous approximations we set:\\[-0.2cm]\[T^* = (\frac{p_0}{p_ref})^\kappa \cdot (\theta^* + \kappa \cdot \theta_0 \cdot \frac{p^*}{p_0} )\]\vspace{0.3cm}\noindentFigure\,\ref{anofield} shows some of these perturbation fields. The positive anomaly of quasi-geostrophic PV isassociated with a cyclonic (anti-clockwise) flow field, which reaches down to surface levels. Furthermore, we know from theoretical studies that a positive PV anomaly goes along with an increase of potential temperature above the anomaly, and correspondingly a decrease ofpotential temperature below. This is nicely confirmed in the perturbation field of the calculation.Finally, the cyclonic flow must be associated with a local pressure minimum, according to thegeostrophic wind equation. This is also fulfilled in our calculation. The following table gives all anomaly fields on the ANO\_10060116\_18 file which are calculated:\begin{figure}[t]\begin{center}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{ano_00_k35_pr.eps}\end{minipage}\hspace{-0.6cm}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{ano_00_k35_tt.eps}\end{minipage}\\[-0.3cm]\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{ano_00_k35_uv.eps}\end{minipage}\hspace{-0.6cm}\begin{minipage}[t]{7.5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{ano_00_k35_psi.eps}\end{minipage}\\\caption{\it Pressure, temperature, wind vectors and streamfunction (from upper-left to lower-right)associated with the quasi-geostrophic PV anomaly. The horizontal cross-section is at level 7\,km. For clarity,some isolines of quasi-geostrophic PV are also shown.}\label{anofield}\end{center}\end{figure}\vspace{0.3cm}\begin{center}\begin{tabular}{|l|l|l|}\hlineSTREAM & Streamfunction ($m^2/s$) & ANO\_20060116\_18 \\THETA & Potential temperature ($K$) & ANO\_20060116\_18 \\U & Velocity component in X direction ($m/s$) & ANO\_20060116\_18 \\V & Velocity in Y direction ($m/s$) & ANO\_20060116\_18 \\T & Temperature ($^\circ C$) & ANO\_20060116\_18 \\P & Pressure ($hPa$) & ANO\_20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.3cm}\noindentFinally, the question emerges whether the convergence of the algorithm was sufficient. In order to assess thequality of convergence a diagnostic tool is presented in section~5.2, which allows to calculate thequasi-geostrophic PV according to its definition and then to compare it with the anomaly given atthe beginning of the PV inversion.\subsubsection{Preparing the next step for iteration [pvin4]}\noindentAt this point, the quasi-geostrophic PV anomaly is inverted and the associated streamfunction andother flow fields have been determined. But the inversion problem is not yet solved. In fact,we specified an anomaly of Ertel's PV, but in the previous step a anomaly of quasi-geostrophic PVwas inverted. By the above reasoning, we expect the two anomalies to be closely linked. However,inversion of the quasi-geostrophic PV equation is a linear problem, whereas the inversion of Ertel'sPV is inherently non-linear. That is why some further iteration must be performed.\\\noindentIn a first step, we take the basic flow fields (temperature, velocity, pressure) from the anomaly (ANO)file and subtract it from the MOD file (Fig.\,\ref{prepiter}). This is done by call to\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh pvin3\end{verbatim}\end{minipage}\end{center}\begin{figure}[t]\begin{center}\begin{minipage}[t]{10cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{prepiter.eps}\end{minipage}\\\caption{\it Preparation for the next iteration: The fields (pressure, temperature, velocity, potentialtemperature) from iteration n and the anomalies of iteration n are combined to give the fields at iterationn+1.}\label{prepiter}\end{center}\end{figure}\vspace{0.3cm}\noindentThere is one external parameter involved in this step. It is found in the NUMERICS section of theparameter file and is called ALPHA. This value determines which fraction of the perturbation has tobe subtracted from the MOD fields. Formally, we do the following transformation (see also Fig.\,\ref{prepiter}):\begin{eqnarray*}u^{n+1}_{MOD} & \leftarrow & u^n_{MOD} - \alpha \cdot u^n_{ANO}\\[0.2cm]v^{n+1}_{MOD} & \leftarrow & v^n_{MOD} - \alpha \cdot v^n_{ANO}\\[0.2cm]T^{n+1}_{MOD} & \leftarrow & T^n_{MOD} - \alpha \cdot T^n_{ANO}\\[0.2cm]p^{n+1}_{MOD} & \leftarrow & p^n_{MOD} - \alpha \cdot p^n_{ANO}\end{eqnarray*}\vspace{0.3cm}\noindentA value $\alpha < 1$ slows down the convergence because only part of the inversion result is used. On the other hand, it was found that the stability of the algorithm is enhanced by values $\alpha < 1$. Inthe case study a value of 0.5 was used, and good convergence reached, whereas a value of 1 resulted in unrealistic small-scale perturbations which diverge with continuing iterative steps.\\\noindentThe variables which are adjusted in the MOD\_20060116\_18 file are given in the following table and an examplefor the adjustment is shown in Fig.\,\ref{prepsub}:\begin{center}\begin{tabular}{|l|l|l|}\hlineTHETA & Potential temperature & MOD\_20060115\_18 \\U & Velocity component in X direction ($m/s$) & MOD\_20060115\_18 \\V & Velocity in Y direction ($m/s$) & MOD\_20060115\_18 \\T & Temperature ($^\circ C$) & MOD\_20060115\_18 \\P & Pressure ($hPa$) & MOD\_20060115\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\noindentIt might be valuable to study the convergence of the inversion in greater detail. To this aim, themaster script allows the call:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh pvin5\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentwhich makes a copy of the momentarily reached MOD and ANO file. For this save option to work, theSAVEITER flag in the NUMERICS section of the parameter file must be set to "yes".\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}BEGIN NUMERICSSAVEITER = yes;END NUMERICS\end{verbatim}\end{minipage}\end{center}\begin{figure}[t]\begin{center}\begin{minipage}[t]{8.3cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{prep_k35_org_ano.eps}\end{minipage}\hspace{-1cm}\begin{minipage}[t]{8.3cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{prep_k35_mod.eps}\end{minipage}\\\caption{\it Left: Temperature in the modified MOD file (in color) and in the anomaly ANO file (with contour lines)at the end of the quasi-geostrophic PV inversion. The temperature anomaly in ANO is subtracted from the initial temperature in MOD. Right: New modified temperature in the MOD file after the subtraction.This new modified field gives the next entry for the PV inversion. }\label{prepsub}\end{center}\end{figure}\subsubsection{Convergence after several iterations [pvin5]}At this stage, the next iterative steps can be performed. The MOD file has been adjusted according tothe outcome of the quasi-geostrophic PV inversion. The modified wind and temperature fields can be used to calculate a new Ertel-PV field, which in turn can be compared with the pre-specified aim-PV field.Hopefully, after several iterative steps, the re-currently calculated PV of the MOD file convergestoward the aim-PV. If so, the non-linear inversion problem for Ertel's PV is solved. Figure\,\ref{convergence}illustrates the convergence for the case study. Note that the iterative steps need not belaunched by hand, but can be run automatically with call to\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh pvin\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe script will run through all inversion steps and will loop through the number of iterations specified in NOFITER in the NUMERICS section of the parameter file.\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}BEGIN NUMERICSNOFITER = 6;END NUMERICS\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe panels of Fig.\,\ref{convergence} show the streamfunction at three consecutive iterative steps.Note that the amplitiude of the streamfunction clearly decreases, indicating that the iterationprocess converges.Generally, after six steps good convergence is reached. This is further supported bythe standard output during the quasi-geostrophic inversion (see listing on page~38). The final line of this outputis shown below for several consecutive iterations (the first one corresponding to the line on page~38):\begin{figure}[t]\begin{center}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{con_01_k35_psi.eps}\end{minipage}\hspace{0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{con_02_k35_psi.eps}\end{minipage}\hspace{0cm}\begin{minipage}[t]{5cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{con_03_k35_psi.eps}\end{minipage}\\\caption{\it streamfunction for three iterative steps. Note the different contour intervalsfor the three sub panels. The decrease of the amplitude clearly indicates a convergence of thePV inversion.}\label{convergence}\end{center}\end{figure}\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}psigauge = -0.309E+03 deltasq = 0.180E-10psigauge = -0.128E+03 deltasq = 0.548E-11psigauge = -0.570E+02 deltasq = 0.233E-11psigauge = -0.265E+02 deltasq = 0.117E-11\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentNote that with each iterative step "less" streamfunction is produced. Since the basic perturbationfields (temperature, pressure, horizontal wind, potential temperature) are directly proportionalto the streamfunction, the corrections to the flow fields alsobecome smaller and smaller.\subsection{Post processing - Changing the P file [post]}The PV inversion was completed in the previous step and the modified temperature, pressure and wind field is available in the run files. It is the aim of the post processing steps to bring these modifiedfields back to the format of the input fields. The steps are summarised in Fig.\,\ref{postproc}.\\\begin{figure}[t]\begin{center}\begin{minipage}[t]{12cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{postproc.eps}\end{minipage}\\\caption{\it Different steps of post processing. Additionally, to the left of the differentblocks the main flow of information is indicated. For instance, MOD $\rightarrow$ GEO meansthat the input is taken from the MOD file and the output written to the GEO file. }\label{postproc}\end{center}\end{figure}\noindentBut at first the input field and the link to the modified output field must be made available with a call to:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh post1\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe P file is copied from the input directory to the output directory and a symbolic link is set to theMOD file in the run directory.\subsubsection{Rotating to the geographical latitude/longitude grid [post2]}Figure~\ref{backrot} illustrates the step which is necessary to transform the meteorological fields to a geographical co-ordinate system. The left panel shows the temperature at 2000\,m above sea level in the local-cartesian co-ordinate system, the right panel is the same field, but projected back to a geographical grid. Note that in this latter frame only a small section is filled by temperature values, whereas most areundefined.\\\begin{figure}[t]\begin{center}\begin{minipage}[t]{8.3cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{rot_k35_rot_t.eps}\end{minipage}\hspace{-1.2cm}\begin{minipage}[t]{8.3cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{rot_k35_geo_t.eps}\end{minipage}\\\caption{\it Modified temperature field at 7\,km above ground in the rotated co-ordinate system (left) and transformed back into the geographical latitude/longitude grid (right). Additionallythe wind vectors are shown in both co-ordinate systems. Note that the transformation of the vectorialwind is much more complicated than the transformation of the scalar temperature.}\label{backrot}\end{center}\end{figure}\noindentThe rotation itself is the reverse transformation performed in the preparatory steps (section~4.4.2). It is called by (and its effect shown in Fig.\,\ref{backrot})\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh post2\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentand its behaviour is controlled by the following entries in the parameter file:\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}BEGIN GRIDGEO_XMIN = -180.;GEO_NX = 361 ;GEO_DX = 1.;GEO_YMIN = 0.;GEO_NY = 91 ;GEO_DY = 1.;CLON = -65.;CLAT = 45.;CROT = 0.;END GRID\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe first six parameters define the geographical grid of the input files. More specifically the left grid boundary is at $180^\circ$\,W (GEO\_XMIN), the number of grid points in the zonal (west-to-east) direction is 361 (GEO\_NX) andthe grid resolution in zonal direction is $1^\circ$\,longitude (GEO\_DX). Analogously, the parameters of thegrid in meridional (south-to-north) direction are given: Lowest latitude $0^\circ$\,N (GEO\_YMIN), number of gridpoints 91 (GEO\_NY) and grid resolution $1^\circ$\,latitude (GEO\_DY). The rotation itself is described bythe last three entries (CLON, CLAT and CROT), which have the exactly same meaning as given in section~4.4.2\\\noindentNote again, that the transformation of a scalar quantity is considerably easier than the transformation of a vectorial quantity. In the latter case, the specific transformationof the vectorial components must be correctly handled. The transformation algorithm for a scalar quantity is basedupon the transformation rules given in Appendix~9.1 (Fortran subroutines {\em lmtolms} and {\em phtophs}). Essentially, thesteps are the reverse of the ones presented in section~4.4.2.The rotated (quasi-cartesian) latitude/longitude corresponding to a grid point in the geographical co-ordinate system is obtained in the following way. Firstly, the geographical latitude/longitude $\phi_{geo},\lambda_{geo}$ is transformed into\begin{eqnarray*}\lambda'_{rot} & = & lmtolms(\phi_{geo},\lambda_{geo},90-\phi_{cen},\lambda_{cen}-180) \\[0.2cm]\phi'_{rot} & = & phtophs(\phi_{geo},\lambda_{geo},90-\phi_{cen},\lambda_{cen}-180))\end{eqnarray*}\vspace{0.3cm}\noindentwhere the centre of the PV anomaly (the centre of the quasi-cartesian co-ordinate system in geographicallatitude/longitude co-ordinates) is given by $\phi_{cen}$ and $\lambda_{cen}$ (CLAT and CLON in theparameter file, see above).These twovalues are then, in a second rotation, transformed into rotated latitude and longitude:\begin{eqnarray*}\lambda_{rot} & = & 90+lmtolms(\phi'_{rot},\lambda'_{rot}-90,90+\alpha,-180) \\[0.2cm]\phi_{rot} & = & phtophs(\phi'_{rot},\lambda'_{rot}-90,90+\alpha,-180)\end{eqnarray*}\vspace{0.3cm}\noindentwhere $\alpha$ is the rotation angle given in the parameter file (CROT, see below). With the correspondence$(\lambda_{geo},\phi_{geo}) \leftrightarrow (\lambda_{rot},\phi_{rot})$ it is straightforward to performthe transformation of a scalar field. In the program package this is done by means of linear interpolation.\\\noindentThe fields which are written to GEO\_20060116\_18 are given in the following table:\\\begin{center}\begin{tabular}{|l|l|l|}\hlineU & Zonal velocity ($m/s$) & GEO\_20060116\_18 \\V & Meridional velocity ($m/s$) & GEO\_20060116\_18 \\T & Temperature ($^\circ C$) & GEO\_20060116\_18 \\P & Pressure ($hPa$) & GEO\_20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.5cm}\begin{figure}[t]\vspace{-3cm}\begin{center}\begin{minipage}[t]{16cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{weight1.eps}\end{minipage}\\[-4.2cm]\caption{\it Weighting function (in color) for the insertion of the modified fields into the originalP file. Additionally, the distance from the boundary of insertion region is plotted as contour lines (positiveinside the region, negative outside region). The zero contour line of the distance corresponds to theboundary of the insertion domain.}\label{comparep}\end{center}\end{figure}\subsubsection{Transformation from height to hybrid ECMWF co-ordinates [post3]}\begin{figure}[t]\vspace{-1cm}\begin{center}\begin{minipage}[t]{8.2cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{inp_tt_k38.eps}\end{minipage}\hspace{-0.7cm}\begin{minipage}[t]{8.2cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{out_tt_k38.eps}\end{minipage}\\[-2.8cm]\begin{minipage}[t]{8.2cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{inp_uv_k38.eps}\end{minipage}\hspace{-0.7cm}\begin{minipage}[t]{8.2cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{out_uv_k38.eps}\end{minipage}\\[-1.5cm]\caption{\it Comparison of original (with PV streamer, left) and modified (without PV streamer, right)temperature (top panels) and velocity/wind vectors bottom panels) at model level 38 of the ECMWF grid.}\label{comparep2}\end{center}\end{figure}\noindentThe vertical co-ordinate in the back-rotated field is still geometrical height, whereas the inputfields are given on the hybrid ECMWF grid. In this step the transformation to the hybrid vertical co-ordinate is performed. The call is:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh post3\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe transformation is based upon a cubic spline interpolation. The fields which are overwrittenin the P20060116\_18 file are:\\\begin{center}\begin{tabular}{|l|l|l|}\hlineU & Velocity component in zonal direction ($m/s$) & P20060115\_18 \\V & Velocity in meridional direction ($m/s$) & P20060115\_18 \\T & Temperature ($^\circ C$) & P20060115\_18 \\PS & Surface pressure ($hPa$) & P20060115\_18 \\\hline\end{tabular}\end{center}\vspace{0.3cm}\noindentAn impression of the modified flow field is given in Fig.\,\ref{comparep2}.\subsubsection{Calculating secondary fields [post4]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{inp_pv.th_45n.eps}\end{minipage}\hspace{0cm}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{out_pv.th_45n.eps}\end{minipage}\\[-1.5cm]\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{inp_pv_350hPa.eps}\end{minipage}\hspace{0cm}\begin{minipage}[t]{7.8cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{out_pv_350hPa.eps}\end{minipage}\\[-1.5cm]\caption{\it Comparison of original (with PV streamer, left) and modified (without PV streamer, right)potential temperature and PV in a west/east cross section along the $45^\circ$\,N latitude circle (top panels)and PV at 350\,hPa (bottom panels)}\label{compares}\end{center}\end{figure}In this last step, Ertel's PV and potential temperature are calculated on the ECMWF grid. This allowsto directly check whether the PV anomaly was removed and to investigate how the corresponding potential temperature ischanged in the absence of the PV anomaly. The call to this step is:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh post4\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe program creates the S file and writes the following two fields onto it:\\[-0.3cm]\begin{center}\begin{tabular}{|l|l|l|}\hlineTH & Potential temperature ($K$) & S20060116\_18 \\PV & Ertel's PV ($pvu$) & S20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.3cm}\noindentFigure~\ref{compares} shows a direct comparison of the input and of the output Ertel-PV and potential temperature.It can clearly be seen that the stratospheric PV streamer is essentially removed from the outputfile. Moreover, the potential temperature is considerably changed. Whereas in the presence of thePV streamer the isolines of potential temperature are pulled upwards, they are much more horizontallyaligned in its absence. This "vacuum cleaner" effect of upper-level PV structures is well documentedand predicted by theoretical considerations (see also Fig.\,2 in section~1).% ----------------------------------------------------------------------------------------------% PV Inversion for Idealised Cases% ----------------------------------------------------------------------------------------------\newpage\section{Diagnostic Tools}\subsection{A consistency check for the boundary condition [diag1]}The problem posed by the inversion equations constitutes a von Neumann boundary value problem.It has only a solution if some additional conditions are fulfilled between the interior PV distribution and the values of potential temperature on the upper and lower boundaries and the values of horizontal wind components on the lateral sides of the inversion domain. What follows is adetailed description of these additional requirements. The discussion very closely follows the one givenin Fehlmann (1997).\\\noindentTo facilitate the derivation, let's define a new vertical co-ordinate such theta the quasi-geostrophic PV q can be expressed as the divergence of a vector field $\vec{E}$. Let\\[-0.2cm]\[\eta(z) = - \frac{p_0(z)}{g f^2} \quad \quad \mbox{and} \quad \quad\Delta_h = \frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2}\]\vspace{0.3cm}\noindentwhere $p_o(z)$ is the reference profile of pressure, $f$ is the Coriolis parameter and $g$ is the Earth's gravity. Note that $\eta$ is a scaled pressure co-ordinate. If we use the hydrostatic assumption $\partial{\eta}/{\partial z} = \rho_0/f^2$, the following expression for the quasi-geostrophic PV q results:\[q = \Delta_h\psi + \frac{\partial}{\partial \eta} ( \frac{\rho_0^2}{f^2 N_0^2}\cdot \frac{\partial \psi}{\partial \eta} )\]\vspace{0.3cm}\noindentHere, $\rho_o(z)$ and $N_o^2(z)$ are the reference profiles of density and squared Brunt-Vais\"al\"a frequency,respectively, and $\psi$ is the streamfunction. Hence, q is now expressed as the divergence of a vector field ${\vec E}$, and Gauss' theorem can beapplied:\[\int_G q(x,y,\eta) dx dy d\eta = \int_{\partial G} \vec{E}(x,y,\eta) \vec{d\sigma} \quad \quad\mbox{with} \quad \quad\vec{E} = ( \frac{\partial \psi}{\partial x}, \frac{\partial \psi}{\partial y},\frac{\rho_0^2}{f^2 N_0^2} \cdot \frac{\partial \psi}{\partial \eta} )\]\vspace{0.3cm}\noindentNote that this integration has to be carried out in the co-ordinate system (x,y,$\eta$). If we now specifythe inversion domain B as a two-dimensional domain in the (x,y)-plane and $[z_a,z_b]$ be the vertical domain, then $G=B \times [z_a,z_b]$ in the Cartesian space. This compatibility condition can betransformed back into the Cartesian co-ordinate system and the integration be split over the boundary ofthe domain G into an integration over the surface, the lid and the lateral boundaries of the domain. It thenfollows that\begin{eqnarray*}\int_G \rho_0(z) q(x,y,z) dx dy dz & = &\int _{z_a}^{z_b} (\int_{\partial B} \vec{v}(x,y,z) \cdot \vec{dr} ) \rho_0(z) dz\\[4mm]& - & \int_B \frac{\rho_0(z_a) g f \theta^*(x,y,z_a)}{\theta_0(z_a) N_0^2(z_a)} dx dy \\[4mm]& + & \int_B \frac{\rho_0(z_b) g f \theta^*(x,y,z_b)}{\theta_0(z_b) N_0^2(z_b)} dx dy \\\end{eqnarray*}\vspace{0.3cm}\noindentOnly if this condition is fulfilled, does there exist a unique solution (up to a constant). This meansthat not every formulation of the inversion problem needs to have a solution.\\\noindentThe inversion program has to check whether the just discussed integral constraint is fulfilled tosatisfactory accuracy. In order to estimate, how big these inconsistencies really are, we ask for a constant perturbation potential temperature $\theta^*$ which is needed in order to fulfill the integralconstraint. If readily follows from the above discussion that this value is:\begin{eqnarray*}\theta^* & = &( \int_G \rho_0(z) q(x,y,z) dx dy dz -\int _{z_a}^{z_b} (\int_{\partial B} \vec{v}(x,y,z) \cdot \vec{dr} ) \rho_0(z) dz )\\[4mm]& &(- \int_B \frac{\rho_0(z_a) g f}{\theta_0(z_a) N_0^2(z_a)} dx dy+ \int_B \frac{\rho_0(z_b) g f}{\theta_0(z_b) N_0^2(z_b)} dx dy )^{-1}\\\end{eqnarray*}\vspace{0.3cm}\noindentIf this quantity is calculated for the present example, $\theta^*=$-2.8\,K results. This value seemssufficiently small that problem can be solved despite the inconsistency. But note that the problems dueto the ill-posedness of the problem are not well understood (see references in Fehlmann, 1997).\\\noindentThe program handling the consistency check related to the boundary values is:\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh diag1\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe output from this program is given in the following table (the labels A,B,C and D are entered for easierreference in the text):\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}A integ = 1.7558686E+12B denombot = 5.6644076E+11C denomtop = 5.9614413E+09D denom = -5.6047934E+11theta adjustment = -3.132798theta shift @ top = 0.000000 613.2715theta shift @ bot = 0.000000 271.9355\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentThe first line is the integral which includes the quasi-geostrophic PV in the interior, thevelocity integrals on the laterals boundaries and the potential temperature integrals at thelower and upper boundary:\begin{eqnarray*}A & = & \int_G \rho_0(z) q(x,y,z) dx dy dz -\int _{z_a}^{z_b} (\int_{\partial B} \vec{v}(x,y,z) \cdot \vec{dr} ) \rho_0(z) dz\\[6mm]& & + \int_B \frac{\rho_0(z_a) g f \theta^*(x,y,z_a)}{\theta_0(z_a) N_0^2(z_a)} dx dy- \int_B \frac{\rho_0(z_b) g f \theta^*(x,y,z_b)}{\theta_0(z_b) N_0^2(z_b)} dx dy \\\end{eqnarray*}\vspace{0.3cm}\noindentIn exact fulfillment of the integral constraint, this term A would vanish, i.e. $A=0$.The second and third line give the integrals over the upper and lower boundary only:\begin{eqnarray*}B & = & \int_B \frac{\rho_0(z_a) g f \theta^*(x,y,z_a)}{\theta_0(z_a) N_0^2(z_a)} dx dy\\[6mm]C & = & \int_B \frac{\rho_0(z_b) g f \theta^*(x,y,z_b)}{\theta_0(z_b) N_0^2(z_b)} dx dy\\\end{eqnarray*}\vspace{0.3cm}\noindentThe difference between these two lines is the contents of the next line:\begin{eqnarray*}D & = & \int_B \frac{\rho_0(z_a) g f \theta^*(x,y,z_a)}{\theta_0(z_a) N_0^2(z_a)} dx dy- \int_B \frac{\rho_0(z_b) g f \theta^*(x,y,z_b)}{\theta_0(z_b) N_0^2(z_b)} dx dy\\\end{eqnarray*}\noindentNote that this term D corresponds to the last two terms in expression~A.With these expressions an estimate can be made for the correction which would eliminate the inconsistencyof the boundary conditions with respect to the interior distribution of quasi-geostrophic PV. This adjustmentof potential temperature is the next line\begin{eqnarray*}\theta^* & = & A / D\end{eqnarray*}\vspace{0.3cm}\noindentand corresponds with the aforementioned expression for $\theta^*$.Finally, in the last two lines the shift in potential temperature at the upper and at thelower boundary is given, together with the mean potential temperatures at these two boundaries.At the moment, no shift (value 0 in the output lines) is performed, i.e. the inconsistency in the boundary conditionsis not "solved".\subsection{Convergence of the quasi-geostrophic inversion [diag2]}The key numerical algorithm is the inversion of the quasi-geostrophic PV equation (see section~4.5.3).It relates the PV to the streamfunction by\\[-0.3cm]\[q_a = \frac{\partial^2\psi}{\partial x^2} + \frac{\partial^2\psi}{\partial y^2} +\frac{f^2}{\rho_0} \cdot \frac{\partial}{\partial z} ( \frac{\rho_0}{N_0^2}\cdot \frac{\partial \psi}{\partial z}\]\vspace{0.3cm}\noindentwith the boundary conditions of potential temperature at the lower and upper lid, and of horizontal windcomponents at the lateral sides of the inversion domain:\\[-0.3cm]\[g \cdot \frac{\theta^*}{\theta_0} = f \cdot \frac{\partial \psi}{\partial z}\quad \quadu = -\frac{\partial \psi}{\partial y}\quad \quadv = \frac{\partial \psi}{\partial x}\]\begin{figure}[t]\begin{center}\begin{minipage}[t]{8.3cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{qgpv_k35_calc.eps}\end{minipage}\hspace{-1cm}\begin{minipage}[t]{8.3cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{qgpv_k35_spec.eps}\end{minipage}\\\caption{\it Comparison of calculated (left) and pre-described (right) quasi-geostrophic PV. }\label{compqg}\end{center}\end{figure}\vspace{0.3cm}\noindentThe numerical solution by means of the successive over-relaxation (SOR) techniquethen completely determines the perturbations of potential temperature and of horizontal wind. These meteorological fields can be expressedin the following way by the streamfunction (see also section~2):\begin{eqnarray*}\theta^* & = & \frac{f}{g} \cdot \theta_0 \cdot \frac{\partial \psi}{\partial z}\\u & = & - \frac{\partial \psi}{\partial y}\\v & = & \frac{\partial \psi}{\partial x}\\\end{eqnarray*}\vspace{0.3cm}\noindentThis allows a simple test whether the inversion of the quasi-geostrophic equation was successful. Indeed, thequasi-geostrophic PV can be calculated from the perturbation fields:\[q_c = \frac{\partial^2\psi}{\partial x^2} + \frac{\partial^2\psi}{\partial y^2} +\frac{f^2}{\rho_0} \cdot \frac{\partial}{\partial z} ( \frac{\rho_0}{N_0^2}\cdot \frac{\partial \psi}{\partial z})\]\vspace{0.3cm}\noindentIf the inversion was successful, this calculated quasi-geostrophic PV ($q_c$) must coincide with thepre-described PV ($q_a$). For the present case study, the validation is shown in Fig.\,\ref{compqg} for the first stepof the iteration. The two panels show the calculated and the pre-described PV, respectively, and it becomesimmediately clear that a reasonable degree of convergence was reached.\\\noindentThe calculation of the quasi-geostrophic PV is accomplished with the call\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}inversion.sh diag2 ANO\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentwhere the second argument (ANO) specifies that the ANO\_20060116\_18 file is taken for thecalculation. It is implictely assumed that the reference file is available on the corresponding REF file. The output of the calculation is then written to the same ANO\_20060116\_18 file,with the name QGPV\_DIAG. Hence the table of modified fields and files is:\begin{center}\begin{tabular}{|l|l|l|}\hlineQGPV\_DIAG & Calculated quasi-geostrophic PV ($1/s$) & ANO\_20060116\_18 \\\hline\end{tabular}\end{center}\vspace{0.3cm}\subsection{Difference between two files [diag3]}\begin{figure}[t]\begin{center}\begin{minipage}[t]{16cm}\vspace{-1cm}\ForceWidth{1.0\textwidth}\BoxedEPSF{difference.eps}\end{minipage}\\[-0.5cm]\caption{\it Difference between the ORG and the MOD file in a vertical cross section. In color, the difference of the meridionalwind velocity is shown. The difference of potential temperature is given by the thin lines (black:positive,blue:negative). The bold black line is the 2.5 isoline of the difference of Ertel's PV. }\label{diff}\end{center}\end{figure}The impact of a PV anomaly is most easily determined if the meteorological fields (temperature, velocity,pressure,...) in the presence of the anomaly is subtracted from the corresponding fields in the absenceof the anomaly. The change in the meteorological fields can then be attributed to the PV anomaly. In orderto facilitate this with/without comparison, a diagnostic tool is provide which calculates the difference.For instance, the call to\begin{center}\begin{minipage}[t]{11cm}\begin{verbatim}inversion.sh diag3 ORG MOD\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindenttakes the ORG and MOD file in the run directory and calculates the difference of all fields whichare available on both input files. The difference fields are then written to a new file with prefix DIA.An example is shown in Fig.\,\ref{diff}.% ---------------------------------------------------------------------------------------------% Final Remarks% ---------------------------------------------------------------------------------------------\newpage\section{Final Remarks and Outlook}Several additional extensions are possible for the PV inversion tool introduced in this study. Most of them will attract a lot of interest in the research and education community. Some extensions which are and will be undertaken recently in our institute are:\begin{itemize}\item [a] The PV inversion is not only of interest in real-case studies, as was described in this work. Considerable insight can also be gained by looking at highly idealised experiments. Such experiments enforce the existence of a tool which allows to set set up them. In the course of this diploma thesis, such a tool was developed. However, it was considered to be preferable to limitthe thesis's documentation itself to the real-case experiments.\\\item [b] Removing and adding, or more generally modifying the initial PV distribution, is particularly interesting if the modified state of the atmosphere is used as the input -initialand boundary values- for a regional weather prediction model. This kind of experiments allows toassess in a quantitative way how the PV field influences the future weather development. In parallel to this thesis a program package has been developed at the Institute for Atmospheric and Climate Science at ETH Zurich (IACETH) which allows to transformthe (modified) P files of the PV inversion directly into the input and boundary files for theClimate HRM model. It is the aim that some case studies will be undertaken in this way by adiploma student at our institute.\\\item [c] From the quasi-geostrophic omega equation it is well known that PV structures are able toenforce vertical motions. These are particularly interesting because vertical motion leads tocondensation or convective instability, if the vertical temperature and humidity profile are suitable. Therefore,it would be of great interest to see how the modified PV distribution is associated with differentvertical motions. Technically this means that an additional equation, the aforementionedquasi-geostrophic omega equation, has to be solved. In the coming summer semester, a student with focus on scientificprogramming will attack this problem.\\\item [d] Teaching atmospheric dynamics at the graduate level involves several challenges. Oneparticular challenge is associated with the abstract concept of potential vorticity. An easy-to-usePV inversion tool might be of great relieve to the teacher since he can easily illustrate andapply the concepts to real and idealised cases. It is quite certain that such a visualisation helpwould be much appreciated by graduate students in atmospheric dynamics. It is one aim of thedynamic's group at {\it IAC}ETHto improve teaching in this respect, while keeping the mathematical and physicallevel of the taught contents.\end{itemize}\newpage\section{Acknowledgment}There are many persons which need to be mentioned in this acknowledgment. Perhaps, most crucially isa heartily thanks to Rene Fehlmann who initially developed the inversion tool. I had the joy to start my atmospheric research under Rene's supervision, and his enthusiasm for mathematics, numerics and atmospherealways was and still is very inspiring for me. \\\noindentRecently I read that success in science cannot be attributed solely to one's own intelligence an"superiority". And with my long experience in science, I fully agree with that statement. Success needsluck, and last but not least it needs excellent teachers, supervisors and colleagues. I had the great pleasureto work together and get help from excellent scientists and teachers: Christoph Sch\"ar, Heini Wernli and Huw Davies. I appreciated very much their scientific qualities, but probably still more their warmth andfriendliness as colleagues.\\\noindentMany research colleagues were indirectly important in the development of this PV inversion tool. Conny Schwierz, Olivia Martius, Mischa Croci-Maspoli, Sarah Kew. Certainly, thanks should also go to Linda Schlemmer whoaccepted a diploma thesis based on this tool, and is now testing all aspects of it.\\\noindentFinally, this work was done in the frame of the postgraduate course in Computer Science at the Fernfachhochschule Schweiz. Thanks goes to all teachers, and in particular to Lars Kruse who accepted to supervise this diploma thesis and discussed with me the different steps. Although we had somedifferent views what should be included into this thesis ("Why do you want to send this part to the appendix? This is a diploma thesis,...") I enjoyed working with him, particularly because of his interest in the atmospheric sciences.\newpage\section{References}\noindent{\bf [1]} Acheson, D.\,J., 1990:Elementary Fluid Dynamics.{\sl Oxford Applied Mathematics and Computing Science Series,}, Oxford UP, 395pp.\\\noindent{\bf [2]} Appenzeller, C., H.~C.~Davies, and W.~A.~Norton, 1996:Fragmentation of stratospheric intrusions.{\sl J.~Geophys.~Res.,} {\bf 101,} 1435-1456.\\\noindent{\bf [3]} Hoskins, B.\,J., M.\,E.\,McIntyre, and A.\,W.\,Robertson, 1985:On the use and significance of isentropic potential vorticity maps. Quart.\,J.\,Roy.\,Meteor.\,Soc.,{\bf 111}, 877-946.\\\noindent{\bf [4]} Bluestein,\,H.\,B., 1993:Synoptic-Dynamic Meteorology in Midlatitudes. Volume II: Observations and Theory of Weather Systems, Oxford University Press, {594 pp}.\\\noindent{\bf [5]} Charney, J.\,B., 1993:On the scale of atmospheric motions. Geofysisk.\,Publ.,{\bf 17}, No.\,2.\\\noindent{\bf [6]} Davis, C.\,A., 1992:Piecewise potential vorticity inversion. J.\,Atmos.\,Sci., {\bf 49}, 1397-1411.\\\noindent{\bf [7]} Davis, C.\,A., and K.\,A.\,Emanuel, 1992:Potential vorticity diagnostic of cyclogenesis. Mon.\,Wea.\,Rev., {\bf 119}, 1929-1953.\\\noindent{\bf [8]} Ertel, H., 1942:Ein neuer hydrodynamischer Wirbelsatz. Meteor.\,Z., {\bf 59}, 277-281.\\\noindent{\bf [9]} Fehlmann, R., 1997:Dynamics of seminal PV elements.PhD thesis No. 12229, ETH Z\"urich, 143 pp.\\\noindent{\bf [10]} Fehlmann, R. and H.\,C.\,Davies, 1997:Misforecasts of synoptic systems: Diagnosis via PV retrodiction. Mon.\,Wea.\,Rev., {\bf 125}, 2247-2264.\\\noindent{\bf [11]} Holton, J.\,R., 1992:An Introduction to Dynamic Meteorology. Third Edition.Academic Press, San Diego, California, 511pp.\\\noindent{\bf [12]} Kleinschmidt, E., 1950:\"Uber Aufbau und Entstehung von Zyklonen. Teil 1. Meteor.\,Rundsch., {\bf 3}, 1-6.\\\noindent{\bf [13]} Martius, O., E.\,Zenklusen, C. Schwierz, and H.\,C.\,Davies 2006:Episodes of alpine heavy precipitation with an overlying elongated stratospheric intrusion: a climatology. Intl.\,J.\,Climatology., {\bf Vol. 96, Issue 9}, 1149-1164.\\\noindent{\bf [14]} McIntyre, M., 1997:GEFD (Geophysical and Environmental Fluid Dynamics) Summer School, DAMPTP University of Cambridge.\\\noindent{\bf [15]} Lynch, P., 2006:The Emergence of Numerical Weather Prediction. Richardson's Dream.Cambridge UP, Cambridge, UK. 279pp.\\\noindent{\bf [16]} Nebeker, F., 1995:Calculating the Weather. Meteorology in the 20th Century..Academic Press, San Diego, California, 255pp.\\\noindent{\bf [17]} Press, W.\,H., Flannery, B.\,P., Teukolsky, S.\,A., and Vetterling, W.\,T., 1992:Numerical Recipes in FORTRAN: The Art of Scientific Computing.Cambridge University Press, Cambridge, UK, 1447pp.\\\noindent{\bf [18]} Sprenger, M.~and H.~Wernli, 2003:A northern hemispheric climatology of cross-tropopause exchange for the ERA15time period (1979-1993).{\sl J.~Geophys.~Res.,} {\bf 108}(D12), 8521, doi:10.1029/2002JD002636.\\\noindent{\bf [19]} Stohl, A., P. Bonasoni, P. Cristofanelli, W. Collins, J. Feichter,A. Frank, C. Forster, E. Gerasopoulos, H. G\"uggeler, P. James,T. Kentarchos, H. Kromp-Kolb, B. Kr\"uger, C. Land, J. Meloen,A. Papayannis, A. Priller, P. Seibert, M. Sprenger, G. J. Roelofs,H. E. Scheel, C. Schnabel, P. Siegmund, L. Tobler, T. Trickl,H. Wernli, V. Wirth, P. Zanis, and C. Zerefos: 2003.Stratosphere-troposphere exchange: A review, and what we have learned from STACCATO.J.\,Geophys.\,Res.,{\bf Vol. 108}, No. D12, 8516, doi:10.1029/2002JD002490.\\\noindent{\bf [20]} Wallace, J.\,M. and P.\,V.\,Hobbs, R., 1977:Atmospheric Science. An Introductory Survey.Academic Press, San Diego, California, 467pp.\\\newpage\section{Appendix}\subsection{Scalar co-ordinate transformation}Four real function are needed for the transformation between the geographical latitude/-longitude gridused by ECMWF and the quasi-cartesian grid used by the PV inversion. Physically the new quasi-cartesianco-ordinate system is obtained by introducing a new latitude/longitude grid, but now the two co-ordinatesbeing defined relative to a rotated north pole. Therefore, the new longitude and latitude are referred to as rotated co-ordinates. The position (in geographical latitude and longitude) of the new north pole is given as parameters POLPHI and POLLAM. Then, the functions\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}LAM = REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)PHI = REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentrelate the rotated latitude (PHIS) and longitude (LAMS) to corresponding latitude (PHI) andlongitude (LAM) in the geographical system. Correspondingly, the following two functions givethe reverse transformation, i.e. to every position in geographical latitude/longitude a rotatedpair of co-ordinates is attributed. Again, the pole position (in the geographical grid) must bepassed as parameters (POLPHI and POLLAT).\\[-0.3cm]\begin{center}\begin{minipage}[t]{13cm}\begin{verbatim}LAMS = REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)PHIS = REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)\end{verbatim}\end{minipage}\end{center}\vspace{0.3cm}\noindentHere, the geographical co-ordinates (PHI, LAM) are transformed into rotated co-ordinates (PHIS, LAMS).If the corresponding pair of coordinates are given, any scalar field can easily be transformed. The followingFortran functions are taken from the source code from the numerical weather prediction model of the German/Swiss weather service.\begin{small}\begin{verbatim}C -------------------------------------------------------------------------REAL FUNCTION LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)C -------------------------------------------------------------------------CC**** LMSTOLM - FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUERC**** EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)C**** IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HATC**** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** AUFRUF : LAM = LMSTOLM (PHIS, LAMS, POLPHI, POLLAM)C** ENTRIES : KEINEC** ZWECK : BERECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE FUERC** EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)C** IM ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HATC** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** VERSIONS-C** DATUM : 03.05.90C**C** EXTERNALS: KEINEC** EINGABE-C** PARAMETER: PHIS REAL GEOGR. BREITE DES PUNKTES IM ROT.SYS.C** LAMS REAL GEOGR. LAENGE DES PUNKTES IM ROT.SYS.C** POLPHI REAL WAHRE GEOGR. BREITE DES NORDPOLSC** POLLAM REAL WAHRE GEOGR. LAENGE DES NORDPOLSC** AUSGABE-C** PARAMETER: WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTIONC** ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)C**C** COMMON-C** BLOECKE : KEINEC**C** FEHLERBE-C** HANDLUNG : KEINEC** VERFASSER: D.MAJEWSKIREAL LAMS,PHIS,POLPHI,POLLAMDATA ZRPI18 , ZPIR18 / 57.2957795 , 0.0174532925 /ZSINPOL = SIN(ZPIR18*POLPHI)ZCOSPOL = COS(ZPIR18*POLPHI)ZLAMPOL = ZPIR18*POLLAMZPHIS = ZPIR18*PHISZLAMS = LAMSIF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0ZLAMS = ZPIR18*ZLAMSZARG1 = SIN(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS) +1 ZCOSPOL* SIN(ZPHIS)) -2 COS(ZLAMPOL)* SIN(ZLAMS)*COS(ZPHIS)ZARG2 = COS(ZLAMPOL)*(- ZSINPOL*COS(ZLAMS)*COS(ZPHIS) +1 ZCOSPOL* SIN(ZPHIS)) +2 SIN(ZLAMPOL)* SIN(ZLAMS)*COS(ZPHIS)IF (ABS(ZARG2).LT.1.E-30) THENIF (ABS(ZARG1).LT.1.E-30) THENLMSTOLM = 0.0ELSEIF (ZARG1.GT.0.) THENLMSTOLAM = 90.0ELSELMSTOLAM = -90.0ENDIFELSELMSTOLM = ZRPI18*ATAN2(ZARG1,ZARG2)ENDIFRETURNENDC -------------------------------------------------------------------------REAL FUNCTION PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)C -------------------------------------------------------------------------CC**** PHSTOPH - FC:BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUERC**** EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IMC**** ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HATC**** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** AUFRUF : PHI = PHSTOPH (PHIS, LAMS, POLPHI, POLLAM)C** ENTRIES : KEINEC** ZWECK : BERECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE FUERC** EINEN PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IMC** ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HATC** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** VERSIONS-C** DATUM : 03.05.90C**C** EXTERNALS: KEINEC** EINGABE-C** PARAMETER: PHIS REAL GEOGR. BREITE DES PUNKTES IM ROT.SYS.C** LAMS REAL GEOGR. LAENGE DES PUNKTES IM ROT.SYS.C** POLPHI REAL WAHRE GEOGR. BREITE DES NORDPOLSC** POLLAM REAL WAHRE GEOGR. LAENGE DES NORDPOLSC** AUSGABE-C** PARAMETER: WAHRE GEOGRAPHISCHE BREITE ALS WERT DER FUNKTIONC** ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)C**C** COMMON-C** BLOECKE : KEINEC**C** FEHLERBE-C** HANDLUNG : KEINEC** VERFASSER: D.MAJEWSKIREAL LAMS,PHIS,POLPHI,POLLAMDATA ZRPI18 , ZPIR18 / 57.2957795 , 0.0174532925 /SINPOL = SIN(ZPIR18*POLPHI)COSPOL = COS(ZPIR18*POLPHI)ZPHIS = ZPIR18*PHISZLAMS = LAMSIF(ZLAMS.GT.180.0) ZLAMS = ZLAMS - 360.0ZLAMS = ZPIR18*ZLAMSARG = COSPOL*COS(ZPHIS)*COS(ZLAMS) + SINPOL*SIN(ZPHIS)PHSTOPH = ZRPI18*ASIN(ARG)RETURNENDC -------------------------------------------------------------------------REAL FUNCTION LMTOLMS (PHI, LAM, POLPHI, POLLAM)C -------------------------------------------------------------------------CC%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%CC**** LMTOLMS - FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAMC**** AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)C**** IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HATC**** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** AUFRUF : LAM = LMTOLMS (PHI, LAM, POLPHI, POLLAM)C** ENTRIES : KEINEC** ZWECK : UMRECHNUNG DER WAHREN GEOGRAPHISCHEN LAENGE LAM AUFC** EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IMC** ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HATC** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** VERSIONS-C** DATUM : 03.05.90C**C** EXTERNALS: KEINEC** EINGABE-C** PARAMETER: PHI REAL BREITE DES PUNKTES IM GEOGR. SYSTEMC** LAM REAL LAENGE DES PUNKTES IM GEOGR. SYSTEMC** POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMSC** POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMSC** AUSGABE-C** PARAMETER: WAHRE GEOGRAPHISCHE LAENGE ALS WERT DER FUNKTIONC** ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)C**C** COMMON-C** BLOECKE : KEINEC**C** FEHLERBE-C** HANDLUNG : KEINEC** VERFASSER: G. DE MORSIERREAL LAM,PHI,POLPHI,POLLAMDATA ZRPI18 , ZPIR18 / 57.2957795 , 0.0174532925 /ZSINPOL = SIN(ZPIR18*POLPHI)ZCOSPOL = COS(ZPIR18*POLPHI)ZLAMPOL = ZPIR18*POLLAMZPHI = ZPIR18*PHIZLAM = LAMIF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0ZLAM = ZPIR18*ZLAMZARG1 = - SIN(ZLAM-ZLAMPOL)*COS(ZPHI)ZARG2 = - ZSINPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL)+ZCOSPOL*SIN(ZPHI)IF (ABS(ZARG2).LT.1.E-30) THENIF (ABS(ZARG1).LT.1.E-30) THENLMTOLMS = 0.0ELSEIF (ZARG1.GT.0.) THENLMTOLMS = 90.0ELSELMTOLMS = -90.0ENDIFELSELMTOLMS = ZRPI18*ATAN2(ZARG1,ZARG2)ENDIFRETURNENDC -------------------------------------------------------------------------REAL FUNCTION PHTOPHS (PHI, LAM, POLPHI, POLLAM)C -------------------------------------------------------------------------CC%Z% Modul %M%, V%I% vom %G%, extrahiert am %H%CC**** PHTOPHS - FC:UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHIC**** AUF EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS)C**** IM ROTIERTEN SYSTEM. DER NORDPOL DES SYSTEMS HATC**** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** AUFRUF : PHI = PHTOPHS (PHI, LAM, POLPHI, POLLAM)C** ENTRIES : KEINEC** ZWECK : UMRECHNUNG DER WAHREN GEOGRAPHISCHEN BREITE PHI AUFC** EINEM PUNKT MIT DEN KOORDINATEN (PHIS, LAMS) IMC** ROTIERTEN SYSTEM. DER NORDPOL DIESES SYSTEMS HATC** DIE WAHREN KOORDINATEN (POLPHI, POLLAM)C** VERSIONS-C** DATUM : 03.05.90C**C** EXTERNALS: KEINEC** EINGABE-C** PARAMETER: PHI REAL BREITE DES PUNKTES IM GEOGR. SYSTEMC** LAM REAL LAENGE DES PUNKTES IM GEOGR. SYSTEMC** POLPHI REAL GEOGR.BREITE DES N-POLS DES ROT. SYSTEMSC** POLLAM REAL GEOGR.LAENGE DES N-POLS DES ROT. SYSTEMSC** AUSGABE-C** PARAMETER: ROTIERTE BREITE PHIS ALS WERT DER FUNKTIONC** ALLE WINKEL IN GRAD (NORDEN>0, OSTEN>0)C**C** COMMON-C** BLOECKE : KEINEC**C** FEHLERBE-C** HANDLUNG : KEINEC** VERFASSER: G. DE MORSIERREAL LAM,PHI,POLPHI,POLLAMDATA ZRPI18 , ZPIR18 / 57.2957795 , 0.0174532925 /ZSINPOL = SIN(ZPIR18*POLPHI)ZCOSPOL = COS(ZPIR18*POLPHI)ZLAMPOL = ZPIR18*POLLAMZPHI = ZPIR18*PHIZLAM = LAMIF(ZLAM.GT.180.0) ZLAM = ZLAM - 360.0ZLAM = ZPIR18*ZLAMZARG = ZCOSPOL*COS(ZPHI)*COS(ZLAM-ZLAMPOL) + ZSINPOL*SIN(ZPHI)PHTOPHS = ZRPI18*ASIN(ZARG)RETURNEND\end{verbatim}\end{small}\newpage\subsection{Controlling Linux Shell Script}In this appendix the controlling Linux Shell script of the PV inversion is reproduced. This scriptoffers a user-friendly interface to the inversion. It is essentially split into fivedifferent section: (1) installation and parameter settings, (2) preparatory steps, (3)iterative solution of the PV inversion problem, (4) post-processing, and (5) diagnostictools.\\\begin{small}\begin{verbatim}#!/bin/csh# Master Linux script for PV inversion# Michael Sprenger / Winter 2006,2007# -------------------------------------------------------------------# Set some variables and paths# -------------------------------------------------------------------# Handling of input parametersset step="help"if ( $#argv == 1 ) thenset step=$1endifif ( $#argv == 2 ) thenset step=$1set file1=$2endifif ( $#argv == 3 ) thenset step=$1set file1=$2set file2=$3endif# Set base directory for programmesset bdir=/home/sprenger/PV_Inversion_Tool/real/# Set name of the parameter file, the coastline file and the sample filesset parafile="${PWD}/inversion.param"set coastfile="${bdir}/prep/coastline.dat"set sampledir="/net/rossby/lhome/sprenger/PV_Inversion_Tool/real/inp/"# Extract parameters from parameter fileset progex=${bdir}/inversion.perlset date=`${progex} ${parafile} date | awk '{ print $2}'`set nofiter=`${progex} ${parafile} n_of_iteration | awk '{ print $2}'`set save=`${progex} ${parafile} save_iteration | awk '{ print $2}'`set idir=`${progex} ${parafile} inp_dir | awk '{ print $2}'`set rdir=`${progex} ${parafile} run_dir | awk '{ print $2}'`set odir=`${progex} ${parafile} out_dir | awk '{ print $2}'`# ---------------------------------------------------------------------------# Installation, help and sample# ---------------------------------------------------------------------------# Create the needed directoriesif ( ${step} == "inst" ) thenif ( ! -d ${idir} ) mkdir ${idir}if ( ! -d ${rdir} ) mkdir ${rdir}if ( ! -d ${odir} ) mkdir ${odir}endif# Create the needed directoriesif ( ${step} == "help" ) thenechoecho "Installation"echo " inst: Creates the input, run and output directory"echoecho "Sample case study"echo " sample: Copy all files for a sample case study"echoecho "Preparing input files [prep]"echo " prep0: Calculate S file with PV and TH"echo " prep1: Interpolate onto height levels"echo " prep2: Rotate into local cartesian co-ordinate system"echo " prep3: Add TH,PV,NSQ and RHO to the data file"echo " prep4: Define modified and anomaly PV field and boundary values"echo " prep5: Reduce the domain size and split the input files"echo " prep6: Add the reference profile"echo " prep7: Add coastlines to REF file"echo " prep8: Move the files to the run directory"echoecho "Perform the PV inversion [pvin]"echo " pvin1: Add NSQ, TH, RHO, and PV"echo " pvin2: Change Ertel's PV anomaly into one of quasi-geostrophic PV"echo " pvin3: Inversion of quasi-geostrophic PV anomaly"echo " pvin4: Subtract anomaly from MOD file"echo " pvin5: Keep iterative steps if save flag is set"echoecho "Postprocessing [post]"echo " post1: Copy needed files from input and run directory"echo " post2: Rotate from quasi-cartesian co-ordinate frame to lat/lon system"echo " post3: Bring modified fields back to P file"echo " post4: Calculate S file with PV and TH"echo " post5: Make clean"echoecho "Diagnostic Tools"echo " diag1: Check the consistency of the boundary conditions"echo " diag2: Calculate the quasi-geostrophic PV"echo " diag3: Get the difference between two files"'echoendif# Copy sample files (if specified)if ( ${step} == "sample" ) then\cp ${sampledir}/P20060116_18 ${idir}\cp ${sampledir}/ml_cst ${idir}\cp ${sampledir}/Z20060116_18 ${idir}\cp ${sampledir}/pl_cst ${idir}endif# ---------------------------------------------------------------------------# Preparatory steps# ---------------------------------------------------------------------------# Change to data directorycd ${idir}# Step 0: Calculate S file with PV and TH (not in prep mode)if ( ${step} == "prep0" ) then\rm -f S${date}p2s P${date} TH PVendif# Step 1: Interpolate onto height levelsif ( ${step} == "prep1" | ${step} == "prep" ) thenecho "P${date}" >! fort.10echo "Z${date}" >> fort.10echo "H${date}" >> fort.10${bdir}/inversion.perl ${parafile} p2z >> fort.10echo "U U P${date}" >> fort.10echo "V V P${date}" >> fort.10echo "T T P${date}" >> fort.10echo "Q Q P${date}" >> fort.10${bdir}/prep/p2z\mv H${date}_cst zl_cstchangecst H${date} zl_cst#\rm -f fort.10endif# Step 2: Rotate into local cartesian co-ordinate systemif ( ${step} == "prep2" | ${step} == "prep" ) thenecho "H${date}" >! fort.10echo "R${date}" >> fort.10${bdir}/inversion.perl ${parafile} rotate_grid >> fort.10echo "5" >> fort.10echo "ORO" >> fort.10echo "U.V" >> fort.10echo "P" >> fort.10echo "T" >> fort.10echo "Q" >> fort.10${bdir}/prep/rotate_grid\mv R${date}_cst ro_cstchangecst R${date} ro_cst\rm -f fort.10endif# Step 3: Add TH,PV,NSQ and RHO to the data fileif ( ${step} == "prep3" | ${step} == "prep" ) thenecho "TH" >! fort.10echo "R${date}" >> fort.10echo "R${date}" >> fort.10echo "5 " >> fort.10${bdir}/prep/z2secho "PV" >! fort.10echo "R${date}" >> fort.10echo "R${date}" >> fort.10echo "5 " >> fort.10${bdir}/prep/z2secho "NSQ" >! fort.10echo "R${date}" >> fort.10echo "R${date}" >> fort.10echo "5 " >> fort.10${bdir}/prep/z2secho "RHO" >! fort.10echo "R${date}" >> fort.10echo "R${date}" >> fort.10echo "5 " >> fort.10${bdir}/prep/z2s\rm -f fort.10endif# Step 4: Set the modified PV field and boundary valuesif ( ${step} == "prep4" | ${step} == "prep" ) thenecho "R${date}" >! fort.10${bdir}/inversion.perl ${parafile} def_anomaly >> fort.10${bdir}/prep/def_anomaly\rm -f fort.10endif# Step 5: Reduce the domain size and split the input filesif ( ${step} == "prep5" | ${step} == "prep" ) thenecho "PV PV R${date} ORG_${date}" >! fort.10echo "U U R${date} ORG_${date}" >> fort.10echo "V V R${date} ORG_${date}" >> fort.10echo "TH TH R${date} ORG_${date}" >> fort.10echo "Q Q R${date} ORG_${date}" >> fort.10echo "P P R${date} ORG_${date}" >> fort.10echo "T T R${date} ORG_${date}" >> fort.10echo "PV_FILT PV_AIM R${date} MOD_${date}" >> fort.10echo "U U R${date} MOD_${date}" >> fort.10echo "V V R${date} MOD_${date}" >> fort.10echo "Q Q R${date} MOD_${date}" >> fort.10echo "P P R${date} MOD_${date}" >> fort.10echo "T T R${date} MOD_${date}" >> fort.10echo "NSQ NSQ R${date} MOD_${date}" >> fort.10echo "RHO RHO R${date} MOD_${date}" >> fort.10echo "TH TH R${date} MOD_${date}" >> fort.10echo "PV_ANOM PV R${date} ANO_${date}" >> fort.10echo "TH_ANOM TH R${date} ANO_${date}" >> fort.10echo "UU_ANOM U R${date} ANO_${date}" >> fort.10echo "VV_ANOM V R${date} ANO_${date}" >> fort.10echo "ORO ORO R${date} REF_${date}" >> fort.10echo "X X R${date} REF_${date}" >> fort.10echo "Y Y R${date} REF_${date}" >> fort.10echo "LAT LAT R${date} REF_${date}" >> fort.10echo "LON LON R${date} REF_${date}" >> fort.10echo "CORIOL CORIOL R${date} REF_${date}" >> fort.10${bdir}/prep/cutnetcdf\rm -f fort.10endif# Step 6: Add the reference profileif ( ${step} == "prep6" | ${step} == "prep" ) then\rm -f fort.10echo "MOD_${date}" >! fort.10echo "REF_${date}" >> fort.10${bdir}/prep/ref_profile\rm -f fort.10endif# Step 7: Add coastlines to REF fileif ( ${step} == "prep7" | ${step} == "prep" ) then\rm -f fort.10echo \"REF_${date}\" >! fort.10echo \"${coastfile}\" >> fort.10${bdir}/inversion.perl ${parafile} coastline >> fort.10${bdir}/prep/coastline\rm -f fort.10endif# Step 8: Move the files to the run directoryif ( ${step} == "prep8" | ${step} == "prep" ) then\mv MOD_${date} MOD_${date}_cst ${rdir}\mv ORG_${date} ORG_${date}_cst ${rdir}\mv ANO_${date} ANO_${date}_cst ${rdir}\mv REF_${date} REF_${date}_cst ${rdir}\rm -f fort.10endif# ---------------------------------------------------------------------------# Inversion# ---------------------------------------------------------------------------# Change to data directorycd ${rdir}# Start loopset count=0loop:# Step 1: Add NSQ, TH, RHO, and PV to MOD file, take grid from REF fileif ( ${step} == "pvin1" | ${step} == "pvin" ) thenecho "NSQ" >! fort.10echo "MOD_${date}" >> fort.10echo "REF_${date}" >> fort.10echo "5 " >> fort.10${bdir}/pvin/z2secho "RHO" >! fort.10echo "MOD_${date}" >> fort.10echo "REF_${date}" >> fort.10echo "5 " >> fort.10${bdir}/pvin/z2secho "TH" >! fort.10echo "MOD_${date}" >> fort.10echo "REF_${date}" >> fort.10echo "5 " >> fort.10${bdir}/pvin/z2secho "PV" >! fort.10echo "MOD_${date}" >> fort.10echo "REF_${date}" >> fort.10echo "5 " >> fort.10${bdir}/pvin/z2s\rm -f fort.10endif# Step 2: Change Ertel's PV anomaly into an anomaly of quasi-geostrophic PVif ( ${step} == "pvin2" | ${step} == "pvin" ) thenecho "MOD_${date}" >! fort.10echo "REF_${date}" >> fort.10echo "ANO_${date}" >> fort.10${bdir}/pvin/pv_to_qgpv\rm -f fort.10endif# Step 3: Inversion of quasi-geostrophic PV anomaly with Neumann boundaryif ( ${step} == "pvin3" | ${step} == "pvin" ) thenecho "ANO_${date}" >! fort.10echo "REF_${date}" >> fort.10${bdir}/pvin/inv_cart\rm -f fort.10endif# Step 4: Prepare the output of the inversion for next iteration stepif ( ${step} == "pvin4" | ${step} == "pvin" ) then\rm -f fort.10echo "MOD_${date}" >! fort.10echo "ANO_${date}" >> fort.10${bdir}/inversion.perl ${parafile} prep_iteration >> fort.10${bdir}/pvin/prep_iteration\rm -f fort.10endif# Step 5: Keep iterative steps if save flag is setif ( ${step} == "pvin5" | ${step} == "pvin" ) thenif ( "${save}" == "yes" ) thenset pre=''if ( ${count} < 10 ) thenset pre='0'endif\cp MOD_${date} MOD_${date}_${pre}${count}\cp ANO_${date} ANO_${date}_${pre}${count}endifendif# End loop for iterationsif ( ${step} == "pvin" ) then@ count = ${count} + 1if ( ${count} < ${nofiter} ) goto loopendif# ---------------------------------------------------------------------------# Postprocessing# ---------------------------------------------------------------------------# Change to data directorycd ${odir}# Step 1: Copy needed files from input and run directoryif ( ${step} == "post1" | ${step} == "post" ) thenln -sf ${rdir}/MOD_${date} ${rdir}/MOD_${date}_cst .\cp ${idir}/P${date} ${idir}/ml_cst .endif# Step 2: Rotate from quasi-cartesian co-ordinate frame to lat/lon systemif ( ${step} == "post2" | ${step} == "post" ) thenecho "MOD_${date}" >! fort.10echo "GEO_${date}" >> fort.10${bdir}/inversion.perl ${parafile} rotate_lalo >> fort.10echo "3" >> fort.10echo "T" >> fort.10echo "U.V" >> fort.10echo "P" >> fort.10${bdir}/post/rotate_lalo\rm -f fort.10endif# Step 3: Bring modified fields back to P fileif ( ${step} == "post3" | ${step} == "post" ) then\rm -f fort.10echo "P${date}" >! fort.10echo "GEO_${date}" >> fort.10${bdir}/inversion.perl ${parafile} add2p >> fort.10${bdir}/post/add2p\rm -f fort.10endif# Step 4: Calculate S file with PV and THif ( ${step} == "post4" | ${step} == "post" ) then\rm -f S${date}p2s P${date} TH PVendif# Step 5: Make cleanif ( ${step} == "post5" | ${step} == "post" ) then\rm -f MOD_${date} MOD_${date}_cst\rm -f GEO_${date} GEO_${date}_cstendif# ---------------------------------------------------------------------------# Diagnostic Tools# ---------------------------------------------------------------------------# Change to run directorycd ${rdir}# Step 1: Check the consistency of the boundary conditions (diag1)if ( ${step} == "diag1" ) then\rm -f fort.10echo "ANO_${date}" >! fort.10echo "REF_${date}" >> fort.10${bdir}/diag/check_boundcon\rm -f fort.10endif# Step 2: Calculate the quasi-geostrophic PV (diag2 [ORG|MOD|ANO]if ( ${step} == "diag2" ) then\rm -f fort.10echo "${file1}_${date}" >! fort.10echo "REF_${date}" >> fort.10${bdir}/diag/calc_qgpv\rm -f fort.10endif# Step 3: Get difference between two files (diag3 [ORG|MOD|ANO] - [ORG|MOD|ANO])if ( ${step} == "diag3" ) then\rm -f fort.10echo "${file1}_${date}" >! fort.10echo "${file2}_${date}" >> fort.10echo "DIA_${date}" >> fort.10${bdir}/diag/difference\rm -f fort.10endif\end{verbatim}\end{small}\newpage\subsection{Controlling Parameter File}The inversion problem is specified in a parameter file. This file is set as a parameter in thecontrolling Linux Shell script (see Appendix~9.2) and is often the only file which has to be adapted.\begin{small}\begin{verbatim}BEGIN DATADATE = 20060116_18; ! Date for case studyINP_DIR = /lhome/sprenger/PV_Inversion_Tool/real/inp; ! Input directoryRUN_DIR = /lhome/sprenger/PV_Inversion_Tool/real/run; ! Run directoryOUT_DIR = /lhome/sprenger/PV_Inversion_Tool/real/out; ! Output directoryEND DATABEGIN GRIDGEO_XMIN = -180.; ! Geographical grid in zonal directionGEO_NX = 361 ;GEO_DX = 1.;GEO_YMIN = 0.; ! Geographical grid in meridional directionGEO_NY = 91 ;GEO_DY = 1.;GEO_ZMIN = 0.; ! Vertical levels ( ZMIN and DZ in [m] )GEO_NZ = 125 ;GEO_DZ = 200.;ROT_NX = 250 ; ! Rotated grid ( DX and DY in [deg] )ROT_NY = 250 ;ROT_DX = 0.25;ROT_DY = 0.25;CLON = -65.; ! Longitude, latitude [deg] and angle of rotated gridCLAT = 45.;CROT = 0.;END GRIDBEGIN ANOMALYBOX_XMIN = -1200.; ! Box where to apply the digital filterBOX_XMAX = 1200.;BOX_YMIN = -1200.;BOX_YMAX = 1200.;BOX_ZMIN = 2000.;BOX_ZMAX = 10000.;NFILTER = 5 ; ! Number of filter iterations;BOUND_XY = 500.; ! Transition zone for horizontal boundaries ( in [km] )BOUND_Z = 500.; ! Transition zone for vertical boundaries ( in [m] )END ANOMALYBEGIN NUMERICSALPHA = 0.5; ! Adjustment factor after one iteration stepNOFITER = 6; ! Number of "external" iterationsSAVEITER = no; ! Flag whether to save iteration stepsEND NUMERICS\end{verbatim}\end{small}\newpage\subsection{List of Fortran, Perl and Linux programs}The main tasks of the PV inversion are handled by Fortran programs. The following table contains a complete listof these programs with some details. The first column gives the name of the program, the second column the section(pre-processing, inversion, post-processing, diagnostics) where this program is needed, the third column the authors (inorder of their contribution), and the fourth column is a short description of the code. In the table, Fortran programsare marked with the appendix ".f", Perl programs with the appendix ".perl", and Linux Shell scripts with the appendix ".sh".\begin{center}\begin{tabular}{|l|l|l|l|}\hline{\bf Name of program} & {\bf Section} & {\bf Author} & {\bf Short description} \\[2mm]\hline{\bf p2z.f} & prep & Michael Sprenger & Interpolation onto height levels\\[2mm]\hline{\bf rotate\_grid.f} & prep & Michael Sprenger & Rotation to quâsi-cartesian system\\[2mm]\hline{\bf z2s.f} & prep, pvin & Michael Sprenger & Calculation of secondary fields\\[2mm]\hline{\bf def\_anomaly.f} & prep & Michael Sprenger & Definition of modified Ertel's PV\\[2mm]\hline{\bf cutnetcdf.f } & prep & Michael Sprenger & Splitting of netcdf files\\& & Heini Wernli & \\[2mm]\hline{\bf ref\_profile.f} & prep & Michael Sprenger & Definition of reference profile\\& & Olivia Martius & \\[2mm]\hline{\bf coastline.f} & prep & Michael Sprenger & Add coastlines to reference file\\[2mm]\hline{\bf pv\_to\_qgpv.f} & pvin & Michael Sprenger & Calculate quasi-geostrophic PV\\[2mm]\hline{\bf inv\_cart.f} & pvin & Rene Fehlmann & Inversion of quasi-geostrophic PV\\& & Michael Sprenger & \\[2mm]\hline{\bf prep\_iteration.f} & pvin & Michael Sprenger & Prepare next iteration step\\& & Rene Fehlmann & \\[2mm]\hline{\bf rotate\_lalo.f} & post & Michael Sprenger & Rotate to geographical grid\\[2mm]\hline{\bf add2p.f} & post & Michael Sprenger & Interpolation to hybrid grid\\[2mm]\hline{\bf p2s.f} & prep, post & Heini Wernli & Secondary fields on hybrid grid\\[2mm]\hline{\bf check\_boundcon.f} & diag & Rene Fehlmann & Consistency check for boundaries\\& & Michael Sprenger & \\[2mm]\hline{\bf calc\_qgpv.f} & diag & Sebastien Dirren & Convergence check for inversion\\& & Michael Sprenger & \\[2mm]\hline{\bf difference.f} & diag & Michael Sprenger & Difference of two netcdf files\\[2mm]\hline{\bf inversion.sh} & & Michael Sprenger & Master Linux Shell script\\[2mm]\hline{\bf inversion.perl} & & Michael Sprenger & Extraction of parameters\\[2mm]\hline\end{tabular}\end{center}\end{document}