Log In | Users | Register
Edit | Attach | New | Raw | Diff | Print | | Tools
You are here: Data » DocTools » ToolsVis » VisNCL » VisNCLCosmoLibraryDoc

COSMO Library

This page contains the documentation of the COSMO library. It provides a set of NCL scripts that make analysing and plotting COSMO model output easier.

Introduction

The COSMO Library is a set of NCL scripts which should facilitate the the reading and plotting of the COSMO model output. Note that it works both for grib and NetCDF output. It actually also works for ECMWF and several other models and can greatly reduce your "time to plot" if you simply want to produce some standard plots. All main library commands start with the abbreviation jmb_. The libary consists of commands for reading and deriving atmospheric data fields( jmb_getvar, jmb_getgrid), for extraction 2-dimensional data slices ( jmb_slice), and for plotting the data slice with an underlying geographical map ( jmb_map, jmb_contour, jmb_geography, jmb_overlays). It also supplies a set of useful utility scripts and defines a set of useful constants.

In the standard installation of NCL at CSCS, the COSMO Library is automaticall loaded. This is acknowledged via a short message stating "COSMO Library Version 0.4 loaded" with the appropriate version number of the installation.

A typical script using the COSMO Library to make a simple contour plot would look like this

begin
  f = addfile("lm_fine/lfff00210000.grb", "r")    ; open file
  c = addfile("lm_fine/lfff00000000c.grb", "r")   ; open constants file
  p = jmb_getvar(f, "P", False)                     ; get pressure field
  jmb_getgrid(f, c, p, False)                       ; get grid attributes for field
  wks = gsn_open_wks("pdf", "pressure")             ; open PDF file pressure.pdf
  rc = jmb_set_ct(wks, "perc_11lev", False)         ; set color table
  rc@cnLevels = (/1,2,3,4,5,6,7,8,9,10,11/)*10000.0 ; set color scale values
  s = jmb_slice(p, "lat", 47.0, False)              ; vertical slice of pressure field at lat=47N
  cn = jmb_contour(wks, s, rc)                      ; make a filled contour plot
  plt = jmb_overlays(wks, (/cn/), False)            ; compose plot and draw it
  delete(wks)                                       ; close graphic port
end

jmb_getvar

Function to read a variable from a COSMO model output file in grib1 format.

Prototype

function jmb_getvar( f:file, name:string, opt:logical )

Arguments

f A file variable as returned by addfile corresponding to a COSMO grib1 output file
name A string specifying the variable to read
opt A variable containing an optional list of resources, attached as attributes

Description

This function read a variable from a file previously opened using the addfile command. The file must correspond to the grib1 format written by the COSMO model. It is possible to read a Trash.NetCDF file which has previously been converted from the grib1 format using the ncl_convert2nc command. The Trash.NetCDF format written by the COSMO model is currently not supported. The variable to read can be specified in one of the following ways

Specification Example Description
Name "P_GDS10_HYBY" The name of the variable as it is present in the file f. Use printVarSummary(f) to inspect the variables present in the file.
Wildcard "P_*_HYBY" A name containing a wildcard character. There must be a unique match in the file f.
Grib Key "P" A grib key as specified in the operational grib key file (c.f. ~osm/opr/lib/grib_keys_cosmo.txt).
Derived "theta" A variable which has to be computed from other variables present in the file (e.g. potential temperature "theta"). It is conventional to write derived variables in smallcaps.

Usually, it is sufficient to use the grib key specification to access a certain variable. If you have variables which are not present in the operational grib keys file or need more precise control over the variable you want to access, you will most probably use the exact name of the variable. The naming convections for grib1 variables in NCL are rather involved. For example, the variable ASOB_GDS10_SFC_ave24h corresponds to the average surface net downward shortwave radiation (ASOB, i.e. grib table 10, parameter number 111), is defined on a rotated lat/lon grid (GDS10, i.e. grid type 10), is a surface field (SFC, i.e. level indicator 1) and has been averaged over 24 hours (ave24h). For a complete documentation of the naming convention, check out the NCL grib1 format support page.

A variable read using jmb_getvar does not only contain the values, but also has a set of attached attributes (just like in the Trash.NetCDF data model) which contain information about the name, the units, the fill value, the grid and the validity time of the field. To inspect all the attributes of a field read by jmb_getvar try printVarSummary(var) in an interactive NCL session or a script.

The derived variables that can be computed via a call to jmb_getvar are listed in the table below.

Name Dependencies Formula
 rho 
 P T QV QC QI QR QS QG 
 P/(r_d*T*(1.0+rvd_m_o*QV-QC-QI-QR-QS-QG)) 
 theta 
 P T 
 T*(p0/P)^(r_d/cp_d) 
 thetae 
 P T QV 
 theta*exp(lh_v/cp_d*QV/(1-QV)/T) 
 esat 
 P T 
 b1*exp(b2w*(T-b3)/(T-b4w) 
 relhum 
 P T QV 
 100.0*qv/(rdv*esat/(P-o_m_rdv*esat)) 
 tot_prec 
 RAIN_GSP SNOW_GSP RAIN_CON SNOW_CON 
 RAIN_GSP+SNOW_GSP+RAIN_CON+SNOW_CON 
 snow_% 
 RAIN_GSP SNOW_GSP RAIN_CON SNOW_CON 
 100.0*(SNOW_GSP+SNOW_CON)/tot_prec 
 conv_% 
 RAIN_GSP SNOW_GSP RAIN_CON SNOW_CON 
 100.0*(RAIN_CON+SNOW_CON)/tot_prec 

If a variable which you want to compute is not present, you will have to compute it yourself. Care should be taken to not only compute the variable but also update to corresponding attributes. For an example of how to compute the potential temperature, see Example 1 below. If you think that a derived variable you have computed might be useful for others, make sure it gets added to the official COSMO Library instead of copying and pasting it into every NCL script you write.

Example 1

f = addfile("lfff00000000.grb","r")
p = jmb_getvar(f,"P",False)
t = jmb_getvar(f,"T",False)
pt = t*(cosmo_p0/p)^(cosmo_r_d/cosmo_cp_d)
pt@name = "THETA"
pt@long_name = "potential temperature"
pt@units = "K"

jmb_getgrid

Read and attach attributes describing the grid on which a field lives.

Prototype

procedure jmb_getgrid( f:file, c:file, var:numeric, opt:logical )

Arguments

f A file variable as returned by addfile corresponding to a COSMO grib1 output file
c A file variable as returned by addfile corresponding to a COSMO grib1 constants file
var A variable read using jmb_getvar
opt A variable containing an optional list of resources, attached as attributes

Description

This procedure attaches dimension variables and attributes describing the grid on which a certain field lives. The variable var should have been read using the jmb_getvar command. This procedure is useful in case you want to access the grid locations of a field or make a georeferenced plot of your data. You might also want to call this procedure before extracting a data slice using the jmb_slice command.

When a field is read using jmb_getvar it has named dimensions corresponding to index space (i.e. "k", "j", "i"). The jmb_getgrid procedure will rename the dimensions of a field and assign physical values to the corresponding coordinate variables. For example, if you've read the 3-dimensional pressure field p, it will have dimensions named "lev", "rlat" and "rlon" and the corresponding coordinate variables p&lev, p&rlat and p&rlon will have the approriate vectors assigned.

In addition, jmb_getgrid assigns several attributes which give more information about the grid-structure of a field. The following table contains a list of all the attributes jmb_getgrid will try to assign. Note that the attributes that can be assigned to each variable is dependent on the grid structure as well as the rank of the variable. For example, a two dimensional variable will never contain the lev_height attribute.

Attribute Description
dlatlon Grid increment in latitude and longitude direction (in rotated system)
domain Grid domain boundaries (lat1, lon1, lat2, lon2) in rotated coordinates
grid_type String describing type of grid (e.g. "Rotated Latitutde/Longitude Grid")
lat2d 2-dimensional array containing geographical latitudes of grid
lon2d 2-dimensional array containing geographical longitudes of grid
lev_height Name of attribute containing vertical position of grid (e.g. "z")
lev_height_long_name Description of vertical coordinate variable (e.g. "height"
lev_height_units Units of vertical coordinate variable (e.g. "m")
lev_type Type of vertical levels (e.g. "levels" or "layers")
model Model version (e.g. "cosmo-6.6" or "cosmo-2.2")
pollat Geographical latitude of rotated north pole
pollon Geographical longitude of rotated north pole

If you want to plot a field in index space, some information attached by jmb_getgrid will disturb the correct plotting of the field. In order to remove the grid information, issue a call to jmb_rmgrid.

Example 1

f = addfile("lfff01000000.grb","r")
c = addfile("lfff00000000c.grb","r")
p = jmb_getvar(f,"P",False)
jmb_getgrid(f,c,p,False)
printVarSummary(p)

jmb_rmgrid

Remove information added to a variable by jmb_getgrid.

Prototype

procedure jmb_rmgrid( var:numeric )

Arguments

var A variable read using jmb_getvar

Description

This procedure removes any information that has been added to a variable using a call to jmb_getgrid. This can be useful for several reasons. You might want to free up memory, since the storage of the grid locations (z/lat/lon) uses quite a lot of memory. Or you might want to remove the geo-referencing information in order to plot a field in the index space. The coordinate variables are renamed and reset to their default via a call to ijkcoords.

Example 1

f = addfile("lfff01000000.grb","r")
c = addfile("lfff00000000c.grb","r")
p = jmb_getvar(f,"P",False)
jmb_getgrid(f,c,p,False)
jmb_rmgrid(p)
printVarSummary(p)

jmb_slice

Function to extract a slice or a column of data from a more dimensional variable.

Prototype

function jmb_slice( var:numeric, cutname:string, cutval:numeric )

Arguments

var Variable to slice
cutname String containing type of slice requested. Must be one of "i", "rlon", "lon", "j", "rlat", "lat", "ij", "rlatlon", "latlon", "ij_list", "latlon_list", "xy_list", "k", "level", "z".
cutval Value specifying the cut (can be scalar, a vector or a list of points)

Description

This function is a versatile slicer to extract 1-dimensional or 2-dimensional subsets of a variable. It can be used to extract both horizontal slice, vertical sclices, vertical columns or slices along arbitrary isosurfaces of a field. For example, you can extract pressure on the 320K potential temperature isosurface or extract a vertical cross-section along a constant latitude. The following table contains a description of the different cutname values and what they mean.

cutname cutval Description
"i" scalar Cut at fixed zero-based i-index (no interpolation).
"j" scalar Cut at fixed zero-based j-index (no interpolation).
"k" scalar Cut at fixed zero-based k-index (no interpolation).
"level" scalar Cut at fixed level (e.g. pressure in a p-file or height in a z-file (no interpolation).
"ij" 2d vector Extract column at fixed zero-based ij-location (no interpolation).
"ij_list" n x 2 array Cut along list of zero-based ij-locations (interpolation).
"rlon" scalar Cut at fixed rotated longitude (no interpolation).
"rlat" scalar Cut at fixed rotated latitude (no interpolation).
"rlatlon" 2d vector Extract column at fixed rotated latitude/longitude (no interpolation).
"lat" scalar Cut at fixed geographical latitude (interpolation).
"lon" scalar Cut at fixed geographical longitude (interpolation).
"latlon" 2d vector Extract column at fixed geographical latitude/longitude (no interpolation).
"latlon_list" n x 2 array Cut along list of geographical latitude/longitudes (interpolation).
"xy_list" n x 2 array Cut along list of arbitrary horizontal coordinates (interpolation). The x and y coordinates need to be attached to cutval as attributes (e.g. cutval@x = ... and cutval@y = ...).
"z" scalar Cut along an isosurface of an arbitrary vertical coordinate (interpolation). The z coordinate needs to be attached to cutval as an attribute (e.g. cutval@z = ...).

Example 1

Make a slice along a constant latitude at 47.0N.

f = addfile("lfff01000000.grb","r")
c = addfile("lfff00000000c.grb","r")
p = jmb_getvar(f,"P",False)
jmb_getgrid(f,c,p,False)
s = jmb_slice(p,"lat",47.0)

Example 2

Extract relative humidity on the 850hPa level.

f = addfile("lm_coarse/lfff01000000.grb","r")
c = addfile("lm_coarse/lfff00000000c.grb","r")
p = jmb_getvar(f,"P",False)
rh = jmb_getvar(f,"rh",False)
cut = 85000.0
cut@z = p
s = jmb_slice(p,"z",cut)
jmb_getgrid(f,c,s,False)

jmb_set_ct

Sets the color table to use for the current workstation.

Prototype

function jmb_set_ct( wks:graphic, name:string, opt:logical )

Arguments

wks A workstation identifier as returned from gsn_open_wks
name A string identifying the color table to load
opt A variable containing an optional list of resources, attached as attributes

Description

This function builds on top of the NCL function gsn_define_colormap to set the current color table to be used in the supplied workstation. In order to efficiently use the requested color table for a filled contour plot, jmb_set_ct returns a logical with plot resources attached that can directly be supplied to jmb_contour in order to plot a filled contour plot with the specified color table. jmb_set_ct always loads a set of predefined default colors (specified in the "default" color table) which can be used for further labelling/annotation of a plot. In order to have multiple plots with different color tables, see the jmb_add_ct command. The available color tables and the file format for creating your own color tables are given here.

The jmb_set_ct command currently accepts no attributes to res which are specific to the COSMO library.

The jmb_set_ct command returns a logical with the following attributes attached.

Attribute Value
gsnSpreadColors True
gsnSpreadColorStart Start index of loaded color table in wks color table
gsnSpreadColorEnd End index of loaded color table in wks color table
cnLevelSelectionMode "ExplicitLevels"
cnLevels Contour levels associated to loaded color table

Example 1

Draw a map and a filled contour plot of the COSMO-7 topography using a nice color table.

c = addfile("lm_coarse/lfff00000000c.grb","r")
hs = jmb_getvar(c,"HSURF",False)
jmb_getgrid(c,c,hs,False)
wks = gsn_open_wks("pdf", "topography")
rc = jmb_set_ct(wks,"topo_15lev",False)
mp = jmb_map(wks,hs,False)
r = rc
r@trXReverse = True
cn = jmb_contour(wks,hs,r)
delete(r)
plt = jmb_overlays(wks,(/mp,cn/),False)

jmb_add_ct

Adds a color table to use for the current workstation.

Prototype

function jmb_add_ct( wks:graphic, name:string, opt:logical )

Arguments

wks A workstation identifier as returned from gsn_open_wks
name A string identifying the color table to add
opt A variable containing an optional list of resources, attached as attributes

Description

This function can be called after jmb_set_ct to add another color table to an existing workstation. The syntax and usage is exactly the same as for jmb_set_ct except that the color table already attached to the workstation is not removed and the requested color table is appended. Note that currently NCL support a maximum of 256 color table entries which can not be exceeded. The available color tables and instructions to create your own color tables are given here.

The jmb_add_ct command currently accepts no attributes to res which are specific to the COSMO library.

The jmb_add_ct command returns a logical with the following attributes attached.

Attribute Value
gsnSpreadColors True
gsnSpreadColorStart Start index of loaded color table in wks color table
gsnSpreadColorEnd End index of loaded color table in wks color table
cnLevelSelectionMode "ExplicitLevels"
cnLevels Contour levels associated to loaded color table

Example 1

Draw a plot of precipitation and topography on the same page.

begin

  ; open graphic port
  wks = gsn_open_wks("pdf","test20")
  c = addfile("lm_coarse/lfff00000000c.grb","r")
  f = addfile("lm_coarse/lfff00010000.grb", "r")

  ; make a first plot with a specific colortable (jmb_set_ct)
  tp = jmb_getvar(f, "TOT_PREC", False)
  jmb_getgrid(f, c, tp, False)
  r = jmb_set_ct(wks, "precip1h_17lev", False)
  cn = jmb_contour(wks, tp, r) 
  mp = jmb_map(wks, tp, False)
  plt = jmb_overlays(wks, (/mp,cn/), False)
  delete(cn)
  delete(plt)

  ; make a second plot with a specific colortable (jmb_add_ct)
  hsurf = jmb_getvar(c, "HSURF", False)
  jmb_getgrid(c, c, hsurf, False)
  frland = jmb_getvar(c, "FR_LAND", False)
  hsurf = where(hsurf.lt.0.1,0.1,hsurf)
  hsurf = where(frland.lt.0.5,-1.0,hsurf)
  r = jmb_add_ct(wks,"topo_15lev",False)
  cn = jmb_contour(wks, hsurf, r) 
  plt = jmb_overlays(wks, (/mp,cn/), False)

end

jmb_map

Creates a map.

Prototype

function jmb_map( wks:graphic, var[*][*]:numeric, opt:logical )

Arguments

wks A workstation identifier as returned from gsn_open_wks
var A two-dimensional field as returned from jmb_slice or similar
opt A variable containing an optional list of plot resources, attached as attributes

Description

This function builds on top of the NCL function gsn_map to draw a map plot on the given workstation. The field var passed to jmb_map must be geo-referenced, thus either have the attributes lat2d and lon2d attached or contained named dimensions rlat and rlon as well as the necessary attributes pollon and pollat to compute the unrotated lat/lon coordinates. Geo-referencing can be easily achieve via a call to jmb_getgrid. The default setup by jmb_map can be overriden by attaching options to res. The resources are passed on directly to the gsn_map command (see gsn_map documentation for more details). The return value is a plot id value that can be used in jmb_overlays to overlay the map plot with other plots. The map plot should be the first plot in the list passed to jmb_overlays (see Example 1 below).

The jmb_map command accepts the following attributes to res which are specific to the COSMO library.

Attribute Value Description
jmbView "eu","alps","ch" Zoom into a predefined domain
jmbZoom 4d vector Zoom into a region, e.g. (/lon1,lat1,lon2,lat2/)

Example 1

Draw a map and a filled contour plot of the COSMO-7 topography.

c = addfile("lm_coarse/lfff00000000c.grb","r")
hs = jmb_getvar(c, "HSURF", False)
jmb_getgrid(c, c, hs, False)
wks = gsn_open_wks("pdf", "topography")
rc = jmb_set_ct(wks, "rainbow", False)
mp = jmb_map(wks, hs, False)
cn = jmb_contour(wks, hs, rc)
plt = jmb_overlays(wks, (/mp,cn/), False)

jmb_contour

Creates contour plot.

Prototype

function jmb_contour( wks:graphic, var[*][*]:numeric, opt:logical )

Arguments

wks A workstation identifier as returned from gsn_open_wks
var A two-dimensional field as returned from jmb_slice or similar
opt A variable containing an optional list of plot resources, attached as attributes

Description

This function builds on top of the NCL function gsn_contour to draw a contour plot on the given workstation. It can be used to draw both horizonal as well as vertical sclices. The plot can be both in the native grid (model index space) or the transformed grid (lat/lon space or zx space).

If the plot is intended to be in lat/lon space, the field var passed to jmb_contour must be geo-referenced, thus either have the attributes lat2d and lon2d attached or contained named dimensions rlat and rlon as well as the necessary attributes pollon and pollat to compute the unrotated lat/lon coordinates. Geo-referencing can be easily achieve via a call to jmb_getgrid. In this case, the contour plot must always be overlaid on top of a map plot created by jmb_map.

If the plot is intended to be in xz space, the field var passed to jmb_contour muste contain attributes specifying its vertical grid. Namely, it must have a named vertical dimension lev, an attribute lev_height naming an attribute containing the full level heights of the field. This is automatically the case, if jmb_getgrid and jmb_slice are used to extract vertical slices from a model field.

The default setup by jmb_contour can be overriden by attaching options to res. The resources are passed on directly to the gsn_contour command (see gsn_contour documentation for more details). The return value is a plot id value that can be used in jmb_overlays to overlay the map plot with other plots.

The jmb_contour command accepts the following attributes to res which are specific to the COSMO library.

Attribute Value Description
jmbFontHeightF float Font size of text information (default 0.01)
jmbAnnotationsOn logical Add text annotations to plot? (default True)
mpProjection "Native", "Vertical", ... Force a certain transformation (extended from NCL defaults)
jmbTitle string Title of plot
jmbZoom 4d vector Zoom into a region, e.g. (/x1,y1,x2,y2/)

Example 1

Draw a filled contour plot of the COSMO-7 topography in index-space.

c = addfile("lm_coarse/lfff00000000c.grb","r")
hs = jmb_getvar(c, "HSURF", False)
wks = gsn_open_wks("pdf", "topography")
rc = jmb_set_ct(wks, "rainbow", False)
cn = jmb_contour(wks, hs, rc)
plt = jmb_overlays(wks, (/cn/), False)

jmb_vector

wip NOT DOCUMENTED YET wip

jmb_geography

Draw high-resolution geographical information to an existing plot.

Prototype

function jmb_geography(wks:graphic , plt:graphic, type:string, opt:logical)

Arguments

wks A workstation identifier as returned from gsn_open_wks.
plt A plot identifier as returned from jmb_map, jmb_contour or similar.
type A string identifying the database used. Must be one of "cosmo2_ji", "cosmo2_latlon", "cosmo7_ji", "cosmo7_latlon".
opt A variable containing optional list of polyline resources, attached as attributes. The attributes rank and color are interpreted by jmb_geography, all others are passed on to the gsn_add_polyline function which draws the geographical information.

Description

This function can be used to draw coastlines, national boundaries and rivers onto an existing plot. The return value corresponds to the graphic handles that contain the polylines and care should be taken that they are not destroyed before the plot is actually drawn. This can be tricky if the call to jmb_geography is located inside a subroutine or a loop. (For more details refer to the gsn_add_polyline reference page.)

The resource res can be used to control the amount of detail and the color of the coastlines, national boundaries and rivers, respectively. The attribute rank is used to control the amount of detail. It is an vector of three integer values ranging from 0 (nothing to be drawn) to 20 (most detail). For example, setting res@rank = (/20,3,0/) will draw the coastlines with most detail, the national boundaries with a moderate amount of detail, and will not draw any rivers at all. The attribute color is used to control the color of the geographical features. By default res@color = (/"black","gray","blue"/) is used. Note that in order for the chosen colors to actually appear, they must be present in the colormap associated to the workstation wks.

Example 1

Plot of the topography of Switzerland in native coordinates. Overlayed are coastlines and country borders in black and rivers in red.

f = addfile("lm_fine/lfff00000000c.grb", "r")
h = jmb_getvar(f, "HSURF", False)
wks = gsn_open_wks("pdf", "topography")
rc = jmb_set_ct(wks, "rainbow", False)
cn = jmb_contour(wks, h, rc)
r = True
r@rank = (/20,3,20/)
r@color = (/"black", "black", "red"/)
gg = jmb_geography(wks, cn, "cosmo2_ji", r)
delete(r)
plt = jmb_overlays(wks, (/cn/), False)

cosmo2_topo.png

jmb_overlays

wip NOT DOCUMENTED YET wip

Utilities

meshgridx, meshgridy

Functions to generate 2-dimensional cartesian grid coordinates from two vectors spanning the range on each axis.

Prototype

function meshgridx( x[*]:numeric, y[*]:numeric )
function meshgridy( x[*]:numeric, y[*]:numeric )

Arguments

x Vector spanning x-axis values (must be 1-dimensional)
y Vector spanning y-axis values (must be 1-dimensional)

Description

These functions generate 2-dimensional coordinate values of a regular, Cartesian grid specified by two axis vectors containing the values of the x-, and y-axis respectively. These functions are inspired by their counterpart found in the Matlab software package. A simple application would be to generate the full rotated latitude and longitude coordinate arrays from the dimension values of a COSMO field (see Example 1). The return value is a 2-dimensional array of the dimensions (/dimsizes(x), dimsizes(y)/).

Example 1

f = addfile("lfff00000000c.grb","r")
h = jmb_getvar(f, "HSURF", False)
jmb_getgrid(f, f, h, False)
rlat = meshgridx(h&rlat, h&rlon)
rlon = meshgridy(h&rlat, h&rlon)

latlon2rlat, latlon2rlon

Functions to transform geographical latitudes and longitudes to rotated latitudes and longitudes.

Prototype

function latlon2rlat( lat:numeric, lon:numeric, pollat[1]:numeric, pollon[1]:numeric )
function latlon2rlon( lat:numeric, lon:numeric, pollat[1]:numeric, pollon[1]:numeric )

Arguments

lat Geographical latitudes (can be of any rank and/or dimensions, but must match lon)
lon Geographical longitudes (can be of any rank and/or dimesions, but must match lat)
pollat Geographical latitude of rotated north pole (scalar)
pollon Geographical longitude of rotated north pole (scalar)

Description

These functions compute the rotated latitudes and longitudes given a set of geographical latitudes and longitudes. Return values are of same type and dimensions as lat and lon arguments. The formulas for computation closely match the corresponding routines in the source code of the COSMO model.

Example 1

f = addfile("lfff00000000c.grb","r")
h = jmb_getvar(f, "HSURF", False)
jmb_getgrid(f, f, h, False)
rlat = latlon2rlat(h@lat2d, h@lon2d, h@pollat, h@pollon)
rlon = latlon2rlon(h@lat2d, h@lon2d, h@pollat, h@pollon)

rlatlon2lat, rlatlon2lon

Functions to transform rotated latitudes and longitudes to geographical latitudes and longitudes.

Prototype

function rlatlon2lat( rlat:numeric, rlon:numeric, pollat[1]:numeric, pollon[1]:numeric )
function rlatlon2lon( rlat:numeric, rlon:numeric, pollat[1]:numeric, pollon[1]:numeric )

Arguments

rlat Rotated latitudes (can be of any rank and/or dimensions, but must match rlon if more than 1-dimensional)
rlon Rotated longitudes (can be of any rank and/or dimesions, but must match rlat if more than 1-dimensional)
pollat Geographical latitude of rotated north pole (scalar)
pollon Geographical longitude of rotated north pole (scalar)

Description

These functions compute the geographical latitudes and longitudes given a set of rotated latitudes and longitudes. If rlat and rlon are more than 1-dimensional, the return values are of same type and dimensions as rlat and rlon arguments. If rlat and rlon are 1-dimensional, they are assumed to be vectors to span a 2-dimensional cartesian grid. The return values have the dimensions (/dimsizes(rlat),dimsizes(rlon)/). The formulas for computation closely match the corresponding routines in the source code of the COSMO model.

Example 1

f = addfile("lfff00000000c.grb","r")
h = jmb_getvar(f, "HSURF", False)
jmb_getgrid(f, f, h, False)
s = dimsizes(h)
rlat = fspan(h@domain(0), h@domain(2), s(0))
rlon = fspan(h@domain(1), h@domain(3), s(1))
lat = rlatlon2lat(rlat, rlon, h@pollat, h@pollon)
lon = rlatlon2lon(rlat, rlon, h@pollat, h@pollon)

swissxy2lat, swissxy2lon

Functions to transform CH-coordinates to geographical latitudes and longitudes.

Prototype

function swissxy2lat( x:numeric, y:numeric )
function swissxy2lon( x:numeric, y:numeric )

Arguments

x East-/Westward CH-coordinate in km (can be of any rank and/or dimensions, but must match y)
y North-/Southward CH-coordinate in km (can be of any rank and/or dimesions, but must match x)

Description

These functions compute the geographical latitudes and longitudes given a set of CH-coordinates. The return values have the same dimensions as the x and y arguments. The formulas for computation closely mathc the corresponding routines in the Ruby Library.

Example 1

x = 618.847       ; 4419 Lupsingen, Im Budler 3
y = 255.238
lat = swissxy2lat(x,y)
lon = swissxy2lon(x,y)
print((/lat,lon/))

latlon2swissy, latlon2swissx

Functions to transform geographical latitudes and longitudes to CH-coordinates.

Prototype

function latlon2swissy( lat:numeric, lon:numeric )
function latlon2swissx( lat:numeric, lon:numeric )

Arguments

lat Geographical latitudes (can be of any rank and/or dimensions, but must match y)
lon Geographical longitudes (can be of any rank and/or dimesions, but must match x)

Description

These functions compute the geographical latitudes and longitudes given a set of CH-coordinates. The return values have the same dimensions as the x and y arguments. The formulas for computation closely mathc the corresponding routines in the Ruby Library.

Example 1

f = addfile("lfff00000000c.grb","r")
h = jmb_getvar(f, "HSURF", False)
jmb_getgrid(f, f, h, False)
s = dimsizes(h)
rlat = fspan(h@domain(0), h@domain(2), s(0))
rlon = fspan(h@domain(1), h@domain(3), s(1))
lat = rlatlon2lat(rlat, rlon, h@pollat, h@pollon)
lon = rlatlon2lon(rlat, rlon, h@pollat, h@pollon)
x = latlon2swissx(lat, lon)
y = latlon2swissy(lat, lon)

xy_to_ij

Function to transform points in a regular, deformed, 2-dimensional coordinate system to index space.

Prototype

function xy_to_ij( x[*][*]:numeric, y[*][*]:numeric, xy[*][2]:numeric )

Arguments

x x-positions of the grid (must have rank 2 and match dimensions of y)
y y-positions of the grid (must have rank 2 and match dimensions of x)

Description

This function is used to transform a series of points living in the coordinate system of a deformed but regular 2-dimensional grid to index space, thus a regular grid. The points are given by an array of (x,y)-pairs of points. The return value is an array of (i,j)-points in index space which has the same dimensions as xy. As an example, this function can be used to compute the location of arbitrary lat/lon-points in index space (see Example 1).

Example 1

f = addfile("lfff00000000c.grb","r")
h = jmb_getvar(f, "HSURF", False)
jmb_getgrid(f, f, h, False)
latlon = (/ (/47.0, 3.0/), (/46.0, 2.0/) /)
ji = xy_to_ij(h@lat2d, h@lon2d, latlon)
print(ji)

ijkcoords

Sets index space coordaintes for any 2-dimensional or 3-dimensional variable.

Prototype

procedure ijkcoords( var:numeric )

Arguments

var Any 2-dimensional or 3-dimensional numeric variable

Description

This procedure overwrites the names of all dimensions to "k", "j", "i" for 3-dimensional variables and "j", "i" for 2-dimensional variables. Also, it sets the coordinate variables to a vector spanning the index space. For example var&k = fspan(0.,s(0)-1.,s(0)) where s = dimsizes(var).

Example 1

f = addfile("lfff00000000c.grb","r")
h = jmb_getvar(f, "HSURF", False)
ijkcoords(h)

char

Convert a NCL string to a character.

Prototype

function char(str[1]:string)

Arguments

str A string containing only one letter (if more than one letter is present, only the first letter is considered).

Description

This function convert a string of only one letter to a character. This is useful, as the command stringtochar(str) would give you an array of 2 letters, the second one being the NULL termination character.

Example 1

s = "t"
c = char(s)

strcmpwild

Compare a string possibly containing a wildchard character "*" against an array of strings and return all matching strings.

Prototype

function strcmpwild(ssearch[1]:string, str[*]:string)

Arguments

ssearch The search string containing at most one wildcard character "*"
str An array of strings

Description

This function will return a array of strings containing all those strings of str which match the search string ssearch. The wildcard character in ssearch can be anywhere (start, middle, end) of the string. If no matchin string is found the return value will contain only missing values.

Example 1

s = (/"Apple Pie","Pear Pie","Cat Food","Fruit Pie","Elephant"/)
a = strcmpwild("* Pie",s)
if (.not.all(ismissing(a))) then
  print(a)
end if

startcap

Capitalize the beginning of each word in a string.

Prototype

function startcap( s[1]:string )

Arguments

s A string variable

Description

This function will return a string as a return value where all words in s have been capitalized. This can be useful for making nice labels in a plot, as usually long names are given in smallcaps. Note that the handling of special characters is not very elaborate, e.g. startcap("function(argument)") will return "Function(argument)" and not "Function(Argument)".

Example 1

s1 = "function(argument)"
s2 = "the quick brown fox jumps over the lazy dog"
print(startcap(s1))
print(startcap(s2))

-- OliverFuhrer - 28 Jan 2009

Attach
png
cosmo2_topo.png (165.80K)
version 1 uploaded by OliverFuhrer on 27 Jan 2009 - 10:02
spacer
This site is managed by the Center for Climate Systems Modeling (C2SM).
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems? Send feedback!