spherepack 2.0 : a model development facility297...spherepack 2.0 is a collection of fortran...

62
SPHEREPACK 2.0: A Model Development Facility by John C. Adams* and Paul N. Swarztrauber*t September 1997 ABSTRACT SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates computer modeling of geophysical processes. The package contains programs for computing cer- tain common differential operators including divergence, vorticity, gradients, and the Laplacian of both scalar and vector functions. Programs are also available for inverting these operators. For example, given divergence and vorticity, the package can be used to compute the velocity components. The Laplacian can also be inverted and therefore the package can be used to solve both the scalar and vector Poisson equations. In addition, the package can be used to compute a scalar function with a specified gradient. Its use in model development is demonstrated by a sample program that solves the time-dependent non-linear shallow-water equations. Accurate solutions are obtained via the spectral method that uses both scalar and vector spherical harmonic transforms that are available to the user. The package also contains utility programs for computing the associated Legendre functions, Gauss points and weights, and multiple fast Fourier transforms. Pro- grams are provided for both equally-spaced and Gauss distributed latitudinal points as well as programs that transfer data between these grids. * National Center for Atmospheric Research, Boulder, Colorado 80307 which is sponsored by the National Science Foundation t This work was partially supported by the Computer Hardware, Advanced Mathematics, and Model Physics (CHAMMP) Program which is administered by the Office of Energy Research under the Office of Health and Environmental Research in the U.S. Department of Energy, Environmental Sci- ences Division.

Upload: others

Post on 31-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

SPHEREPACK 2.0: A Model Development Facility

by

John C. Adams* and Paul N. Swarztrauber*t

September 1997

ABSTRACT

SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates computermodeling of geophysical processes. The package contains programs for computing cer-tain common differential operators including divergence, vorticity, gradients, and theLaplacian of both scalar and vector functions. Programs are also available for invertingthese operators. For example, given divergence and vorticity, the package can be used tocompute the velocity components. The Laplacian can also be inverted and therefore thepackage can be used to solve both the scalar and vector Poisson equations. In addition,the package can be used to compute a scalar function with a specified gradient. Its use inmodel development is demonstrated by a sample program that solves the time-dependentnon-linear shallow-water equations. Accurate solutions are obtained via the spectralmethod that uses both scalar and vector spherical harmonic transforms that are availableto the user. The package also contains utility programs for computing the associatedLegendre functions, Gauss points and weights, and multiple fast Fourier transforms. Pro-grams are provided for both equally-spaced and Gauss distributed latitudinal points aswell as programs that transfer data between these grids.

* National Center for Atmospheric Research, Boulder, Colorado 80307 which is sponsored by theNational Science Foundation

t This work was partially supported by the Computer Hardware, Advanced Mathematics, and ModelPhysics (CHAMMP) Program which is administered by the Office of Energy Research under theOffice of Health and Environmental Research in the U.S. Department of Energy, Environmental Sci-ences Division.

Page 2: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-2-

CONTENTS PAGE

1. Introduction 3

2. Contents of SPHEREPACK 2.0 5

3. Sample Programs 12

3.1 Example 1 (Helmholtz equation) 13

3.2 Example 2 (Advection equation) 14

3.3 Example 3 (Shallow-water equations) 15

4. Harmonic transforms and other formulas 19

5. Computational methods 23

References 31

Appendix A (code for example 1) 33

Appendix B (code for example 2) 36

Appendix C (code for example 3) 45

Page 3: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-3-

1. Introduction

SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-

ment of computer models of geophysical processes. In addition to the programs in

SPHEREPACK 1.0, it contains a suite of programs for the application of certain common

differential operators including vorticity, divergence, gradient, Laplacian, and latitudinal

derivatives. In addition, programs are available for inverting these operators. For exam-

ple, given vorticity and divergence, the package can be used to reconstruct the

corresponding vector function. Also, given the gradient, the corresponding scalar func-

tion can be computed. Both the scalar and vector Laplacian can be computed or inverted.

Therefore the programs can be used to solve both the scalar and vector Poisson equa-

tions.

The package can also be used to solve time dependent partial differential equations. In

particular, the package facilitated the development of nine spectral models of the

shallow-water equations that were evaluated in (Swarztrauber, 1996). One such model is

given in section 3.3 which provides an example of how SPHEREPACK 2.0 can be used

to solve the nonlinear shallow-water equations on the sphere. The package also contains

utility programs for computing the associated Legendre functions, multiple fast Fourier

transforms, an icosahedral geodesic, and Gauss points and weights. All computations

can be performed on either a Gauss or equally-spaced latitudinal grid and programs are

available for interpolating between these grid systems. There is no difference in the accu-

racy or computing time of these systems; however, they alias differently (Temperton,

1991).

SPHEREPACK 2.0 is a significant extension of SPHEREPACK 1.0 which included pro-

grams for the spherical harmonic analysis and synthesis of scalar functions only. In addi-

tion to these programs, and those listed above, SPHEREPACK 2.0 contains separate pro-

grams for the analysis and synthesis of vector functions. Although the components of a

vector function, such as a wind field, are smooth in Cartesian coordinates, they can

nevertheless be discontinuous in spherical coordinates because of the discontinuity in the

coordinate system itself (Swarztrauber, 1993). Therefore the spectral representation and

analysis of a vector function is fundamentally different from that of a scalar function.

Scalar and vector harmonic analyses are used for problem solving in spherical coordi-

nates in the same way that Fourier analysis is used in Cartesian coordinates. Conse-

quently SPHEREPACK 2.0 provides the same high level of accuracy that the spectral

method provides in Cartesian coordinates. Furthermore, accuracy is uniform on the

sphere and independent of the location of the poles. This eliminates a number of

Page 4: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-4-

computational difficulties associated with solving partial differential equations on the

sphere including the accuracy and stability problems that can be created by the clustering

of points near the pole. Interpolation and smoothing on the sphere are also significantly

facilitated by harmonic analysis (Swarztrauber, 1979). Indeed the package includes pro-

grams for interpolating between Gaussian and equally-spaced latitudinal grids.

SPHEREPACK 2.0 functionality and programs are listed in Table 1 below.

Table 1

An overview of SPHEREPACK 2.0

computation

colatitude derivative

gradient

inverse gradient

divergence

invert divergence

vorticity

invert vorticity

invert divg.&vort.

scalar Laplacian

inverse Laplacian

vector Laplacian

inv. vct. Laplacian

stream fn. & vel pot.

inv. str. fn. & vel pot

grid transfer

scalar analysis

scalar synthesis

vector analysis

vector synthesis

Legendre functions

icosahedral geodesic

multiple ffts

Gaussain wts&pts

3-d sphere graphics

subprograms

vtsec,vtses,vtsgc,vtsgs

gradec,grades,gradgc,gradgs

igradec,igrades,igradgc,igradgs

divec,dives,divgc,divgs

idivec,idives,idivgc,idivgs

vrtec,vrtes,vrtgc,vrtgs

ivrtec,ivrtes,ivrtgc,ivrtgs

idvtec, idvtes, idvtgc, idvtgs

slapec,slapes,slapgc,slapgs

islapec, islapes, islapgc, islapgs

vlapec, vapes,vlapgc, vlapgs

ivlapec, ivlapes, ivlapgc, ivlapgs

sfvpec, sfvpes, sfvpgc, sfvpgs

isfvpec,isfvpes,isfvpgc,isfvpgs

trssph,trvsph,sshifte,vshifte

shaec,shaes,shagc,shags

shsec,shses,shsgc,shsgs

vhaec,vhaes,vhagc,vhags

vhsec,vhses,vhsgc,vhsgs

alfk, lfp, lfpt, lfim, lfin

ihgeod

hrfftf,hrfftb

gaqd

visequ, visgau, visgeo

.-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- - - ---

. . I~~~-

Page 5: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-5-

Most of the subroutine names end with ec, es, gc, or gs. The character e indicates

the subroutine operates on functions defined on equally-spaced latitude grids. The char-

acter g indicates the subroutine operates on functions defined on Gaussian latitude grids.

The character c indicates the subroutine computes the Legendre polynomials as needed,

and the character s indicates the subroutine utilizes Legendre polynomials that have

been precomputed and stored for repeated use. This provides the option of trading com-

puting time for storage and vice versa. For example, if N is the number of latitude points

then subroutine shses requires 0(N 3 ) storage for the Legendre functions that are

precomputed by subroutine shsesi. However shses is about 30% faster than sub-

routine shsec which requires 0(N 2) storage and recomputes the Legendre functions

for each harmonic synthesis. Most of the programs require the initialization of an array

that can be used repeatedly in subsequent applications of the program. The names of the

initialization programs end with an i and are listed in the next section but not in Table

1. For example, a call to ivlapgc must be preceded by a call to subroutine vhsgci.

IMPORTANT!

It is important to note that SPHEREPACK 2.0 uses the mathematical form of the spheri-

cal coordinate system. Colatitude is the first coordinate and longitude is the second. Cola-

titude is measured from the north to south pole. In Geophysical coordinates, longitude is

the first coordinate and latitude is the second. Latitude is measured from the south to

north pole and is equal to t/2 minus colatitude. Models that are coded in terms of geo-

physical coordinates require the use of short programs that match them to

SPHEREPACK 2.0. For example, if (u ,v) are the east longitudinal and latitudinal velo-

city components in geophysical coordinates, they must be converted to colatitudinal and

east longitudinal components (v',u) where v' =-v before using SPHEREPACK 2.0.

This is demonstrated in section 3.3 by a sample program for solving the shallow-water

equations in geophysical coordinates.

2. Contents of SPHEREPACK 2.0

The contents of the package are listed in this section which contains a sentence or two

description of each program. The complete documentation of the programs is available at

http://www.scd.ucar.edu/css/software/spherepack. The package consists of driver pro-

grams that compute or invert the differential operators that are required by the user's

application. In turn, the driver programs call the utility programs that implement the

Page 6: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-6-

analyses and syntheses required by the harmonic or spectral method on the sphere.

Most of the programs that compute the differential operators require the harmonic

analysis of the scalar or vector function prior to computing the operator. For example, to

compute the Laplacian of a scalar function using slapec, one must first compute the

spectral coefficients using subroutine shaec . The reason shaec is not called by

slapec is to avoid repeated computation of spectral coefficients when more than one

differential operator is applied to the same function.

The major options provided by SPHEREPACK are:

1. The colatitudinal grid Oi can be either Gaussian or equally-spaced. There is no res-

triction on the number of grid points in either the latitude or longitude direction.

The spectral truncation is always triangular.

2. Computations can be performed on the entire sphere or, if symmetries permit, on

the northern hemisphere only. The user can specify even or odd symmetry about

the equator and thereby halve both storage and computing time.

3. The user can elect to store certain quantities for repeated use in subsequent calls to

the same subroutine. Storage is increased from 0(N 2 ) to 0(N 3 ) and computing

time is reduced by about 30%.

4. When applicable, the differential operators and harmonic transforms can be applied

to multiple functions with a single subroutine call. This reduces the computing time

for additional functions by about 30% compared to multiple calls of the subroutine.

This is usually used with the O (N 2) storage option.

A list of user entry programs is given below. Where applicable, the programs are named

with the following conventions: The characters sh or vh denote scalar and vector har-

monic transforms respectively. The character a or s denotes analysis or synthesis. The

character g or e denotes Gaussian or equally-spaced latitudinal grid, and the character

c or s denotes whether or not the quantities in 3. above are computed or stored. That is,

whether the O (N 2) or O (N 3) storage option is selected.

COLATITUDINAL DERIVATIVE OF A VECTOR FUNCTION

Note: for latitudinal derivatives of scalar functions use the gradient programs.

vtsec computes the derivative of the vector function with respect to colatitude 0

on a equally-spaced grid using O (N 2) storage, initialized by vtseci.

Page 7: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-7-

vtses computes the derivative of the vector function with respect to colatitude 0

on a equally-spaced grid using O (N 3) storage, initialized by vtsesi.

vtsgc computes the derivative of the vector function with respect to colatitude 0

on a Gaussian grid using O (N 2) storage, initialized by vtsgci.

vtsgs computes the derivative of the vector function with respect to colatitude 0

on a Gaussian grid using O (N 3 ) storage, initialized by vtsgsi.

GRADIENT OF A SCALAR FUNCTION

grades computes the gradient of a scalar function on an equally spaced grid using

O(N 3) storage, initialized by vhsesi.

gradec computes the gradient of a scalar function on an equally spaced grid using

O(N 2) storage, initialized by vhsec i.

gradgs computes the gradient of a scalar function on a Gaussian grid using O (N 3)

storage, initialized by vhsgs i.

gradgc computes the gradient of a scalar function on a Gaussian grid using O (N 2)

storage, initialized by vhsgc i.

RECONSTRUCT A SCALAR FUNCTION FROM ITS GRADIENT

igrades computes a scalar function whose gradient is a given vector function on an

equally spaced grid using O(N 3) storage, initialized by shsesi.

igradec computes a scalar function whose gradient is a given vector function on an

equally spaced grid using O (N 2) storage, initialized by shseci.

igradgs computes a scalar function whose gradient is a given vector function on a

Gaussian grid using O (N 3) storage, initialized by shsgs i

igradgc computes a scalar function whose gradient is a given vector function on a

Gaussian grid using O (N 2) storage, initialized by shsgci.

DIVERGENCE OF A VECTOR FUNCTION

dives computes the divergence of a vector function on an equally spaced grid

using (N 3) storage, initialized by shsesi.

divec computes the divergence of a vector function on an equally spaced grid

using (N 2) storage, initialized by shseci.

divgs computes the divergence of a vector function on a Gaussian grid using

O(N 3 ) storage, initialized by shsgsi.

divgc computes the divergence of a vector function on a Gaussian grid using

O (N 2) storage, initialized by shsgci.

Page 8: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-8-

RECONSTRUCT A VECTOR FUNCTION FROM ITS DIVERGENCE

idives computes an irrotational vector function whose divergence is given on an

equally spaced grid using O (N 3) storage, initialized by vhsesi.

idivec computes an irrotational vector function whose divergence is given on an

equally spaced grid using (N 2) storage, initialized by vhseci.

idivgs computes an irrotational vector function whose divergence is given on a

Gaussian grid using (N 3) storage, initialized by vhsgsi.

idivgc computes an irrotational vector function whose divergence is given on a

Gaussian grid using 0(N 2) storage, initialized by vhsgci.

VORTICITY OF A VECTOR FUNCTION

vrtes computes the scalar vorticity of a vector function on an equally spaced

grid using O (N 3) storage, initialized by shsesi.

vrtec computes the scalar vorticity of a vector function on an equally spaced

grid using O (N 2 ) storage, initialized by shseci.

vrtgs computes the scalar vorticity of a vector function on a Gaussian grid using

O (N 3) storage, initialized by shsgsi.

vrtgc computes the scalar vorticity of a vector function on a Gaussian grid using

O(N 2) storage, initialized by shsgci.

RECONSTRUCT A VECTOR FUNCTION FROM ITS VORTICITY

ivrtes computes a divergence-free vector function whose vorticity is given on an

equally spaced grid using (N 3) storage, initialized by vhsesi.

ivrtec computes a divergence-free vector function whose vorticity is given on an

equally spaced grid using (N 2) storage, initialized by vhseci.

ivrtgs computes a divergence-free vector function whose vorticity is given on a

Gaussian grid using O (N 3) storage, initialized by vhsgsi.

ivrtgc computes a divergence-free vector function whose vorticity is given on a

Gaussian grid using O(N 2) storage, initialized by vhsgci.

RECONSTRUCT VECTOR FUNCTION FROM ITS

DIVERGENCE AND VORTICITY

idvtes computes a vector function with given divergence and vorticity on an

equally spaced grid using O(N 3) storage, initialized by vhsesi.

Page 9: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-9-

idvtec computes a vector function with given divergence and vorticity on anequally spaced grid using O(N 2) storage, initialized by vhseci.

idvtgs computes a vector function with given divergence and vorticity on a Gaus-sian grid using O (N 3) storage, initialized by vhsgsi.

idvtgc computes a vector function with given divergence and vorticity on a Gaus-

sian grid using O (N 2) storage, initialized by vhsgci.

LAPLACIAN OF A SCALAR FUNCTION

slapes computes the scalar Laplacian of a scalar function on an equally spaced

grid using O (N 3) storage, initialized by shsesi.

slapec computes the scalar Laplacian of a scalar function on an equally spaced

grid using O (N 2) storage, initialized by shseci.

slapgs computes the scalar Laplacian of a scalar function on a Gaussian gridusing O (N 3) storage, initialized by shsgsi.

slapgc computes the scalar Laplacian of a scalar function on a Gaussian grid

using O (N 2) storage, initialized by shsgci

INVERT THE LAPLACIAN OF A SCALAR FUNCTION

OR SOLVE THE HELMHOLTZ EQUATION

islapes computes a scalar function whose scalar Laplacian is given on an equally

spaced grid using O (N 3) storage, initialized by shsesi.

islapec computes a scalar function whose scalar Laplacian is given on an equally

spaced grid using O (N 2) storage, initialized by shseci.

islapgs computes a scalar function whose scalar Laplacian is given on a Gaussian

grid using O (N 3) storage, initialized by shsgs i.

islapgc computes a scalar function whose scalar Laplacian is given on a Gaussian

grid using O (N 2 ) storage, initialized by shsgci,

THE VECTOR LAPLACIAN OF A VECTOR FUNCTION

vlapes computes the vector Laplacian of a given vector function on an equally

spaced grid using O (N 3) storage, initialized by vhsesi.

vlapec computes the vector Laplacian of a given vector function on an equally

spaced grid using O (N2) storage, initialized by vhseci.

vlapgs computes the vector Laplacian of a given vector function on a Gaussian

grid using O (N 3) storage, initialized by vhsgsi.

Page 10: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 10-

vlapgc computes the vector Laplacian of a given vector function on a Gaussian

grid using 0 (N 2) storage, initialized by vhsgci.

INVERT THE VECTOR LAPLACIAN OF A VECTOR FUNCTION

ivlapes computes a vector function whose vector Laplacian is a given vector func-

tion on an equally spaced grid using O(N 3) storage, initialized by

vhsesi.

ivlapec computes a vector function whose vector Laplacian is a given vector func-

tion on an equally spaced grid using O(N 2) storage, initialized by

vhseci.

ivlapgs computes a vector function whose vector Laplacian is a given vector func-

tion on a Gaussian grid using O (N 3) storage, initialized by vhsgs i.

ivlapgc computes a vector function whose vector Laplacian is a given vector func-

tion on a Gaussian grid using O (N 2) storage, initialized by vhsgci.

STREAM FUNCTION AND VELOCITY POTENTIAL

computes the stream function and velocity potential of a vector function

on an equally spaced grid using 0(N 3) storage, initialized by shsesi.

computes the stream function and velocity potential of a vector function

on an equally spaced grid using (N 2) storage, initialized by shseci.

computes the stream function and velocity potential of a vector function

on a Gaussian spaced grid using O (N 3) storage, initialized by shsgsi.

computes the stream function and velocity potential of a vector function

on an Gaussian spaced grid using O(N 2) storage, initialized by vhsgci.

INVERT STREAM FUNCTION AND VELOCITY POTENTIAL

isfvpes computes a vector function with a given stream

potential on an equally spaced grid using O(N3 )

vhsesi.

isfvpec computes a vector function with a given stream

potential on an equally spaced grid using 0(N 2)

vhseci.

isfvpgs

function and velocity

storage, initialized by

function and velocity

storage, initialized by

computes a vector function with a given stream function and velocity

potential on a Gaussian spaced grid using O(N 3) storage, initialized by

vhsgsi.

sfvpes

sfvpec

sfvpgs

sfvpgc

Page 11: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-11-

is fvpgc computes a vector function with a given stream function and velocity

potential on a Gaussian spaced grid using O(N2 ) storage, initialized by

vhsgci.

GRID TRANSFERS

trssph transfers scalar data from one spherical grid to another. The grids can be

Gaussian or equally spaced.

trvsph transfers vector data from one spherical grid to another. The grids can be

Gaussian or equally spaced.

sshifte transfers scalar data on the sphere between an equally spaced grid that is

offset by a half grid increment in both longitude and latitude (which

excludes the poles) and an equally spaced grid that includes the poles.

vshifte transfers vector data on the sphere between an equally spaced grid that is

offset by a half grid increment in both longitude and latitude (which

excludes the poles) and an equally spaced grid that includes the poles.

SCALAR SPHERICAL HARMONIC ANALYSIS

shaec computes the spherical harmonic analysis on an equally spaced grid using

0 (N 2) storage, initialized by shaeci.

shaes computes the spherical harmonic analysis on an equally spaced grid using

O(N 3 ) storage, initialized by shaesi.

shagc computes the spherical harmonic analysis on a Gaussian grid using O (N 2)

storage, initialized by shigc.

shags computes the spherical harmonic analysis on a Gaussian grid using O (N 3)

storage, initialized by shigs.

SCALAR SPHERICAL HARMONIC SYNTHESIS

shsec computes the spherical harmonic synthesis on an equally spaced grid

using O (N 2) storage, initialized by shseci.

shses computes the spherical harmonic synthesis on an equally spaced grid

using O (N 3 ) storage, initialized by shses i.

shsgc computes the spherical harmonic synthesis on a Gaussian grid using

O (N 2) storage, initialized by shigc.

shsgs computes the spherical harmonic synthesis on a Gaussian grid using

O (N3 ) storage, initialized by shigs.

Page 12: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-12-

VECTOR SPHERICAL HARMONIC ANALYSIS

vhaec computes the vector harmonic analysis on an equally spaced grid using

O (N 2) storage, initialized by vhaeci.

vhaes computes the vector harmonic analysis on an equally spaced grid using

O (N 3) storage, initialized by vhaesi.

vhagc computes the vector harmonic analysis on a Gaussian grid using O (N 2)

storage, initialized by vhigc.

vhags computes the vector harmonic analysis on a Gaussian grid using O(N 3 )

storage, initialized by vhigs.

VECTOR SPHERICAL HARMONIC SYNTHESIS

vhsec computes the vector harmonic synthesis on an equally spaced grid using

O (N 2) storage, initialized by vhseci.

vhses computes the vector harmonic synthesis on an equally-spaced grid using

O (N 3) storage, initialized by vhsesi.

vhsgc computes the vector harmonic synthesis on a Gaussian grid using O (N 2 )

storage, initialized by vhigc.

vhsgs computes the vector harmonic synthesis on a Gaussian grid using O (N 3 )

storage, initialized by vhigs.

ASSOCIATED LEGENDRE FUNCTIONS

alfk computes the coefficients in the trigonometric series representation of

Pno(0).

lfp uses coefficients computed by routine alfk to tabulate Pm(O) at

equally-spaced colatitudes.

lfpt uses coefficients computed by routine alfk to compute Pnt(9) at a single

colatitude 0.

If im given n, L,and Oi f im computes Pm(9f) for m =0,...,n and i=l1,...,L.

lf in given N, m, L and Oi lf in computes Pnn(0i) for n=m,...,N and

i=1,...,L.

Additional programs for computing the associated Legendre functions are included in

ALFPACK which is also available from the National Center for Atmospheric Research.

Page 13: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 13 -

ICOSAHEDRAL GEODESIC

ihgeod computes the Cartesian coordinates of the points on the surface of the

sphere corresponding to a twenty-sided geodesic.

MULTIPLE FFTS

hrfftf multiple real forward fast fourier transforms, initialized by hrf f ti.

hrf f tb multiple real backward fast fourier transforms, initialized by hr f ft i

Additional programs are included in FFTPACK which is also available from the National

Center for Atmospheric Research.

GAUSS POINTS AND WEIGHTS

gaqd computes the Gaussian colatitudes and weights that are used in the Gaus-

sian quadrature.

GRAPHICS ON THE SPHERE

visequ three-dimensional rendering of a scalar function defined on an equally-

spaced latitudinal grid (see Figure 1).

visgau three-dimensional rendering of a scalar function defined on a Gauss distri-

buted latitudinal grid, initialized by gaqd (see Figure 2).

visgeo three-dimensional rendering of a scalar function defined on a geodesic

grid, initialized by geopts (see Figure 3).

3. Sample programs that illustrate the use of SPHEREPACK 2.0.

Three sample programs, each followed by its output, are presented in this section. The

first example solves the Helmholtz equation. The second solves the time-dependent

linear advection equation and the third solves the time-dependent non-linear shallow-

water equations. The FORTRAN programs are listed in appendices A, B, and C respec-

tively.

3.1 Example 1: Solving the Helmholtz equation on the sphere.

In this example we solve the two-dimensional Helmholtz type equation

V2u (Xk,) - Au (X,O) = r (X,0) (3.1)

Page 14: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 14-

where X is longitude, 0 is latitude, and V2 is defined by equation (4.19). For testing pur-

poses, we assume A = 1 and the exact solution

u (,0) =(1 +x y)ez (3.2)

which are used to compute the right hand side r (X,0). Here we assume a unit sphere and

therefore x = cosO cosk, y =cos sink, and z = sin0. Subroutine islapec from

SPHEREPACK 2.0 is used to provide an easy and highly accurate approximation on a

relatively coarse ten-degree, equally-spaced latitude and east longitude grid which

includes the poles. SPHEREPACK 2.0 uses the spectral method which eliminates the

computational problems that can be induced by the polar singularities. Methods based on

finite difference approximations, including multi-grid and cyclic reduction, require spe-

cial treatment at the poles (Adams, et al. 1981), (Adams, 1991).

The program to solve equation (3.1) is listed in Appendix A together with the accuracy of

the solution using both 32- and 64 bit arithmetic.

3.2 Example 2: Solving the time-dependent linear advection equation.

In this subsection, we use SPHEREPACK 2.0 to solve the first test case given in (Willi-

amson, et al. 1992); namely, the advection of the cosine bell shown in Figure 4. The bell

advects on a sphere in solid rotation at the rate of one rotation per twelve days. It is given

as the solution of the advection equation

^ =- U ac-v -^0=-V~-VOl) (3.3)t a cosO - v = -v V

where the velocity is given by solid rotation about an axis that is at an angle a relative to

the coordinate axis. Let X, 0, a, and v correspond to the coordinate system with axis

coincident with the axis of rotation so that u = a cocosO and v = 0. The radius of the earth

is a=6.37122x106 meters and co = 2m/(12-24-3600) radians per second (r/s) which

corresponds to one complete rotation in twelve days.

Let X, 0, u and v correspond to the coordinate system with axis tilted relative to the axis

of rotation. Given X and 0, we first determine X and 0 from the formulas following (3.12)

through (3.14). Next, u and v are determined from (3.16) and (3.17) using u = a cocosO.

Page 15: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 15-

The initial cosine bell (Figure 4) is defined as

)(X0,e)=¢ )(X,)== P(cosr-- + 1) for r <re (3.4)2 re

where r is the spherical angle or great circle arc length between the axis of the bell

(xCYc,, zc) and the point (x ,y,z) on the surface of the sphere. The maximum support is

defined by re, i.e. =0 if r>re. On a unit sphere r =2sin-1 (d/2) where d =[(x-Xc) 2 +

(y-yc)2 + (Z-Zc)2] 1/2. In the working coordinate system, 0 is determined as follows:

Given X and 0 we first determine X and 0 from the formulas following (3.12) through

(3.14). Next, ( is determined from (3.4).

A sample code for solving (3.3) is given in Appendix B. Subroutine gradgs is used to

compute the gradient of {. The maximum geopotential is po=1000 and re =1/3. The

center of the cosine bell is located at 30 degrees north latitude.

3.3 Example 3: Solving the time-dependent non-linear shallow-water equations.

In this subsection SPHEREPACK 2.0 is used to solve the nonlinear shallow-water equa-

tions on the sphere. The sample program is listed in Appendix C. Let a be the radius of

the earth; X be east longitude; 0 be latitude; and u, v be the respective velocity com-

ponents. Then surface vorticity and divergence are

as1 [ , - -(cosu)] (3.5)= a cos0 [A -d9

and

- lacosl8 [Os + .(3.6)a cos0 'cs

Let Q be the rotational rate of the earth and f = 2QsinO be the Coriolis parameter then

the shallow-water equations can be written

Du v au u av 1vu + f V (3.7)

-- = - - u 6 - a- + a w + V - a cose t (3.)- a a-3--' a d -cos{) 3 )

v Dv _ _ , v1^"it ^ i~u a v aav -af1 (3.8)

Page 16: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-16-

- 6-acosOU 0 a (3.9)a o - a ' a

It can be shown that a number of individual terms in these equations are unbounded near

the poles (Swarztrauber, 1993). Yet these terms must cancel since the time derivatives

are bounded. This provides one of the key motivations for using the spectral method to

solve partial differential equations in spherical coordinates. Here we use a variant called

the vector harmonic transform method (Swarztrauber, 1993, 1996) with the following

steps that are implemented in the program at the end of this section. SPHEREPACK 2.0

can be used to perform the calculations in each step.

1. Analyze u and v by computing the coefficients br,,,,, bi,,, cr , and cim,n in

equations (4.10) through (4.13) using subroutine vhaes. Next, truncate the

coefficients to n <N modes and resynthesize using (4.8) and (4.9) as implemented

in vhses.

2. Analyze ( by computing ar,, and ai,, in equations (4.3) and (4.4) using subrou-

tine shaes. Next, truncate the coefficients to n <N modes and resynthesize ¢

using (4.1) as implemented in shses.

3. Using the coefficients from step 1, compute the vorticity r and divergence 6 using

the procedure starting at (4.14) which is implemented in subroutines vrtes and

dives.

4, Compute the latitudinal derivatives au/aO and avA/0. from a vector synthesis like

(4.8) and (4.9) but with V(O) and W(O) replaced with -- Vd(9) and W'n(Q)dO V (O) and dO Wn

respectively. This step is implemented in subroutine vtses.

5. Compute the gradient ( a cs ' ) using the procedure starting at (4.17)

which is implemented in subroutine grades.

Following these steps, the spatial derivatives are substituted into the right side of (3.7)

through (3.9) and the resulting time derivatives are used to advance the solution to the

next time level using explicit leap-frog time stepping. The maximum mode N is chosen

so that the truncation and resynthesis in steps 1 and 2 eliminate aliasing in the spectral

analysis of the product terms in the shallow-water equations.

The sample program at the end of this section implements test case 3, "steady-state Non-

linear Zonal Geostrophic Flow with Compact Support" (Williamson, et al. 1992) which

Page 17: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 17 -

we now proceed to describe. In what follows, . and 0 are the spherical coordinates of

the unrotated coordinate system in which the velocity is zonal (v1 = 0). The coordinates X,

0 correspond to the rotated or working coordinate system in which the wind flows over

the pole. The longitudinal velocity u is zero except for 9b < 0 < 0e where it is given by

"( uoex(p +b -2--0) 2(0) = uoexp[- 02(Oe_~)(_ ,']. (3.10)

u(0) is zero at 0=60b and 0 =0 e and has a maximum value of u 0 at =(0 e +0b)/2. To

compute the flow in terms of the working coordinates X and 0, first define the.rotation in

Cartesian coordinates. Let x, y, and f correspond to X and 0 and let x, y, and z

correspond to X and 0; then, in Cartesian coordinates the rotation is given by

=cosocx - sincez , y=y, and z= sinax +cosoz. (3.11)

where oc is the angle of rotation. The axis of rotation is y7 which is coincident with the y

axis. Replacing Cartesian coordinates with spherical coordinates

cosocosX = cosacosOcosX - sinasinO = b (3.12)

cosOsinX = cososinX = c (3.13)

sin0 = sinacos0cosX + cosasinO = d (3.14)

Given X and 0, in the working coordinate system, these equations permit the computation

of the corresponding X and 0 in the unrotated coordinate system. For example, X =

tan-lc/b, after which 6 = tan- [d/(b cosX + c sinX)].

The velocity components u and v, in the working coordinate system, are computed as

follows: Given X and 0, first compute X and 0. Next compute ut(0) from (3.10). It remains

then, to compute u and v from ui. This last step has three parts; (a) convert VT = (i ,0,0)

to Cartesian coordinates vT = (X,Y,O); (b) compute v[ = (X,Y,Z) from VC using the

inverse of (3.11) applied to the Cartesian velocity components; (c) convert vc back to

spherical coordinates. The conversion of the velocity components between Cartesian and

spherical coordinates is given by vs = Q V where

Page 18: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

18-

cosX o- sinO sink cos . (3.15)cosO sink sinO

The three steps described above can be combined to provide the following formulas for u

and v in terms of u

u = (cosocsinksinX + cosXcos) uT (3.16)

v = (cosasinOcosksinX- sinOsinXcos + sinocosOsin,) u . (3.17)

In summary, X and 0 are first determined from the formulas following (3.12) through

(3.14). Next, u is computed from (3.10) and finally u and v are computed from (3.16)

and (3.17).

Consider now the computation of the geopotential. Since the flow is zonal, v = 0 and

hence from (3.7) and (3.9), au/at = Daj/Dt =0. However, from (3.6) and (3.8), av/at =0

only if

aQ = -a (f + utanQ) u (3.18)DO a

which can be numerically integrated to determine ( to any accuracy. The integration con-

stant can be determined from the mean geopotential )0 which is specified as an input

parameter pzero in the sample program. Given X and 0 first compute 0 using the for-

mulas following (3.12) through (3.14). Then (Xk,0) = <(0). The Coriolis parameter must

also be rotated and therefore computed in the same manner as f (k,0) = f ().

The exact steady-state solution was computed from (3.10) with uo= 40. m/sec; a2=.3;

0tb =-7/6, and 0 e =i/2. This corresponds to a maximum wind positioned at 30 degrees

north. For the sample program, the wind is rotated a = 60 degrees about the y axis which

directs the maximum wind across the north pole. The geopotential is computed from

(3.18) with mean value pzero set to )0 =2.94x10 4 m 2/s 2. The rotational rate of the

earth is Q=7.292x10- 5r/s and its radius is a =6.37122x106 m. The solution is computed

on an equally-spaced latitude grid.

The sample program that implements the solution of the non-linear shallow-water equa-

tions on the sphere as formulated in this section is listed in Appendix C. It is important

to note that SPHEREPACK 2.0 uses mathematical notation for the spherical coordinate

--

Q=

Page 19: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 19-

system. The first coordinate is colatitude measured from the north pole and the secondcoordinate is east longitude. Geophysical coordinates are used throughout this paper withlongitude being the first coordinate and latitude being the second coordinate. Colatitudeis equal to ir/2 minus latitude and is measured in the direction opposite that of latitude;namely, from the north to south pole. The program below is written in terms of geophysi-cal coordinates which therefore requires the use of short programs that match it toSPHEREPACK 2.0. For example, instead of calling vhaes for the analysis of the velo-city, the sample program calls vhaesgeo which then calls vhaes.

4. Harmonic transforms and other formulas

In this section, we describe the harmonic transforms and formulas used to compute thevarious differential oerators provided by SPHEREPACK 2.0. We first consider the trad-itional spherical harmonic transform of a scalar geopotential function. Next, we presentthe spherical harmonic transform of the velocity vector function (u ,v). These transformsare then used to compute the spatial derivatives and differential expressions that arerequired in the solution steps given in section 2. The computational details of the Legen-dre transforms, Fourier transforms, and Gauss quadrature are given in section 5.

Consider first the scalar harmonic transform. If ( is sufficiently smooth then, to arbitraryprecision, there exists N such that

<(X,0) = 'P(arm ,n cosm X + ain,n sinm ) (4.1)

where P, are the associated Legendre functions. The prime notation on the sum in (4.1)

indicates that the first term corresponding to m = 0 is multiplied by /2. Define

- 2n+l (n-m)! .tn',m= 2I) (4.2)2n (n+m)! '

then the coefficients in (4.1) are given by

2= n '2amY,,,: a,,n = f3 J ~( ) P n( O)y csm kcosm OdOd ,X (43)arinu~ti -A<2L3m~I~Vn U/(43

and

Page 20: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 20-

2 7/2

aim,n =c,, ,n (X,0)Pn"(0O)sinm XcosOd Od X. (4.4)

Equations (4.3) and (4.4) constitute the scalar spherical harmonic analysis or forward

transform and (4.1) corresponds to the synthesis or backward transform.

Next we consider the vector harmonic transforms. Because u and v are discontinuous

(multi-valued) at the poles, a series representation in terms of smooth functions, such as

the scalar harmonics, would not be satisfactory. Rather, the representation is given in

terms of the vector basis functions with discontinuities that "fit" the discontinuities

induced by the spherical coordinate system. The vector harmonics

Bm-= Vn e imx and C n= eiim (4.5)

provide such a set of basis functions (Morse and Feshback,1953). V,'n() and Wnn(0) are

given by

dP mIn (n+l)Vm(e) = dO = /2[P+l - (n+m)(n-m+l)Pn-1] (4.6)

and

In(n+l )Wnm(O) = coso Pn = 1/2[PnmL +(n+m)(n +m-1)Pn L1 ]. (4.7)

Then, to arbitrary precision, there exists N such that

u (,0) ' [Wnn(bim n cosm X - br ,n sinm X)n -'m=0

+ Vnn(crm,,z cosm X + ci ,,sinm X)] (4.8)

and

v (X,) z ' t [Vn(brm,n, cosm X + bi ,n sinm X)n=O mn=

+ wm(- ci,n ,n cosm X + cr,, n sinm X)] (4.9)

Page 21: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-21-

where

2nr t/2

brm,,,= n = , 1 /[vVIncosm X -uW n tsinmM ] cosOd OdX (4.10)

2Xn V

bi ,n = Cm,n , {2[uWVncosm X + vVWnsinm X] cosOd Od X (4.11)

2n (1/2Crm ,n = t n,n U J[ u V nm cosm ) + vW~nsinm X] cosrd Od , (4.12)

im ,n = Cm,n I [-vWn"cosm X + uV'sinm X] cosd Od X. (4.13)

Equations (4.10) through (4.13) constitute the vector spherical harmonic analysis or the

forward transform from physical to spectral space. Equations (4.8) and (4.9) constitute

the vector synthesis or the backward transform from spectral to physical space.

The vector transforms provide the fundamental tool for computing the spatial derivatives

required by the spectral transform method. Consider first the computation of vorticity and

divergence. Both terms on the right side of (3.5) and (3.6) are unbounded near the pole.

Therefore, these terms must be evaluated collectively as a single, bounded, differential

expression. Substituting (4.8) and (4.9) into (3.5) and using

1 d dag(co sc1O d(cosO + d[n (n +l) - ]Pn() = 0 (4.14)

cos0 d0 d0 . cos20

we obtain

= , xIn (n +1 )Pnm()(crn ,, cosm +ci ,,, sinm X) (4.15)n=O Im=0

which has the same form as (4.1). Therefore the vorticity can be computed from the vec-

tor analysis by setting arm,nn = 'n (n +l)cr,n, andaim,n =In (n+l)cim, followed by a

scalar spherical harmonic synthesis (4.1). This procedure avoids the loss of accuracy

induced by the explicit computation of the individual unbounded terms in (3.5).

Page 22: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 22-

Substituting (4.8) and (4.9) into (3.6), and again using (4.14), we obtain

6 = - m' i n (n +l)PA(O)(br,3 , cosm +bi sinm ?) (4.16)m=0 n==m

which also like equation (4.1). Therefore the divergence can be computed by setting

armn = -n (n + 1)brm ,n and aim,, = -in (n + 1)bi ,n followed by a single scalar spheri-

cal harmonic synthesis (4.1).

This procedure can be inverted to compute a vector function with a given vorticity and

divergence. If 5 and 5 are given, -\I(n (N+l))br,,n,, -I(n (N+l))bim,n, In(n (+l))crm,,,

and 'z(n(N+l))cim, can be computed by scalar harmonic analyses of (4.15) and (4.16).

The vector function (u,v) with the specified vorticity and divergence can then be com-

puted by a vector synthesis (4.8) and (4.9). If either the vorticity or divergence is zero,

this procedure yields the corresponding irrotational or divergence-free vector (u,v)

respectively.

The derivatives au/aO and av/0a can be computed from a vector synthesis like (4.8) and

(4.9) but with V(0) and W(0) replaced with V m(0) and -Wn(0) respectively.dO dO W~(O) rpctively.

Next, we show that the gradient of a scalar function can be computed from a vector syn-

thesis. From (4.1), (4.6), and (4.7)

cosO = mTin (n +l) Wnm(O)(aim,n cosm - arm,n sinm X), (4.17)

and

- = - -' n In (n +1)Vnm(O)(arm , cosm X + aim, sinm X), (4.18)in =0

which has the form of a vector synthesis (4.8) and (4.9) with crm,n = ci,n = 0. There-

fore the gradient of) can be computed as a vector synthesis by setting

brm ,, = In = (n + )arm ,n, bim ,n = in (n +l )aim ,, and cr ,n = i,,,,n = 0.

Next we consider the computation of the surface scalar Laplacian

Vs = a2o I 2 +- (cos0)]. (4.19)

Page 23: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 23 -

If we substitute (4.1) into (4.19) and use (4.14) we obtain

Vs20 = -t n (n + 1 )P (O)(arm n cOSt + ai,, , sinm ) . (4.20)

Therefore the Laplacian of ) is obtained by first analyzing ) using (4.3) and (4.4) and

multiplying the resulting coefficients arm,, and aim,n by -n (n+1) which is then followed

by a synthesis (4.1).

Finally, we consider the computation of the vector Laplacian

V2u 2sinO av uoS 20 X - COS20

L(u,v)= V2v + 2sinO Du v (4.21)cos2O - - cos2 0

The vector harmonics (4.5) are eigenvectors of L corresponding to eigenvalues -n (n +1)

(Morse and Feshback, 1953), (Swarztrauber, 1993). That is

LBm = -n(n+l)Bn and LCn =-n (n+l)Cm. (4.22)

Hence, the vector Laplacian is computed by first analyzing (u,v) using (4.10) through

(4.13), multiplying the coefficients by -n (n+1) and performing the vector synthesis (4.8)

and (4.9).

The solution of the scalar or vector Poissons' equation is obtained by inverting the com-

putations described above. However, note that a division by -n (n + ) for n = 0 provides a

non-unique solution only if the corresponding coefficients in the numerator are also zero;

otherwise, a least squares solution is obtained (Swarztrauber and Sweet, 1975).

5. Computational methods

In this section we will describe efficient and accurate methods for computing PA(O),

V1(O), and. Wnn(O). We will also describe the computation of the integrals in the har-

monic analyses both on a Gauss and equally distributed latitudinal grid. Several com-

ments on spectral truncation and aliasing are included at the end of the section. The pur-

pose of this section is to provide the numerical techniques that are central to the com-

puter implementation of the harmonic transforms and thereby provide the means to

Page 24: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 24-

implement the theoretical developments that were presented in the previous sections.

Two methods for computing the associated Legendre functions are presented. The first is

the Fourier method which can be used to tabulate the Prn(0) as a function of 0 for any m

and n independent of any other m and n. If a real trigonometric series is substituted into

(4.14), then it can be determined that the P,'(0O) have one of the following trigonometric

forms depending on the parity of m and n:

Pm(O) =am,, ,kcos2k0 n even ; m even (5.1)

Pm()= am,,,k sin2k 0 n even ; m odd (5.2)

Pn (f9)= amn,ksin (2k-1)0 n odd ; m even (5.3)

Pn(0)=i) = nam,n kcos(2k-1)0 n odd ; m odd. (5.4)

The coefficients am,n ,k can be determined from the following three-term recurrence rela-

tions that result when (5.1) through (5.4) are substituted into (4.14). If n is even

[(2k -1)(2k-2)-n (n +l)am ,n ,k-1 + 2[4k2-n (n +1)+2m 2]am ,n ,k

+ [(2k+l)(2k+2)-n (n+l)]am,n,k+l= 0. (5.5)

If n is odd

[(2k-2)(2k-3)-n (n +l)]an ,n k- + 2[(2k -1) 2-n (n +1)+2m 2]am, ,k

+ [2k(2k+l)-n (n+l)]am,n,k+l = 0 (5.6)

Although these relations define an infinite set of tridiagonal equations, they have a solu-

tion with a finite number of non zero amn,,2 ,k For example, in (5.5) the coefficient of

a,,,n,k-1 is zero for k=n/2+1 and the coefficient of an,,,,k+I is zero for k=-n/2-l. The

resulting set of equations corresponding to k=-n/2 to k=n/2 is singular with a nonzero

solution an,,,,k. Furthermore, it can be shown that am,,,,-k = ±an,,k depending on the

Page 25: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

25 -

parity of m and n which can be used to halve the number of equations and simplify their

solution.

A nontrivial solution to the resulting singular system of equations can be determined by

inverse iteration or by the following method that also produces the correct scaling. The

coefficient a,n,,, is first computed from Rodrigue's formula and the remaining

coefficients at,,t,k are determined from (5.5) or (5.6) by a backward recurrence that

preserves the relative accuracy of small values of am,n,k, corresponding to large values of

k. This permits the accurate calculation of Vn(0O) from the formal derivative of the tri-

gonometric series for Ppn(O).

Consider now the computation of amn ,n from Rodrigue's formula

n (- cos) m d n +mPm(O) - 2n 2- 1)n (5.7)2. n dx n +m(

Expanding the highest power of both sinO and cos0, we obtain the coefficient of the tri-

gonometric term with the highest wave number n. For even n -m

n-m

Pnm() = (- (2n)! cosn + ] (5.8)2ny! 2n-1 (nr-m)!

and for odd n -m

n -m -1

Pnm(0) = (-1)) sinn8 (5.9)2nn![ 2n.1 (n -mr)!

Therefore,

n -m

am,n = 22 n! (n - mn)! n-m even (5.10)m ,nn 22n-\n! (n-m)!

and

n-m-1

amnn = 2 ( n- )! n-m odd. (5.11)m ,n 1 22nI (n -m)

As previously mentioned, the remaining am,n,k are determined by the backward

recurrence of either (5.5) or (5.6). Pm(O) can then be computed from the appropriate

equation in (5.1) through (5.4).

Page 26: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 26-

The Fourier method may be an efficient way of computing a few P/? (0), particularly for

large values of m and n. However, the harmonic transforms require a complete set of

the functions that can be computed more efficiently using the four-point recurrence rela-

tion

pt -I =(n+m )(n+m-l)Pnlli 1 - (n-m+l)(n-m+2)Pnm. l + P'l . (5.12)

This recurrence is initialized by computing P,°(0) and Pl(0) using the Fourier method. It

can also be used to compute P m(O) for m = n and m = n -1 by setting Pm(0Q)=O for n <m.

The values of m and n form a square with stride two in (m ,n) space. Therefore, equa-

tion (5.12) can be used to compute P m(9) for even (odd) n -m without computing P/ (0)

for odd (even) n -m. This can be used to halve the amount of computation for problems

that are either symmetric or antisymmetric about the equator and can therefore be limited

to a single hemisphere.

Unlike other recurrence relations for Pm(0), the coefficients in (5.12) do not have a func-

tional dependence on latitude 0. Hence, the derivative of pm(0) also satisfies (5.12).

From (4.6)

Vn0) = (n -2)(n -1) [VnL 2 (0) + (n+m-2)(n +m-3)Vnm- 2 (0)]\vt/ n (n +1)

- (n -m +1)(n -m +2)Vm -2(0). (5.13)

This recurrence can be initialized from Vn°(0) and V l(0) which can be obtained by dif-

ferentiating the trigonometric series for P°(0) and Pnl(0). A recurrence relation for

Wnm(0) can also be obtained by substituting Pn (0) = m-lcos0Wnf(0) into (5.12).

Wnn(O) = (n -2)(n -1) [W'2 () + m(n +m-2)(n +m-3) W #2 2 (0)]Wn M n(n+1l) im-2

m(n -m +1 )(n-m +2) W- 2(). (5.14)i -2

Since W,°(0)=0, (5.14) is initialized with Wn (0) and W,2(0) which can be computed

from the trigonometric series for P n(0) and P,2(0). This completes our discussion of the

computation of the associated Legendre and related functions.

Page 27: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 27-

Consider now the approximation of the integrals in the harmonic analyses. We begin

with the approximation of the integrals on an equally-spaced latitude grid (Machenhauer

and Daley, 1972; Swarztrauber, 1979). An analysis using Gauss quadrature with N

points is exact to within roundoff error for any function with finite expansion

(X~,O) = , n' PA(0)(an ,n cosm X+bm ,n sinm X) . (5.15)

An exact quadrature for these functions can also be developed on an equally-spaced grid

Oi = -7/2+ i 7V for i =0, .. , N. From (4.3) we obtain

7U/2

arm ,n = Cm ,n J2an (O)Pn()cos0 d 0 (5.16)

where

2nam (0) = I(9,0)cosm Xd . (5.17)

For even m it can be shown that Pm(O) and hence am (0) have a cosine expansion in

terms of colatitude trl2-0 with wave numbers that are less than or equal to N if (,O)

has the finite expansion (5.15). Hence, am (O) is given exactly by

am() = i "_[/oam (Oi )cosk (/2-O )]cosk (i)2- O) (5.18)

The double prime notation on the sum indicates that the first and last terms are multiplied

by 1/2. Substituting (5.18) into (5.16) we obtain the desired formula

arm , = tZn(9 )am(i) (5.19)

where

Zt(2i ) N ( ) n (5.20)ZII(Q1 ) -f j "cosk (7t12-0 1) J cosk (7r/2-9)PAn(O)sinOd9 . (5.20)

A similar development for odd m yields formulas like (5.19), but with i=1,...,N l and

Page 28: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 28 -

2 N2 x/2 in(OnsinJd 0 (5.21)Zln(i) -- j"sink (r2-0i) sink (7./2-O)P#'(0)sinZ Od . (5.21)

The main difference between the equally-spaced and Gauss analysis is that the weights

Zn(0i ) are functions of the three index variables i, m , and n. Nevertheless, use of the

Znn(0i) in the analysis is consistent with the use of PM (09) in the synthesis and requires

the same computational effort.

The finite representation (5.15) is called a triangular truncation because the values of m

and n that correspond to nonzero am,n and b ,n lie in a triangle in (m ,n) space. A tri-

angular truncation is preferred since the analysis of 4(X,0) will be exact for any orienta-

tion of the spherical coordinate system. That is, the analysis is exact no matter where the

poles are located.

Just as (5.12) was used to compute both VAn(O) and Wnn(O), it can also be used to compute

Zn(06). If the operator on the right side of (5.20) is applied to the recurrence (5.12), then

Zm(0) is seen to also satisfy (5.12). Therefore, Znm(9) can be computed in the same

manner as Pn(0), namely:

1. The integrals in (5.20) and (5.21) are computed exactly by substituting one of the

exact forms (5.1) through (5.4) for Pm(0) formally integrating. These integrals then

constitute the Fourier coefficients in a trigonometric series which in turn yield tri-

gonometric expansions for Znm(O) similar to (5.1) through (5.4). A noteworthy

difference is that the range of summation in the trigonometric expansion is equal to

the number of latitudes, rather than n/2 or (n+1)/2, as in the case of the Pn(0). The

fast Fourier transform can then be used to tabulate Znm(Oi).

2. Like the computation of P (0), one could use the Fourier expansion of Znm(0) to

compute Z4m(0) for any m and n. However, since all Znm(0) are required for a syn-

thesis, it is more efficient to compute Z 0°(0) and Z,1(0) using the Fourier expansion

and the remaining Zn(06) using (5.12) with Pm(0) replaced by Zm(0). This completes

the discussion of the discrete transform for equally-spaced latitudinal points.

Consider now the computation of the Gauss Legendre quadrature. Gauss quadrature also

provides an accurate approximation to the latitudinal integrals required for both the

scalar and vector harmonic transforms. Here we will briefly review an accurate method

(Golub and Welsch, 1969) for computing the Gauss latitude points xj = sinOj and weights

wj. forj = 1,.. .,N.

For reasons that will become evident, we will use the normalized associated Legendre

functions

Page 29: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 29 -

Pa(O) = (-)m [ 2+ (n-m)! ]/2pn() (5.22)~~n \ 2 (n +m 5)! ])

and the normalized Legendre polynomials PN (x)=P/(O) where x = sine. It is known

that the Gauss points xi are given as the zeros of PN(x). If we define Pi_(x)=0, and

use Po(x )= 1/2, then the remaining Pn (x) can be computed from the recurrence

- n n+ 1xPn(x)= l(2n+ l)1(n-l Pn.(x)+ \(2 n-1 )( 2 n3) +Pn (x) (5.23)

Define vectors pT(X) = [P(X),..., PN-(X)] and p =p(xj). Golub and Welsch credit

Wilf with the following formula for the Gauss weights

Wj = [pjTPj -1. (5.24)

Therefore, the zeros xj of PN (x) provide the Gauss points and they can also be used to

compute the weights using (5.24). We show now that the Gauss points xj and weights wj

can be computed from the eigenvalues and eigenvectors of a symmetric tridiagonal

matrix. The QR algorithm can then be used to compute the eigensystem and therefore the

points and weights that constitute the Gauss Legendre quadrature.

Define T as the symmetric tridiagonal matrix with zero diagonal and elements

an =n/(2n-1)(2n+1) below the diagonal for n=l,...,N-l. Also define eN as an N-

vector with zero elements except for the last element which is 1. From (5.23)

Tp(x)=xp(x)+ (2N- )(2 n+1)PN(x)eN (5.25)

T is symmetric since (5.23) is written in terms of the normalized associated Legendre

polynomials. If xj is a zero of PN (x) then pj =p(xj) is an eigenvector of T and hence

the Gauss points are given as the eigenvalues of T. Let qj = (q j, . q.,j) be a nor-

malized eigenvector of T, i.e. qTqj = 1. Since pj is also an eigenvector of T it differsfrom qj only by a multiplicative constant, i.e., qj = cpj. However, from (5.24)

wj ppp = 1 = qjTq= c 2ppJT (5.26)

Therefore, c = ij and hence q lj = -\jP o(xj) j= '/I2 which implies

Wj =2qj j. (5.27)

Page 30: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-30-

This provides a convenient way to compute the weights for the Gauss Legendre quadra-

ture. The Gauss points are given as the eigenvalues of the symmetric matrix T and the

Gauss weights wj can be computed from the first element of the jth eigenvector using

(5.27). Both the eigenvalues and eigenvectors can be computed efficiently using the QR

algorithm available in EISPACK (Smith, et.al., 1976). The Gauss points on the sphere

are given by j = arcsin(xj ). The weights wi on the sphere are symmetric about the equa-

tor.

Page 31: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-31-

REFERENCES

Adams, J. C., P. N. Swarztrauber, P. N., and R. A. Sweet, 1981: Efficient FORTRAN

subprograms for the solution of elliptic partial differential equations. In:

Elliptic Problem Solvers, M.H. Schultz, ed., Academic Press, New York.

Adams, J. C., 1991: Recent enhancements in MUDPACK, A multigrid package for

elliptic partial differential equations. Applied Math. and Comp., 43, 79-94.

Efficient FORTRAN subprograms for the solution of elliptic partial differential

equations. In: Elliptic Problem Solvers, M.H. Schultz, ed., Academic Press,

New York.

Eliasen, E., B. Machenhauer, and E. Rasmussen, 1970: On a numerical method for

integration of the hydrodynamical equations with a spectral representation of the

horizontal fields. Rep. No. 2, Institut for Teoretisk Meteorologi, Kobenhavns

Universitet, Denmark.

Golub G. H., and J. H. Welsch, 1969: Calculation of Gauss quadrature rules. Math.

Comp., 23, 221-230.

Morse, P. M., and H. Feshbach, 1953: Methods of Theoretical Physics. McGraw-Hill,

New York.

Smith, B. T., J. M. Boyle, J. J. Dongarra, B. So Garbow, Y. Ikebe, V. C. Klema, and C. B.

Moler, 1976: Matrix Eigensystem Routines - EISPACK Guide, 2nd edition,

Lecture Notes in Computer Science, no. 6, Springer-Verlag, New York, NY.

Swarztrauber, P. N. and R. A. Sweet, 1975: Efficient FORTRAN subprograms for the

solution of elliptic partial differential equations., Technical Note TN/IA-109,

National Center for Atmospheric Research.

Swarztrauber, P. N., 1979: On the spectral approximation of discrete scalar and vector

functions on the sphere. SIAM J. Numer. Anal., 16, 934-949.

Swarztrauber, P. N., 1981: The approximation of vector functions and their derivatives

Page 32: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 32-

on the sphere. SIAM J. Numer. Anal., 18, 191-210.

Swarztrauber, P. N., 1993: The vector harmonic transform method for solving partial

differential equations in spherical geometry. Mon. Wea. Rev. 121, 3415-3437.

Swarztrauber, P. N., 1996: Spectral transform methods for solving the shallow-water

equations on the sphere. Mon. Wea. Rev., 124, 730-744.

Temperton, C., 1991: On scalar and vector transform methods for global spectral

methods. Mon. Wea. Rev., 119, 1303-1307.

Williamson, D. L., J. B. Drake, J. J. Hack, R. Jakob, and P. N. Swarztrauber, 1992: A

Standard test set for numerical approximations to the shallow-water equations in

spherical geometry. J. Comp. Phys., 102, 211-224.

Page 33: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 33

APPENDIX A

A program for solving the Helmholtz equation on the sphere. A description of the problem

is given in section (3.1).

cc

c

c output from executing the program belowc on a cray ymp and sun work station:cc helmholtz approximation on a ten degree gridc nlat = 19 nlon = 36c xlmbda = 1.00 pertrb = .00Oe+00c maximum error = 0.715e-06 *** (error on sun)c maximum error = 07114e-12 *** (error on cray ymp)c

program helmsphcc set grid size with parameter statementsc

parameter (nnlat=19,nnlon=36)cc set saved and unsaved work space lengths in terms of nnlat,nnlonc (see documentation for shaec,shsec,islapec)c

parameter (nnl5=nnlon+15)parameter (llsave=nnlat*(nnlat+1)+3*((nnlat-2)*(nnlat-1)+nnl5))parameter(llwork=(nnlat+l)*(nnlon+3*nnlat)+nnlat*(2*nnlat+l))

c

c dimension arrays

dimension u(nnlat,nnlon), r(nnlat,nnlon)dimension sint(nnlat),cost(nnlat),sinp(nnlon),cosp(nnlon)dimension work(llwork) ,wshaec (llsave) ,wshsec (llsave)dimension a(nnlat,nnlat), b(nnlat,nnlat)pi = 4,0*atan(1.0)

c

c set helmholtz constantc

xlmbda = o Occ set work space length argumentsc

lwork = 11worklshaec = llsavelshsec = llsave

c

Page 34: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 34-

c set grid size argumentsc

nlat = nnlatnlon = nnlon

c

c set sine and cosine vectorsc

dlat = pi/(nlat-1)dlon = (pi+pi)/nlondo i=l,nlattheta = -0.5*pi+(i-l)*dlatsint(i) = sin(theta)cost(i) = cos(theta)end dodo j=l,nlonphi = (j-l)*dlonsinp(j) = sin(phi)cosp(j) = cos(phi)

end doc

c set right hand side as helmholtz operatorc to ue = (l.+x*y)*exp(z)c

do j=l,nlondo i=l,nlat

x = cost(i)*cosp(j)y = cost(i)*sinp(j)z = sint(i)r(i,j) = -(x*y*(z*z+6.*(z+l.))+z*(z+2.))*exp(z)

end doend do

cc initialize saved work space arrays for scalar harmonicc analysis and Helmholtz inversion of rc

call shaeci(nlat,nlon,wshaec, lshaec,work,lwork,ierror)if (ierror .gt. 0) thenwrite (6,200) ierror

200 format(7h shaeci, lOh ierror = ,i2)call exit(0)end if

call shseci(nlat,nlon,wshsec,lshsec,work,lwork,ierror)if (ierror .gt. 0) thenwrite (6,201) ierror

201 format(7h shseci,10h ierror = ,i2)call exit(0)end if

cc set no symmetry and one arrayc

isym = 0nt = 1

c

Page 35: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 35 -

c compute coefficients of r for input to islapecc

call shaec(nlat,nlon,isym,nt,r,nlat, nlon,a,b,nlat,nlat,+ wshaec, lshaec,work, lwork, ierror)if (ierror .gt. 0) thenwrite (6,202) ierror

202 format(7h shaec ,10h ierror = ,i2)call exit(0)end if

cc solve Helmholtz equation *on the sphere in uc

write (6,100) nlat,nlon100 format(46h helmholtz approximation on a ten degree grid

+ /8h nlat = ,i3,2x,8h nlon = , i3)call islapec(nlat,nlon, isym,nt,xlmbda,u,nlat,nlon,a,b,nlat,nlat,

+ wshsec, lshsec,work, lwork,pertrb, ierror)if (ierror .ne. 0) thenwrite (6,103) ierror

103 format(8h islapec, lOh ierror = ,i2)if (ierror .gt. 0) call exit(0)end if

cc compute and print maximum error in uc

errm = 0.0do j=l,nlondo i=l,nlat

x = cost(i)*cosp(j)y = cost(i)*sinp(j)z = sint(i)ez = exp(z)ue = (1.+x*y)*ezerrm = amaxl(errm,abs(u(i,j)-ue))

end doend dowrite (6,204) xlmbda,pertrb,errm

204 format(lOh xlmbda = f5.2,2x,10h pertrb = ,elO.3,+ /17h maximum error = ,elO.3)end

Page 36: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 36-

APPENDIX B

A program for solving the time-dependent linear advection equation. A description of the

problem is given in section (3.2).

cc subroutine advec solves the time-dependent linear advection equationc for geopotential phi using the SPHEREPACK 2.0 softwarecc d(phi)/dt = -(u,v) DOT gradient(phi)cc = -(u*gdphl + v*gdpht)ccc definitions:ccc nlat number of gaussian latitudes excluding polesc nlon number of distinct longitudesc omega rotation rate of earth in radians per secondc alpha angle between axis of rotation and the coordinatec axisc beta latitude of the cosine bellc aa radius of earth in metersc ncycle cycle numberc time model time in secondsc dt time stepc lambda longitudec theta latitudecc the first dimension of the following two dimensional arraysc corresponds to the latitude index with values i=l,...,nlatc where i=1 is the northern most gaussian point thetag(i)c and i=nlat is the southern most gaussian point thetag(nlat).c the second dimension is longitude with values j=l,...,nlonc where j=l corresponds to zero longitude and j=nlon correspondsc to 2pi minus 2pi/nlon.ccc thetag(i) vector of gaussian points on the full sphere whichc have north to south orientation as i=1,.. .,nlatcc u(i,j) east longitudinal velocity componentc vi(i,j) latitudinal velocity componentcc phi(i,j) the geopotential at t = timecc phnew(i,j) the geopotential at t=time+dtcc phold(i,j) the geopotential at t=time-dtc

Page 37: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-37-

c gdphl(i,j) the longitudinal derivative component ofc the gradient of phic

c gdphl = 1/(cos(theta))*d(phi)/dlambda

c

c gdpht(i,j) the latitudinal derivative component ofc the gradient of phic

c gdpht = d(phi)/dtheta

c

c the following two dimensional arrays are nonzero in the trianglec n=l,...,nlat and m less than or equal to n.cc ar(m,n),br(m,n) spectral coefficients of phicc

program adveccc set grid size with parameter statementscc parameter (nnlat=23,nnlon=45,ddt=600.)

parameter (nnlat=45,nnlon=90,ddt=300.)c parameter (nnlat=90,nnlon=180,ddt=150.)cc set saved and unsaved work space lengths in terms of nnlat,nnlonc (see documentation for shagc,vhsgc,gradgc for estimates)c

parameter (nnl5=nnlon+15)parameter(llwork=4*nnlat*nnlon+2*nnlat*(nnlat+l))parameter (llvhsgc = 7*nnlat*nnlat+nnlon+15)parameter (llshagc = 5*nnlat*nnlat + nnlon+15)

cc dimension arraysc

dimension u(nnlat,nnlon),v(nnlat,nnlon)dimension phold(nnlat, nnlon) ,phnew(nnlat,nnlon) , phi(nnlat, nnlon)dimension pexact(nnlat,nnlon)dimension dpdt(nnlat,nnlon)dimension gdphl (nnlat,nnlon),gdpht(nnlat,nnlon)dimension work(llwork),wshagc (llshagc) ,wvhsgc (llvhsgc)dimension ar(nnlat,nnlat),br(nnlat,nnlat)dimension thetag(nnlat),colat(nnlat)double precision dtheta(nnlat),dwts(nnlat)

cc set constantsc

pi = 4.0*atan(1.0)omega = (pi+pi) / (12.*24,*3600o)pO = 1000.re = 1.0/3.0hzero = 1000oalphad = 60.

Page 38: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-38-

alpha = pi*alphad/180.beta = pi/6.

c

c set one array and no equatorial symmetryc

nt = 1isym = 0

c

c set time step depending on resolutionc

dt = ddttdt = dt+dt

c

c set work space length argumentsc

lwork = llworklshagc = llshagclvhsgc = llvhsgc

c

c set grid size argumentsc

nlat = nnlatnlon = nnlon

c

c compute nlat latitudinal gaussian points in thetag with

c north to south orientation using gaqd from SPHEREPACK 2.0

ccall gaqd(nlat,dtheta,dwts,work,lwork,ier)do i=l,nlat

thetag(i) = 0.5*pi- dtheta(i)colat(i) = dtheta(i)

end docc preset saved work spaces for gradgc and shagcc

call vhsgci(nlat,nlon,wvhsgc,lvhsgc,work,lwork,ierror)if(ierror .ne. 0) write(6,10) ierror

10 format(' error in vsgci = 'i5)call shagci(nlat,nlon,wshagc,lshagc,work,lwork,ierror)if(ierror .ne. 0) write(6,20) ierror

20 format(' error in vsgci = 'i5)cc set vector velocities and cosine bell in geopotentialc

ca = cos(alpha)sa = sin(alpha)dlon = (pi+pi)/nlondo j=l,nlonxlm = (j-1)*dlonsl = sin(xlm)cl = cos(xlm)do i=l,nlatst = cos(colat(i))ct = sin(colat(I))

Page 39: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 39-

sth = ca*st+sa*ct*clcthclh = ca*ct*cl-sa*stcthslh = ct*slxlhat = atanxy(cthclh,cthslh)clh = cos(xlhat)slh = sin(xlhat)cth = clh*cthclh+slh*cthslhuhat = omega*cthu(i,j) = (ca*sl*slh+cl*clh)*uhatv(i,j) = (ca*st*cl*slh-st*sl*clh+sa*ct*slh)*uhatend doend do

c

c compute initial geopotentialc

call gpot(0.,alpha,beta,omega,hzero,re,nlat,nlon,1 nlat,colat,phold)

p2 = 0.0pmax = 0.0do j=l,nlondo i=l,nlatphi(i,j) = phold(i,j)pmax = amaxl(abs(phold(i,j)),pmax)p2 = p2 + phi(i,j)**2end doend dop2 = sqrt(p2)

cc compute number of time steps for 12 daysc (time to circumvent the earth)c

ntime = int((12e*24.*3600.)/dt+0.5)mprint = ntime/12time - 0.0ncycle = 0do k=l,ntime+l

cc compute harmonic coefficients for phi at current timec

call shagc(nlat,nlon,isym,nt,phinlat,nlon,ar,br,nlat,+ nlat,wshagc,lshagc,work,lwork,ierror)if (ierror .ne.0) write(*,26) ierror

26 format(' ierror in shagc = 'i5)cc compute gradient of phi at current timec

call gradgc(nlat,nlon,isym,nt,gdpht,gdphl,nlat,nlon,ar,br,+ nlat, nlat,wvhsgc,lvhsgc,work, lwork,ierror)if (ierror ene.O) write(*,27) ierror

27 format(' ierror in gradgc = 'i5)cc compute the time derivative of phi, note that the signc of the last term is positive because the gradient isC computed with respect to colatitude rather than latitude.

Page 40: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 40 -

c

do j=l,nlondo i=l,nlat

dpdt(i,j) = -u(i,j)*gdphl(i,j) + v(i,j)*gdpht(i,j)end do

end doc

if (mod(ncycle,mprint) .eq. 0) thenc

c write variablesc

err2 = 0.0errm = 0.0call gpot(time,alpha,beta,omega,hzero,re,nlat,nlon,nlat,

+ colat,pexact)do j=l,nlon

do i=l,nlaterr2 = err2 + (pexact(i,j)-phi(i,j))**2errm = amaxl(abs(pexact(i,j)-phi(i,j)),errm)

end doend doerrm = errm/pmaxerr2 = sqrt(err2)/p2htime = time/3600.write(6,390) ncycle,htime,dt,nlat,nlon,omega,hzero,1 alphad, errm, err2

390 format(//' advecting cosine bell, test case 2'/1 ' cycle number ' i102 ' model time in hours ' fl0.2/3 ' time step in seconds ' f10.04 ' number of latitudes ' il0/5 ' number of longitudes ' ilO6 ' rotation rate ' lpe15.6/'7 ' mean height ' lpe15.68 ' tilt angle ' OpflO.2/9 ' max geopot. error ' lpel5.61 ' RMS geopot. error ' lpe15.6)end if

time = time + dtncycle = ncycle+l

ccc

update phold and phi for next time step

do j=l,nlondo i=l,nlat

phnew(i,j) = phold(i,j) + tdt*dpdt(i,j)phold(i,j) = phi(i,j)phi(i,j) = phnew(i,j)

end doend do

end of time loopccc

end do

Page 41: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-41-

endsubroutine gpot(t,alpha,beta,omega,hzero,re,nlat,nlon,idim,

+ colat,h)

c computes advecting cosine bell on a tilted grid a time tocc input parameterscc t time in secondscc alpha tilt angle in radianscc beta colatitude of cosine bell in untilted coordinatec system in radianscc omega angular velocity in radians per secondcc hzero maximum value of cosine bellcc re radius of support for cosine bell in radianscc nlat number of latitudes including the polescc nlon number of distinct longitude linescc idim first dimension of output array hcc colat vector of Gauss colatitude grid pointscc output parametercc h an nlat by nlon array containing the geopotentialcc on a tilted gridc

dimension h(idim,nlon),colat(nlat)real lamba,ambdc, lhatlambdc = omega*tcall stoc(l.,beta,lambdc,xc,yc,zc)ca = cos(alpha)sa = sin(alpha)pi = 4.*atan(1.)tpi = pi+pi

c dlat = pi/(nlat-l)dlon = tpi/nlondo 10 j=l,nlonlambda = (j-1)*dloncl = cos(lambda)sl = sin(lambda)do 10 i=l,nlattheta = colat(i)st = cos(theta)ct = sin(theta)sth = ca*st+sa*ct*cl

Page 42: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-42-

cthclh = ca*ct*cl-sa*stcthslh = ct*sllhat = atanxy(cthclh,cthslh)clh = cos(lhat)slh = sin(lhat)cth = clh*cthclh+slh*cthslhthat = atanxy(sth,cth)call stoc(1.,that,lhat,xl,yl,zl)dist = sqrt((xl-xc)**2+(yl-yc)**2

1 +(zl-zc)**2)h(i,j) = 0.if(dist .ge. re) go to 10r = 2.*asin(dist/2.)if(r .ge. re) go to 10h(i,j) = hzero*.5*(cos(r*pi/re)+l.)

10 continuereturnendfunction atanxy(x,y)atanxy = 0.if(x.eq.0. .and. y.eq.0.) returnatanxy = atan2(y,x)returnendsubroutine ctos(x,y,z,r,theta,phi)rl = x*x+y*yif(rl .ne. 0.) go to 10phi = 0.theta = 0..if(z .lt. 0.) theta = 4.*atan(1.)return

10 r = sqrt(rl+z*z)rl = sqrt(rl)phi = atan2.(y,x)theta = atan2(rl,z)returnendsubroutine stoc(r,theta,phi,x,y,z)st = sin(theta)x = r*st*cos(phi)y = r*st*sin(phi)z = r*cos(theta)returnend

ccc output from the code listed abovecc

advecting cosine bell, test case 2cycle number 0 model time in hours 0.00time step in seconds 300. number of latitudes 45number of longitudes 90 rotation rate 6.060171E-06

Page 43: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-43 -

mean heightmax geopot. error

1.000000E+03 tilt angle0EOOOOOOE+00 RMS geopoto error

60.00.O000000E+00

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

test case 2288

300.90

1.00000OE+037 .868629E-03

test case 2576

300.90

1. 0000E+035 851913E-03

model time in hoursnumber of latitudesrotation ratetilt angleRMS geopot. error

model time in hoursnumber of latitudesrotation ratetilt angleRMS geopot. error

test case 2864 model time in hours

300. number of latitudes90 rotation rate

loOOOOOOE+03 tilt angle5.595739E-03 RMS geopoto error

test case 21152 model time in hours300. number of latitudes

90 rotation rateloOOOOOOE+03 tilt angle5.587526E-03 RMS geopot. error

test case 21440 model time in hours300. number of latitudes

90 rotation rate1.000000E+03 tilt angle6.464275E-03 RMS geopot. error

test case 21728 model time in hours300. number of latitudes

90 rotation rate1.0000OE+03 tilt angle5.017628E-03 RMS geopoto error

24.0045

6.060171E-0660.00

9.232500E-03

48.0045

6.060171'E-0660.00

9.505491E-03

72.0045

6.060171E-0660.00

9.376185E-03

96.0045

6.060171E-0660.00

1.029551E-02

120.0045

6. 060171E-0660.00

1.142673E-02

144.0045

6.060171E-0660.00

1.045407E-02

advecting cosine bell,cycle number

test case 22016 model time in hours 168.00

Page 44: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-44 -

time step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

300.90

1.000000E+035.499706E-03

test case 22304300.

901.000000E+035.575483E-03

number of latitudesrotation ratetilt angleRMS geopot. error

model time in hoursnumber of latitudesrotation ratetilt angleRMS geopot. error

456.060171E-06

60.001.124255E-02

192.0045

6.060171E-0660.00

1.036771E-02

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

advecting cosine bell,cycle numbertime step in secondsnumber of longitudesmean heightmax geopot. error

test case 22592 model time in hours300. number of latitudes

90 rotation rate1.000000E+03 tilt angle5.816972E-03 RMS geopot. error

test case 22880 model time in hours300. number of latitudes

90 rotation rate1.000000E+03 tilt angle6.341717E-03 RMS geopot. error

test case 23168 model time in hours300. number of latitudes

90 rotation rate1.000000E+03 tilt angle6.575711E-03 RMS geopot. error

test case 23456 model time in hours300. number of latitudes

90 rotation rate1.000000E+03 tilt angle2.702806E-04 RMS geopot. error

216.0045

6.060171E-0660.00

9.410505E-03

240.0045

6.060171E-0660.00

9.560002E-03

264.0045

6.060171E-0660.00

9.404644E-03

288.0045

6.060171E-0660.00

3.466496E-04

Page 45: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-45 -

APPENDIX C

A program for solving the time-dependent non-linear shallow-water equations. A descrip-

tion of the problem is given in section (3.3). Output follows the code.

program shallowcc the nonlinear shallow-water equations on the sphere arec solved using a spectral method based on the sphericalc vector harmonics. the method is described in the paper:cc [1] p. n. swarztrauber, spectral transform methods for solvingc the shallow-water equations on the sphere, p.n. swarztrauber,c monthly weather review, vol. 124, no. 4, april 1996, pp. 730-744.cc this program implements test case 3 (steady nonlinear rotated flow)c in the paper:cc [2] d.l. williamson, j ob drake, j.j. hack, r. jakob, andc p.n. swarztrauber, j. comp. phys., a standard test setc for numerical approximations to the shallow-waterc equations in spherical geometry, j. comp. phys.,c vol. 102, no. 1, sept. 1992, pp. 211-224.cc definitions:ccc nlat number of latitudes including polesc nlon number of distinct longitudesc mmode max wave numberc omega rotation rate of earth in radians per secondc aa radius of earth in metersc pzero mean height of geopotentialc uzero maximum velocityc alpha tilt angle of the rotated gridc ncycle cycle numberc time model time in secondsc dt time stepc lambda longitudec theta colatitudecc the first dimension of the following two dimensional arraysc corresponds to the latitude index with values i=l,...,nlatc where i=l is the north pole and i=nlat is the south pole.c the second dimension is longitude with values j=l,...,nlonc where j=l corresponds to zero longitude and j=nlon correspondsc to 2pi minus 2pi/nlon.cc u(i,j) east longitudinal velocity component at t=timec v(i,j) latitudinal velocity component at t=timec p(i,j) +pzero = geopotential at t=time

Page 46: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-46 -

unew(i, j)vnew(i, j)pnew(i,j)

uold(i,j)vold(i,j)pold(i,j)

divg (i, j)

vort (i,j)

ut(i,j)

vt(i,j)

dudt(i,j)dvdt (i, j)dpdt (i, j)

gpdl(i, j)

gpdt(i, j)

uxact(i,j)vxact(i,j)uxact(i,j)

f(i,j)

east longitudinal velocity component at t=time+dtlatitudinal velocity component at t=time+dt+pzero = geopotential at t=time+dt

east longitudinal velocity component at t=time-dtlatitudinal velocity component at t=time-dt+pzero = geopotential at t=time-dt

divergence (d/dtheta (cos(theta) v)+ du/dlambda)/cos (theta)

vorticity (d/dtheta (cos(theta) u)- dv/dlambda)/cos(theta)

latitudinal derivative of longitudinalvelocity componentlatitudinal derivative of latitudinalvelocity component

time derivative of longitudinal velocity componenttime derivative of latitudinal velocity componenttime derivative of geopotential

first component of the gradient of p(i,j)the longitudinal derivative of the geopotentialdivided by the cosine of the latitude

second component of the gradient of p(i,j)the latitudinal derivative of the geopotential

the "exact" longitudinal veloctiy componentthe "exact" latitudinal veloctiy componentthe "exact" geopotential

the coriolis force on rotated grid

c the following two dimensional arrays are nonzero in the trianglec n=l,...,nlat and m less than or equal to n.

a(m,n) ,b(m,n)

br(m,n) ,bi(m,n)cr (m,n), ci (m,n)

spectral coefficients of the geopotential

spectral coefficients of the velocityvector [u(i,j),v(i,j)]

.phlt(i) the coefficients in the cosine seriesrepresentation of the unrotated geopotential

parameter (idp=73, jdp=144, mdab=73,ndab=73 )

dimension u(idp,jdp),v(idp, jdp) ,p(idp, jdp) ,f(idp,jdp),1 unew(idp, jdp) ,vnew(idp, jdp) ,pnew(idp, jdp) ,2 uold(idp, jdp), vold(idp, jdp) , pold(idp, jdp) ,3 uxact(idp,jdp),vxact(idp,jdp),pxact(idp,jdp),

C

C

C

c

C

C

C

C

C

C

C

C

c

C

C

C

C

c

c

c

c

c

c

c

c

c

c

c

c

c

c

c

c

cc

C

cccccccccc

cC

Page 47: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-47 -

4 divg (idp, jdp) , vort (idp, jdp) , ut (idp, jdp) ,5 vt (idp, jdp) , dudt (idp, jdp) , dvdt (idp, jdp) ,6 dpdt (idp, jdp) ,gpdt (idp, jdp) ,gpdl (idp, jdp) ,7 a(mdab,ndab), b(mdab,ndab) ,br (mdab,ndab),8 bi(mdab,ndab),cr(mdab,ndab),ci(mdab,ndab),9 phlt(361)

c

c the following work arrays are initialized and subsequentlyc used repeatedly by spherepack (2.0) routines.c

dimension wsha(70928),wshs(70928) ,wvha(141647),wvhs(141647),1 wvts(141647),work(40000)

c

real lambda,lhat

lwsha = 70928lwshs = 70928lwvha = 141647lwvhs = 141647lwvts = 141647Iwork = 40000

c

pi = 4.*atan(l,)hpi = pi/2.dtr = pi/180.aa = 6.37122e6omega = 7.292e-5fzero = omega+omegauzero = 40.pzero = 2.94e4alphad = 60.alpha = dtr*alphad

c

itmax = 720mprint = 72mmode = 42nlat = 65nlon = 128dt = 600.tdt = dt+dt

cc initialize spherepack 2.0 routinesc

call shaesi(nlat,nlon,wsha,lwsha,work, lwork,ierror)if(ierror .ne. 0) write(*,55) ierror

55 format(' error' i4 ' in shaesi')call shsesi(nlat,nlon,wshs,lwshs,work, lwork,ierror)if(ierror .ne. 0) write(*,56) ierror

56 format(' error' i4 ' in shsesi')call vhaesi(nlat,nlon,wvha, lwvha,work,lwork,ierror)if(ierror .ne. 0) write(*,57) ierror

57 format(' error' i4 ' in vhaesi')call vhsesi (nlat, nlon,wvhs, lwvhs,work, lwork, ierror)if(ierror .ne. 0) write(*,58) ierror

Page 48: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-48-

58 format(' error' i4 ' in vhsesi')call vtsesi(nlat,nlon,wvts,lwvts,work, work,ierror)if(ierror .ne. O) write(*,59) ierror

59 format(' error' i4 ' in vtsesi')c

c

c compute the derivative of the unrotated geopotentialc p as a function of latitudec

nl = 91nlml = nl-1nlm2 = nl-2cfn = 1./nlmldlath = pi/nlmldo 10 i=l,nlm2theta = i*dlathsth = sin(theta)cth = cos(theta)uhat = ui(uzero,hpi-theta)phlt(i) = cfn*cth*uhat*(uhat/sth+aa*fzero)

10 continuecc compute sine transform of the derivative of the geopotentialc for the purpose of computing the geopotential by integrationc see equation (3.9) in reference [1] abovec

call sine(nlm2,phlt,work)cc compute the cosine coefficients of the unrotated geopotentialc by the formal integration of the sine series representationc

do 12 i=l,nlm2phlt(i) = -phlt(i)/i

12 continuecc phlt(i) contains the coefficients in the cosine seriesc representation of the unrotated geopotential that are usedc below to compute the geopotential on the rotated grid.

cc compute the initial values of east longitudinalc and latitudinal velocities u and v as well as thec geopotential p and coriolis f on the rotated grid.c

ca = cos(alpha)sa = sin(alpha)dtheta = pi/(nlat-1)dlam = (pi+pi)/nlondo 50 j=l,nlonlambda = (j-l)*dlamcl = cos(lambda)sl = sin(lambda)do 50 i=l,nlat

cc lambda is longitude, theta is colatitude, and pi/2-theta is

Page 49: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-49-

c latitude on the rotated grid. lhat and that are longitudec and colatitude on the unrotated grid. see text starting atc equation (3.10)c

theta = (i-l)*dthetast = cos(theta)ct = sin(theta)sth = ca*st+sa*ct*clcthclh = ca*ct*cl-sa*stcthslh = ct*sllhat = atanxy(cthclh,cthslh)clh = cos(lhat)slh = sin(lhat)cth = clhcththclh+slh*cthslhthat = atanxy(sth,cth)uhat = ui(uzero,hpi-that)pxact(ij) = cosine(that,nlm2,phlt)uxact(i,j) = uhat*(ca*sl*slh+cl*clh)vxact(i,j) = uhat*(ca*cl*slh*st-clh*sl*st+sa*slh*ct)f(i,j) = fzero*sth

50 continuec

vmax = 0.pmax = 0.v2max = 0.p2max = 0.do 54 j=l,nlondo 54 i=l,nlatv2max = v2max+uxact(i,j)**2+vxact(i,j)**2p2max = p2max+pxact(i,j)**2vmax = amaxl(abs(uxact(i,j)),abs(vxact(i,j)),vmax)pmax = amaxl(abs(pxact(i,j)),pmax)

54 continuec

c initialize first time stepc

do 60 j=l,nlondo 60 i=l,nlatu(i,j) = uxact(i,j)v(i,j) = vxact(i,j)p(i,j) = pxact(i,j)

60 continuec

isym = 0nt = 1time = 0.ctime = 0.ncycle = 0

c

c start of the time loopc

c begin step 1, section 3cc analyze the velocity components (u/v)

Page 50: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-50-

c

90 call vhaesgo(nlat,nlon,isym,nt,u,v,idp,jdp,br,bi,cr,ci,1 mdab,ndab,wvha,lwvha,work,lwork,ierror)if(ierror .ne. 0) write(*,91) ierror

91 format(' error' i4 ' in vhaes')c

c truncate spectrum to eliminate aliasing of the

c product terms in the shallow-water equationsc

call trunc(nlat,mmode,mdab,br,bi)call trunc(nlat,mmode,mdab,cr,ci)

cc resynthesize the velocity componentsc

call vhsesgo(nlat,nlon,isym,nt,u,v,idp, jdp,br,bi,cr,ci,1 mdab,ndab,wvhs, lwvhs,work, lwork,ierror)if(ierror .ne. O) write(*,92) ierror

92 format(' error' i4 ' in vhses')

c begin step 2, section 3cc analyze geopotential pc

call shaes(nlat,nlon,isym,nt,p,idp,jdp,a,b,mdab,ndab,1 wsha, wsha,work, work, ierror)if(ierror .ne. 0) write(*,93) ierror

93 format(' error' i4 ' in shaes')cc truncate spectrum to eliminate aliasing of the

c product terms in the shallow-water equationsc

call trunc(nlat,mmode,mdab, a,b)

c resynthesize the geopotential pc

call shses(nlat,nlon,isym,nt,p,idp,jdp,a,b,mdab,ndab,1 wshs, lwshs,work,lwork,ierror)if(ierror .ne. O) write(*,94) ierror

94 format(' error' i4 ' in shses')ccc begin step 3, section 3cc compute the vorticity of the velocity (u,v)c

call vrtes'(nlat,nlon,isym,nt,vort,idp,jdp,cr,ci,mdab,ndab,1 wshs, lwshs,work, lwork, ierror)if(ierror .ne. 0) write(*,95) ierror

95 format(' error' i4 ' in vrtes')cc compute the divergence of the velocity (u,v)

ccall dives(nlat,nlon,isym,nt,divg,idp,jdp,br,bimdab,ndab,1 wshs, lwshs,work, lwork,ierror)

Page 51: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-51-

if(ierror .ne. 0) write(*,96) ierror96 format(' error' i4 ' in dives')

begin step 4, section 3

compute the derivative of the velocity (u,v) withrespect to colatitude theta.

call vtsesgo(nlat,nlon,isym,nt,ut,vt,idp,jdp,br,bi,cr,ci,1 mdab,ndab,wvts,lwvts,work, work,ierror)if(ierror .ne. 0) write(*,97) ierror

97 format(' error' i4 ' in vtsesgo')

begin step 5, section 3

compute the gradient of the geopotential p

call gradesgo(nlat,nlon,isymnt,gpdl,gpdt,idp,jdp,a,b,mdab,ndab,lwvhs, lwvhs,work, work,ierror)if(ierror .ne. 0) write(*,98) ierror

98 format(' error' i4 ' in grades')

compute the time derivatives of the velocity (u,v)and the geopotential p using the shallow-waterequations (2.8), (2.9), and (2.10), section 3.

do 200 j=l,nlondo 200 i=l,nlatdudt(i,j) = (u(i,j)*(vt(i,j)-divg(i,j))-v(i,j)*ut(i,j)

[L -gpdl (i,j))/aa+f(i,j) *v(i,j)dvdt(i,j) = (u(i,j)*(vort(i,j)+ut(i,j) )+v(i,j)*vt(i,j)

L +gpdt(i,j))/aa-f(i,j)*u(i,j)dpdt(i,j) = -((p(i,j)+pzero)*divg(i,j)+v(i,j)*gpdt(i,j)L +u (i, j)*gpdl(i,j))/aa

200 continue

if(mod(ncycle,mprint) .ne. 0) go to 370htime = time/3600.write(*,390) ncycle,htime,dt,nlat,nlon,mmode,omega,pzero,1 uzero,alphad

390 format(//' steady nonlinear rotated flow, test case 3'/1 ' cycle number ' ilO2 ' model time in hours ' fl0.2/3 ' time step in seconds ' flO.O4 ' number of latitudes ' ilO/5 ' number of longitudes ' ilO6 ' max wave number ' ilO/7 ' rotation rate ' lpel5.68 ' mean height ' lpel5.6/9 ' maximum velocity ' lpel5.61 ' tilt angle ' flO.2)dvgm = 0.dvmax = 0.dpmax = 0.

cccccc

ccccc

ccccc

c

3

I

. I

Page 52: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 52 -

evmax = 0.0epmax = 0.0do 217 j=l,nlondo 217 i=l,nlatdvgm = amaxl(dvgm,abs(divg(i,j)))dvmax = dvmax+(u(i,j)-uxact(i,j))**2+(v(i,j)-vxact(i,j))**2dpmax = dpmax+(p(i,j)-pxact(i,j))**2evmax = amaxl(evmax,abs(v(i,j)-vxact(i,j)),abs(u(i,j)-uxact(i,j)))epmax = amaxl(epmax,abs(p(i,j)-pxact(i,j)))

217 continuedvmax = sqrt(dvmax/v2max)dpmax = sqrt(dpmax/p2max)evmax = evmax/vmaxepmax = epmax/pmaxwrite(*,391) evmax,epmax,dvmax,dpmax,dvgm

391 format(' max error in velocity' lpel5.6+ ' max error in geopot. ' lpel5.6/+ '12 error in velocity ' lpel5.6+ ' 12 error in geopot. ' lpel5.6/+ ' maximum divergence ' lpel5.6)

cc set values at time = -dt to values at time = 0.c

370 if(ncycle .gt. 0) go to 206do 205 j=l,nlondo 205 i=l,nlatuold(i,j) = u(i,j)vold(i,j) = v(i,j)pold(i,j) = p(i,j)

205 continuecc compute values at next time level using leap frogc time differencingc

206 do 210 j=l,nlondo 210 i=l,nlatunew(i,j) = uold(i,j)+tdt*dudt(i,j)vnew(i,j) = vold(i,j)+tdt*dvdt(i,j)pnew(i,j) = pold(i,j)+tdt*dpdt(i,j)

210 continueCc update values to next time levelc

do 300 j=l,nlondo 300 i=l,nlatuold(i,j) = u(i,j)vold(i,j) = v(i,j)pold(i,j) = p(i,j)u(i,j) = unew(i,j)v(i,j) = vnew(i,j)p(i,j) = pnew(i,j)

300 continuencycle = ncycle+ltime = time+dt

Page 53: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-53-

if(ncycle ,leo itmax) go to 90end

subroutine vtsesgo(nlat,nlon,ityp,nt,ut,vt,idvw,jdvw,br,bi,cr,ci,1 mdab,ndab,wvts,lwvts,work, work,ierror)

c

c vtsesgo computes the latitudinal derivatives of thec velocity components using subroutine vtses whichc assumes the velocity components are given in termsc of mathematical coordinatesc

dimension ut(idvw,jdvw, 1) ,vt(idvw,jdvw,1),br(mdab,ndab, 1),1 bi(mdab,ndab,1),cr(mdab,ndab,1),ci(mdab,ndab,1),2 work(*),wvts(*)call vtses(nlat, nlon, ityp,nt,vt,ut,idvw, jdvw,br,bi,cr,ci,

1 mdab,ndab,wvts, lwvts,work, lwork,ierror)do k=l,nt

do j=l,nlondo i=l,nlatut(i,j,k) = -ut(i,j,k)

end doend doend doreturnend

cfunction ui(amp,thetad)

cc computes the initial unrotated longitudinal velocityc see section 3 3oc

pi=4. atan(lo)thetab=-pi/6thetae= pi/2.xe=3 .e-lx =xe* (thetad-thetab) /(thetae-thetab)ui = 0.if(x.leo0 .or. x.ge.xe) returnui=amp*exp(-1 /x-l / (xe-x)+4./xe)returnend

c

function atanxy(x,y)atanxy = 0.if(x.eq.0 .and. y.eq.0.) returnatanxy = atan2(y,x)returnendsubroutine sine(n,x,w)

cc computes the sine transform

dimension x(n),w(n)arg = 4.*atan(1.)/(n+l)

Page 54: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 54-

do 10 j=l,nw(j) = 0.do 10 i=l,nw(j) = w(j)+x(i)*sin(i*j*arg)

10 continuedo 15 i=l,nx(i) = 2.*w(i)

15 continuereturnend

cfunction cosine(theta,n,cf)

cc computes the cosine transformc

dimension cf(n)cosine = 0.do 10 i=l,ncosine = cosine+cf(i)*cos(i*theta)

10 continuereturnend

csubroutine trunc(nm,ms,id,a,b)

cc truncates spectral coefficients so that aliasingc does not occur when computing the spectral representationsc of the product terms.c

dimension a(id,1),b(id,1)mp = ms+2do 10 n=mp,nmdo 10 m=l,na(m,n) = 0.b(m,n) = 0,

10 continuereturnend

subroutine vhaesgo(nlat,nlon, ityp,nt,u,v,iduv,jduv,+br,bi,cr,ci,mdab,ndab,wsav, lwsav,work, lwork,ierror)dimension u(iduv,jduv,*),v(iduv,jduv,*),br(mdab,ndab,*),

+ bi(mdab,ndab,*),cr(mdab,ndab,*),ci(mdab, ndab,*),2 work(1),wsav(l)

cc vhaesgo computes the vector harmonic analysis of (u,v) using vhaes whichc assumes the velocity components are given in mathematical coordinatesc

do k=l,ntdo j=l,nlon

do i=l,nlatv(i,j,k) = -v(i,j,k)

end doend do

Page 55: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 55 -

end docall vhaes(nlat,nlon, ityp,nt,v,u, iduv, jduv,+br,bi,cr,ci,mdab,ndab,wsav, lwsav,work, lwork, ierror)

c

C restore vc

do k=l,ntdo j=l,nlon

do i=l,nlatv(i,j,k) = -v(i,j,k)

end doend do

end doif (ierrorone.O) returnreturnend

subroutine vhsesgo(nlat,nlon,ityp,nt,u,v,iduv,jduv,+br,bi,cr,ci,mdab, ndab,wsav, lwsav,work, lwork, ierror)dimension u(iduv,jduv,*),v(iduv,jduv,*),br(mdab,ndab, *),

+ bi(mdab,ndab,*) ,cr(mdab,ndab,*) ,ci(mdab,ndab,*) ,2 work (),wsav(1)

c

c vhsesgo computes a vector harmonic synthesis in (u,v) using vhses whichc assumes the velocity components are given in mathematical coordinatesc

call vhses(nlat,nlon,ityp,nt,v,u,iduv,jduv,+br,bi,cr,ci,mdab,ndab,wsav, lwsav,work, lwork,ierror)if (ierror.ne.O) returndo k=l,nt

do j=1,nlondo i=l,nlatv(ij,k) = -v(i,j,k)

end doend doend doreturnend

subroutine gradesgo(nlat,nlon,isym,nt,u,v,iduv,jduv,a,b,+mdab,ndab,wsav, lwsav,work, lwork,ierror)dimension u(iduv, jduv,nt) ,v(iduv jduv,nt)dimension a(mdab,ndab,nt),b(mdab,ndab,nt)dimension wsav(lwsav) ,work(lwork)

c

c gradesgo computes the. gradient in (u,v) using grades which assumesc the velocity components are given in mathematical coordinatesc

call grades(nlat,nlon,isym,nt,v,u,iduv,jduv,a,b,+mdab, ndab,wsav, lwsav,work, lwork, ierror)if (ierror .ne.O) returndo k=l,nt

do j=l;,nlondo i=l,nlat

Page 56: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 56-

v(i,j,k) = -v(i,j,k)end do

end doend doreturnend

c

c

c output from the code listed abovec

csteady nonlinear rotated flow, test case 3cycle number 0 model time in hours

time step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt angle

max error in velocity 1.282242E-07 max error in geopot.

12 error in velocity 6.740759E-08 12 error in geopot.maximum divergence 2.449165E-09

steady nonlinear rotated flow, test case 3cycle number 72 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt anglemax error in velocity 1.277154E-07 max error in geopot.12 error in velocity 6.742625E-08 12 error in geopot.maximum divergence 1.279898E-05

steady nonlinear rotated flow, test case 3cycle number 144 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave number.rotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt anglemax error in velocity 1.277748E-07 max error in geopot.

12 error in velocity 6.742359E-08 12 error in geopot.

maximum divergence 3.055318E-06-

steady nonlinear rotated flow, test case 3cycle number 216 model time in hours

time step in seconds 600. number of latitudes

number of longitudes 128 max wave number

rotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt angle

max error in velocity 1.277752E-07 max error in geopot.

12 error in velocity 6.743588E-08 12 error in geopot.

maximum divergence 1.235478E-05

0.006542

2.940000E+041.047198E+001.755338E-083.003702E-09

12.006542

2.940000E+041.047198E+002.618623E-083.584620E-09

24.006542

2.940000E+041.047198E+002.714583E-084.110956E-09

36.006542

2.940000E+041.047198E+002.578312E-083.437655E-09

Page 57: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

-57-

steady nonlinear rotated flow, test case 3cycle number 288 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt anglemax error in velocity 1.281757E-07 max error in geopot.12 error in velocity 6746247E-08 12 error in geopot.maximum divergence 2.493223E-05

steady nonlinear rotated flow, test case 3cycle number 360 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.OOOOOOE+01 tilt anglemax error in velocity 1.277949E-07 max error in geopot.12 error in velocity 6.745876E-08 12 error in geopot.maximum divergence 6.740834E-06

steady nonlinear rotated flow, test case 3cycle number 432 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt anglemax error in velocity 1.278225E-07 max error in geopoto12 error in velocity 6.747434E-08 12 error in geopot.maximum divergence 2.461883E-05

steady nonlinear rotated flow, test case 3cycle number 504 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.OOOOOOE+01 tilt anglemax error in velocity 1.277342E-07 max error in geopoto12 error in velocity 6.748779E-08 12 error in geopot.maximum divergence 2.853471E-05

steady nonlinear rotated flow, test case 3cycle number 576 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt anglemax error in velocity 1o280315E-07 max error in geopot.12 error in velocity 6.748012E-08 12 error in geopot.maximum divergence 4.963562E-06

48.006542

2.940000E+041.047198E+002.941151E-083.754395E-09

60.006542

2o940000E+041.047198E+002 921763E-084.548691E-09

72.006542

2.940000E+041.047198E+003.486083E-084.222247E-09

84.006542

2.940000E+041.047198E+003.884087E-084.488104E-09

96.006542

2.940000E+041.047198E+002.795369E-085.099854E-09

Page 58: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

- 58-

steady nonlinear rotated flow, test case 3cycle number 648 model time in hourstime step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt anglemax error in velocity 1.279363E-07 max error in geopot.12 error in velocity 6.746955E-08 12 error in geopot.maximum divergence 1.109072E-05

steady nonlinear rotated flow, test case 3cycle number 720 model time in hours

time step in seconds 600. number of latitudesnumber of longitudes 128 max wave numberrotation rate 7.292000E-05 mean heightmaximum velocity 4.000000E+01 tilt anglemax error in velocity 1.276961E-07 max error in geopot.

12 error in velocity 6.747544E-08 12 error in geopot.maximum divergence 2.767553E-05

108.006542

2.940000E+041.047198E+003.499742E-084.819337E-09

120.006542

2.940000E+041.047198E+004.370070E-085.006913E-09

Page 59: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

Figure 1. Re[Y 2 (X,0)] =P fP (O)cos6X on an equally spaced latitudinal grid

Page 60: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

Figure 2. Re[YP 2 (X,0)] =P P ()cos6X on a Gaussian spaced latitudinal grid

Page 61: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

Figure 3. Re[Y 2(k,,)] =P 2 (O)cos6)k on an icosahedral Geodesic grid.

Page 62: SPHEREPACK 2.0 : a model development facility297...SPHEREPACK 2.0 is a collection of FORTRAN programs that facilitates the develop-ment of computer models of geophysical processes

Figure 4. Cosine bell at 30 degrees north latitude, example 2.