Ordering AML for interconnected stream channel network

See also: ord1.aml , ord2.aml , ord3.aml , ord4.aml



/* ************************************************************* /* USDA - ARS /* Southwest Watershed Research Center /* 2000 E. Allen Rd. /* Tucson, AZ 85719 /* ************************************************************* /* Program: order.aml. /* /* Function: Calculates the ordering sequence for an /* interconnected vector stream system. /* /* History: Created 1994 by Scott Miller, USDA - ARS SWRC, /* 2000 E. Allen Rd. Tucson, AZ 85719. /* ph: 520-670-6380. miller@tucson.ars.ag.gov /* ************************************************************* /* Routines called: ord1.aml, ord2.aml, ord3.aml, ord4.aml /* /* Requirements: Stream network coverage must be contiguous /* (no gaps) and all channels must be "pointed" /* in the downstream direction i.e. all /* "from" nodes must be at a farther distance /* from the outlet than the corresponding /* "to" node. /* /* The coverage must be built as a line /* coverage and contain a numeric item /* called "order". /* /* Results: The order of each stream segment will be /* stored as a value in the .aat file in /* the "order" item. /* ************************************************************* /* Usage: &r order.aml /* /* Arguments: stream_cover - name of the stream network /* ************************************************************* &args cov &if [null %cov%] &then &do &type Usage: &r order &return &inform &end &of %:PROGRAM% = ARC &then ae &if %:PROGRAM% ne ARCEDIT &then &do quit arcedit &end ec %cov% &sv howmany = 0 &label beginning &sv .num1 = 0 /* Select all the labels and figure out how many times you must go through /* the loop to select all the records. ef node &sv .num2 [show maximum node#] ef arc &label here /* Set up a counter which will bail you out of the program when it reaches /* beyond the number of records in the attribute field. &sv .num1 = %.num1% + 1 &if %.num1% > %.num2% &then &goto test /* If the arc attached to the node already has been ordered, skip /* down to the bottom. This avoids calculating the order and all the /* logic statements sel fnode# = %.num1% &sv .num70 = [show number select] &if %.num70% = 0 &then &goto down &sv .num71 = [show select 1] &sv .num72 = [show arc %.num71% item order] &if %.num72% > 0 &then &goto here &label down sel tnode# = %.num1% &sv .num3 = [show number select] &if %.num3% = 0 &then &goto skip &sv .num31 = [show select 1] &sv .num32 = [show arc %.num31% item order] &if %.num32% > 0 &then &goto here /* Select a to-node equal to the counter. If none are selected, then run /* ord1.aml. If one is selected, it is a pseudonode, and ord2.aml will /* be run. If two or more are selected, a slew of possible iterations /* occurs. Ord3.aml and ord4.aml are designed to handle those /* occurences. &label skip sel tnode# = %.num1% &sv .num3 = [show number select] &if %.num3% = 0 &then &run ord1.aml &if %.num3% = 1 &then &run ord2.aml &if %.num3% = 2 &then &run ord3.aml &if %.num3% = 3 &then &run ord4.aml &goto here &label test /* Check to see if there are any records without orders attached to them. /* If there are none, then the program is done and it stops. If there are /* still some unordered streams, go back to the beginning and start over. sel order = 0 &sv .nozero [show number select] &if %.nozero% = 0 &then &goto ender &if %.nozero% ne 0 &then &goto beginning &label ender save &return

Subroutine "ord1.aml": orders all 1st order channels

See also:
order.aml , ord2.aml , ord3.aml , ord4.aml

/*  *************************************************************
/* 		 	USDA - ARS 
/* 			Southwest Watershed Research Center
/*	     		2000 E. Allen Rd.
/*			Tucson,  AZ 85719
/*  *************************************************************
/*  Program:		ord1.aml.  
/*
/*  Function:		Subroutine of order.aml: orders dangling 
/*			arcs as first order channels.
/*
/*  History:		Created 1994 by Scott Miller, USDA - ARS SWRC, 
/*			2000 E. Allen Rd.  Tucson,  AZ  85719.  
/*			ph: 520-670-6380.  miller@tucson.ars.ag.gov
/*  *************************************************************
/*  Routines called:	none
/*
/*  Requirements:	see order.aml
/*  *************************************************************


sel fnode# = %.num1%
calc order = 1
&return




Subroutine "ord2.html": orders channels below pseudonodes

See also: order.aml , ord1.aml , ord3.aml , ord4.aml



/*  *************************************************************
/* 		 	USDA - ARS 
/* 			Southwest Watershed Research Center
/*	     		2000 E. Allen Rd.
/*			Tucson,  AZ 85719
/*  *************************************************************
/*  Program:		ord2.aml.  
/*
/*  Function:		Subroutine of order.aml: orders arcs 
/*			downchannel of pseudonodes appropriately.
/*
/*  History:		Created 1994 by Scott Miller, USDA - ARS SWRC, 
/*			2000 E. Allen Rd.  Tucson,  AZ  85719.  
/*			ph: 520-670-6380.  miller@tucson.ars.ag.gov
/*  *************************************************************
/*  Routines called:	none
/*
/*  Requirements:	see order.aml
/*  *************************************************************


sel tnode# = %.num1%
  &sv .num4 [show select 1]
    &sv .num5 = [show arc %.num4% item order]

/*  If the contributing stream has no order attached, return to the program
	&if %.num5% = 0 &then &return

/*  Calc the order of the downstream section equal to the value of
/*  the upstream section.

sel fnode# = %.num1%
calc order = %.num5%

&return


/*  If one of the streams has a higher order, use that value

	&if %.num8% > %.num9% &then &sv .num10 = %.num8%
	&if %.num9% > %.num8% &then &sv .num10 = %.num9%

/*  If they have the same value, use that value + 1

	&if %.num8% = %.num9% &then &sv .num10 = %.num8% + 1

/*  Select the appropriate vector and calc its order equal to .num1

sel fnode# = %.num1%
  calc order = %.num10%

&return




Subroutine "ord3.aml": orders channels below the confluence of 2 channels

See also: order.aml , ord1.aml , ord2.aml , ord4.aml



/*  *************************************************************
/* 		 	USDA - ARS 
/* 			Southwest Watershed Research Center
/*	     		2000 E. Allen Rd.
/*			Tucson,  AZ 85719
/*  *************************************************************
/*  Program:		ord3.aml.  
/*
/*  Function:		Subroutine of order.aml: calculates the
/*			order of channels below the confluence of
/*			two channels. 
/*
/*  History:		Created 1994 by Scott Miller, USDA - ARS SWRC, 
/*			2000 E. Allen Rd.  Tucson,  AZ  85719.  
/*			ph: 520-670-6380.  miller@tucson.ars.ag.gov
/*  *************************************************************
/*  Routines called:	none
/*
/*  Requirements:	see order.aml
/*  *************************************************************

/*  First set up the global variables equal to the order of incoming streams

&sv .num6 [show select 1]
   &sv .num8 [show arc %.num6% item order]
&sv .num7 [show select 2]
   &sv .num9 [show arc %.num7% item order]

/*  If either of the streams is unlabeled, return to the main program

	&if %.num8% = 0 &then &return
	&if %.num9% = 0 &then &return

/*  If one of the streams has a higher order, use that value

	&if %.num8% > %.num9% &then &sv .num10 = %.num8%
	&if %.num9% > %.num8% &then &sv .num10 = %.num9%

/*  If they have the same value, use that value + 1

	&if %.num8% = %.num9% &then &sv .num10 = %.num8% + 1

/*  Select the appropriate vector and calc its order equal to .num1

sel fnode# = %.num1%
  calc order = %.num10%

&return



Subroutine "ord4.aml": orders channels below the confluence of 3 channels

See also: order.aml , ord1.aml , ord2.aml , ord3.aml



/*
/*  *************************************************************
/* 		 	USDA - ARS 
/* 			Southwest Watershed Research Center
/*	     		2000 E. Allen Rd.
/*			Tucson,  AZ 85719
/*  *************************************************************
/*  Program:		ord4.aml.  
/*
/*  Function:		Subroutine of order.aml: calculates the
/*			order of channels below the confluence of
/*			three channels. 
/*
/*  History:		Created 1994 by Scott Miller, USDA - ARS SWRC, 
/*			2000 E. Allen Rd.  Tucson,  AZ  85719.  
/*			ph: 520-670-6380.  miller@tucson.ars.ag.gov
/*  *************************************************************
/*  Routines called:	none
/*
/*  Requirements:	see order.aml
/*  *************************************************************
/*

/*  Set up some global variable equal to the order values of the 
/*  three incoming streams.

&sv .num11 [show select 1]
    &sv .num12 [show arc %.num11% item order]
&sv .num13 [show select 2]
    &sv .num14 [show arc %.num13% item order]
&sv .num15 [show select 3]
    &sv .num16 [show arc %.num15% item order]

/*  Return to the main program if any of the incoming streams are unlabeled

	&if %.num12% = 0 &then &return
	&if %.num14% = 0 &then &return
	&if %.num16% = 0 &then &return

/* if all the values for incoming streams are labeled, then go ahead and      
/* figure out if they are all different, and if so set the variable .num17
/* equal to the greatest of the three

	&if %.num12% > %.num14% and %.num12% > %.num16% &then ~
&sv .num17 = %.num12%

	&if %.num14% > %.num12% and %.num14% > %.num16% &then ~
&sv .num17 = %.num14%

	&if %.num16% > %.num14% and %.num16% > %.num12% &then ~
&sv .num17 = %.num16%

/*  Determine if all incoming streams have the same order - if they do, 
/*  then calc .num17 = order + 1	

	&if %.num12% = %.num14% and %.num12% = %.num16% &then ~
&sv .num17 = %.num12% + 1

/*  Determine if two of the streams are the same, but the third is 
/*  higher order than they - if so, then calc .num17 = highest order.

	&if %.num12% > %.num14% and %.num14% = %.num16% &then ~
&sv .num17 = %.num12%

	&if %.num14% > %.num12% and %.num12% = %.num16% &then ~
&sv .num17 = %.num14%

	&if %.num16% > %.num12% and %.num12% = %.num14% &then ~
&sv .num17 = %.num16%

/*  Determine if two are the same but the third is smaller - if so, 
/*  then calc .num17 = order of the two + 1

	&if %.num12% < %.num14% and %.num14% = %.num16% &then ~
&sv .num17 = %.num14% + 1

	&if %.num14% < %.num12% and %.num12% = %.num16% &then ~
&sv .num17 = %.num12% + 1

	&if %.num16% < %.num12% and %.num12% = %.num14% &then ~
&sv .num17 = %.num12% + 1

/*  Now select the fnode needed and calc its order = .num17

sel fnode# = %.num1%
   calc order = %.num17%

&return