SamUL - Writing multiple arrays in .csv file

5 posts / 0 new
Last post
azanalo
SamUL - Writing multiple arrays in .csv file

Hello everyone!

I started using SamUL this week, and I have a general question on what the correct "Write" function is for the following:

I created a "for" function to loop through all the tmy files in the /exelib folder located in my computer. Within each element of the loop I have a "while" function to calculate the LCOE for several inverter DC/AC ratios. In summary, the "while" loop will create two arrays, one for the LCOE and another one for the DC/AC ratio. The final goal is to plot these two variables together to find out what is the optimum DC/AC ratio. How can I write these two arrays in a .csv file such that Column A = LCOE and Column B = DC/AC Ratio? I tried the functions Write and WriteResults but I may be using them incorrectly, or maybe there's a better function for this.

Thank you so much in advance!
AZ

Paul Gilman

Hello AZ,

I've had success creating an array of values of type String to store the entire contents of the CSV file, and then writing the array to the file using the WriteTextFile() function.

Best regards,
Paul.

azanalo

Thank you Paul!

I gave a try to your recommendation in the script below and I got very close. The only problem is that the array is written as a row, not as column which is what I want. Would you mind taking a quick look at it? Thanks.

My next step would be to add another column with the Array Size such that for each Array Size there's a LCOE associated. Will this possible with the WriteTextFile() function as well?

I know this script is kind of sloppy, so please don't laugh ;-).

Thanks!

count = 5
for(i=0 ; i< count ; i=i+1)
SetInput("pv.array.desired_size",(i+1)*1000)
simulate()
LCOE_calc[i] = GetOutput("sv.lcoe_nom")
Out(LCOE_calc[i] + "\n")
LCOE = String(LCOE_calc[i]) + "\n"
WriteTextFile("C:/Users/alvazano/Desktop/test.csv", LCOE_calc)
end

azanalo

Mmmhhh, is there a Transpose function in SamUL by any chance? That would do it

Thanks!
Alvaro

Paul Gilman

You might try something like the following:

BEGIN SCRIPT

count = 5
for(i=0 ; i SetInput("pv.array.desired_size",(i+1)*1000)
simulate()
LCOE_calc[i] = GetOutput("sv.lcoe_nom") + "\n"
Out(LCOE_calc[i])
end

ok = WriteTextFile("C:/Users/alvazano/Desktop/test.csv", LCOE_calc)
if (not ok) OutLn("Error writing text file.")

END SCRIPT

For more about arrays in SamUL, please see the Help topic SamUL: Arrays of Data.

Best regards,
Paul.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer