|
Creating a calculated field
|
Top Previous Next |
|
1. Open your lookup file and create a table called CALCULATEDFIELDS. This section may be placed anywhere, but convention calls for it to follow the FIELDS table near the top of the file. For each calculated field that you wish to add, create a new entry. For example: 1 Injury severity. This section might look like this: CALCULATEDFIELDS 1 Injury severity
2. While still in the lookup file, add a table for your new calculated field. For example, the Injury severity field table might look like this: INJURYSEVERITY 1 PDO 2 INJURY 3 FATALITY
Now, save and close the lookup file. If you leave it like this, the program will think you have a calculated field, but it won't know how to calculate it.
3. Create, or open your calculated fields file. (normally named CITY.CAL using your configuration prefix name in place of CITY) This file is in Windows .INI format. Create a section that has the same name as your calculated field. In that section create a value called "expression". That value should contain an expression that yields the numeric value representing the calculated field's value when called. For example: [INJURY SEVERITY] Expression=@IF( Fatalities > 0, 3, @IF( Injuries > 0, 2, 1 ))
Note that the syntax for the expression is the same as is used in filters in the program. Save and close this file.
4. Depending on the version of the program you are running, the calculated fields file may already be specified in your configuration. If it is not, you'll have to add it manually to the imw.ini file. To check if it is specified, select Utilities / Configuration / Default file names. Select the attributes button. Look for an entry called Calculations. This entry should contain the name of the file that you just created. If it doesn't, close the program and modify the imw.ini file in your data directory so that the line that says "calculations=" specifies your calculations file.
5. Test your new field. One of the easiest ways to test the field is to open a diagram containing crashes that should include unique values for this calculated field. If you've prepared these files correctly, the calculated field will be available in the filter editor, along with the appropriate possible values. Create a filter and check the results. |