370 likes | 611 Views
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
E N D
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 A series of instructions Set mapextent Shade polygons Draw legend End
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 Begin AML programs can respond with an appropriate action by branching Set mapextent Build Topology And Shade polygons Does the coverage have polygon topology? No Yes Shade polygons Draw legend End End
AML programs can loop Begin Do you want to draw a coverage? Yes Draw coverage Do you want to draw another coverage? No An AML program can repeat procedures Yes End No
AML programs can communicate with users By selecting from menus By typing from a keyboard Picture a keyboard
AML programs can communicate with other programs AML programs can run other programs (modules) Begin Menu to get a coverage Get a coverage Program to check topology Check topology Draw coverage Program to draw a coverage End
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
Decision Flow charts • Map out the logic of a program • Use different symbols for different actions Begin or end Get a coverage Action Flow Menu to get a coverage 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 displayed Display the coverage on the screen
The Header Detailed Remarks Coverages Name Arguments Other Amls, Menus Purpose Global Variables Local Variables 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
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 Draw.aml • 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 = street ARCS %cov% &return Redraw.aml &s .cov = street &r reset ARCS %.cov% &return Arc: &lp program: :PROGRAM ARC
Returns values • Enclosed within square brackets [ ] Functions • 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
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% &end ARCS %cov% A block
Decision making example &describe %cov% Describe the coverage Yes Does the coverage have arcs? &if %des$arcs% > 0 &then &do LINECOLOR RED ARCS %cov% &end &END Draw them red No End
&ELSE &describe %cov% &if %dsc$arcs% > 0 &then &do LINECOLOR RED ARCS %cov% &end &else &do &typeERROR - NO ARCS &end Describe the coverage Yes Does the coverage have arcs? Draw them red No Error message
&ELSE &IF &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 Describe the coverage Yes ARCS > 0? Draw them red No Error message Yes Draw points green Points > 0? No 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 loops Four 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
AML 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 Nesting &do loop Results: outside = 1 inside = 100 outside = 1 inside = 200 outside = 1 inside = 300 outside = 1 inside = 400 outside = 2 inside = 100 outside = 2 inside = 200 outside = 2 inside = 300 outside = 2 inside = 400 outside = 3 inside = 100 outside = 3 inside = 200 outside = 3 inside = 300 outside = 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 these one at a time Make sure each one works before you go to the next one!
Decision Changing formats on an image &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 Begin No end Yes Get an image Ask for name of a grid Convert to a grid Convert an image Kill the grid