Personal tools
You are here: Home Documentation Users Guide 11. Writing External Functions 11.3 QUICK START EXAMPLE
Document Actions

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.



Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: