# RiverWare_Ruleset 6.4.6 Patch # Created 18:47 March 18, 2014 # RULESET AGENDA_ORDER ASCENDING; DESCRIPTION ""; PRECISION 8; BEGIN POLICY_GROUP "Adjustments"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Handle Reservoir Adjustments"; DESCRIPTION "Rule Handle Reservoir Adjustments
# This rule will run after adjustments have been calculated.
# Based on the reservoir adjustment options, the adjustments will be routed correctly for the user settings.

# DON'T START DOING ADJUSTMENT UNTIL SECOND YEAR
# CHANGE HERE IF WANT TO START ADJUSTMENTS SOONER

IF (timestep after start timestep + 11 AND timestep before last timestep) THEN

# Calculate total outflow from Luis Leon due to adjustments at Madero, La Boquilla and Luis Leon
Total outflow =
Luis Leon observed outflow + Luis LeonAbove NAMO adjustment + Luis Leon Additional Releases adjustment + Get Upstream Res Transfer in Luis Leon (100)
Set LuisLeon.Outflow = Total outflow
# Set adjustments at Luis Leon due to conditions at Luis Leon
US share of Luis LeonAbove NAMO outflow =
Results.LuisLeonAboveNAMOAdjustment x GetNamedTrib_USPercent ()

MX share of Luis LeonAbove NAMO outflow =
Results.LuisLeonAboveNAMOAdjustment x (1 - GetNamedTrib_USPercent () )

US share of Luis Leon Additional Releases outflow =
Results.LuisLeonAdditionalReleasesAdjustment x GetNamedTrib_USPercent ()

MX share of Luis Leon Additional Releases outflow =
Results.LuisLeonAdditionalReleasesAdjustment x (1 - GetNamedTrib_USPercent ())

# Set adjustments at Madero due to conditions at Madero
IF (Madero option is to release adjustment from Luis Leon) THEN
# Transfer adjustment volume in Madero to keep track of it, no release from Madero
MaderoAbove NAMO transfer to Trans_Rel_Dwnstrm account =
Results.MaderoAboveNAMOAdjustment + Results.MaderoAdditionalReleasesAdjustment

ELSE IF (Madero option is to transfer adjustment in Amistad) THEN
# Transfer adjustment volume in Madero to keep track of it, no release from Madero
MaderoAbove NAMO transfer to Trans_in_Amistad account =
Results.MaderoAboveNAMOAdjustment + Results.MaderoAdditionalReleasesAdjustment

END IF

# Set total outflow from Madero
Madero.Outflow = Madero observed outflow + Get Madero Total Adjustment Release ()

# Set AboveNAMO outflow from Madero
MaderoAbove NAMO outflow = Get MaderoAbove NAMO Adjustment Release ()


# Set Additional Releases outflow from Madero
MaderoAdditional Releases outflow = Get Madero AddRel Adjustment Release ()

# Set adjustments at La Boquilla due to conditions at La Boquilla
IF (La Boquilla option is to release adjustment from Luis Leon) THEN
# Transfer adjustment volume in La Boquilla to keep track of it, no release from Madero
LaBoquillaAbove NAMO transfer to Trans_Rel_Dwnstrm account =
Results.LaBoquillaAboveNAMOAdjustment + Results.LaBoquillaAdditionalReleasesAdjustment


ELSE IF (La Boquilla option is to transfer adjustment in Amistad) THEN
# Transfer adjustment volume in La Boquilla to keep track of it, no release from Madero
LaBoquillaAbove NAMO transfer to Trans_in_Amistad account =
Results.LaBoquillaAboveNAMOAdjustment + Results.LaBoquillaAdditionalReleasesAdjustment

END IF

# Set total outflow from La Boquilla
LaBoquilla.Outflow = LaBoquilla observed outflow + Get LaBoquilla Total Adjustment Release ()

# Set AboveNAMO outflow from La Boquilla
LaBoquillaAbove NAMO outflow = Get LaBoquillaAbove NAMO Adjustment Release ()

# Set Additional Releases outflow from LaBoquilla
LaBoquillaAdditional Releases outflow = Get LaBoquilla AddRel Adjustment Release ()


# Transfer in Amistad due to adjustments
Amistad transfer from MX to US = Get Transfer in Amistad ()


# Pass-through flows at Luis Leon from upstream reservoirs
US pass-through flow at Luis Leon from Madero and La Boquilla =
Get Upstream Res Transfer in Luis Leon (NamedTribs_AdjSettings.ActionPct)

MX pass-through flow at Luis Leon from Madero and La Boquilla =
Get Upstream Res Transfer in Luis Leon (100 - NamedTribs_AdjSettings.ActionPct)

END IF # (in first year)
End Rule

"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN IF_STATEMENT (@"t" > @"Start Timestep + 11" AND @"t" < @"Finish Timestep") THEN PRINT "=========HANDLE ADJUSTMENTS==========="; DESCRIPTION "
CALCULATE TOTAL OUTFLOW FROM LUIS LEON DUE TO ADJUSTMENTS AT MADERO, LA BOQUILLA AND LUIS LEON"; WITH_STATEMENT (NUMERIC totflow = "FlowToVolume"( $ "ReservoirOutflow_Obs.LuisLeon" [], @"t" ) + ( $ "Results.Luis Leon Above NAMO Adjustment" [] + $ "Results.Luis Leon Additional Releases Adjustment" [] ) + "FlowToVolume"( "Get Upstream Res Transfer In Luis Leon"( 100.00000000 ), @"t" )) DO $ "Luis Leon.Outflow" [] := "VolumeToFlow"( totflow, @"t" ); PRINT ".... Luis Leon outflow " CONCAT totflow; PRINT "........Luis Leon obs outflow " CONCAT "FlowToVolume"( $ "ReservoirOutflow_Obs.LuisLeon" [], @"t" ); PRINT "........Luis Leon outflow Above NAMO " CONCAT ( $ "Results.Luis Leon Above NAMO Adjustment" [] ); PRINT "........Luis Leon outflow Add Rel " CONCAT ( $ "Results.Luis Leon Additional Releases Adjustment" [] ); DESCRIPTION "
======================================
ADJUSTMENTS AT LUIS LEON DUE TO LUIS LEON CONDITIONS
======================================

SET ABOVE NAMO US ADJUSTMENT FOR LUIS LEON"; $ "Luis Leon AboveNAMO to Rio Conchos AboveNAMO_US.Supply" [] := "VolumeToFlow"( ( $ "Results.Luis Leon Above NAMO Adjustment" [] * "GetNamedTrib_USPercent"( ) ), @"t" ); DESCRIPTION "
SET ABOVE NAMO MX ADJUSTMENT FOR LUIS LEON"; $ "Luis Leon AboveNAMO to Rio Conchos AboveNAMO_MX.Supply" [] := "VolumeToFlow"( ( $ "Results.Luis Leon Above NAMO Adjustment" [] * ( 1.00000000 - "GetNamedTrib_USPercent"( ) ) ), @"t" ); DESCRIPTION "
SET ADDITIONAL RESERVOIR RELEASE US ADJUSTMENT FOR LUIS LEON"; $ "Luis Leon AddResRel to Rio Conchos AddResRel_US.Supply" [] := "VolumeToFlow"( ( $ "Results.Luis Leon Additional Releases Adjustment" [] * "GetNamedTrib_USPercent"( ) ), @"t" ); DESCRIPTION "
SET ADDITIONAL RESERVOIR RELEASE MX ADJUSTMENT FOR LUIS LEON"; $ "Luis Leon AddResRel to Rio Conchos AddResRel_MX.Supply" [] := "VolumeToFlow"( ( $ "Results.Luis Leon Additional Releases Adjustment" [] * ( 1.00000000 - "GetNamedTrib_USPercent"( ) ) ), @"t" ); DESCRIPTION "
==============================
ADJUSTMENTS DUE TO CONDITIONS AT MADERO
==============================

SET MADERO ADJUSTMENTS CONTINGENT ON UPSTREAM RESERVOIR RELEASE OPTION"; IF_STATEMENT ($ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" []) THEN DESCRIPTION "
RELEASE ADJUSTMENT AMOUNT FROM DOWNSTREAM RESERVOIR, NO LOSSES (NO RELEASE FROM MADERO)
TRANSFER IN MADERO TO KEEP TRACK OF VOLUME"; $ "Madero AboveNAMO to Madero Trans_Rel_Dwnstrm Tran.Supply" [] := "VolumeToFlow"( $ "Results.Madero Above NAMO Adjustment" [], @"t" ); $ "Madero AddResRel to Madero Trans_Rel_Dwnstrm Tran.Supply" [] := "VolumeToFlow"( $ "Results.Madero Additional Releases Adjustment" [], @"t" ); ELSE IF_STATEMENT ($ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_INTL_RES_TRANSFER" []) THEN DESCRIPTION "
TRANSFER ADJUSTMENT AMOUNT IN AMISTAD (NO RELEASE FROM MADERO)
TRANSFER IN MADERO TO KEEP TRACK OF VOLUME"; $ "Madero AboveNAMO to Madero Trans_in_Amistad Tran.Supply" [] := "VolumeToFlow"( $ "Results.Madero Above NAMO Adjustment" [], @"t" ); $ "Madero AddResRel to Madero Trans_in_Amistad Tran.Supply" [] := "VolumeToFlow"( $ "Results.Madero Additional Releases Adjustment" [], @"t" ); END_IF_STATEMENT; END_IF_STATEMENT; DESCRIPTION "
SET TOTAL OUTFLOW FROM MADERO"; $ "Madero.Outflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "ReservoirOutflow_Obs.Madero" [], @"t" ) + "Get Madero Total Adjustment Release"( ), @"t" ); DESCRIPTION "
SET ADDITIONAL RESERVOIR RELEASE ADJUSTMENT FOR MADERO"; $ "Madero AddResRel to Rio San Pedro AddResRel.Supply" [] := "VolumeToFlow"( "Get Madero AddRel Adjustment Release"( ), @"t" ); DESCRIPTION "
SET ABOVE NAMO RELEASE ADJUSTMENT FOR MADERO"; $ "Madero AboveNAMO to Rio San Pedro AboveNAMO.Supply" [] := "VolumeToFlow"( "Get Madero Above NAMO Adjustment Release"( ), @"t" ); DESCRIPTION "
=================================
ADJUSTMENTS DUE TO CONDITIONS AT LA BOQUILLA
=================================

SET LA BOQUILLA ADJUSTMENTS CONTINGENT ON UPSTREAM RESERVOIR RELEASE OPTION"; IF_STATEMENT ($ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" []) THEN DESCRIPTION "
RELEASE ADJUSTMENT AMOUNT FROM DOWNSTREAM RESERVOIR, NO LOSSES (NO RELEASE FROM MADERO)
TRANSFER IN LA BOQUILLA TO KEEP TRACK OF VOLUME"; $ "La Boquilla AboveNAMO to La Boquilla Trans_Rel_Dwnstrm Tran.Supply" [] := "VolumeToFlow"( $ "Results.La Boquilla Above NAMO Adjustment" [], @"t" ); $ "La Boquilla AddResRel to La Boquilla Trans_Rel_Dwnstrm Tran.Supply" [] := "VolumeToFlow"( $ "Results.La Boquilla Additional Releases Adjustment" [], @"t" ); ELSE IF_STATEMENT ($ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_INTL_RES_TRANSFER" []) THEN DESCRIPTION "
TRANSFER ADJUSTMENT AMOUNT IN AMISTAD (NO RELEASE FROM LA BOQUILLA)
TRANSFER IN LA BOQUILLA TO KEEP TRACK OF VOLUME"; $ "La Boquilla AboveNAMO to La Boquilla Trans_in_Amistad Tran.Supply" [] := "VolumeToFlow"( $ "Results.La Boquilla Above NAMO Adjustment" [], @"t" ); $ "La Boquilla AddResRel to La Boquilla Trans_in_Amistad Tran.Supply" [] := "VolumeToFlow"( $ "Results.La Boquilla Additional Releases Adjustment" [], @"t" ); END_IF_STATEMENT; END_IF_STATEMENT; DESCRIPTION "
SET TOTAL OUTFLOW FROM LA BOQUILLA"; $ "La Boquilla.Outflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "ReservoirOutflow_Obs.LaBoquilla" [], @"t" ) + "Get La Boquilla Total Adjustment Release"( ), @"t" ); $ "La Boquilla AboveNAMO to Upper Rio Conchos 2 AboveNAMO.Supply" COMMENTED_BY "
SET ABOVE NAMO RELEASE ADJUSTMENT FOR LA BOQUILLA" [] := "VolumeToFlow"( "Get La Boquilla Above NAMO Adjustment Release"( ), @"t" ); $ "La Boquilla AddResRel to Upper Rio Conchos 2 AddResRel.Supply" COMMENTED_BY "
SET ADDITIONAL RESERVOIR RELEASE ADJUSTMENT FOR LA BOQUILLA" [] := "VolumeToFlow"( "Get La Boquilla AddRel Adjustment Release"( ), @"t" ); DESCRIPTION "
============================
TRANSFER IN AMISTAD DUE TO ADJUSTMENTS
============================"; $ "AMISTAD ResTransfer_MX to AMISTAD ResTransfer_US Tran.Supply" [] := "Get Transfer In Amistad"( ); PRINT "...MX to US transfer in Amistad..." CONCAT "FlowToVolume"( "Get Transfer In Amistad"( ), @"t" ); DESCRIPTION "
==========================================
PASS THROUGH FLOWS AT LUIS LEON FROM UPSTREAM RESERVOIRS
=========================================="; $ "Luis Leon UpstreamResAdj to Luis Leon PassThru_US Tran.Supply" [] := "Get Upstream Res Transfer In Luis Leon"( $ "NamedTribs_AdjSettings.ActionPct" [] ); $ "Luis Leon UpstreamResAdj to Luis Leon PassThru_MX Tran.Supply" [] := "Get Upstream Res Transfer In Luis Leon"( 100.00000000 - $ "NamedTribs_AdjSettings.ActionPct" [] ); PRINT "....US upstream passthru in Luis Leon " CONCAT "FlowToVolume"( "Get Upstream Res Transfer In Luis Leon"( $ "NamedTribs_AdjSettings.ActionPct" [] ), @"t" ) CONCAT " US pct " CONCAT ( $ "NamedTribs_AdjSettings.ActionPct" [] ); PRINT "....MX upstream passthru in Luis Leon " CONCAT "FlowToVolume"( "Get Upstream Res Transfer In Luis Leon"( 100.00000000 - $ "NamedTribs_AdjSettings.ActionPct" [] ), @"t" ); END_WITH_STATEMENT; END_IF_STATEMENT; END; RULE "Do Adjustments"; DESCRIPTION "Rule Do Adjustments
# Do the calculations for the adjustments and options specified by the user

# DON'T START CHECKING ADJUSTMENT UNTIL SECOND YEAR
# CHANGE HERE IF WANT TO START ADJUSTMENTS SOONER

IF (timestep after start timestep + 11 AND timestep before last timestep) THEN
# Loop through adjustment priorities
FOR (priority = 1 to number of adjustment types) DO
# Loop through adjustment types to do in priority order
FOR (adjType = each of {list of adjustment types}) DO
# Match adjustment type priority
IF (priority = adjType.Priority) THEN
# Make sure adjustment type is enabled
IF (adjType.Enabled = TRUE) THEN
# Check for percent deviation within adjustment type trigger range
IF (prev month pct deviation within adjType.MinTriggerPct and adjType.MaxTriggerPct) THEN
# Do calculations for each adjustment type
IF (adjType = AboveNAMO) THEN
# Loop through reservoir priorities
FOR (resPriority = 1 to number of reservoirs) DO
# Loop through reservoirs to do in priority order
FOR (res = each of {list of reservoir}) DO
# Match reservoir priority
IF (resPriority = res.Priority) THEN
# Get calculated adjustment
adjustment = Get_AboveNAMO_Adjustment_Release (res)
# Do adjustment for each reservoir
IF (res = Madero) THEN
# Make sure hydrologic conditions allow adjustments
IF (ConchosHydOK_ForAdj = TRUE and adjustment > 0) THEN
# Store adjustment
Results.MaderoAbove NAMO Adjustment = adjustment
END IF
ELSE IF (res = La Boquilla) THEN
# Make sure hydrologic conditions allow adjustments
IF (ConchosHydOK_ForAdj = TRUE and adjustment > 0) THEN
# Store adjustment
Results.LaBoquillaAbove NAMO Adjustment = adjustment
END IF
ELSE IF (res = Luis Leon) THEN
# Make sure hydrologic conditions allow adjustments
IF (ConchosHydOK_ForAdj = TRUE and adjustment > 0) THEN
# Store adjustment
Results.LuisLeonAbove NAMO Adjustment = adjustment
END IF
END IF # (which reservoir)
END IF # (priority matches)
END FOR # (loop through reservoirs)
END FOR # (loop through reservoir priorities)

ELSE IF (adjType = AdditionalReservoirRelease) THEN
# Loop through reservoir priorities
FOR (resPriority = 1 to number of reservoirs) DO
# Loop through list of reservoirs
FOR (res = each of {list of reservoir}) DO
# Match reservoir priority
IF (resPriority = res.Priority) THEN
# Get calculated adjustment
adjustment = Get_AddRes_Adjustment_Release (res)

# Do adjustment for each reservoir
IF (res = Madero) THEN
# Make sure hydrologic conditions are ok for adjustment
IF (ConchosHydOK_ForAdj = TRUE and adjustment > 0) THEN
# Check for Above NAMO Adjustment made
IF (Above NAMO Adjustment = 0) THEN
# Store adjustment
Results.MaderoAdditionalReleaseAdjustment = adjustment
ELSE
# Above NAMO adjustment made, cannot do additional releases also
Results.MaderoAdditionalReleaseAdjustment = 0
END IF
END IF
ELSE IF (res = La Boquilla) THEN
# Make sure hydrologic conditions are ok for adjustment
IF (ConchosHydOK_ForAdj = TRUE and adjustment > 0) THEN
# Check for Above NAMO Adjustment made
IF (Above NAMO Adjustment = 0) THEN
# Store adjustment
Results.LaBoquillaAdditionalReleaseAdjustment = adjustment
ELSE
# Above NAMO adjustment made, cannot do additional releases also
Results.LaBoquillaAdditionalReleaseAdjustment = 0
END IF
END IF
ELSE IF (res = Luis Leon) THEN
# Make sure hydrologic conditions are ok for adjustment
IF (ConchosHydOK_ForAdj = TRUE and adjustment > 0) THEN
# Check for Above NAMO Adjustment made
IF (Above NAMO Adjustment = 0) THEN
# Store adjustment
Results.LuisLeonAdditionalReleaseAdjustment = adjustment
ELSE
# Above NAMO adjustment made, cannot do additional releases also
Results.LuisLeonAdditionalReleaseAdjustment = 0
END IF
END IF
END IF # (which reservoir)
END IF # (priority matches)
END FOR # (loop through reservoirs)
END FOR # (loop through reservoir priorities)

ELSE IF (adjType = Greater Proportion Named Tributaries) THEN

IF (ConchosHydOK_ForAdj = TRUE) THEN
# No losses will be applied to adjustment volume
Set US adjustment of Rio Conchos from Luis Leon =
(Obs Rio Conchos x new proportion) – (Obs Rio Conchos x 1/3)
Set MX adjustment of Rio Conchos from Luis Leon =
(Obs Rio Conchos x 1/3) – (Obs Rio Conchos x new proportion)
END IF

ELSE IF (adjType = Greater Proportion MX Unmeasured Tributaries) THEN
IF (ConchosHydOK_ForAdj = TRUE) THEN
# No losses will be applied to adjustment volumes
Set US adjustment for unmeasured tributary at Reach 1 =
(Obs MX unmeasured tributary at Reach 1) x (new proportion)
Set MX adjustment for unmeasured tributary at Reach 1 =
(Obs MX unmeasured tributary at Reach 1) x (new proportion) x (-1)

Set US adjustment for unmeasured tributary at Reach 2 =
(Obs MX unmeasured tributary at Reach 2) x (new proportion)
Set MX adjustment for unmeasured tributary at Reach 2 =
(Obs MX unmeasured tributary at Reach 2) x (new proportion) x (-1)

Set US adjustment for unmeasured tributary at Reach 3 =
(Obs MX unmeasured tributary at Reach 3) x (new proportion)
Set MX adjustment for unmeasured tributary at Reach 3 =
(Obs MX unmeasured tributary at Reach 3) x (new proportion) x (-1)

Set US adjustment for unmeasured tributary at Reach 4 =
(Obs MX unmeasured tributary at Reach 4) x (new proportion)
Set MX adjustment for unmeasured tributary at Reach 4 =
(Obs MX unmeasured tributary at Reach 4) x (new proportion) x (-1)

END IF

ELSE IF (adjType = Greater Proportion MX Springflow) THEN

IF (ConchosHydOK_ForAdj = TRUE) THEN
# No losses will be applied to adjustment volumes
Set US adjustment for Springflow =
(Obs MX springflow) x (new proportion)
Set US adjustment for Springflow =
(Obs MX springflow) x (new proportion) x (-1)

END IF # (which adjustment type)

# Make sure observed outflows are set
IF (Madero outflow not set) THEN
Madero outflow = Madero observed outflow
END IF
IF (La Boquilla outflow not set) THEN
La Boquilla outflow = La Boquilla observed outflow
END IF
IF (Luis Leon outflow not set) THEN
Luis Leon outflow = Luis Leon observed outflow
END IF

ELSE
# Percent deviation not in trigger range, make sure observed outflows are set
IF (Madero outflow not set) THEN
Madero outflow = Madero observed outflow
END IF
IF (La Boquilla outflow not set) THEN
La Boquilla outflow = La Boquilla observed outflow
END IF
IF (Luis Leon outflow not set) THEN
Luis Leon outflow = Luis Leon observed outflow
END IF
END IF # (percent deviation in trigger range)

ELSE
# Adjustment type not enabled, make sure observed outflows are set
IF (Madero outflow not set) THEN
Madero outflow = Madero observed outflow
END IF
IF (La Boquilla outflow not set) THEN
La Boquilla outflow = La Boquilla observed outflow
END IF
IF (Luis Leon outflow not set) THEN
Luis Leon outflow = Luis Leon observed outflow
END IF

END IF # (adjustment type enabled)
END IF # (matched adjustment priority)
END FOR # (loop through list of adjustment types)
END FOR # (loop through adjustment priorities)
ELSE
# Not in first year, just make sure observed outflows are set
IF (Madero outflow not set) THEN
Madero outflow = Madero observed outflow
END IF
IF (La Boquilla outflow not set) THEN
La Boquilla outflow = La Boquilla observed outflow
END IF
IF (Luis Leon outflow not set) THEN
Luis Leon outflow = Luis Leon observed outflow
END IF
END IF # (in first year)

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN DESCRIPTION "====================================
DON'T START CHECKING ADJUSTMENT UNTIL SECOND YEAR
====================================
CHANGE HERE IF WANT TO START ADJUSTMENTS SOONER
===================================="; IF_STATEMENT (@"t" > @"Start Timestep + 11" AND @"t" < @"Finish Timestep") THEN DESCRIPTION "
DON'T USE ACTION MONTHS SETTING TO DO ADJUSTMENTS (USE TO SELECT TRIGGER PERCENT)
DO ADJUSTMENTS EVERY MONTH"; IF_STATEMENT ($ "Settings.ActionMonths" [] == $ "Constants.TRUE" [] OR $ "Settings.ActionMonths" [] == $ "Constants.FALSE" []) THEN PRINT "============"; DESCRIPTION "
LOOP THROUGH ADJUSTMENT TYPES IN PRIORITY ORDER"; FOREACH (NUMERIC priority IN "GetNumbers"( 1.00000000, LENGTH "ListSubbasin"( "Adjustments Subbasin" ), 1.00000000 )) DO PRINT "ADJUSTMENT PRIORITY: " CONCAT priority; DESCRIPTION "
FIND ADJUSTMENT MATCHING PRIORITY NUMBER"; FOREACH (OBJECT obj IN "ListSubbasin"( "Adjustments Subbasin" )) DO IF_STATEMENT (obj CONCAT ".Priority" [] == priority) THEN PRINT "....ADJUSTMENT TYPE: " CONCAT obj; DESCRIPTION "
MAKE SURE ADJUSTMENT IS ENABLED BEFORE DOING IT"; IF_STATEMENT (obj CONCAT ".IsEnabled" [] == $ "Constants.TRUE" []) THEN DESCRIPTION "
MAKE SURE PERCENT DEVIATION IS WITHIN SPECIFIED TRIGGER RANGE FOR ADJUSTMENT"; IF_STATEMENT ($ "Results.PctDevFromTarget_ForActionMonths" [@"t - 1"] >= obj CONCAT ".MinTriggerPct" [@"t"] AND $ "Results.PctDevFromTarget_ForActionMonths" [@"t - 1"] <= obj CONCAT ".MaxTriggerPct" [@"t"]) THEN PRINT "....In Trigger Range: Prev Pct Deviation = " CONCAT ( $ "Results.PctDevFromTarget_ForActionMonths" [@"t - 1"] ) CONCAT " Min Pct = " CONCAT ( obj CONCAT ".MinTriggerPct" [@"t"] ) CONCAT ( " Max Pct = " CONCAT ( obj CONCAT ".MaxTriggerPct" [@"t"] ) ); DESCRIPTION "
FIND ADJUSTMENT TYPE"; IF_STATEMENT (obj == % "AboveNAMO_AdjSettings") THEN DESCRIPTION "
===================
DO ABOVE NAMO ADJUSTMENT
==================="; IF_STATEMENT ($ "USER_INPUT.UseResPriorityOrder" [] == $ "Constants.TRUE" []) THEN DESCRIPTION "
DO ABOVE NAMO ADJUSTMENT IN RESERVOIR PRIORITY ORDER"; FOREACH (NUMERIC resPriority IN "GetNumbers"( 1.00000000, LENGTH "ListSubbasin"( "Reservoirs Subbasin" ), 1.00000000 )) DO PRINT "........RESERVOIR PRIORITY: " CONCAT resPriority; DESCRIPTION "
LOOP THROUGH RESERVOIRS TO FIND ONE MATCHING PRIORITY ORDER"; FOREACH (OBJECT resObj IN "ListSubbasin"( "Reservoirs Subbasin" )) DO IF_STATEMENT (resObj CONCAT ".Priority" [] == resPriority) THEN PRINT "............Reservoir: " CONCAT resObj; WITH_STATEMENT (OBJECT adjObj = resObj) DO DESCRIPTION "
GET ABOVE NAMO ADJUSTMENT FOR RESERVOIR"; WITH_STATEMENT (NUMERIC adjustment = "Get_AboveNAMO_Adjustment_Release"( adjObj )) DO DESCRIPTION "
FOUND NEXT RESERVOIR IN PRIORITY ORDER - SET RESULTS FOR THAT RESERVOIR"; IF_STATEMENT (adjObj == % "Madero_ResSettings") THEN DESCRIPTION "
MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK FOR MADERO ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" [] AND adjustment > 0.00000000 "MCM/month") THEN DESCRIPTION "
SELECTED OPTION THAT RELEASES ADJUSTMENT FROM MADERO"; $ "Results.Madero Above NAMO Adjustment" [] := "FlowToVolume"( adjustment, @"t" ); PRINT "................ADJUSTMENT = " CONCAT ( "FlowToVolume"( adjustment, @"t" ) CONCAT " with Conchos Hyd OK" ); END_IF_STATEMENT; ELSE IF_STATEMENT (adjObj == % "LaBoquilla_ResSettings") THEN DESCRIPTION "
MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK FOR LA BOQUILLA ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" [] AND adjustment > 0.00000000 "MCM/month") THEN $ "Results.La Boquilla Above NAMO Adjustment" [] := "FlowToVolume"( adjustment, @"t" ); PRINT "................ADJUSTMENT = " CONCAT ( "FlowToVolume"( adjustment, @"t" ) CONCAT " with Conchos Hyd OK" ); END_IF_STATEMENT; ELSE IF_STATEMENT (adjObj == % "LuisLeon_ResSettings") THEN DESCRIPTION "
MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK FOR LUIS LEON ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" [] AND adjustment > 0.00000000 "MCM/month") THEN DESCRIPTION "
SAVE LUIS LEON ADJUSTMENTS FOR NOW, APPLY IN UPSTREAM RESERVOIR RULE"; $ "Results.Luis Leon Above NAMO Adjustment" [] := "FlowToVolume"( adjustment, @"t" ); PRINT "................ADJUSTMENT = " CONCAT ( "FlowToVolume"( adjustment, @"t" ) CONCAT " with Conchos Hyd OK" ); END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; END_WITH_STATEMENT; END_WITH_STATEMENT; END_IF_STATEMENT; ENDFOREACH; ENDFOREACH; ELSE DESCRIPTION "
DO IN VOLUME ABOVE NAMO ORDER"; PRINT "TODO:..vol above namo"; END_IF_STATEMENT; ELSE DESCRIPTION "
===============================
FOUND ADDITIONAL RELEASES ADJUSTMENT TYPE
==============================="; IF_STATEMENT (obj == % "AddResRel_AdjSettings") THEN DESCRIPTION "
DO ADDIITONAL DELIVERIES ADJUSTMENT"; IF_STATEMENT ($ "USER_INPUT.UseResPriorityOrder" [] == $ "Constants.TRUE" []) THEN PRINT "........RESERVOIR PRIORITY: "; DESCRIPTION "
DO ADDITIONAL DELIVERIES ADJUSTMENT IN RESERVOIR PRIORITY ORDER"; FOREACH (NUMERIC resPriority IN "GetNumbers"( 1.00000000, LENGTH "ListSubbasin"( "Reservoirs Subbasin" ), 1.00000000 )) DO PRINT "....RESERVOIR PRIORITY: " CONCAT resPriority; DESCRIPTION "
LOOP THROUGH RESERVOIRS TO FIND ONE MATCHING PRIORITY ORDER"; FOREACH (OBJECT resObj IN "ListSubbasin"( "Reservoirs Subbasin" )) DO IF_STATEMENT (resObj CONCAT ".Priority" [] == resPriority) THEN PRINT "............Reservoir: " CONCAT resObj; WITH_STATEMENT (OBJECT adjObj = resObj) DO DESCRIPTION "
GET ADDITIONAL DELIVERY ADJUSTMENT"; WITH_STATEMENT (NUMERIC adjustment = "Get_AddRes_Adjustment_Release"( adjObj )) DO DESCRIPTION "
FOUND NEXT RESERVOIR IN PRIORITY ORDER - SET SUPPLY FOR THAT RESERVOIR"; IF_STATEMENT (adjObj == % "Madero_ResSettings") THEN DESCRIPTION "
MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK AND NO ABOVE NAMO ADJUSTMENTS FOR MADERO ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" [] AND adjustment > 0.00000000 "MCM/month") THEN IF_STATEMENT ($ "Results.Madero Above NAMO Adjustment" [] == 0.00000000 "MCM") THEN DESCRIPTION "
SELECTED OPTION THAT RELEASES ADJUSTMENT FROM MADERO"; $ "Results.Madero Additional Releases Adjustment" [] := "FlowToVolume"( adjustment, @"t" ); PRINT "................ADJUSTMENT = " CONCAT ( "FlowToVolume"( adjustment, @"t" ) CONCAT " with Conchos Hyd OK" CONCAT " Above NAMO Adj = " CONCAT ( $ "Results.Madero Above NAMO Adjustment" [] ) ); ELSE DESCRIPTION "
DONT DO ADDITIONAL RELEASES ADJUSTMENT IF HAVE DONE ABOVE NAMO RELEASES"; $ "Results.Madero Additional Releases Adjustment" [] := 0.00000000 "MCM"; PRINT "................reset adjustment = " CONCAT ( " 0.00 " CONCAT " with Conchos Hyd OK" CONCAT " Above NAMO Adj = " CONCAT ( $ "Results.Madero Above NAMO Adjustment" [] ) ); END_IF_STATEMENT; END_IF_STATEMENT; ELSE IF_STATEMENT (adjObj == % "LaBoquilla_ResSettings") THEN DESCRIPTION "
MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK AND NO ABOVE NAMO ADJUSTMENTS
FOR LA BOQUILLA ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" [] AND adjustment > 0.00000000 "MCM/month") THEN IF_STATEMENT ($ "Results.La Boquilla Above NAMO Adjustment" [] == 0.00000000 "MCM") THEN $ "Results.La Boquilla Additional Releases Adjustment" [] := "FlowToVolume"( adjustment, @"t" ); PRINT "............ADJUSTMENT = " CONCAT ( "FlowToVolume"( adjustment, @"t" ) CONCAT " with Conchos Hyd OK" CONCAT " Above NAMO Adj = " CONCAT ( $ "Results.La Boquilla Above NAMO Adjustment" [] ) ); ELSE DESCRIPTION "
NO ADJUSTMENT IF ALREADY DID ABOVE NAMO ADJUSTMENT"; $ "Results.La Boquilla Additional Releases Adjustment" [] := 0.00000000 "MCM"; PRINT "............reset adjustment = " CONCAT ( " 0.00 " CONCAT " already did" CONCAT " Above NAMO Adj = " CONCAT ( $ "Results.La Boquilla Above NAMO Adjustment" [] ) ); END_IF_STATEMENT; END_IF_STATEMENT; ELSE IF_STATEMENT (adjObj == % "LuisLeon_ResSettings") THEN DESCRIPTION "
MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK AND NO ABOVE NAMO ADJUSTMENT FOR LUIS LEON ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" [] AND adjustment > 0.00000000 "MCM/month") THEN IF_STATEMENT ($ "Results.Luis Leon Above NAMO Adjustment" [] == 0.00000000 "MCM") THEN DESCRIPTION "
SAVE LUIS LEON ADJUSTMENTS FOR NOW, APPLY IN UPSTREAM RESERVOIR RULE LATER"; $ "Results.Luis Leon Additional Releases Adjustment" [] := "FlowToVolume"( adjustment, @"t" ); PRINT "................ADJUSTMENT = " CONCAT ( "FlowToVolume"( adjustment, @"t" ) CONCAT " with Conchos Hyd OK" CONCAT " Above NAMO Adj = " CONCAT ( $ "Results.Luis Leon Above NAMO Adjustment" [] ) ); ELSE DESCRIPTION "
NO ADJUSTMENT IF ALREADY DID ABOVE NAMO ADJUSTMENT"; $ "Results.Luis Leon Additional Releases Adjustment" [] := 0.00000000 "MCM"; PRINT "................reset adjustment = " CONCAT ( " 0.00 " CONCAT " already did" CONCAT " Above NAMO Adj = " CONCAT ( $ "Results.Luis Leon Above NAMO Adjustment" [] ) ); END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; END_WITH_STATEMENT; END_WITH_STATEMENT; END_IF_STATEMENT; ENDFOREACH; ENDFOREACH; ELSE DESCRIPTION "
DO IN VOLUME ABOVE NAMO ORDER"; PRINT "TODO:...vol above namo"; END_IF_STATEMENT; ELSE IF_STATEMENT (obj == % "NamedTribs_AdjSettings") THEN DESCRIPTION "
============================
FOUND NAMED TRIBUTARY ADJUSTMENT TYPE
============================

MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK FOR RIO CONCHOS ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" []) THEN DESCRIPTION "
SET ADJUSTMENT TO DIFFERENCE OF ACTION PERCENT AND 1/3"; $ "Luis Leon NamedTribs to Rio Conchos NamedTribs_US.Supply" [] := "VolumeToFlow"( $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( $ "NamedTribs_AdjSettings.ActionPct" [] / 100.00000000 ) - $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( 1.00000000 / 3.00000000 ), @"t" ); $ "Results.Rio Conchos US Prop Named Tribs Adjustment" [] := $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( $ "NamedTribs_AdjSettings.ActionPct" [] / 100.00000000 ) - $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( 1.00000000 / 3.00000000 ); $ "Luis Leon NamedTribs to Rio Conchos NamedTribs_MX.Supply" [] := "VolumeToFlow"( $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( 1.00000000 / 3.00000000 ) - $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( $ "NamedTribs_AdjSettings.ActionPct" [] / 100.00000000 ), @"t" ); PRINT "............RIO CONCHOS US ADJUSTMENT = " CONCAT ( ( $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( $ "NamedTribs_AdjSettings.ActionPct" [] / 100.00000000 ) - $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( 1.00000000 / 3.00000000 ) ) CONCAT " with Conchos Hyd OK" ); PRINT "............RIO CONCHOS MX ADJUSTMENT = " CONCAT ( ( $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( 1.00000000 / 3.00000000 ) - $ "NamedTribs_PartialMonths_Obs.Rio Conchos" [] * ( $ "NamedTribs_AdjSettings.ActionPct" [] / 100.00000000 ) ) CONCAT " with Conchos Hyd OK" ); END_IF_STATEMENT; ELSE IF_STATEMENT (obj == % "UnmeasTribs_AdjSettings") THEN DESCRIPTION "
============================
FOUND UNMEASURED TRIBUTARY ADJUSTMENT TYPE
============================

MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK FOR RIO CONCHOS ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" []) THEN DESCRIPTION "
SET ADJUSTMENT TO ACTION PERCENT OF MX SHARE"; $ "Reach 1 Unmeas Tribs^UnmeasTribs_US.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 1 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ), @"t" ); $ "Reach 1 Unmeas Tribs^UnmeasTribs_MX.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 1 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / - 100.00000000 ), @"t" ); $ "Reach 2 Unmeas Tribs^UnmeasTribs_US.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 2 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ), @"t" ); $ "Reach 2 Unmeas Tribs^UnmeasTribs_MX.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 2 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / - 100.00000000 ), @"t" ); $ "Reach 3 Unmeas Tribs^UnmeasTribs_US.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 3 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ), @"t" ); $ "Reach 3 Unmeas Tribs^UnmeasTribs_MX.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 3 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / - 100.00000000 ), @"t" ); $ "Reach 4 Unmeas Tribs^UnmeasTribs_US.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 4 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ), @"t" ); $ "Reach 4 Unmeas Tribs^UnmeasTribs_MX.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 4 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / - 100.00000000 ), @"t" ); $ "Results.Greater Prop Unmeas Tribs Adjustment" [] := "Get UnmeasTribs Adjustments Above Amistad"( ); PRINT "............UNMEAS TRIBS US ADJUSTMENT ABOVE AMISTAD = " CONCAT ( "Get UnmeasTribs Adjustments Above Amistad"( ) CONCAT " with Conchos Hyd OK" ); END_IF_STATEMENT; ELSE IF_STATEMENT (obj == % "MXSpringFlow_AdjSettings") THEN DESCRIPTION "
============================
FOUND MX SPRINGFLOW ADJUSTMENT TYPE
============================

MAKE SURE CONCHOS HYDROLOGIC CONDITIONS OK FOR RIO CONCHOS ADJUSTMENTS"; IF_STATEMENT ($ "RunTimeSettings.IsConchosHydOK_ForAdj" [] == $ "Constants.TRUE" []) THEN DESCRIPTION "
SET ADJUSTMENT TO ACTION PERCENT OF MX SHARE"; $ "Reach 5 Spring Inflow^Springflow_US.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 5 Spring Inflow^Obs_SprFlow_MX.Slot Inflow" [], @"t" ) * ( $ "MXSpringFlow_AdjSettings.ActionPct" [] / 100.00000000 ), @"t" ); $ "Reach 5 Spring Inflow^Springflow_MX.Slot Inflow" [] := "VolumeToFlow"( "FlowToVolume"( $ "Reach 5 Spring Inflow^Obs_SprFlow_MX.Slot Inflow" [], @"t" ) * ( $ "MXSpringFlow_AdjSettings.ActionPct" [] / - 100.00000000 ), @"t" ); $ "Results.Greater Prop MX Springflow Adjustment" [] := "FlowToVolume"( $ "Reach 5 Spring Inflow^Obs_SprFlow_MX.Slot Inflow" [], @"t" ) * ( $ "MXSpringFlow_AdjSettings.ActionPct" [] / 100.00000000 ); PRINT "............MX SPRINGFLOW US ADJUSTMENT = " CONCAT ( ( "FlowToVolume"( $ "Reach 5 Spring Inflow^Obs_SprFlow_MX.Slot Inflow" [], @"t" ) * ( $ "MXSpringFlow_AdjSettings.ActionPct" [] / 100.00000000 ) ) CONCAT " with Conchos Hyd OK" ); END_IF_STATEMENT; ELSE PRINT "TODO...check for next adj"; END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; END_IF_STATEMENT; DESCRIPTION "
MAKE SURE OUTFLOW IS SET"; IF_STATEMENT (IsNaN $ "Madero.Outflow" []) THEN $ "Madero.Outflow" [] := $ "ReservoirOutflow_Obs.Madero" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "La Boquilla.Outflow" []) THEN $ "La Boquilla.Outflow" [] := $ "ReservoirOutflow_Obs.LaBoquilla" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "Luis Leon.Outflow" []) THEN $ "Luis Leon.Outflow" [] := $ "ReservoirOutflow_Obs.LuisLeon" []; END_IF_STATEMENT; ELSE DESCRIPTION "
NOT IN TRIGGER RANGE, NO ADJUSTMENTS"; IF_STATEMENT (IsNaN $ "Madero.Outflow" []) THEN $ "Madero.Outflow" [] := $ "ReservoirOutflow_Obs.Madero" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "La Boquilla.Outflow" []) THEN $ "La Boquilla.Outflow" [] := $ "ReservoirOutflow_Obs.LaBoquilla" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "Luis Leon.Outflow" []) THEN $ "Luis Leon.Outflow" [] := $ "ReservoirOutflow_Obs.LuisLeon" []; END_IF_STATEMENT; PRINT "....NOT In Trigger Range: Prev Pct Deviation = " CONCAT ( $ "Results.PctDevFromTarget_ForActionMonths" [@"t - 1"] ) CONCAT " Min Pct = " CONCAT ( obj CONCAT ".MinTriggerPct" [@"t"] ) CONCAT ( " Max Pct = " CONCAT ( obj CONCAT ".MaxTriggerPct" [@"t"] ) ); END_IF_STATEMENT; ELSE DESCRIPTION "
ADJUSTMENT TYPE NOT ENABLED, NO ADJUSTMENTS"; IF_STATEMENT (obj == % "AboveNAMO_AdjSettings") THEN IF_STATEMENT (IsNaN $ "Madero.Outflow" []) THEN $ "Madero.Outflow" [] := $ "ReservoirOutflow_Obs.Madero" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "La Boquilla.Outflow" []) THEN $ "La Boquilla.Outflow" [] := $ "ReservoirOutflow_Obs.LaBoquilla" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "Luis Leon.Outflow" []) THEN $ "Luis Leon.Outflow" [] := $ "ReservoirOutflow_Obs.LuisLeon" []; END_IF_STATEMENT; END_IF_STATEMENT; PRINT "....Not enabled"; END_IF_STATEMENT; END_IF_STATEMENT; ENDFOREACH; ENDFOREACH; ELSE DESCRIPTION "
NOT AN ACTION MONTH, NO ADJUSTMENTS"; IF_STATEMENT (IsNaN $ "Madero.Outflow" []) THEN $ "Madero.Outflow" [] := $ "ReservoirOutflow_Obs.Madero" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "La Boquilla.Outflow" []) THEN $ "La Boquilla.Outflow" [] := $ "ReservoirOutflow_Obs.LaBoquilla" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "Luis Leon.Outflow" []) THEN $ "Luis Leon.Outflow" [] := $ "ReservoirOutflow_Obs.LuisLeon" []; END_IF_STATEMENT; END_IF_STATEMENT; ELSE DESCRIPTION "
FIRST MONTH, NO ADJUSTMENTS"; IF_STATEMENT (IsNaN $ "Madero.Outflow" []) THEN $ "Madero.Outflow" [] := $ "ReservoirOutflow_Obs.Madero" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "La Boquilla.Outflow" []) THEN $ "La Boquilla.Outflow" [] := $ "ReservoirOutflow_Obs.LaBoquilla" []; END_IF_STATEMENT; IF_STATEMENT (IsNaN $ "Luis Leon.Outflow" []) THEN $ "Luis Leon.Outflow" [] := $ "ReservoirOutflow_Obs.LuisLeon" []; END_IF_STATEMENT; END_IF_STATEMENT; END; END; POLICY_GROUP "Reservoir Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Get Flood Pool Storage"; DESCRIPTION "Rule Get Flood Pool Storage
# Get the amount of water in each international reservoir above conservation storage levels

IF (Amistad total storage – US conservation storage – MX conservation storage > 0) THEN
Amistad Flood Pool storage = Amistad total storage – US conservation storage – MX conservation storage
ELSE
Amistad Flood Pool storage = 0
END IF

IF (Falcon total storage – US conservation storage – MX conservation storage > 0) THEN
Falcon Flood Pool storage = Falcon total storage – US conservation storage – MX conservation storage
ELSE
Falcon Flood Pool storage = 0
END IF


End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN IF_STATEMENT ($ "AMISTAD.Storage" [] - $ "ReservoirStorage_Obs.Amistad_ConsStg_US" [] - $ "ReservoirStorage_Obs.Amistad_ConsStg_MX" [] > 0.00000000 "MCM") THEN $ "AMISTAD^Flood Pool.Storage" [] := $ "AMISTAD.Storage" [] - $ "ReservoirStorage_Obs.Amistad_ConsStg_US" [] - $ "ReservoirStorage_Obs.Amistad_ConsStg_MX" []; ELSE $ "AMISTAD^Flood Pool.Storage" [] := 0.00000000 "MCM"; END_IF_STATEMENT; IF_STATEMENT ($ "FALCON.Storage" [] - $ "ReservoirStorage_Obs.Falcon_ConsStg_US" [] - $ "ReservoirStorage_Obs.Falcon_ConsStg_MX" [] > 0.00000000 "MCM") THEN $ "FALCON^Flood Pool.Storage" [] := $ "FALCON.Storage" [] - $ "ReservoirStorage_Obs.Falcon_ConsStg_US" [] - $ "ReservoirStorage_Obs.Falcon_ConsStg_MX" []; ELSE $ "FALCON^Flood Pool.Storage" [] := 0.00000000 "MCM"; END_IF_STATEMENT; END; END; POLICY_GROUP "Get Flags"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Get_ConchoHydCondFlags"; DESCRIPTION "Rule Get_ConchosHydCondFlags
# Calls function to get flag indicating if hydrologic conditions allow adjustments at the named tributary

RunTimeSettings.IsConchosHydOK_ForAdj [] = IsNamedTribHyd_OK_ForAdj (RioConchosHydCondition, IsMX_AmistadStgOK_ForAdj)

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsConchosHydOK_ForAdj" [] := "IsNamedTribHyd_OK_ForAdj"( $ "RunTimeSettings.RioConchosHydCondition", $ "RunTimeSettings.IsMX_AmistadStgOK_ForAdj" ); END; RULE "Get_ArroyoVacasHydCondFlags"; DESCRIPTION "Rule Get_ArroyoVacasHydCondFlags
# Calls function to get flag indicating if hydrologic conditions allow adjustments at the named tributary

RunTimeSettings.IsVacasHydOK_ForAdj [] = IsNamedTribHyd_OK_ForAdj (ArroyoVacasHydCondition, IsMX_FalconStgOK_ForAdj)

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsVacasHydOK_ForAdj" [] := "IsNamedTribHyd_OK_ForAdj"( $ "RunTimeSettings.ArroyoVacasHydCondition", $ "RunTimeSettings.IsMX_FalconStgOK_ForAdj" ); END; RULE "Get_SanDiegoHydCondFlags"; DESCRIPTION "Rule Get_SanDiegoHydCondFlags
# Calls function to get flag indicating if hydrologic conditions allow adjustments at the named tributary

RunTimeSettings.IsSanDiegoHydOK_ForAdj [] = IsNamedTribHyd_OK_ForAdj (SanDiegoHydCondition, IsMX_FalconStgOK_ForAdj)

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsSanDiegoHydOK_ForAdj" [] := "IsNamedTribHyd_OK_ForAdj"( $ "RunTimeSettings.SanDiegoHydCondition", $ "RunTimeSettings.IsMX_FalconStgOK_ForAdj" ); END; RULE "Get_SanRodrigoHydCondFlags"; DESCRIPTION "Rule Get_SanRodrigoHydCondFlags
# Calls function to get flag indicating if hydrologic conditions allow adjustments at the named tributary

RunTimeSettings.IsSanRodrigoHydOK_ForAdj [] = IsNamedTribHyd_OK_ForAdj (SanRodrigoHydCondition, IsMX_FalconStgOK_ForAdj)

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsSanRodrigoHydOK_ForAdj" [] := "IsNamedTribHyd_OK_ForAdj"( $ "RunTimeSettings.SanRodrigoHydCondition", $ "RunTimeSettings.IsMX_FalconStgOK_ForAdj" ); END; RULE "Get_EscondidoHydCondFlags"; DESCRIPTION "Rule Get_EscondidoHydCondFlags
# Calls function to get flag indicating if hydrologic conditions allow adjustments at the named tributary

RunTimeSettings.IsEscondidoHydOK_ForAdj [] = IsNamedTribHyd_OK_ForAdj (RioEscondidoHydCondition, IsMX_FalconStgOK_ForAdj)

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsEscondidoHydOK_ForAdj" [] := "IsNamedTribHyd_OK_ForAdj"( $ "RunTimeSettings.RioEscondidoHydCondition", $ "RunTimeSettings.IsMX_FalconStgOK_ForAdj" ); END; RULE "Get_SaladoHydCondFlags"; DESCRIPTION "Rule Get_SaladoHydCondFlags
# Calls function to get flag indicating if hydrologic conditions allow adjustments at the named tributary

RunTimeSettings.IsSaladoHydOK_ForAdj [] = IsNamedTribHyd_OK_ForAdj (RioSaladoHydCondition, IsMX_FalconStgOK_ForAdj)

End Rule
"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsSaladoHydOK_ForAdj" [] := "IsNamedTribHyd_OK_ForAdj"( $ "RunTimeSettings.RioSaladoHydCondition", $ "RunTimeSettings.IsMX_FalconStgOK_ForAdj" ); END; RULE "Get_MXFalconStorageFlags"; DESCRIPTION "Rule Get_MXFalconStgFlags
# Calls function to get flag indicating if Mexican share of storage in Falcon Reservoir is enough to allow adjustments

RunTimeSettings.IsMX_FalconStgOK_ForAdj [] = Is_MX_FalconStg_OK_ForAdjustments ()

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsMX_FalconStgOK_ForAdj" [] := "Is_MX_FalconStg_OK_ForAdjustments"( ); END; RULE "Get_MXAmistadStorageFlags"; DESCRIPTION "Rule Get_MXAmistadStgFlags
# Calls function to get flag indicating if Mexican share of storage in Amistad Reservoir is enough to allow adjustments

RunTimeSettings.IsMX_AmistadStgOK_ForAdj [] = Is_MX_AmistadStg_OK_ForAdjustments ()

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsMX_AmistadStgOK_ForAdj" [] := "Is_MX_AmistadStg_OK_ForAdjustments"( ); END; RULE "Get_MXIntlStgFlags"; DESCRIPTION "Rule Get_MXIntlStgFlags
# Calls function to get flag indicating if Mexican share of storage in International Reservoirs is enough to allow adjustments

RunTimeSettings.IsMX_IntlStgOK [] = Is_MX_IntlStg_OK_ForAdjustments ()

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsMX_IntlStgOK_ForAdj" [] := "Is_MX_IntlStg_OK_ForAdjustments"( ); END; RULE "Get_USIntlStgFlags"; DESCRIPTION "Rule Get_USIntlStgFlags
# Calls function to get flag indicating if US share of storage in International Reservoirs is high enough to not warrant more aggressive actions

RunTimeSettings.IsUS_IntlStgOK [] = Is_US_IntlStg_OK ()

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "RunTimeSettings.IsUS_IntlStgOK" [] := "Is_US_IntlStg_OK"( ); END; RULE "Get_USPctConsStg"; DESCRIPTION "Rule Get_USPctConsStg
# Get the percent of US conservation storage at the international reservoirs for the previous time-step

Results.US_PctConsStg [] =

End Rule
"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN DESCRIPTION "Get the percent of US conservation storage at the international reservoirs for the previous time-step"; $ "Results.US_PctConsStg" [] := ( $ "AMISTAD^Observed_US.Storage" [@"t - 1"] + $ "AMISTAD^Adjustments_US.Storage" [@"t - 1"] + ( $ "FALCON^Observed_US.Storage" [@"t - 1"] + $ "FALCON^Adjustments_US.Storage" [@"t - 1"] ) ) / ( $ "ReservoirStorage_Obs.Amistad_ConsLevel_US" [@"t - 1"] + $ "ReservoirStorage_Obs.Falcon_ConsLevel_US" [@"t - 1"] ); END; END; POLICY_GROUP "Verify Setup"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Check Cycle Month Index"; DESCRIPTION "Rule Check Cycle Month Index
# Determine if the monthly indexes for each cycle were generated correctly
# If the monthly indexes are all set to zero, the simulation will abort with a message

IF (SUM of (Settings.CycleMonthIndex []) from start to finish timesteps) = 0) THEN

Abort with message:
"Run dates must correspond to cycle dates. 'Initial' run date must be one month before a 'CycleStartMonth'; 'Finish' date must be same month as a 'CycleEndMonth'"
END IF

End Rule "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN IF_STATEMENT ("SumSlot"( $ "Settings.CycleMonthIndex", @"Start Timestep", @"Finish Timestep" ) == 0.00000000) THEN STOP_RUN_STATEMENT "Run dates must correspond to cycle dates. 'Initial' run date must be one month before 'CycleStartMonth'; 'Finish' date must be same month as 'CycleEndMonth'"; END_IF_STATEMENT; END; END; UTILITY_GROUP "Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "Is_MX_IntlStg_OK_ForAdjustments" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Is_MX_IntlStg_OK_ForAdj ()
# Determine if Mexican share of storage in International Reservoirs is enough to allow adjustments

# Return TRUE if adjustments are allowed or this option was not enabled
# Return FALSE if adjustments are not allowed

IF (MX_IntlRes_MinStorage is enabled) THEN
IF (MX_IntlRes_MinStorage.Total > 0) THEN # Set Total = 0 to disable checking total storage
IF (prev. month MX share of storage in Amistad + Falcon = MX_IntlRes_MinStorage.Total) THEN
# Have enough total storage in Amistad + Falcon to allow adjustments
RETURN (TRUE)
ELSE
RETURN (FALSE)
END IF
ELSE
# MX_IntlRes_MinStorage.Total was set to 0 which disables checking for total storage; adjustments are allowed at any total storage
RETURN (TRUE)
END IF
ELSE
# This option was disabled, so adjustments are allowed at any storage
RETURN (TRUE)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "USER_INPUT.IntlRes_MXMins" [$ "Constants.ROW_0" [], $ "Constants.ENABLE_OPTION" []] == $ "Constants.ENABLED" [] ) THEN IF ( $ "USER_INPUT.IntlRes_MXMins" [$ "Constants.ROW_0" [], $ "Constants.MX_MIN_TOTAL_INTL" []] > 0.00000000 "MCM" ) THEN IF ( $ "AMISTAD^Observed_MX.Storage" [@"t - 1"] + $ "AMISTAD^Adjustments_MX.Storage" [@"t - 1"] + ( $ "FALCON^Observed_MX.Storage" [@"t - 1"] + $ "FALCON^Adjustments_MX.Storage" [@"t - 1"] ) >= $ "USER_INPUT.IntlRes_MXMins" [$ "Constants.ROW_0" [], $ "Constants.MX_MIN_TOTAL_INTL" []] ) THEN $ "Constants.TRUE" [] COMMENTED_BY "
Have enough total storage in Amistad + Falcon to allow adjustments" ELSE $ "Constants.FALSE" [] ENDIF COMMENTED_BY "
COMBINE AMISTAD AND FALCON" ELSE $ "Constants.TRUE" [] COMMENTED_BY "
MX_IntlRes_MinStorage.Total was set to 0 which disables checking for total storage; adjustments are allowed at any storage" ENDIF ELSE $ "Constants.TRUE" [] COMMENTED_BY "
This option was disabled, so adjustments are allowed at any storage" ENDIF COMMENTED_BY "Determine if Mexican share of storage in International Reservoirs is enough to allow adjustments

Return TRUE if adjustments are allowed or this option was not enabled
Return FALSE if adjustments are not allowed
"; END; FUNCTION "Is_US_IntlStg_OK" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Is_US_IntlStg_OK ()
# Determine if US share of storage in International Reservoirs is high enough to not warrant more aggressive actions

# Return TRUE if more aggressive actions are not warranted or this option was not enabled
# Return FALSE if more aggressive actions should be taken

IF (US_IntlRes_MinPct is enabled) THEN
IF (prev. month US share of storage in Amistad + Falcon =
(Total US Conservation Level in Amistad + Falcon) x US_IntlRes_MinPct.Percent Total Stg) THEN
# Have enough US storage in Amistad + Falcon to not warrant more aggressive actions
RETURN (TRUE)
ELSE
RETURN (FALSE)
END IF
ELSE
# This option was disabled, so more aggressive actions are not warranted
RETURN (TRUE)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "USER_INPUT.IntlRes_USMinPct" [$ "Constants.ROW_0" [], $ "Constants.ENABLE_OPTION" []] == $ "Constants.ENABLED" [] ) THEN IF ( $ "Results.US_PctConsStg" [] >= $ "USER_INPUT.IntlRes_USMinPct" [$ "Constants.ROW_0" [], $ "Constants.US_MIN_PCT_INTL" []] ) THEN $ "Constants.TRUE" [] COMMENTED_BY "
Have enough US storage in Amistad + Falcon to not warrant more aggressive actions" ELSE $ "Constants.FALSE" [] ENDIF ELSE $ "Constants.TRUE" [] COMMENTED_BY "
This option was disabled, so more aggressive actions are not warranted" ENDIF COMMENTED_BY "Determine if US share of storage in International Reservoirs is high enough to not warrant more aggressive actions

Return TRUE if more aggressive actions are not warranted or this option was not enabled
Return FALSE if more aggressive actions should be taken
"; END; FUNCTION "Is_MX_AmistadStg_OK_ForAdjustments" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Is_MX_AmistadStg_OK_ForAdj ()
# Determine if Mexican share of storage in Amistad Reservoirs is enough to allow adjustments above Amistad

# Return TRUE if adjustments are allowed or this option was not enabled
# Return FALSE if adjustments are not allowed

IF (Is_MX_TotalStg_OK () is TRUE) THEN
IF (MX_IntlRes_MinStorage.Amistad > 0) THEN
IF (prev. month MX share of storage in Amistad = MX_IntlRes_MinStorage.Amistad) THEN
# Have enough storage in Amistad to allow adjustments above Amistad
RETURN (TRUE)
ELSE
RETURN (FALSE)
END IF
ELSE
# MX_IntlRes_MinStorage.Amistad was set to 0 which disables checking for storage; adjustments are allowed at any storage
RETURN (TRUE)
END IF
ELSE
# The Total share of MX storage does not allow any adjustments be made
RETURN (FALSE)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "RunTimeSettings.IsMX_IntlStgOK_ForAdj" [] == $ "Constants.TRUE" [] ) THEN IF ( $ "USER_INPUT.IntlRes_MXMins" [$ "Constants.ROW_0" [], $ "Constants.MX_MIN_AMISTAD" []] > 0.00000000 "MCM" ) THEN IF ( $ "AMISTAD^Observed_MX.Storage" [@"t - 1"] + $ "AMISTAD^Adjustments_MX.Storage" [@"t - 1"] >= $ "USER_INPUT.IntlRes_MXMins" [$ "Constants.ROW_0" [], $ "Constants.MX_MIN_AMISTAD" []] ) THEN $ "Constants.TRUE" [] COMMENTED_BY "
Have enough total storage in Amistad to allow adjustments" ELSE $ "Constants.FALSE" [] ENDIF ELSE $ "Constants.TRUE" [] COMMENTED_BY "
MX_IntlRes_MinStorage.Amistad was set to 0 which disables checking for storage; adjustments are allowed at any storage" ENDIF ELSE $ "Constants.FALSE" [] COMMENTED_BY "
This Total Storage doesn't allow any adjustments be made" ENDIF COMMENTED_BY "Determine if Mexican share of storage in Amistad Reservoir is enough to allow adjustments

Return TRUE if adjustments are allowed or this option was not enabled
Return FALSE if adjustments are not allowed
"; END; FUNCTION "Is_MX_FalconStg_OK_ForAdjustments" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Is_MX_FalconStg_OK_ForAdj ()
# Determine if Mexican share of storage in Falcon Reservoirs is enough to allow adjustments between Amistad and Falcon

# Return TRUE if adjustments are allowed or this option was not enabled
# Return FALSE if adjustments are not allowed

IF (Is_MX_TotalStg_OK () is TRUE) THEN
IF (MX_IntlRes_MinStorage.Falcon > 0) THEN
IF (prev. month MX share of storage in Falcon = MX_IntlRes_MinStorage.Falcon) THEN
# Have enough storage in Falcon to allow adjustments between Amistad and Falcon
RETURN (TRUE)
ELSE
RETURN (FALSE)
END IF
ELSE
# MX_IntlRes_MinStorage.Falcon was set to 0 which disables checking for storage; adjustments are allowed at any storage
RETURN (TRUE)
END IF
ELSE
# The Total share of MX storage does not allow any adjustments be made
RETURN (FALSE)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "RunTimeSettings.IsMX_IntlStgOK_ForAdj" [] == $ "Constants.TRUE" [] ) THEN IF ( $ "USER_INPUT.IntlRes_MXMins" [$ "Constants.ROW_0" [], $ "Constants.MX_MIN_FALCON" []] > 0.00000000 "MCM" ) THEN IF ( $ "FALCON^Observed_MX.Storage" [@"t - 1"] + $ "FALCON^Adjustments_MX.Storage" [@"t - 1"] >= $ "USER_INPUT.IntlRes_MXMins" [$ "Constants.ROW_0" [], $ "Constants.MX_MIN_FALCON" []] ) THEN $ "Constants.TRUE" [] COMMENTED_BY "
Have enough total storage in Falcon to allow adjustments" ELSE $ "Constants.FALSE" [] ENDIF ELSE $ "Constants.TRUE" [] COMMENTED_BY "
MX_IntlRes_MinStorage.Falcon was set to 0 which disables checking for storage; adjustments are allowed at any storage" ENDIF ELSE $ "Constants.FALSE" [] COMMENTED_BY "
This Total Storage doesn't allow any adjustments be made" ENDIF COMMENTED_BY "Determine if Mexican share of storage in Falcon Reservoir is enough to allow adjustments

Return TRUE if adjustments are allowed or this option was not enabled
Return FALSE if adjustments are not allowed
"; END; FUNCTION "IsNamedTribHyd_OK_ForAdj" ( SLOT namedTrib, SLOT intlResFlag ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function IsNamedTribHydOK_ForAdj (SLOT namedTrib, SLOT intlResFlag)
# Determine if hydrologic conditions allow adjustments at namedTrib designated by parameter passed in
# intlResFlag passes in the flag for Amistad or Falcon indicating if it is OK for adjustments
# Return TRUE if adjustments are allowed or this option was not enabled
# Return FALSE if adjustments are not allowed

IF (UseHydConditions is enabled) THEN
IF (intlResFlag = TRUE) THEN
# Adjustments allowed at international reservoir
IF (namedTrib_HydConditions [] = DRY) AND (AssignIfDry = TRUE) OR
(namedTrib_HydConditions [] = SEMI_DRY) AND (AssignIfSemiDry = TRUE) OR
(namedTrib_HydConditions [] = MEDIAN) AND (AssignIfMedian = TRUE) OR
(namedTrib_HydConditions [] = SEMI_WET) AND (AssignIfSemiWet = TRUE) OR
(namedTrib_HydConditions [] = WET) AND (AssignIfWet = TRUE) THEN
#Adjustments allowed for hydrologic conditions
RETURN (TRUE)
ELSE
RETURN (FALSE)
END IF
ELSE
# Adjustments not allowed for international reservoir
RETURN (FALSE)
END IF
ELSE
# Checking hydrologic conditions is disabled, so allow adjustments for all conditions
RETURN (TRUE)
END IF
End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "USER_INPUT.UseHydConditions" [$ "Constants.ROW_0" [], $ "Constants.ENABLE_OPTION" []] == $ "Constants.ENABLED" [] ) THEN IF ( intlResFlag [] == $ "Constants.TRUE" [] ) THEN IF ( namedTrib [] == $ "Constants.DRY" [] AND $ "USER_INPUT.UseHydConditions" [$ "Constants.ROW_0" [], $ "Constants.ASSIGN_IF_DRY" []] == $ "Constants.TRUE" [] OR ( namedTrib [] == $ "Constants.SEMI_DRY" [] AND $ "USER_INPUT.UseHydConditions" [$ "Constants.ROW_0" [], $ "Constants.ASSIGN_IF_SEMI_DRY" []] == $ "Constants.TRUE" [] ) OR ( namedTrib [] == $ "Constants.MEDIAN" [] AND $ "USER_INPUT.UseHydConditions" [$ "Constants.ROW_0" [], $ "Constants.ASSIGN_IF_MEDIAN" []] == $ "Constants.TRUE" [] ) OR ( namedTrib [] == $ "Constants.SEMI_WET" [] AND $ "USER_INPUT.UseHydConditions" [$ "Constants.ROW_0" [], $ "Constants.ASSIGN_IF_SEMI_WET" []] == $ "Constants.TRUE" [] ) OR ( namedTrib [] == $ "Constants.WET" [] AND $ "USER_INPUT.UseHydConditions" [$ "Constants.ROW_0" [], $ "Constants.ASSIGN_IF_WET" []] == $ "Constants.TRUE" [] ) ) THEN $ "Constants.TRUE" [] ELSE $ "Constants.FALSE" [] ENDIF ELSE $ "Constants.FALSE" [] ENDIF COMMENTED_BY "
MAKE SURE INTL RESERVOIR STORAGE ALLOWS ADJUSTMENTS" ELSE $ "Constants.TRUE" [] ENDIF COMMENTED_BY "# Determine if hydrologic conditions allow adjustments on the named tributary passed in

# Return TRUE if adjustments are allowed or this option was not enabled
# Return FALSE if adjustments are not allowed

"; END; FUNCTION "Get_AboveNAMO_Adjustment_Release" ( OBJECT resObj ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get_AboveNAMO_Adjustment_Release (OBJECT res)
# Calculate above NAMO adjustment for reservoir res designated by parameter passed in

# Make sure reservoir is enabled
IF (res is enabled) THEN
# Calculate amount of previous month storage above NAMO level
Set amountAboveNAMO = GetPreviousStg (res) – GetNAMOLevel (res)
# Check if storage is above NAMO level
IF (amountAboveNAMO > 0) THEN
# Storage above NAMO level, compare to user-specified cap on releases
Set capRelease = minimum of (amountAboveNAMO, user specified reservoir cap)
# Calculate amount of previous month storage above minimum storage allowed
Set availStg = GetPreviousStg (res) – GetMinStorage (res)
# Check if storage above minimum
IF (availStg > 0) THEN
# Calculate minimum storage release as minimum of cap and storage above minimum
Set minStgRelease = minimum of (capRelease, availStg)

# Calculate allowed release as minimum of max physical release and storage above minimum
Set allowedRelease = minimum of (GetMaxRelease (res), minStgRelease)


# Check additional limits on release
IF (reservoir release limit option is ‘no limits’) THEN
# no further limits on release, return calculated value
RETURN (allowedRelease)
ELSE IF (reservoir release limit option is ‘percent release limit’) THEN
# user-specified percent must be greater than loss factor to release adjustment
IF (user-specified percent > reservoir loss factor) THEN
RETURN (allowedRelease)
ELSE

RETURN (0)
END IF

ELSE IF (reservoir release limit option is ‘minimum release volume’) THEN
# release adjustment must be greater than user-specified minimum release to release adjustment
IF (allowedRelease > user-specified minimum release) THEN
RETURN (allowedRelease)
ELSE

RETURN (0)
END IF
END IF # reservoir limit options
ELSE
# Storage below minimum, no adjustment
RETURN (0)
END IF # availStg > 0
ELSE
# Storage below NAMO level, no adjustment
RETURN (0)
END IF # amountAboveNAMO > 0
ELSE
# Reservoir not enabled, no adjustment
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( resObj CONCAT ".IsEnabled" [] == $ "Constants.TRUE" [] ) THEN WITH NUMERIC amtAboveNAMO = "GetPreviousStg"( resObj ) - "GetNAMOLevel"( resObj ) DO IF ( amtAboveNAMO > 0.00000000 "MCM" ) THEN WITH NUMERIC capRelease = "Min"( resObj CONCAT ".AboveNAMOCap" [@"t - 1"], amtAboveNAMO ) DO WITH NUMERIC availStg = "GetPreviousStg"( resObj ) - "GetMinStorage"( resObj ) DO IF ( availStg > 0.00000000 "MCM" ) THEN WITH NUMERIC minStgRelease = "Min"( capRelease, availStg ) DO WITH NUMERIC allowedRelease = "Min"( "FlowToVolume"( "GetMaxRelease"( resObj ), @"t" ), minStgRelease ) DO IF ( resObj CONCAT ".UpstreamResLimitOption" [@"t - 1"] == $ "Constants.NO_RES_LIMIT" [] ) THEN "VolumeToFlow"( allowedRelease, @"t" ) COMMENTED_BY "
NO ADDITIONAL LIMITS, RELEASE CALCULATED VOLUME" ELSE IF ( resObj CONCAT ".UpstreamResLimitOption" [@"t - 1"] == $ "Constants.PCT_RES_LIMIT" [] ) THEN IF ( resObj CONCAT ".UpstreamResLimitPct" [@"t - 1"] > resObj CONCAT ".LossFactor" [@"t - 1"] ) THEN "VolumeToFlow"( allowedRelease, @"t" ) COMMENTED_BY "
USER SPECIFIED PERCENT IS GREATER THAN LOSS FACTOR, OK TO RELEASE" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
USER SPECIFIED PERCENT IS LESS THAN THE LOSS FACTOR, NO RELEASE" ENDIF COMMENTED_BY "
LIMIT RELEASE BY COMPARING USER-SPECIFIED PERCENT TO LOSS FACTOR" ELSE IF ( resObj CONCAT ".UpstreamResLimitVol" [@"t - 1"] > allowedRelease ) THEN "VolumeToFlow"( allowedRelease, @"t" ) COMMENTED_BY "
PROPOSED RELEASE GREATER THAN USER-SPECIFIED MINIMUM, OK TO RELEASE" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
PROPOSED RELEASE LESS THAN USER-SPECIFIED MINIMUM, NO RELEASE" ENDIF COMMENTED_BY "
LIMIT RELEASE BY COMPARING USER-SPECIFIED MINIMUM RELEASE VOLUME TO RELEASE" ENDIF ENDIF COMMENTED_BY "
CHECK FOR ADDITIONAL LIMITS ON RELEASE" ENDWITH COMMENTED_BY "
COMPARE NEW PROJECTED RELEASE TO MAXIMUM RELEASE ALLOWED, USE LOWER VALUE" ENDWITH COMMENTED_BY "
COMPARE AVAILABLE STORAGE ABOVE MIN TO PROJECTED RELEASE, USE LOWER VALUE" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
BELOW MINIMUM STORAGE, NO ADJUSTMENT" ENDIF ENDWITH COMMENTED_BY "
COMPARE PREVIOUS STORAGE TO MINIMUM STORAGE FOR ADJUSTMENT" ENDWITH COMMENTED_BY "
COMPARE VOLUME ABOVE NAMO TO CAP, USE LOWER VALUE" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
STORAGE BELOW NAMO, NO ADJUSTMENT" ENDIF ENDWITH COMMENTED_BY "
GET VOLUME ABOVE NAMO" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
NOT ENABLED, NO ADJUSTMENT" ENDIF; END; FUNCTION "Get_AddRes_Adjustment_Release" ( OBJECT resObj ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get_AddRes_Adjustment_Release (OBJECT res)
# Calculate additional releases adjustment for reservoir res designated by parameter passed in

# Make sure reservoir is enabled
IF (res is enabled) THEN
# Check if previous month storage is above user-specified percent of NAMO level
IF [(GetPreviousStg (res) > GetNAMOLevel (res) x (user-specified pct of NAMO)/100] THEN
# Calculate amount of previous month storage above minimum storage allowed
Set availStg = GetPreviousStg (res) – GetMinStorage (res)
# Check if storage above minimum
IF (availStg > 0) THEN
# Calculate minimum storage release as minimum of user-specified release volume and storage above minimum
Set minStgRelease = minimum of (AddResRelVolume, availStg)

# Calculate allowed release as minimum of max physical release and storage above minimum
Set allowedRelease = minimum of (GetMaxRelease (res), minStgRelease)


# Check additional limits on release
IF (reservoir release limit option is ‘no limits’) THEN
# no further limits on release, return calculated value
RETURN (allowedRelease)
ELSE IF (reservoir release limit option is ‘percent release limit’) THEN
# user-specified percent must be greater than loss factor to release adjustment
IF (user-specified percent > reservoir loss factor) THEN
RETURN (allowedRelease)
ELSE

RETURN (0)
END IF

ELSE IF (reservoir release limit option is ‘minimum release volume’) THEN
# release adjustment must be greater than user-specified minimum release to release adjustment
IF (allowedRelease > user-specified minimum release) THEN
RETURN (allowedRelease)
ELSE

RETURN (0)
END IF
END IF # reservoir limit options
ELSE
# Storage below minimum, no adjustment
RETURN (0)
END IF # availStg > 0
ELSE
# Storage below user-specified percent of NAMO level, no adjustment
RETURN (0)
END IF # amountAbove user-specified percent of NAMO level
ELSE
# Reservoir not enabled, no adjustment
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( resObj CONCAT ".IsEnabled" [] == $ "Constants.TRUE" [] ) THEN IF ( "GetPreviousStg"( resObj ) > "GetNAMOLevel"( resObj ) * ( $ "AddResRel_AdjSettings.ActionPct" [] / 100.00000000 ) ) THEN WITH NUMERIC availStg = "GetPreviousStg"( resObj ) - "GetMinStorage"( resObj ) DO IF ( availStg > 0.00000000 "MCM" ) THEN WITH NUMERIC minStgRelease = "Min"( resObj CONCAT ".AddResRelVol" [], availStg ) DO WITH NUMERIC allowedRelease = "Min"( "FlowToVolume"( "GetMaxRelease"( resObj ), @"t" ), minStgRelease ) DO IF ( resObj CONCAT ".UpstreamResLimitOption" [@"t - 1"] == $ "Constants.NO_RES_LIMIT" [] ) THEN "VolumeToFlow"( allowedRelease, @"t" ) COMMENTED_BY "
NO ADDITIONAL LIMITS, RELEASE CALCULATED VOLUME" ELSE IF ( resObj CONCAT ".UpstreamResLimitOption" [@"t - 1"] == $ "Constants.PCT_RES_LIMIT" [] ) THEN IF ( resObj CONCAT ".UpstreamResLimitPct" [@"t - 1"] > resObj CONCAT ".LossFactor" [@"t - 1"] ) THEN "VolumeToFlow"( allowedRelease, @"t" ) COMMENTED_BY "
USER SPECIFIED PERCENT IS GREATER THAN LOSS FACTOR, OK TO RELEASE" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
USER SPECIFIED PERCENT IS LESS THAN THE LOSS FACTOR, NO RELEASE" ENDIF COMMENTED_BY "
LIMIT RELEASE BY COMPARING USER-SPECIFIED PERCENT TO LOSS FACTOR" ELSE IF ( resObj CONCAT ".UpstreamResLimitVol" [@"t - 1"] > allowedRelease ) THEN "VolumeToFlow"( allowedRelease, @"t" ) COMMENTED_BY "
PROPOSED RELEASE GREATER THAN USER-SPECIFIED MINIMUM, OK TO RELEASE" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
PROPOSED RELEASE LESS THAN USER-SPECIFIED MINIMUM, NO RELEASE" ENDIF COMMENTED_BY "
LIMIT RELEASE BY COMPARING USER-SPECIFIED MINIMUM RELEASE VOLUME TO RELEASE" ENDIF ENDIF COMMENTED_BY "
CHECK FOR ADDITIONAL LIMITS ON RELEASE" ENDWITH COMMENTED_BY "
COMPARE NEW PROJECTED RELEASE TO MAXIMUM RELEASE ALLOWED, USE LOWER VALUE" ENDWITH COMMENTED_BY "
COMPARE AVAILABLE STORAGE ABOVE MIN TO PROJECTED RELEASE, USE LOWER VALUE" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
BELOW MINIMUM STORAGE, NO ADJUSTMENT" ENDIF ENDWITH COMMENTED_BY "
CHECK AVAILABLE STORAGE ABOVE MINIMUM" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
NO ADDITIONAL RELEASE" ENDIF COMMENTED_BY "
CHECK FOR ADDITIONAL RELEASE VOLUME" ELSE 0.00000000 "MCM/month" COMMENTED_BY "
NOT ENABLED, NO ADJUSTMENT" ENDIF; END; FUNCTION "GetPreviousStg" ( OBJECT obj ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function GetPreviousStg (OBJECT res)
# Get storage for previous month for reservoir res designated by parameter passed in

IF (res is Luis Leon) THEN
RETURN (LuisLeon.Storage [t-1])

ELSE IF (res is Madero) THEN
RETURN (Madero.Storage [t-1] – Madero adjustment transferred in Amistad –
Madero adjustment transferred for release at Luis Leon)
ELSE IF (res is LaBoquilla) THEN
RETURN (LaBoquilla.Storage [t-1] – La Boquilla adjustment transferred in Amistad –
LaBoquilla adjustment transferred for release at Luis Leon)

END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( obj == % "LuisLeon_ResSettings" ) THEN $ "Luis Leon.Storage" [@"t - 1"] ELSE IF ( obj == % "Madero_ResSettings" ) THEN $ "Madero.Storage" [@"t - 1"] - $ "Madero^Trans_in_Amistad.Storage" [@"t - 1"] - $ "Madero^Trans_Rel_Dwnstrm.Accrual" [@"t - 1"] ELSE IF ( obj == % "LaBoquilla_ResSettings" ) THEN $ "La Boquilla.Storage" [@"t - 1"] - $ "La Boquilla^Trans_in_Amistad.Storage" [@"t - 1"] - $ "La Boquilla^Trans_Rel_Dwnstrm.Storage" [@"t - 1"] ELSE 0.00000000 "MCM" ENDIF ENDIF ENDIF; END; FUNCTION "GetNAMOLevel" ( OBJECT obj ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function GetNAMOLevel (OBJECT res)
# Get NAMO level for reservoir res designated by parameter passed in

IF (res is Luis Leon) THEN
RETURN (LuisLeon NAMO level)
ELSE IF (res is Madero) THEN
RETURN (Madero NAMO level)
ELSE IF (res is LaBoquilla) THEN
RETURN (LaBoquilla NAMO level)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( obj == % "LuisLeon_ResSettings" ) THEN $ "USER_INPUT.ResNAMOLevels" ["GetRowIndex"( $ "USER_INPUT.ResNAMOLevels", "Luis Leon" ), 0.00000000] ELSE IF ( obj == % "Madero_ResSettings" ) THEN $ "USER_INPUT.ResNAMOLevels" ["GetRowIndex"( $ "USER_INPUT.ResNAMOLevels", "Madero" ), 0.00000000] ELSE IF ( obj == % "LaBoquilla_ResSettings" ) THEN $ "USER_INPUT.ResNAMOLevels" ["GetRowIndex"( $ "USER_INPUT.ResNAMOLevels", "La Boquilla" ), 0.00000000] ELSE 0.00000000 "MCM" ENDIF ENDIF ENDIF; END; FUNCTION "GetMinStorage" ( OBJECT obj ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function GetMinStorage (OBJECT res)
# Get minimum allowed storage for reservoir res designated by parameter passed in

IF (res is Luis Leon) THEN
RETURN (LuisLeon minimum storage)
ELSE IF (res is Madero) THEN
RETURN (Madero minimum storage)
ELSE IF (res is LaBoquilla) THEN
RETURN (LaBoquilla minimum storage)
END IF
End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( obj == % "LuisLeon_ResSettings" ) THEN $ "USER_INPUT.ResMinStorage" [@"t - 1", "GetColumnIndex"( $ "USER_INPUT.ResMinStorage", "Luis Leon" )] ELSE IF ( obj == % "Madero" ) THEN $ "USER_INPUT.ResMinStorage" [@"t - 1", "GetColumnIndex"( $ "USER_INPUT.ResMinStorage", "Madero" )] ELSE IF ( obj == % "La Boquilla" ) THEN $ "USER_INPUT.ResMinStorage" [@"t - 1", "GetColumnIndex"( $ "USER_INPUT.ResMinStorage", "La Boquilla" )] ELSE 0.00000000 "MCM" ENDIF ENDIF ENDIF; END; FUNCTION "GetMaxRelease" ( OBJECT obj ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function GetMaxRelease (OBJECT res)
# Get physical maximum release for reservoir res designated by parameter passed in

IF (res is Luis Leon) THEN
RETURN (LuisLeon max release)
ELSE IF (res is Madero) THEN
RETURN (Madero max release)
ELSE IF (res is LaBoquilla) THEN
RETURN (LaBoquilla max release)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( obj == % "LuisLeon_ResSettings" ) THEN $ "USER_INPUT.ResMaxRelease" [@"t", "GetColumnIndex"( $ "USER_INPUT.ResMaxRelease", "Luis Leon" )] ELSE IF ( obj == % "Madero_ResSettings" ) THEN $ "USER_INPUT.ResMaxRelease" [@"t", "GetColumnIndex"( $ "USER_INPUT.ResMaxRelease", "Madero" )] ELSE IF ( obj == % "LaBoquilla_ResSettings" ) THEN $ "USER_INPUT.ResMaxRelease" [@"t", "GetColumnIndex"( $ "USER_INPUT.ResMaxRelease", "La Boquilla" )] ELSE 0.00000000 "MCM/month" ENDIF ENDIF ENDIF; END; FUNCTION "GetNamedTrib_USPercent" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function GetNamedTrib_USPercent
# Get percent specified for the greater proportion of named tributaries adjustment

IF (Greater proportion of named tributaries adjustment is enabled) THEN
RETURN (NamedTribs_AdjSettings.ActionPct / 100)
ELSE
RETURN (1/3)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "NamedTribs_AdjSettings.IsEnabled" [] == $ "Constants.ENABLED" [] ) THEN $ "NamedTribs_AdjSettings.ActionPct" [] / 100.00000000 ELSE 1.00000000 / 3.00000000 ENDIF; END; FUNCTION "Get Luis Leon Release due to Madero" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get Luis Leon Release due to Madero
# Get the adjustment release at Luis Leon due to adjustment and settings at Madero

IF (Madero.AboveNAMOAdjustment + Madero.AdditionalReleaseAdjustment > 0) THEN
IF (Madero reservoir option is to pass adjustment through Luis Leon) THEN
RETURN (Madero.AboveNAMOAdjustment + Madero.AdditionalReleaseAdjustment) x (1 – loss factor)
ELSE IF (Madero reservoir option is to release adjustment at Luis Leon) THEN
RETURN (Madero.AboveNAMOAdjustment + Madero.AdditionalReleaseAdjustment)
ELSE
RETURN (0)
END IF
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( ( $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] ) > 0.00000000 "MCM" ) THEN IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] ) THEN ( $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] ) * ( 1.00000000 - $ "Madero_ResSettings.LossFactor" [] ) ELSE IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] ) THEN $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] ELSE 0.00000000 "MCM" ENDIF ENDIF ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get Madero Total Adjustment Release" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get Madero Total Adjustment Release
# Get the total adjustment release at Madero due to adjustment and settings at Madero

IF (Madero reservoir option is to pass adjustment through Luis Leon OR
Madero reservoir option is to release adjustment and let Luis Leon calculate adj with this inflow) THEN
RETURN (Madero.AboveNAMOAdjustment + Madero.AdditionalReleaseAdjustment)
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] OR $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_RELEASE" [] ) THEN $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get Madero AddRel Adjustment Release" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get Madero AddRel Adjustment Release
# Get the Additional Release adjustment release at Madero due to adjustment and settings at Madero

IF (Madero reservoir option is to pass adjustment through Luis Leon OR
Madero reservoir option is to release adjustment and let Luis Leon calculate adj with this inflow) THEN
RETURN (Madero.AdditionalReleaseAdjustment)
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] OR $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_RELEASE" [] ) THEN $ "Results.Madero Additional Releases Adjustment" [] ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get Madero Above NAMO Adjustment Release" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get MaderoAbove NAMO Adjustment Release
# Get the Above NAMO adjustment release at Madero due to adjustment and settings at Madero

IF (Madero reservoir option is to pass adjustment through Luis Leon OR
Madero reservoir option is to release adjustment and let Luis Leon calculate adj with this inflow) THEN
RETURN (Madero.AboveNAMOAdjustment)
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] OR $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_RELEASE" [] ) THEN $ "Results.Madero Above NAMO Adjustment" [] ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get La Boquilla Total Adjustment Release" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get La Boquilla Total Adjustment Release
# Get the total adjustment release at la Boquilla due to adjustment and settings at La Boquilla

IF (La Boquilla reservoir option is to pass adjustment through Luis Leon OR
La Boquilla reservoir option is to release adjustment and let Luis Leon calculate adj with this inflow) THEN
RETURN (LaBoquilla.AboveNAMOAdjustment + LaBoquilla.AdditionalReleaseAdjustment)
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] OR $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_RELEASE" [] ) THEN $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get La Boquilla Above NAMO Adjustment Release" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get La BoquillaAbove NAMO Adjustment Release
# Get the Above NAMO adjustment release at la Boquilla due to adjustment and settings at La Boquilla

IF (La Boquilla reservoir option is to pass adjustment through Luis Leon OR
La Boquilla reservoir option is to release adjustment and let Luis Leon calculate adj with this inflow) THEN
RETURN (LaBoquilla.AboveNAMOAdjustment)
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] OR $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_RELEASE" [] ) THEN $ "Results.La Boquilla Above NAMO Adjustment" [] ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get La Boquilla AddRel Adjustment Release" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get La Boquilla AddRel Adjustment Release
# Get the Additional Release adjustment release at la Boquilla due to adjustment and settings at La Boquilla

IF (La Boquilla reservoir option is to pass adjustment through Luis Leon OR
La Boquilla reservoir option is to release adjustment and let Luis Leon calculate adj with this inflow) THEN
RETURN (LaBoquilla.AdditionalReleaseAdjustment)
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] OR $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_RELEASE" [] ) THEN $ "Results.La Boquilla Additional Releases Adjustment" [] ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get Luis Leon Release due to La Boquilla" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get Luis Leon Release due to La Boquilla
# Get the adjustment release at Luis Leon due to adjustment and settings at La Boquilla

IF (LaBoquilla.AboveNAMOAdjustment + LaBoquilla.AdditionalReleaseAdjustment > 0) THEN
IF (La Boquilla reservoir option is to pass adjustment through Luis Leon) THEN
RETURN (LaBoquilla.AboveNAMOAdjustment+ LaBoquilla.AdditionalReleaseAdjustment) x (1 – loss factor)
ELSE IF (La Boquilla reservoir option is to release adjustment at Luis Leon) THEN
RETURN (LaBoquilla.AboveNAMOAdjustment + LaBoquilla.AdditionalReleaseAdjustment)
ELSE
RETURN (0)
END IF
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( ( $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ) > 0.00000000 "MCM" ) THEN IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] ) THEN ( $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ) * ( 1.00000000 - $ "LaBoquilla_ResSettings.LossFactor" [] ) ELSE IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] ) THEN $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ELSE 0.00000000 "MCM" ENDIF ENDIF ELSE 0.00000000 "MCM" ENDIF; END; FUNCTION "Get Transfer In Amistad" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get Transfer in Amistad
# Get the adjustment amount to transfer in Amistad due to Madero and La Boquilla adjustments

IF (Madero reservoir option is to transfer adjustment in Amistad AND
La Boquilla reservoir option is to transfer adjustment in Amistad) THEN
RETURN (Madero.AboveNAMOAdjustment + Madero.AdditionalReleaseAdjustment +
LaBoquilla.AboveNAMOAdjustment+ LaBoquilla.AdditionalReleaseAdjustment)
ELSE IF (Madero reservoir option is to transfer adjustment in Amistad) THEN
RETURN (Madero.AboveNAMOAdjustment + Madero.AdditionalReleaseAdjustment)
ELSE IF (La Boquilla reservoir option is to transfer adjustment in Amistad) THEN
RETURN ( LaBoquilla.AboveNAMOAdjustment+ LaBoquilla.AdditionalReleaseAdjustment)
ELSE
RETURN (0)
END IF

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_INTL_RES_TRANSFER" [] AND $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_INTL_RES_TRANSFER" [] ) THEN "VolumeToFlow"( $ "Results.Madero Above NAMO Adjustment" [] + ( $ "Results.Madero Additional Releases Adjustment" [] + $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ), @"t" ) ELSE IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_INTL_RES_TRANSFER" [] ) THEN "VolumeToFlow"( $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [], @"t" ) ELSE IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_INTL_RES_TRANSFER" [] ) THEN "VolumeToFlow"( $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [], @"t" ) ELSE 0.00000000 "MCM/month" ENDIF ENDIF ENDIF; END; FUNCTION "Get Upstream Res Transfer In Luis Leon" ( NUMERIC pct ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get Upstream Res Transfer in Luis Leon (NUMERIC pct)
# Get the amount of water from adjustments in Madero and La Boquilla that will outflow from Luis Leon
# pct is used to indicate percent of volume if want to split outflow to US and MX shares (or 100 pct for total outflow)

IF (Madero option is to release adjustment at Luis Leon AND
La Boquilla option is to release adjustment at Luis Leon) THEN
RETURN (MaderoAbove NAMO adjustment + Madero Additional Releases adjustment +
LaBoquillaAbove NAMO adjustment + La Boquilla Additional Releases adjustment) x pct /100

ELSE IF (Madero option is to release adjustment at Luis Leon AND
La Boquilla option is to release adjustment at La Boquilla and pass through Luis Leon) THEN
RETURN [MaderoAbove NAMO adjustment + Madero Additional Releases adjustment +
LaBoquillaAbove NAMO adjustment x (1-loss factor) +
La Boquilla Additional Releases adjustment x (1-loss factor)] x pct /100

ELSE IF (Madero option is to release adjustment at Madero and pass through Luis Leon AND
La Boquilla option is to release adjustment at La Boquilla and pass through Luis Leon) THEN
RETURN [MaderoAbove NAMO adjustment x (1-loss factor) +
Madero Additional Releases adjustment x (1-loss factor) +
LaBoquillaAbove NAMO adjustment x (1-loss factor) +
La Boquilla Additional Releases adjustment x (1-loss factor)] x pct /100

ELSE IF (Madero option is to release adjustment at Madero and pass through Luis Leon AND
La Boquilla option is to release adjustment at Luis Leon) THEN
RETURN [MaderoAbove NAMO adjustment x (1-loss factor) +
Madero Additional Releases adjustment x (1-loss factor) +
LaBoquillaAbove NAMO adjustment + La Boquilla Additional Releases adjustment] x pct /100

ELSE IF (Madero option is to release adjustment at Luis Leon) THEN
RETURN [MaderoAbove NAMO adjustment + Madero Additional Releases adjustment] x pct /100

ELSE IF (La Boquilla option is to release adjustment at Luis Leon) THEN
RETURN [LaBoquillaAbove NAMO adjustment + La Boquilla Additional Releases adjustment] x pct /100

ELSE IF (Madero option is to release adjustment at Madero and pass through Luis Leon) THEN
RETURN [MaderoAbove NAMO adjustment x (1-loss factor) +
Madero Additional Releases adjustment x (1-loss factor)] x pct /100

ELSE IF (La Boquilla option is to release adjustment at La Boquilla and pass through Luis Leon) THEN
RETURN [LaBoquillaAbove NAMO adjustment x (1-loss factor) +
La Boquilla Additional Releases adjustment x (1-loss factor)] x pct /100
ELSE
RETURN (0)
END IF
End Function"; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] AND $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] ) THEN "VolumeToFlow"( ( $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] + $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ) * ( pct / 100.00000000 ), @"t" ) ELSE IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] AND $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] ) THEN "VolumeToFlow"( ( $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] + $ "Results.La Boquilla Above NAMO Adjustment" [] * ( 1.00000000 - $ "LaBoquilla_ResSettings.LossFactor" [] ) + $ "Results.La Boquilla Additional Releases Adjustment" [] * ( 1.00000000 - $ "LaBoquilla_ResSettings.LossFactor" [] ) ) * ( pct / 100.00000000 ), @"t" ) ELSE IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] AND $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] ) THEN "VolumeToFlow"( ( $ "Results.Madero Above NAMO Adjustment" [] * ( 1.00000000 - $ "Madero_ResSettings.LossFactor" [] ) + $ "Results.Madero Additional Releases Adjustment" [] * ( 1.00000000 - $ "Madero_ResSettings.LossFactor" [] ) + $ "Results.La Boquilla Above NAMO Adjustment" [] * ( 1.00000000 - $ "LaBoquilla_ResSettings.LossFactor" [] ) + $ "Results.La Boquilla Additional Releases Adjustment" [] * ( 1.00000000 - $ "LaBoquilla_ResSettings.LossFactor" [] ) ) * ( pct / 100.00000000 ), @"t" ) ELSE IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] AND $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] ) THEN "VolumeToFlow"( ( $ "Results.Madero Above NAMO Adjustment" [] * ( 1.00000000 - $ "Madero_ResSettings.LossFactor" [] ) + $ "Results.Madero Additional Releases Adjustment" [] * ( 1.00000000 - $ "Madero_ResSettings.LossFactor" [] ) + $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ) * ( pct / 100.00000000 ), @"t" ) ELSE IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] ) THEN "VolumeToFlow"( ( $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] ) * ( pct / 100.00000000 ), @"t" ) ELSE IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_DOWNSTREAM_RELEASE" [] ) THEN "VolumeToFlow"( ( $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ) * ( pct / 100.00000000 ), @"t" ) ELSE IF ( $ "Madero_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] ) THEN "VolumeToFlow"( ( $ "Results.Madero Above NAMO Adjustment" [] + $ "Results.Madero Additional Releases Adjustment" [] ) * ( 1.00000000 - $ "Madero_ResSettings.LossFactor" [] ) * ( pct / 100.00000000 ), @"t" ) ELSE IF ( $ "LaBoquilla_ResSettings.UpstreamResRelOption" [] == $ "Constants.UPSTREAM_RES_PASSTHRU" [] ) THEN "VolumeToFlow"( ( $ "Results.La Boquilla Above NAMO Adjustment" [] + $ "Results.La Boquilla Additional Releases Adjustment" [] ) * ( 1.00000000 - $ "LaBoquilla_ResSettings.LossFactor" [] ) * ( pct / 100.00000000 ), @"t" ) ELSE 0.00000000 "MCM/month" ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF; END; FUNCTION "Get UnmeasTribs Adjustments Above Amistad" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Function Get UnmeasTribs AdjustmentsAbove Amistad
# Get the combined adjustment for the unmeasured tributaries above Amistad
RETURN [(MX share of observed unmeasured tributary at Reach 1) x (unmeas tribs action percent)/100 +
(MX share of observed unmeasured tributary at Reach 2) x (unmeas tribs action percent)/100 +
(MX share of observed unmeasured tributary at Reach 3) x (unmeas tribs action percent)/100 +
(MX share of observed unmeasured tributary at Reach 4) x (unmeas tribs action percent)/100]

End Function "; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN "FlowToVolume"( $ "Reach 1 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ) + "FlowToVolume"( $ "Reach 2 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ) + "FlowToVolume"( $ "Reach 3 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ) + "FlowToVolume"( $ "Reach 4 Unmeas Tribs^Obs_Unmeas_MX.Slot Inflow" [], @"t" ) * ( $ "UnmeasTribs_AdjSettings.ActionPct" [] / 100.00000000 ); END; END; END