// THIS INTERPOLATE DOESN'T WORK PROPERLY\r
b.append(\r
"\nfunction Interpolate\n" +\r
- " input Real table[:, 2];\n" +\r
- " input Real xp;\n" +\r
- " output Real yp;\n" +\r
- "protected\n" +\r
- " Integer i, sz;\n" +\r
- "algorithm\n" +\r
- " sz := size(table,1);\n" +\r
- " for i in 1:(sz-1) loop // assume monotonically increasing\n" +\r
- " if ((i == 1 and xp <= table[i+1,1]) or\n" +\r
- " (i == sz - 1) or\n" +\r
- " (xp > table[i,1] and xp <= table[i+1,1])) then // found appropriate segment\n" +\r
- " yp := table[i,2] + (xp - table[i,1]) * (table[i+1,2] - table[i,2]) / (table[i+1,1] - table[i,1]);\n" +\r
- " end if;\n" +\r
- " end for;\n" +\r
+ " input Real u \"in1;put value (first column of table)\";\n" +\r
+ " input Real table[:, :] \"table to be interpolated\";\n" +\r
+ " input Integer icol \"column of table to be interpolated\";\n" +\r
+ " output Real y \"interpolated input value (icol column of table)\";\n" +\r
+ "protected \n" +\r
+ " Integer i;\n" +\r
+ " Integer n \"number of rows of table\";\n" +\r
+ " Real u1;\n" +\r
+ " Real u2;\n" +\r
+ " Real y1;\n" +\r
+ " Real y2;\n" +\r
+ "algorithm \n" +\r
+ " n := size(table, 1);\n" +\r
+ " if n <= 1 then\n" +\r
+ " y := table[1, icol];\n" +\r
+ " else\n" +\r
+ " // Search interval\n" +\r
+ " if u <= table[1, 1] then\n" +\r
+ " i := 1;\n" +\r
+ " else\n" +\r
+ " i := 2;\n" +\r
+ " while i < n and u > table[i, 1] loop\n" +\r
+ " i := i + 1;\n" +\r
+ " end while;\n" +\r
+ " i := i - 1;\n" +\r
+ " end if;\n" +\r
+ \r
+ " // Get interpolation data\n" +\r
+ " u1 := table[i, 1];\n" +\r
+ " u2 := table[i + 1, 1];\n" +\r
+ " y1 := table[i, icol];\n" +\r
+ " y2 := table[i + 1, icol];\n" +\r
+ " // Interpolate\n" +\r
+ " if u1 >= u2 then\n" +\r
+ " y := y1;\n" +\r
+ " // since not possible to throw error\n" +\r
+ " else\n" +\r
+ " y := y1 + (y2 - y1)*(u - u1)/(u2 - u1);\n" +\r
+ " end if;\n" +\r
+ " end if;\n" +\r
"end Interpolate;\n");\r
\r
b.append(\r