What is AML?
• What is a program?
• What is AML?
• An AML can:– Automate frequently performed actions– Provide a quick and consistent way to set
environments– Decide what to do– Do things over and over
• An AML can: (.cont)– Interact with users using text or menus– Run other AMLs and programs
• Running an AML• Useful tips - &echo and &pause• Watch files
– Recording your session with a watch file– Converting a watch file to an AML
What is a program?
Begin
End
Set mapextent
Shade polygons
Draw legend
A series of instructions
Advantages of programming
• Reduces typing errors
• Maintains consistency
• Documents your work
• Automates repetitive tasks
• Offers new users a way to be more productive
AML programs can branch
AML programs can respond with an appropriate action by branching
Begin
End
Set mapextent
Shade polygons
Draw legend
End
Build TopologyAnd
Shade polygonsYes NoDoes the
coveragehave polygon
topology?
AML programs can loop
An AML program can repeat procedures
Begin
Draw coverage
End
Do you want to draw a coverage?
No
Yes
Do you want to draw
another coverage?
NoYes
AML programs can communicate with users
By selectingfrom menusBy typing
from a keyboard
Picture a keyboard
AML programs can communicate with other programs
AML programs can run other programs (modules)
Begin
Get a coverage
End
Check topology
Draw coverage
Menu to get a coverage
Program to check topology
Program to draw a coverage
AML programs should be clear and reliable
• Document AML programs
• Test AML programs
• Handle errors gracefully
Designing an application
• Determine functionally– User needs assessment
• System design strategies– Data flow diagram
Flow charts•Map out the logic of a program•Use different symbols for different actions
Beginor end
Get a coverage
Menu to get a coverageDecision
Flow
Action
Separate module
Pseudocode•Represents the flowchart in a common language•No code words should be used in the pseudocode
Sample pseudocode:
Get a coverage name from the user
If the coverage has both polygon and line topology then Allow the user to choose either polygon or line topology
If the coverage has only line topology then Allow the user to choose only line topology
If the coverage has only point topology then Allow the user to choose only point topology
Establish where on the screen the coverage will be displayedDisplay the coverage on the screen
The Header
Name
Purpose
Arguments
Global VariablesLocal Variables
CoveragesDetailed Remarks
Other Amls, Menus
History
Major components of AML
• Directives are AML “commands”– Begin with an &
• Variables store a value– Surrounded by % %
• Functions return a value– Surrounded by [ ]
AML directives
• The first character is always an ampersand (&)– Example: &watch, &run, &popup
• AML directives work anywhere– (e.g., ARC, ARCPLOT, ARCEDIT)
• ARC: &run test.aml• Arcplot: &popup test.aml• Arcedit: &watch edit.wat
DirectivesThis directive: …tells AML to:
&TERMINAL Sets the terminal type
&ECHO Display lines of program asthey are executed
&PAUSE Wait for the user to hit thereturn key
&WATCH Captures the session in awatch file
&SHOW List the current value of anAML program or menu
&TYPE Print a message at theterminal
Variables: %cov%
• Store a value
• Set variables with the &setvar directive
– Arc: &setvar cover = soil
• Use percent signs (%) to evaluate a variable– Arc: DESCRIBE %cover%
– is the same as:
– Arc: DESCRIBE soil
• Variable names are not case sensitive– Arc: DESCRIBE %cover%
– is the same as:
– Arc: DESCRIBE %COVER%
Local, global, and program variables
• Local variables– No dot (.) at beginning of name– Only available to the current AML program
• Global variables– Starts with a dot (.)– Available to all AML programs
• Program variables– Start with a colon (:)– Available to all AML programs
• Examples:• :PROGRAM is automatically set• to the current program
&s cov = streetARCS %cov%&return
Draw.aml
&s .cov = street&r resetARCS %.cov%&return
Redraw.aml
Arc: &lpprogram: :PROGRAM ARC
Functions •Returns values•Enclosed within square brackets [ ]
This function: …tells the AML processor to and returns:[GETCOVER] Displays a menu of coverages /tom/street
[RESPONSE] Ask the user to type some text Enter text
AML Example: buildpoly.aml BUILD [response ‘Enter the coverage to build’] poly
End part 1
How to ask a question of a user with function statements
[RESPONSE]•Prompts the user to enter a response (accepts any text)•Text that the user types becomes the return value of the function
•Arc: &s answer = [RESPONSE ‘Type ARC or POLY’]•Type: ARC or POLY: POINT•Arc: &type The user typed %answer%•The user typed POINT
[QUERY]•Accepts only a yes or no answer from the user•Returned value is .TRUE or .FALSE.
•Arc: &s continue = [QUERY ‘Do you want to kill the coverage’ .FALSE.]•Do you want to kill the coverage? YES•Arc: &type %continue%• .TRUE
Branching
• Obtaining information about a coverage
• &IF statements - &IF &THEN
• Logical expressions
• Indention
Getting information about a coverage
• ARC command: DESCRIBE <geo_dataset>– Displays <geo_dataset> characteristics on the screen
– Sets AML reserved variables for the <geo_dataset>
• AML directive: &DESCRIBE <geo_dataset>
– Only sets the AML reserved variables for the <geo_dataset>
– Can be executed from any Arc/Info environment
– Coverage examples:• THIS VARIABLE CONTAINS THIS VALUE• DSC$ARCS Number of arcs• DSC$POINTS Number of points• DSC$POLYGONS Number of polygons• DSC$TOPOLOGY .TRUE. If polygon topology is present
.FALSE. If not• DSC$QEDIT .TRUE. If coverage has been edited .FALSE.
If not
Handouts p4-5
Blocks of statements
• &DO &END– Every &DO must have an &END– Groups related code into a single block– Can be substituted for the single statement
of &IF &THEN– Example:
&IF [NULL %cov%] &then &do &sv cov = [GETCOV] &type Cover is %cov% &endARCS %cov%
A block
Decision making example
Describe the coverage
End
Draw them red
Yes
No
Does the coverage have
arcs?
&describe %cov%
&if %des$arcs% > 0 &then &do LINECOLOR RED ARCS %cov% &end&END
&ELSE
Describe the coverage
Draw them redYes
No
Does the coverage
have arcs?
Error message
&describe %cov%
&if %dsc$arcs% > 0 &then &do LINECOLOR RED ARCS %cov% &end
&else &do &type ERROR - NO ARCS &end
&ELSE &IF
Describe the coverage
Draw them redYes
No
ARCS > 0?
Draw points green
&describe %cov%
&if %dsc$arcs% > 0 &then &do LINECOLOR RED ARCS %cov% &end&else &do &type ERROR - NO ARCS &end&else &if %dsc$points > 0 &then &do MARKERCOLOR GREEN POINTS %COV% &end&else &do &type ERROR - NO POINTS &end&END
Points > 0?Yes
Error messageNo
Error message
Looping
• Nesting loops• Making a decision at the beginning of a loop• Making a decision at the end of a loop
• &do &to &by• &do &list• &do &repeat• &do &until• &do &while
Controlling the number of loopsFour basic ways
•Count up to a set number &do&to&by
•Loop once for each element in list &do &list
•Make a logical decision at the• beginning of the loop &do &while
•Make a logical decision at the• end of the loop &do &until
Counting &do loops
• AML coding Results • &do i - 1 &to 5 I = 1• &type i = %i% I = 2• &end I = 3• I = 4• I = 5
• The default auto increment is one
Nesting &do loopAML coding
&do outside = 1 &to 3 &do inside = 100 &to 400 &by 100 &type outside = %outside% inside = %inside% &end /* inside do loop&end /* outside do loop Results:
outside = 1 inside = 100outside = 1 inside = 200outside = 1 inside = 300outside = 1 inside = 400outside = 2 inside = 100outside = 2 inside = 200outside = 2 inside = 300outside = 2 inside = 400outside = 3 inside = 100outside = 3 inside = 200outside = 3 inside = 300outside = 3 inside = 400
Making a decision at the beginning of a loop
Use &DO &UNTIL
&s color = 1 &do &until not [QUERY ‘DRAW ANOTHER COVERAGE’] LINECOLOR %color% ARCS [GETCOVER] &s color = %color% + 1 &end /* DO
Will always execute at least once The first coverage is drawn before the user sees the question asking to draw another coverage
The loop terminates when the condition is .TRUE.
Write an AML program that accepts user input:
Use your text editor to write a simple startup AML program (Start.aml)
1) Have your AML program get a coverage and copy it to a new coverage as the coverage name version 2.
2) Have the AML program open ArcPlot and select an arc coverage, and draw the coverage to the screen in red.
3) Add to your AML the ability to select a coverage and decide if it has arcs and draw it in red, or if no arcs display an
error message
4) Add to your AML the ability to keep asking to draw more coverages.
Do
the
se o
ne at a
time
Ma
ke sure each
on
e w
orks
befo
re yo
u go to
the
ne
xt one
!
Changing formats on an image
Begin
Get an image
Decision
Ask for name of a grid
Convert to a grid Convert an image
Kill the grid
end
&do &while [Query 'Do you want to convert an~ image:' .false] &s image = [getimage # -tiff 'Select an image to convert:'] &s grid = [response 'Enter the grid name']
IMAGEGRID %image% %grid% GRIDIMAGE %grid% GRAY %grid% TIFF KILL %grid% ALL
&type 'You just created an image named' %grid%'.tif'&end
Yes
No
End
Top Related