>>>> install spectra tool and spherepack 3.2 library with pgf90 or ifort
(g95,gfortran... not  possible yet)

wget -c https://www2.cisl.ucar.edu/sites/default/files/spherepack3.2.tar
tar -xvf spherepack3.2.tar
cd spherepack3.2

>>>> install spherepack 3.2 library
>for pgf90, after discussion with Richard A. Valent (valent@ucar.edu), change line 12 of make.inc in spherepack3.2 folder:
  F90 := pgf90 -module ../lib -I../lib
and replace by
  F90 := pgf90 -r8 -module ../lib -I../lib
to run in double precision (better).

>for ifort:
change line 10 to 20 of make.inc
  ifeq ($(PGI),pgf90-Warning-No files to process)

    F90 := pgf90 -module ../lib -I../lib
    CPP := pgf90 -E

  else

    F90 := g95 -DG95 -g -fmod=../lib -I../lib 
    CPP := g95 -E -DG95

  endif
and replace by
  F90 := ifort -r8 -module ../lib -I../lib
  CPP := ifort -fpp
change line 16 of test/Makefile
	$(F90) $< -o $@ -L../lib -l spherepack
and replace by
	$(F90) $< -o $@ -L../lib -lspherepack
	

> make all > log_install 2>&1

> OK 'lib' ,... are in /planeto/milmd/library/spherepack/spherepack3.2_levan_pgf90


>>>> compile spectra_analysis program with pgf90 or ifort

cd ..

change the first 3 lines of the makefile: path of spherepack library you have just installed, path of netcdf libray, compiler
netcdfpath=/planeto/milmd/library/netcdf/netcdf-4.0.1_levan_pgf90 (on levan)
netcdfpath=/smplocal/pub/NetCDF/4.1.3/seq (on ada)
netcdfpath=/usr/local (on gnome)
spherepackpath=/path/to/spherepack3.2
FC=pgf90 or ifort

for some machine, may load netcdf module:
module load netcdf

for ciclad machine, if using netcdf4:
in makefile change line 7
LDFLAGS=-L${netcdfpath}/lib -lnetcdf -L${spherepackpath}/lib -lspherepack
and replace by
LDFLAGS=-L${netcdfpath}/lib -lnetcdf -lnetcdff -L${spherepackpath}/lib -lspherepack 

make spectra_analysis

>>>>> test on some harmonic cases

> compile test program
make test_harmonic

> create harmonic winds
./test_harmonic

>>>>> some examples

> compute kinetic energy spectrum for one harmonic test file

./spectra_analysis harmonic_64x48_lmdz_22.nc -alt none -time none -o harmonic_64x48_lmdz_22_spectra

output file harmonic_64x48_lmdz_22_spectra contains:
first column -> harmonic numbers 
second column -> amplitude of harmonic component, here only component 22 is non zero.


> compute kinetic energy spectrum with temporal and vertical mean

./spectra_analysis diagfi.nc -t 5 -mt 10 -z 15 -mz 2 -o spectra

compute kinetic energy spectrum for t=5,6,...,15 and z=15,16,17 and average all spectra obtained.


> compute divergence and rotational part of kinetic energy spectrum

./spectra_analysis diagfi.nc -t 5 -z 15 -o spectra -divrot

in spectra file, will find the rotationnal and divergent part of the decomposition of the velocity on the vectorial spherical harmonic basis:
#Spherical  diagfi.nc                                         
#wavenumber t=  150 z=    1                                   
#           spec_tot        spec_div        spec_rot          
    0       0.000000E+00    0.000000E+00    0.000000E+00     
    1       0.119347E+01    0.101938E+01    0.174095E+00     
    2       0.530388E+00    0.250037E+00    0.280350E+00     
    3       0.106973E+01    0.589848E+00    0.479880E+00     
...


>>>>> output interpretation

One can plot velocity projection against spherical wavenumber with gnuplot for instance.
In geostrophic turbulence, a n^-3 slope must appear for wavenumber n=1..100(?) and a n^-(5/3) slope for higher n.


>>>>> reference
J. N. Koshyk, 2001, The Horizontal Kinetic Energy Spectrum and Spectral Budget Simulated by a High-Resolution Troposphere–Stratosphere–Mesosphere GCM






