/**************************************************************************** /* Program: VARCOMMA.AML /* /* Purpose: AML to insert commas in a 'big' number (>999) for display /* purposes only, e.g., 1000000 => 1,000,000. /* /* Usage: varcomma /* /* Language: ARC/INFO, Ver. 6.1.2 /* /* System: DECStation 5000/260, Ultrix 4.3c /* /* Programmer: Robert Harmon /* Senior G.I.S. Analyst /* Idaho Dept. of Water Resources /* 1301 N. Orchard St. /* Boise, ID 83706-2237 /* Tel. 208-327-7995 /* FAX 208-327-7886 /* email: bharmon@idwr.state.id.us /* /****************************** HISTORY ************************************ /* /* Author Group Date Event /* ----------- ----- -------- ------------------------------------- /* R HARMON IDWR 1/31/95 Working version /* R HARMON IDWR 3/13/95 More comments & error trapping /* /*************************** AML VARIABLES ********************************* /* /* Local /* variables: in_val - numeric value to be parsed with commas /* out_var_name - name of outgoing global variable with /* 'comma'-ed number from 'in_val' /* work_val - portion of the number before the decimal /* dec_val - portion of the number after the decimal /* count - counter; increments in series of 3's (the /* amount of numbers separated by a comma) /* leng_wval - length of the number before the decimal /* (work_val) /* work2_val - initialized with value of 'work_val'; during /* processing contains the portion of the number /* that hasn't been parsed with a comma /* com_val - initialized with a null value; during /* processing contains portion of the number /* that has been parsed with a comma /* work_leng - length of the number (work2_val) during /* processing /* bef_cval - during processing, the left portion of the /* number before the insertion point of the /* comma /* aft_cval - during processing, the right portion of the /* number after the insertion point of the /* comma (including the comma) /* /* Global variable: Variable name supplied by the user on the /* command line which contains the 'comma'-ed number. /* Stored in local variable 'out_var_name.' /* /* Subroutines called: BAILOUT - error bailout routine; called /* when program encounters a fatal error /* /************************* BEGIN MAIN PROGRAM ****************************** /* &args in_val:REST &echo &off /* /* Check command-line arguments &if [null %in_val%] or [search %in_val% ' '] = 0 &then &return &warning Usage: varcomma ~ /* /* Parse out comman line &sv out_var_name [after %in_val% ' '] &sv in_val [before %in_val% ' '] /* /* Check contents of 'in_val' &if [type %in_val%] > 0 &then &return &warning Input value is not a number... /* &severity &error &routine BAILOUT &messages &off &info /* /* /* Determine if out-variable name has been specified as global or not /* by the user. If not, make it global. &if [substr %out_var_name% 1 1] <> . &then &sv out_var_name = .%out_var_name% /* /* If number is 3 characters or less, than pass it back to the outgoing /* global variable and end the program. &if [length %in_val%] le 3 &then &do &sv %out_var_name% = %in_val% &goto END &end /* /* If the number is a type 'real,' then work with only that portion /* before the decimal. &sv work_val = [before %in_val% . ] &if ( %in_val% - %work_val% ) <> 0 &then &sv dec_val = [after %in_val% .] /* /* Initialize working variables (see comment section at top for /* definitions). &sv count = 3 &sv leng_wval = [length %work_val%] &sv work2_val = %work_val% &sv com_val &sv work_leng = %leng_wval% /* /* 'Process' the number into a string with commas, working from /* the right. &do &while %count% < %leng_wval% &sv bef_cval = [substr %work2_val% 1 [calc %work_leng% - 3]] &sv aft_cval = [substr %work2_val% [calc %work_leng% - 2] 3] &sv com_val = ,%aft_cval%%com_val% &sv work2_val = %bef_cval% &sv work_leng = [length %work2_val%] &sv count = %count% + 3 &end /* /* If the incoming number was a real, reattach the portion after /* the decimal. Save the number, real or integer, to the outgoing /* global variable. &if ( %in_val% - %work_val% ) <> 0 &then &sv %out_var_name% = %bef_cval%%com_val%.%dec_val% &else &sv %out_var_name% = %bef_cval%%com_val% /* &label END /* &messages &on &ret /* end VARCOMMA.AML... /* /* &routine BAILOUT &messages &on &echo &off &ty &ty Error encountered during processing in VARCOMMA.AML &ty Last error message => [value aml$message] &ty &ret &error ...Exiting via BAILOUT routine...