Skip to main content
  • Home >
  • Documentation
  • FAQ
  • Downloads
  • Support
  • Current Release Notes
  • Ferret Users Guide
    • Users Guide Index
    • Commands Reference
    • 1. Introduction
    • 2. Data Set Basics
    • 3. Variables & Expressions
    • 4. Grids & Regions
    • 5. Animations & Gif Images
    • 6. Customizing Plots
    • 7. Handling String Data Symbols
    • 8. Working with Special Data Sets
    • 9. Computing Environment
    • 10. Converting to NetCDF
    • 11. Writing External Functions
    • Glossary
    • Appendix A: Functions
    • Appendix B: PPLUS Guide
    • Appendix C: Ferret-Specific PPLUS Enhancements
  • Previous Release Notes
  • Tutorials and Demos
    • Ferret Tour
    • DSG files: Discrete Sampling Geometries Demo
    • Ferret sorting demo
    • Fast Fourier Transforms demo
    • Empirical Orthogonal Functions demo
    • Ferret objective analysis demo
    • Ferret Palette Demo
    • Map projections
    • Ferret polygon vector demo
    • Ferret Graticules demo
    • Ferret Polytube Demo
    • Ferret Polymark Demo
    • Ferret Constant-Array demo
    • Ferret land_detail demo
    • COADS Tour
    • Levitus Tour
    • Use OPeNDAP
    • Ferret binary read demo
  • PyFerret
    • PyFerret Downloads and Install ../../faq/ferret-faqs.html
    • What is PyFerret?
    • Why use PyFerret?
    • PyFerret for the Ferret user
    • PyFerret command syntax: quick-start notes
    • PyFerret for the Python user
    • Graphics in PyFerret ?
    • New Ferret functionality
    • PyFerret Python functions and constants
    • PyFerret Python objects and methods
    • Ferret external functions in Python
    • Ferret Fortran external functions
    • PyFerret metadata-and-data dictionaries
  • OPeNDAP
    • OPeNDAP usage in Ferret
    • Use OPeNDAP Demo
    • Test OPeNDAP

7.6 ORDER OF STRING SUBSTITUTIONS


The above example illustrates that the order in which Ferret performs string substitutions and evaluates immediate mode expressions in the command line is significant. The successful evaluation of the embedded expression `($ppl$xlen)/2` requires that ($ppl$xlen) is evaluated before attempting the divide by 2 operation. The order of Ferret string substitutions is as follows:

1. substitute "GO" command arguments of the form "$1", "$2", ..

2. substitute symbols of the form ($symbol_name) (discussed here)

3. substitute command aliases

4. substitute immediate mode expressions. (But see example 3 below).

Example 1

If the script snoopy.jnl contains

DEFINE SYMBOL fcn = $1
DEFINE ALIAS ANSWER LIST/NOHEAD/FORMAT=("Result is ",$2)
ANSWER `($fcn)(($3^2)/2)`+5

then the command

yes? GO snoopy EXP F5.2 2.25

would evaluate to

DEFINE SYMBOL fcn = EXP
DEFINE ALIAS ANSWER LIST/NOHEAD/FORMAT=("Result is ",F5.2)
LIST/NOHEAD/FORMAT=("Result is ",F5.2) `EXP((2.25^2)/2)`+5

and would result in Ferret output of "Result is 17.57."

Example 2

We can use grave accent syntax and string variables to substitute the string into the command line.

yes? LET my_reg = "X=0:180,Y=-40:40,L=1"
yes? SHADE sst[`my_reg`]

Example 3

Immediate mode substitution of a string variable may be used to set the values of qualifiers. However the region qualifiers (/X=/Y=etc.) on a command are used to set the context for the grave accent expression. So Ferret parses command qualifiers before it parses grave accent expressions. Thus we can use this syntax to set a region:

yes? LET xreg = "40:180"
yes? LET yreg = "60S:42S"
yes? SET REGION/X=`xreg`/Y=`yreg`

But including the qualifier name in the string variable is NOT valid (the qualifier is parsed BEFORE the grave accent expression is substituted, so Ferret would issue the error that `my_region` is an unknown qualifier).

yes? !The following syntax is NOT valid:
yes? LET my_region = "x=40:180/y=-60:-42"; set region/`my_region`

yes? ! THE FOLLOWING syntax IS valid:
yes? DEFINE SYMBOL my_region = X=40:180/Y=-60:-42
yes? SET REGION/($my_region)
!-> SET REGION/X=40:180/y=-60:-42