setting LK array values from text strings

  • kaiyer
  • Topic Author
More
04 Jul 2020 13:25 #8390 by kaiyer
For example, after using the inputs browser in SAM to export values to CSV we have utility PBI as follows
pbi_uti_amountUtility PBI amount10;11;12;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0
We can read that back into LK as a string

pbi_uti_amount = "10;11;12;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0";

I am looking for a code snippet that will take this string, parse it and set the array value in SAM

sam_set_inputs('pbi_uti_amount', arr).
I'm looking for a code snippet that can initialize arr from values in pbi_uti_amount.
Any help greatly appreciated!

Please Log in or Create an account to join the conversation.

  • pgilman
More
06 Jul 2020 09:50 - 06 Jul 2020 09:50 #8401 by pgilman
Replied by pgilman on topic setting LK array values from text strings
Hi Kaiyer,

The PBI amount and other inputs that appear in the SAM user interface with the "Sched/Value" blue and grey buttons are arrays. If the array has one element, SAM interprets the value as a Year 1 value and applies inflation to calculate values in Years 2 and later. If the array has more than one element, it treats each value as a nominal value in each year. If the array is longer than the analysis period, SAM truncates the array length to the analysis period. If the array is shorter than the analysis period, SAM assigns the value zero to years with no values.

Here is some LK code that reads the string you provided, converts  to an array and assigns the array's value to pbi_uti_amount. It also runs a simulation and shows the PBI amount from the resulting cashflow so you can verify that it works:

Code:
outln( get('pbi_uti_amount') ); str = "10;11;12;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0"; outln(str); arr = split(str,';'); outln(arr); set('pbi_uti_amount',arr); outln( get('pbi_uti_amount') ); simulate(); outln( get('cf_pbi_total_uti') );

Best regards,
Paul.
Last edit: 06 Jul 2020 09:50 by pgilman.

Please Log in or Create an account to join the conversation.

Moderators: pgilman
Powered by Kunena Forum