User Tools

Site Tools


trainingtutorial:tutorial_1:chapter2

Chapter 2 - Building the TOOL Code Logic

Open demogVer1.DMM in Documentor.

Double click on the Calculator node Population. The Population calculator diagram appears.

Double click on the Evolve Population procedure. The Evolve Population procedure editor dialogue appears.

Creating the code

1. Local Object - base[g,a]

Create code for base[g,a] consisting of the following TOOL statements:

local base[g,a]
base[g,a] = shrink (basePop[g,byr,a])

In this TOOL statement the shrink tool is being used to remove reference to extent 1 (indexed by byr) informants.

2. Local Object - mort[t,g,a]

Create code for mort[t,g,a] consisting of the following TOOL statements:

local mort[t,g,a]
mort[t,g,a] = reorder (mortality[g,t,a]; time, gender, age)

In this TOOL statement the reorder tool is being used to reorder the input object “mortality[g,t,a]” into the local object “mort[t,g,a]” since that is the shape needed later in the code.

3. Local Object - netImm[t,g,a]

Create code for netImm[t,g,a] consisting of the following TOOL statements:

local netImm[t,g,a]
netImm[t,g,a] = reorder (netImmgr[g,t,a]; time, gender, age)

In this TOOL statement the reorder tool is being used to reorder the input object “netImmgr[g,t,a]” into the object “netImm[t,g,a]” for use later in the code.

4. Local Object - fert[t,a]

local fert[t,a]
fert[t,a] = create (; dimFrom1=totPeriodFert[t], dimFrom3=mortality[g,t,a], \
   entityFrom=totPeriodFert[t])
fert[t,a] = insert (fertShr[t,ma] * totPeriodFert[t]; age->age:15)

In the first of these TOOL statements the create tool is being used to create the local object “fert[t,a]”.
The parameter “dimFrom1=totPeriodFert[t]” gets fert’s first dimension from the first dimension of “totPeriodFert[t]”,
the parameter “dimFrom3=mortality[g,t,a]” gets fert’s second dimension from the third dimension of “mortality[g,t,a]” and
the parameter “entityFrom=totPeriodFert[t]” gets fert’s entity from “totPeriodFert[t]” (note: \ is the line continuation mark).

At this point “fert[t,a]” is an empty object. The TOOL statement uses the insert tool to insert the product (* tool used with infix notation) of “fertShr[t,ma]” and “totPeriodFert[t]” into “fert[t,a]” starting at age 15 (determined by the parameter “age→age:15”).

5. Output Object - population[g,t,a]

Create code for population[g,t,a] consisting of the following TOOL statements:

population[g,t,a] = reorder (populate (base[g,a], mort[t,g,a], \
   fert[t,a], genderShr[t]; netImmgr=netImm[t,g,a]); \
   gender, time, age)

In this TOOL statement the populate tool has been nested inside the reorder tool (controlled by “()” brackets). The populate tool takes inputs of “base[g,a]”, the base population; “mort[t,g,a]”, the mortality; “fert[t,a]”, the fertility and the parameter “netImmgr=netImm[t,g,a]”; indicates that net immigration is to be taken from “netImm[t,g,a]” and uses the cohort method to evolve the population. The populate tool’s normal population output would be ordered as “[t,g,a]” thus its output is then reordered using the reorder tool to be the right shape for the output object “population[g,t,a]”.

Click OK to save your code.

When complete the TOOL code for the Evolve Population procedure should appear as shown:

procedureeditor.jpg

Running the code

Running code in Documenter is for testing the code structure and doing dimensional analysis (unit/shape checking) without any data.

Click on the running man button. The single man is for running just the current calculator and the multiple men button runs all the calculators.

trainingtutorial/tutorial_1/chapter2.txt · Last modified: 2012/03/01 16:55 by deryn.crockett