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

11.3 QUICK START EXAMPLE

It's always easier to start coding from an example. Any of the external functions we provide should be documented well enough to serve as a starting point for writing a new function. In this section, we take the most trivial example function, pass_thru, and alter it to do something a little more interesting, if no more useful.

11.3.1 The times2bad20 function

We'll use the pass_thru(...) function as a template, modifying it into a times2bad20(...) function. This new function will multiply all values by 2.0 and will replace missing value flags with the value 20.0.

Inside any of the example functions, the areas that you need to (are allowed to) modify are set off with

c*********

c USER CONFIGURABLE PORTION

->Insert your code here<-

c USER CONFIGURABLE PORTION
c*********

Here's what you need to do to create the new function:

1. move to the examples/ directory

2. copy pass_thru.F to times2bad20.F

3. use your favorite editor to change each "pass_thru" to "times2bad20"

4. go down into the "times2bad20_init" section and change the description of the function

5. go to the "times2bad20_compute" subroutine and change the code to look like this

 

c* result(i,j,k,l) = bad_flag_result
result(i,j,k,l) = 20
 
ELSE
 
c* result(i,j,k,l) = arg1(i,j,k,l)
result(i,j,k,l) = 2 * arg1(i,j,k,l)

Assuming you have downloaded all of the ef_utility/ directory development code and you are still in the examples/ directory, you should be able to (Figure 11_1)

Ch11_fig01

> make times2bad20.so
> setenv FER_EXTERNAL_FUNCTIONS .
> ferret
...
yes? use coads_climatology
yes? let a = times2bad20(sst)
yes? shade a[l=1]

Congratulations! You have just written your first external function.