! To make this template work for your specific case earch and replace the following to setup the view (example heatSysShr) ! shrVariableName with heatSysShr ! [upperStkDims,upperWidgetDims, with [rr,dts, ! shrDims, with hs, ! shrDimsName with heatSys ! with 1978 ! with 2006 creview shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][] creview stock[upperStkDims,upperWidgetDims,ts][] boolean $continue if $history == false say ("This view requires a history.") listen (" enter to continue >> ",$continue) quit (-1) endif if $background == false say ("This view requires a background scenario.") listen (" enter to continue >> ",$continue) quit (-1) endif integer $fistHisYear, $lastHisYear, $firstScnYear, $lastScnYear getobjinfo (shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][1], $fistHisYear; info=sequenceStart, dim=time) getobjinfo (shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][1], $lastHisYear; info=sequenceEnd, dim=time) getobjinfo (shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][2], $firstScnYear; info=sequenceStart, dim=time) getobjinfo (shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][2], $lastScnYear; info=sequenceEnd, dim=time) integer $lastHisYearP1, $firstHisTime $lastHisYearP1 = $lastHisYear + 1 !saturating linear trend (default) boolean $nonDefault say ("") say ("Default setting are:") say (" first historical time for basing trends = ") say (" percent change from last year of history = 50%") say ("") say (" You can choose to have the projection either join the;") say (" 1) trend line") say (" or") say (" 2) projection of the last 2 years of history") say (" The default is to join the trend line.") say ("") listen ("Do you want to use non-default values? {y n}[n] ",$nonDefault) boolean $joinHis string $percentChange local percentChangex[] if $nonDefault == false percentChangex[] = create (; data=50.0) $firstHisTime = $joinHis = false else say ("") listen ("What is historical starting year for the projection? {..}[] ",$firstHisTime) if $firstHisTime == 0 $firstHisTime = endif if $firstHisTime < AND ($firstHisTime != 0) $firstHisTime = endif if $firstHisTime > $firstHisTime = endif listen ("What percentage change from last year of history do you want to allow? {0..}[50] ",$percentChange) if $percentChange == "" percentChangex[] = create (; data=50.0) else percentChangex[] = create (; data=$percentChange) endif listen ("Do you want to join the projection of the last 2 years of history? {y n}[n] ",$joinHis) endif local variableHis[upperStkDims,upperWidgetDims,shrDims,t] = shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][1] local trendx[upperStkDims,upperWidgetDims,shrDims,ts], projx[upperStkDims,upperWidgetDims,shrDims,ts] if $joinHis == true trendx[upperStkDims,upperWidgetDims,shrDims,ts], projx[upperStkDims,upperWidgetDims,shrDims,ts] = \ lintrend (extract (variableHis[upperStkDims,upperWidgetDims,shrDims,t]; \ time:$firstHisTime..-0); time=$lastScnYear, join=on) else trendx[upperStkDims,upperWidgetDims,shrDims,ts], projx[upperStkDims,upperWidgetDims,shrDims,ts] = \ lintrend (extract (variableHis[upperStkDims,upperWidgetDims,shrDims,t]; \ time:$firstHisTime..-0); time=$lastScnYear) endif local trend[upperStkDims,upperWidgetDims,shrDims,ts] = norm (min (max (trendx[upperStkDims,upperWidgetDims,shrDims,ts], 0), 1); dim=shrDimsName) local proj[upperStkDims,upperWidgetDims,shrDims,ts] = norm (min (max (projx[upperStkDims,upperWidgetDims,shrDims,ts], 0), 1); dim=shrDimsName) local base[upperStkDims,upperWidgetDims,bt] = extract (trend[upperStkDims,upperWidgetDims,shrDims,ts]; time:-1..-0) local trendp[upperStkDims,upperWidgetDims,shrDims] = extract (delta (trend[upperStkDims,upperWidgetDims,shrDims,ts]); time:-0, shrink=on) local positive[upperStkDims,upperWidgetDims,shrDims] = boolgt (trendp[upperStkDims,upperWidgetDims,shrDims], 0) local negative[upperStkDims,upperWidgetDims,shrDims] = boolle (trendp[upperStkDims,upperWidgetDims,shrDims], 0) local percentChange[] = max (percentChangex[], 0) local firstProjPoint[upperStkDims,upperWidgetDims,shrDims] = extract (proj[upperStkDims,upperWidgetDims,shrDims,ts]; time:+0, shrink=on) local asymtotepositive[upperStkDims,upperWidgetDims,shrDims] = percentChange[] / 100 + 1 * \ firstProjPoint[upperStkDims,upperWidgetDims,shrDims] * positive[upperStkDims,upperWidgetDims,shrDims] local asymtotenegative[upperStkDims,upperWidgetDims,shrDims] = percentChange[] / 100 * -1 + 1 * \ firstProjPoint[upperStkDims,upperWidgetDims,shrDims] * negative[upperStkDims,upperWidgetDims,shrDims] local asymtote[upperStkDims,upperWidgetDims,shrDims] = asymtotepositive[upperStkDims,upperWidgetDims,shrDims] + \ asymtotenegative[upperStkDims,upperWidgetDims,shrDims] local satprojx[upperStkDims,upperWidgetDims,shrDims,ts] = satproj (base[upperStkDims,upperWidgetDims,bt], \ asymtote[upperStkDims,upperWidgetDims,shrDims]; time=$lastScnYear) local satprojection[upperStkDims,upperWidgetDims,shrDims,ts] = norm (min (max (satprojx[upperStkDims,upperWidgetDims,shrDims,ts], 0), 1); \ dim=shrDimsName) local projFirstPoint[upperStkDims,upperWidgetDims,shrDims] = extract (satprojection[upperStkDims,upperWidgetDims,shrDims,ts]; time:+0, shrink=on) local trendFLPx[upperStkDims,upperWidgetDims,shrDims,ts], projFLPx[upperStkDims,upperWidgetDims,shrDims,ts] if $joinHis == true trendFLPx[upperStkDims,upperWidgetDims,shrDims,ts], projFLPx[upperStkDims,upperWidgetDims,shrDims,ts] = \ lintrend (extract (variableHis[upperStkDims,upperWidgetDims,shrDims,t]; \ time:-1..-0); time=$lastHisYearP1, join=on) else trendFLPx[upperStkDims,upperWidgetDims,shrDims,ts], projFLPx[upperStkDims,upperWidgetDims,shrDims,ts] = \ lintrend (extract (trend[upperStkDims,upperWidgetDims,shrDims,ts]; \ time:-1..-0); time=$lastHisYearP1) endif local trendFLP[upperStkDims,upperWidgetDims,shrDims,ts] = norm (min (max ( \ trendFLPx[upperStkDims,upperWidgetDims,shrDims,ts], 0), 1); dim=shrDimsName) local projFLP[upperStkDims,upperWidgetDims,shrDims,ts] = norm (min (max ( \ projFLPx[upperStkDims,upperWidgetDims,shrDims,ts], 0), 1); dim=shrDimsName) local projFLPy[upperStkDims,upperWidgetDims,shrDims] projFLPy[upperStkDims,upperWidgetDims,shrDims] = shrink (projFLP[upperStkDims,upperWidgetDims,shrDims,ts]) local adjust[upperStkDims,upperWidgetDims,shrDims] = projFLPy[upperStkDims,upperWidgetDims,shrDims] / \ projFirstPoint[upperStkDims,upperWidgetDims,shrDims] local shrVariableNameScn[upperStkDims,upperWidgetDims,shrDims,ts] = norm (min (max ( \ satprojection[upperStkDims,upperWidgetDims,shrDims,ts] * adjust[upperStkDims,upperWidgetDims,shrDims], 0), 1); dim=shrDimsName) !must sum to 1 over shrDims, if not use weghted average local isZero[upperStkDims,upperWidgetDims,ts] = booleq (sum (shrVariableNameScn[upperStkDims,upperWidgetDims,shrDims,ts]; dim=shrDimsName), 0) local stockTotal[upperWidgetDims,ts] = sum (stock[upperStkDims,upperWidgetDims,ts][2]; dim=upperStkDims) local shrVariableNameAve[upperStkDims,upperWidgetDims,shrDims,ts] = copyshape (shrVariableNameScn[upperStkDims,upperWidgetDims,shrDims,ts]) local shrVariableNameAve[upperStkDims,upperWidgetDims,shrDims,ts] = insert (norm (sum (stock[upperStkDims,upperWidgetDims,ts][2] * \ shrVariableNameScn[upperStkDims,upperWidgetDims,shrDims,ts]; dim=upperStkDims) / stockTotal[upperWidgetDims,ts]; dim=shrDimsName)) shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][3] = isZero[upperStkDims,upperWidgetDims,ts] * \ shrVariableNameAve[upperStkDims,upperWidgetDims,shrDims,ts] + shrVariableNameScn[upperStkDims,upperWidgetDims,shrDims,ts] boolean $seeResults say ("") listen ("Do you want to see the results? ",$seeResults) if $seeResults == true graph (trend[upperStkDims,upperWidgetDims,shrDims,ts], shrVariableName[upperStkDims,upperWidgetDims,shrDims,ts][all]; \ objColours=$scnColours[all], \ title="historical, background and new shr") endif