import numpy as np

metal_data = {
    "Ag": {
        "n": [298.757050, 1.519000, 302.400421, 1.496000, 306.133759, 1.432500, 309.960449,
              1.323000, 313.884003, 1.142062, 317.908142, 0.932000, 322.036835, 0.719062,
              326.274139, 0.526000, 330.624481, 0.388125, 335.092377, 0.294000, 339.682678,
              0.253313, 344.400482, 0.238000, 349.251221, 0.221438, 354.240509, 0.209000,
              359.374420, 0.194813, 364.659332, 0.186000, 370.102020, 0.192063, 375.709625,
              0.200000, 381.489777, 0.198063, 387.450562, 0.192000, 393.600555, 0.182000,
              399.948975, 0.173000, 406.505493, 0.172625, 413.280579, 0.173000, 420.285339,
              0.166688, 427.531647, 0.160000, 435.032196, 0.158500, 442.800629, 0.157000,
              450.851562, 0.151063, 459.200653, 0.144000, 467.864838, 0.137313, 476.862213,
              0.132000, 486.212463, 0.130250, 495.936707, 0.130000, 506.057861, 0.129938,
              516.600769, 0.130000, 527.592224, 0.130063, 539.061646, 0.129000, 551.040771,
              0.124375, 563.564453, 0.120000, 576.670593, 0.119313, 590.400818, 0.121000,
              604.800842, 0.125500, 619.920898, 0.131000, 635.816284, 0.136125, 652.548279,
              0.140000, 670.184753, 0.140063, 688.800964, 0.140000, 708.481018, 0.144313,
              729.318665, 0.148000, 751.419250, 0.145875, 774.901123, 0.143000, 799.897949,
              0.142563, 826.561157, 0.145000, 855.063293, 0.151938, 885.601257, 0.163000],
        "k": [298.757050, 1.080000, 302.400421, 0.882000, 306.133759, 0.761063, 309.960449,
              0.647000, 313.884003, 0.550875, 317.908142, 0.504000, 322.036835, 0.554375,
              326.274139, 0.663000, 330.624481, 0.818563, 335.092377, 0.986000, 339.682678,
              1.120687, 344.400482, 1.240000, 349.251221, 1.345250, 354.240509, 1.440000,
              359.374420, 1.533750, 364.659332, 1.610000, 370.102020, 1.641875, 375.709625,
              1.670000, 381.489777, 1.735000, 387.450562, 1.810000, 393.600555, 1.878750,
              399.948975, 1.950000, 406.505493, 2.029375, 413.280579, 2.110000, 420.285339,
              2.186250, 427.531647, 2.260000, 435.032196, 2.329375, 442.800629, 2.400000,
              450.851562, 2.478750, 459.200653, 2.560000, 467.864838, 2.640000, 476.862213,
              2.720000, 486.212463, 2.798125, 495.936707, 2.880000, 506.057861, 2.973750,
              516.600769, 3.070000, 527.592224, 3.159375, 539.061646, 3.250000, 551.040771,
              3.348125, 563.564453, 3.450000, 576.670593, 3.553750, 590.400818, 3.660000,
              604.800842, 3.766250, 619.920898, 3.880000, 635.816284, 4.010625, 652.548279,
              4.150000, 670.184753, 4.293125, 688.800964, 4.440000, 708.481018, 4.586250,
              729.318665, 4.740000, 751.419250, 4.908125, 774.901123, 5.090000, 799.897949,
              5.288750, 826.561157, 5.500000, 855.063293, 5.720624, 885.601257, 5.950000]
    },
    "Al": {
        "n": [298.757050, 0.273375, 302.400421, 0.280000, 306.133759, 0.286813, 309.960449,
              0.294000, 313.884003, 0.301875, 317.908142, 0.310000, 322.036835, 0.317875,
              326.274139, 0.326000, 330.624481, 0.334750, 335.092377, 0.344000, 339.682678,
              0.353813, 344.400482, 0.364000, 349.251221, 0.374375, 354.240509, 0.385000,
              359.374420, 0.395750, 364.659332, 0.407000, 370.102020, 0.419125, 375.709625,
              0.432000, 381.489777, 0.445688, 387.450562, 0.460000, 393.600555, 0.474688,
              399.948975, 0.490000, 406.505493, 0.506188, 413.280579, 0.523000, 420.285339,
              0.540063, 427.531647, 0.558000, 435.032196, 0.577313, 442.800629, 0.598000,
              450.851562, 0.620313, 459.200653, 0.644000, 467.864838, 0.668625, 476.862213,
              0.695000, 486.212463, 0.723750, 495.936707, 0.755000, 506.057861, 0.789000,
              516.600769, 0.826000, 527.592224, 0.867000, 539.061646, 0.912000, 551.040771,
              0.963000, 563.564453, 1.020000, 576.670593, 1.080000, 590.400818, 1.150000,
              604.800842, 1.220000, 619.920898, 1.300000, 635.816284, 1.390000, 652.548279,
              1.490000, 670.184753, 1.600000, 688.800964, 1.740000, 708.481018, 1.910000,
              729.318665, 2.140000, 751.419250, 2.410000, 774.901123, 2.630000, 799.897949,
              2.800000, 826.561157, 2.740000, 855.063293, 2.580000, 885.601257, 2.240000],
        "k": [298.757050, 3.593750, 302.400421, 3.640000, 306.133759, 3.689375, 309.960449,
              3.740000, 313.884003, 3.789375, 317.908142, 3.840000, 322.036835, 3.894375,
              326.274139, 3.950000, 330.624481, 4.005000, 335.092377, 4.060000, 339.682678,
              4.113750, 344.400482, 4.170000, 349.251221, 4.233750, 354.240509, 4.300000,
              359.374420, 4.365000, 364.659332, 4.430000, 370.102020, 4.493750, 375.709625,
              4.560000, 381.489777, 4.633750, 387.450562, 4.710000, 393.600555, 4.784375,
              399.948975, 4.860000, 406.505493, 4.938125, 413.280579, 5.020000, 420.285339,
              5.108750, 427.531647, 5.200000, 435.032196, 5.290000, 442.800629, 5.380000,
              450.851562, 5.480000, 459.200653, 5.580000, 467.864838, 5.690000, 476.862213,
              5.800000, 486.212463, 5.915000, 495.936707, 6.030000, 506.057861, 6.150000,
              516.600769, 6.280000, 527.592224, 6.420000, 539.061646, 6.550000, 551.040771,
              6.700000, 563.564453, 6.850000, 576.670593, 7.000000, 590.400818, 7.150000,
              604.800842, 7.310000, 619.920898, 7.480000, 635.816284, 7.650000, 652.548279,
              7.820000, 670.184753, 8.010000, 688.800964, 8.210000, 708.481018, 8.390000,
              729.318665, 8.570000, 751.419250, 8.620000, 774.901123, 8.600000, 799.897949,
              8.450000, 826.561157, 8.310000, 855.063293, 8.210000, 885.601257, 8.210000]
    },
    "Au": {
        "n": [298.757050, 1.795000, 302.400421, 1.812000, 306.133759, 1.822625, 309.960449,
              1.830000, 313.884003, 1.837125, 317.908142, 1.840000, 322.036835, 1.834250,
              326.274139, 1.824000, 330.624481, 1.812000, 335.092377, 1.798000, 339.682678,
              1.782000, 344.400482, 1.766000, 349.251221, 1.752500, 354.240509, 1.740000,
              359.374420, 1.727625, 364.659332, 1.716000, 370.102020, 1.705875, 375.709625,
              1.696000, 381.489777, 1.684750, 387.450562, 1.674000, 393.600555, 1.666000,
              399.948975, 1.658000, 406.505493, 1.647250, 413.280579, 1.636000, 420.285339,
              1.628000, 427.531647, 1.616000, 435.032196, 1.596250, 442.800629, 1.562000,
              450.851562, 1.502125, 459.200653, 1.426000, 467.864838, 1.345875, 476.862213,
              1.242000, 486.212463, 1.086750, 495.936707, 0.916000, 506.057861, 0.754500,
              516.600769, 0.608000, 527.592224, 0.491750, 539.061646, 0.402000, 551.040771,
              0.345500, 563.564453, 0.306000, 576.670593, 0.267625, 590.400818, 0.236000,
              604.800842, 0.212375, 619.920898, 0.194000, 635.816284, 0.177750, 652.548279,
              0.166000, 670.184753, 0.161000, 688.800964, 0.160000, 708.481018, 0.160875,
              729.318665, 0.164000, 751.419250, 0.169500, 774.901123, 0.176000, 799.897949,
              0.181375, 826.561157, 0.188000, 855.063293, 0.198125, 885.601257, 0.210000],
        "k": [298.757050, 1.920375, 302.400421, 1.920000, 306.133759, 1.918875, 309.960449,
              1.916000, 313.884003, 1.911375, 317.908142, 1.904000, 322.036835, 1.891375,
              326.274139, 1.878000, 330.624481, 1.868250, 335.092377, 1.860000, 339.682678,
              1.851750, 344.400482, 1.846000, 349.251221, 1.845250, 354.240509, 1.848000,
              359.374420, 1.852375, 364.659332, 1.862000, 370.102020, 1.883000, 375.709625,
              1.906000, 381.489777, 1.922500, 387.450562, 1.936000, 393.600555, 1.947750,
              399.948975, 1.956000, 406.505493, 1.959375, 413.280579, 1.958000, 420.285339,
              1.951375, 427.531647, 1.940000, 435.032196, 1.924500, 442.800629, 1.904000,
              450.851562, 1.875875, 459.200653, 1.846000, 467.864838, 1.814625, 476.862213,
              1.796000, 486.212463, 1.797375, 495.936707, 1.840000, 506.057861, 1.956500,
              516.600769, 2.120000, 527.592224, 2.326250, 539.061646, 2.540000, 551.040771,
              2.730625, 563.564453, 2.880000, 576.670593, 2.940625, 590.400818, 2.970000,
              604.800842, 3.015000, 619.920898, 3.060000, 635.816284, 3.070000, 652.548279,
              3.150000, 670.184753, 3.445812, 688.800964, 3.800000, 708.481018, 4.087687,
              729.318665, 4.357000, 751.419250, 4.610188, 774.901123, 4.860000, 799.897949,
              5.125813, 826.561157, 5.390000, 855.063293, 5.631250, 885.601257, 5.880000]
    },
    "Cu": {
        "n": [298.757050, 1.400313, 302.400421, 1.380000, 306.133759, 1.358438, 309.960449,
              1.340000, 313.884003, 1.329063, 317.908142, 1.325000, 322.036835, 1.332500,
              326.274139, 1.340000, 330.624481, 1.334375, 335.092377, 1.325000, 339.682678,
              1.317812, 344.400482, 1.310000, 349.251221, 1.300313, 354.240509, 1.290000,
              359.374420, 1.281563, 364.659332, 1.270000, 370.102020, 1.249062, 375.709625,
              1.225000, 381.489777, 1.200000, 387.450562, 1.180000, 393.600555, 1.174375,
              399.948975, 1.175000, 406.505493, 1.177500, 413.280579, 1.180000, 420.285339,
              1.178125, 427.531647, 1.175000, 435.032196, 1.172812, 442.800629, 1.170000,
              450.851562, 1.165312, 459.200653, 1.160000, 467.864838, 1.155312, 476.862213,
              1.150000, 486.212463, 1.142812, 495.936707, 1.135000, 506.057861, 1.131562,
              516.600769, 1.120000, 527.592224, 1.092437, 539.061646, 1.040000, 551.040771,
              0.950375, 563.564453, 0.826000, 576.670593, 0.645875, 590.400818, 0.468000,
              604.800842, 0.351250, 619.920898, 0.272000, 635.816284, 0.230813, 652.548279,
              0.214000, 670.184753, 0.209250, 688.800964, 0.213000, 708.481018, 0.216250,
              729.318665, 0.223000, 751.419250, 0.236500, 774.901123, 0.250000, 799.897949,
              0.254188, 826.561157, 0.260000, 855.063293, 0.280000, 885.601257, 0.300000],
        "k": [298.757050, 1.662125, 302.400421, 1.687000, 306.133759, 1.703313, 309.960449,
              1.720000, 313.884003, 1.744563, 317.908142, 1.770000, 322.036835, 1.791625,
              326.274139, 1.810000, 330.624481, 1.822125, 335.092377, 1.834000, 339.682678,
              1.851750, 344.400482, 1.872000, 349.251221, 1.894250, 354.240509, 1.916000,
              359.374420, 1.931688, 364.659332, 1.950000, 370.102020, 1.972438, 375.709625,
              2.015000, 381.489777, 2.121562, 387.450562, 2.210000, 393.600555, 2.177188,
              399.948975, 2.130000, 406.505493, 2.160063, 413.280579, 2.210000, 420.285339,
              2.249938, 427.531647, 2.289000, 435.032196, 2.326000, 442.800629, 2.362000,
              450.851562, 2.397625, 459.200653, 2.433000, 467.864838, 2.469187, 476.862213,
              2.504000, 486.212463, 2.535875, 495.936707, 2.564000, 506.057861, 2.589625,
              516.600769, 2.605000, 527.592224, 2.595562, 539.061646, 2.583000, 551.040771,
              2.576500, 563.564453, 2.599000, 576.670593, 2.678062, 590.400818, 2.809000,
              604.800842, 3.010750, 619.920898, 3.240000, 635.816284, 3.458187, 652.548279,
              3.670000, 670.184753, 3.863125, 688.800964, 4.050000, 708.481018, 4.239563,
              729.318665, 4.430000, 751.419250, 4.619563, 774.901123, 4.817000, 799.897949,
              5.034125, 826.561157, 5.260000, 855.063293, 5.485625, 885.601257, 5.717000]
    },
    "CuZn": {
        "n": [290, 1.358, 300, 1.388, 310, 1.419, 320, 1.446, 330, 1.473, 340, 1.494, 350, 1.504,
              360, 1.503, 370, 1.497, 380, 1.487, 390, 1.471, 400, 1.445, 410, 1.405, 420, 1.350,
              430, 1.278, 440, 1.191, 450, 1.094, 460, 0.994, 470, 0.900, 480, 0.816, 490, 0.745,
              500, 0.686, 510, 0.639, 520, 0.602, 530, 0.573, 540, 0.549, 550, 0.527, 560, 0.505,
              570, 0.484, 580, 0.468, 590, 0.460, 600, 0.450, 610, 0.452, 620, 0.449, 630, 0.445,
              640, 0.444, 650, 0.444, 660, 0.445, 670, 0.444, 680, 0.444, 690, 0.445, 700, 0.446,
              710, 0.448, 720, 0.450, 730, 0.452, 740, 0.455, 750, 0.457, 760, 0.458, 770, 0.460,
              780, 0.464, 790, 0.469, 800, 0.473, 810, 0.478, 820, 0.481, 830, 0.483, 840, 0.486,
              850, 0.490, 860, 0.494, 870, 0.500, 880, 0.507, 890, 0.515],
        "k": [290, 1.688, 300, 1.731, 310, 1.764, 320, 1.789, 330, 1.807, 340, 1.815, 350, 1.815,
              360, 1.815, 370, 1.818, 380, 1.818, 390, 1.813, 400, 1.805, 410, 1.794, 420, 1.786,
              430, 1.784, 440, 1.797, 450, 1.829, 460, 1.883, 470, 1.957, 480, 2.046, 490, 2.145,
              500, 2.250, 510, 2.358, 520, 2.464, 530, 2.568, 540, 2.668, 550, 2.765, 560, 2.860,
              570, 2.958, 580, 3.059, 590, 3.159, 600, 3.253, 610, 3.345, 620, 3.434, 630, 3.522,
              640, 3.609, 650, 3.695, 660, 3.778, 670, 3.860, 680, 3.943, 690, 4.025, 700, 4.106,
              710, 4.186, 720, 4.266, 730, 4.346, 740, 4.424, 750, 4.501, 760, 4.579, 770, 4.657,
              780, 4.737, 790, 4.814, 800, 4.890, 810, 4.965, 820, 5.039, 830, 5.115, 840, 5.192,
              850, 5.269, 860, 5.346, 870, 5.423, 880, 5.500, 890, 5.575]
    },
    "Fe": {
        "n": [301, 1.67, 311, 1.69, 320, 1.74, 332, 1.78, 342, 1.85,
              354, 1.93, 368, 2.02, 381, 2.12, 397, 2.24, 413, 2.35,
              431, 2.48, 451, 2.59, 471, 2.67, 496, 2.74, 521, 2.86,
              549, 2.95, 582, 2.94, 617, 2.88, 659, 2.92, 704, 2.86,
              756, 2.87, 821, 2.94, 892, 2.96],
        "k": [301, 2.00, 311, 2.06, 320, 2.12, 332, 2.19, 342, 2.27,
              354, 2.35, 368, 2.43, 381, 2.50, 397, 2.58, 413, 2.65,
              431, 2.71, 451, 2.77, 471, 2.82, 496, 2.88, 521, 2.91,
              549, 2.93, 582, 2.99, 617, 3.05, 659, 3.10, 704, 3.19,
              756, 3.28, 821, 3.39, 892, 3.56]
    },
    "Ti": {
        "n": [301, 1.45, 311, 1.50, 320, 1.55, 332, 1.61, 342, 1.72, 354, 1.82,
              368, 1.90, 381, 1.99, 397, 2.08, 413, 2.14, 431, 2.21, 451, 2.27,
              471, 2.32, 496, 2.36, 521, 2.44, 549, 2.54, 582, 2.60, 617, 2.67,
              659, 2.76, 704, 2.86, 756, 3.00, 821, 3.21, 892, 3.29],
        "k": [301, 2.46, 311, 2.57, 320, 2.66, 332, 2.74, 342, 2.82, 354, 2.87,
              368, 2.90, 381, 2.93, 397, 2.95, 413, 2.98, 431, 3.01, 451, 3.04,
              471, 3.10, 496, 3.19, 521, 3.30, 549, 3.43, 582, 3.58, 617, 3.72,
              659, 3.84, 704, 3.96, 756, 4.01, 821, 4.01, 892, 3.96]
    },
    "V": {
        "n": [301, 2.07, 311, 2.17, 320, 2.28, 332, 2.37, 342, 2.42, 354, 2.51,
              368, 2.68, 381, 2.87, 397, 3.07, 413, 3.31, 431, 3.52, 451, 3.59,
              471, 3.81, 496, 3.92, 521, 3.86, 549, 4.00, 582, 3.83, 617, 3.54,
              659, 3.25, 704, 3.18, 756, 3.20, 821, 3.16, 892, 3.12],
        "k": [301, 2.95, 311, 3.06, 320, 3.15, 332, 3.22, 342, 3.29, 354, 3.34,
              368, 3.40, 381, 3.45, 397, 3.48, 413, 3.49, 431, 3.49, 451, 3.46,
              471, 3.38, 496, 3.26, 521, 3.18, 549, 3.04, 582, 3.00, 617, 3.02,
              659, 3.09, 704, 3.15, 756, 3.20, 821, 3.25, 892, 3.34]
    },
    "VN": {
        "n": [310.0, 2.20E0, 354.2, 2.18E0, 413.3, 2.13E0, 495.9, 2.17E0,
              619.9, 2.35E0, 826.6, 2.73E0, 1239.9, 3.19E0],
        "k": [310.0, 1.54E0, 354.2, 1.58E0, 413.3, 1.70E0, 495.9, 1.98E0,
              619.9, 2.47E0, 826.6, 2.92E0, 1239.9, 3.66E0]
    },
    "Li": {
        "n": [359.37, 0.31009, 364.66, 0.30404, 370.10, 0.29531, 375.71, 0.28993, 381.49, 0.28191, 387.45, 0.27423,
              393.60, 0.26970, 399.95, 0.26258, 406.51, 0.25378, 413.28, 0.24549, 420.29, 0.23668, 427.53, 0.22763,
              435.03, 0.22207, 442.80, 0.21396, 450.85, 0.20635, 459.20, 0.19683, 467.86, 0.19016, 476.86, 0.18385,
              486.21, 0.17389, 495.94, 0.16838, 506.06, 0.16165, 516.60, 0.15539, 527.59, 0.14953, 539.06, 0.14601,
              551.04, 0.14359, 563.56, 0.14428, 576.67, 0.14585, 590.40, 0.14653, 604.80, 0.14817, 619.92, 0.14898,
              635.82, 0.15069, 652.55, 0.15243, 670.18, 0.15574, 688.80, 0.15828, 708.48, 0.16159, 729.32, 0.16422,
              751.42, 0.16954, 774.90, 0.17282, 799.90, 0.17926, 826.56, 0.18374, 855.06, 0.18995],
        "k": [359.37, 1.54795, 364.66, 1.57875, 370.10, 1.60848, 375.71, 1.63831, 381.49, 1.66718, 387.45, 1.69564,
              393.60, 1.72416, 399.95, 1.75184, 406.51, 1.79288, 413.28, 1.83310, 420.29, 1.85904, 427.53, 1.91097,
              435.03, 1.93631, 442.80, 1.98640, 450.85, 2.03533, 459.20, 2.08297, 467.86, 2.12983, 476.86, 2.17573,
              486.21, 2.24282, 495.94, 2.28656, 506.06, 2.35077, 516.60, 2.41333, 527.59, 2.47434, 539.06, 2.53403,
              551.04, 2.61163, 563.56, 2.66849, 576.67, 2.74249, 590.40, 2.83222, 604.80, 2.90206, 619.92, 2.98700,
              635.82, 3.08589, 652.55, 3.18170, 670.18, 3.27479, 688.80, 3.38010, 708.48, 3.49659, 729.32, 3.62312,
              751.42, 3.74550, 774.90, 3.87684, 799.90, 4.01648, 826.56, 4.16338, 855.06, 4.31695]
    }
}


def sample_metal_ior(w, wavelengths, v):
    assert wavelengths[0] <= w < wavelengths[-1]
    for i, l in enumerate(wavelengths):
        if w < l:
            lo, hi = wavelengths[i - 1], wavelengths[i]
            t = (w - lo) / (hi - lo)
            return (1 - t) * v[i - 1] + t * v[i]


def upsample_metal_ior(data):
    lambda_min = 360
    lambda_max = 830
    n = data["n"]
    k = data["k"]
    wn, n = n[0::2], n[1::2]
    wk, k = k[0::2], k[1::2]
    n = [sample_metal_ior(w, wn, n) for w in range(lambda_min, lambda_max + 1, 5)]
    k = [sample_metal_ior(w, wk, k) for w in range(lambda_min, lambda_max + 1, 5)]
    return n, k


def codegen(name, data):
    init_list = ", ".join(f"make_float2({ni:.10}f, {ki:.10}f)" for ni, ki in zip(*data)) + ",\n"
    print(f"std::array {name}{{\n{init_list}}};")


if __name__ == "__main__":
    converted = {
        name: upsample_metal_ior(data) for
        name, data in metal_data.items()
    }
    for name, data in converted.items():
        codegen(name, data)

import numpy as np

metal_data = {
    "Ag": {
        "n": [298.757050, 1.519000, 302.400421, 1.496000, 306.133759, 1.432500, 309.960449,
              1.323000, 313.884003, 1.142062, 317.908142, 0.932000, 322.036835, 0.719062,
              326.274139, 0.526000, 330.624481, 0.388125, 335.092377, 0.294000, 339.682678,
              0.253313, 344.400482, 0.238000, 349.251221, 0.221438, 354.240509, 0.209000,
              359.374420, 0.194813, 364.659332, 0.186000, 370.102020, 0.192063, 375.709625,
              0.200000, 381.489777, 0.198063, 387.450562, 0.192000, 393.600555, 0.182000,
              399.948975, 0.173000, 406.505493, 0.172625, 413.280579, 0.173000, 420.285339,
              0.166688, 427.531647, 0.160000, 435.032196, 0.158500, 442.800629, 0.157000,
              450.851562, 0.151063, 459.200653, 0.144000, 467.864838, 0.137313, 476.862213,
              0.132000, 486.212463, 0.130250, 495.936707, 0.130000, 506.057861, 0.129938,
              516.600769, 0.130000, 527.592224, 0.130063, 539.061646, 0.129000, 551.040771,
              0.124375, 563.564453, 0.120000, 576.670593, 0.119313, 590.400818, 0.121000,
              604.800842, 0.125500, 619.920898, 0.131000, 635.816284, 0.136125, 652.548279,
              0.140000, 670.184753, 0.140063, 688.800964, 0.140000, 708.481018, 0.144313,
              729.318665, 0.148000, 751.419250, 0.145875, 774.901123, 0.143000, 799.897949,
              0.142563, 826.561157, 0.145000, 855.063293, 0.151938, 885.601257, 0.163000],
        "k": [298.757050, 1.080000, 302.400421, 0.882000, 306.133759, 0.761063, 309.960449,
              0.647000, 313.884003, 0.550875, 317.908142, 0.504000, 322.036835, 0.554375,
              326.274139, 0.663000, 330.624481, 0.818563, 335.092377, 0.986000, 339.682678,
              1.120687, 344.400482, 1.240000, 349.251221, 1.345250, 354.240509, 1.440000,
              359.374420, 1.533750, 364.659332, 1.610000, 370.102020, 1.641875, 375.709625,
              1.670000, 381.489777, 1.735000, 387.450562, 1.810000, 393.600555, 1.878750,
              399.948975, 1.950000, 406.505493, 2.029375, 413.280579, 2.110000, 420.285339,
              2.186250, 427.531647, 2.260000, 435.032196, 2.329375, 442.800629, 2.400000,
              450.851562, 2.478750, 459.200653, 2.560000, 467.864838, 2.640000, 476.862213,
              2.720000, 486.212463, 2.798125, 495.936707, 2.880000, 506.057861, 2.973750,
              516.600769, 3.070000, 527.592224, 3.159375, 539.061646, 3.250000, 551.040771,
              3.348125, 563.564453, 3.450000, 576.670593, 3.553750, 590.400818, 3.660000,
              604.800842, 3.766250, 619.920898, 3.880000, 635.816284, 4.010625, 652.548279,
              4.150000, 670.184753, 4.293125, 688.800964, 4.440000, 708.481018, 4.586250,
              729.318665, 4.740000, 751.419250, 4.908125, 774.901123, 5.090000, 799.897949,
              5.288750, 826.561157, 5.500000, 855.063293, 5.720624, 885.601257, 5.950000]
    },
    "Al": {
        "n": [298.757050, 0.273375, 302.400421, 0.280000, 306.133759, 0.286813, 309.960449,
              0.294000, 313.884003, 0.301875, 317.908142, 0.310000, 322.036835, 0.317875,
              326.274139, 0.326000, 330.624481, 0.334750, 335.092377, 0.344000, 339.682678,
              0.353813, 344.400482, 0.364000, 349.251221, 0.374375, 354.240509, 0.385000,
              359.374420, 0.395750, 364.659332, 0.407000, 370.102020, 0.419125, 375.709625,
              0.432000, 381.489777, 0.445688, 387.450562, 0.460000, 393.600555, 0.474688,
              399.948975, 0.490000, 406.505493, 0.506188, 413.280579, 0.523000, 420.285339,
              0.540063, 427.531647, 0.558000, 435.032196, 0.577313, 442.800629, 0.598000,
              450.851562, 0.620313, 459.200653, 0.644000, 467.864838, 0.668625, 476.862213,
              0.695000, 486.212463, 0.723750, 495.936707, 0.755000, 506.057861, 0.789000,
              516.600769, 0.826000, 527.592224, 0.867000, 539.061646, 0.912000, 551.040771,
              0.963000, 563.564453, 1.020000, 576.670593, 1.080000, 590.400818, 1.150000,
              604.800842, 1.220000, 619.920898, 1.300000, 635.816284, 1.390000, 652.548279,
              1.490000, 670.184753, 1.600000, 688.800964, 1.740000, 708.481018, 1.910000,
              729.318665, 2.140000, 751.419250, 2.410000, 774.901123, 2.630000, 799.897949,
              2.800000, 826.561157, 2.740000, 855.063293, 2.580000, 885.601257, 2.240000],
        "k": [298.757050, 3.593750, 302.400421, 3.640000, 306.133759, 3.689375, 309.960449,
              3.740000, 313.884003, 3.789375, 317.908142, 3.840000, 322.036835, 3.894375,
              326.274139, 3.950000, 330.624481, 4.005000, 335.092377, 4.060000, 339.682678,
              4.113750, 344.400482, 4.170000, 349.251221, 4.233750, 354.240509, 4.300000,
              359.374420, 4.365000, 364.659332, 4.430000, 370.102020, 4.493750, 375.709625,
              4.560000, 381.489777, 4.633750, 387.450562, 4.710000, 393.600555, 4.784375,
              399.948975, 4.860000, 406.505493, 4.938125, 413.280579, 5.020000, 420.285339,
              5.108750, 427.531647, 5.200000, 435.032196, 5.290000, 442.800629, 5.380000,
              450.851562, 5.480000, 459.200653, 5.580000, 467.864838, 5.690000, 476.862213,
              5.800000, 486.212463, 5.915000, 495.936707, 6.030000, 506.057861, 6.150000,
              516.600769, 6.280000, 527.592224, 6.420000, 539.061646, 6.550000, 551.040771,
              6.700000, 563.564453, 6.850000, 576.670593, 7.000000, 590.400818, 7.150000,
              604.800842, 7.310000, 619.920898, 7.480000, 635.816284, 7.650000, 652.548279,
              7.820000, 670.184753, 8.010000, 688.800964, 8.210000, 708.481018, 8.390000,
              729.318665, 8.570000, 751.419250, 8.620000, 774.901123, 8.600000, 799.897949,
              8.450000, 826.561157, 8.310000, 855.063293, 8.210000, 885.601257, 8.210000]
    },
    "Au": {
        "n": [298.757050, 1.795000, 302.400421, 1.812000, 306.133759, 1.822625, 309.960449,
              1.830000, 313.884003, 1.837125, 317.908142, 1.840000, 322.036835, 1.834250,
              326.274139, 1.824000, 330.624481, 1.812000, 335.092377, 1.798000, 339.682678,
              1.782000, 344.400482, 1.766000, 349.251221, 1.752500, 354.240509, 1.740000,
              359.374420, 1.727625, 364.659332, 1.716000, 370.102020, 1.705875, 375.709625,
              1.696000, 381.489777, 1.684750, 387.450562, 1.674000, 393.600555, 1.666000,
              399.948975, 1.658000, 406.505493, 1.647250, 413.280579, 1.636000, 420.285339,
              1.628000, 427.531647, 1.616000, 435.032196, 1.596250, 442.800629, 1.562000,
              450.851562, 1.502125, 459.200653, 1.426000, 467.864838, 1.345875, 476.862213,
              1.242000, 486.212463, 1.086750, 495.936707, 0.916000, 506.057861, 0.754500,
              516.600769, 0.608000, 527.592224, 0.491750, 539.061646, 0.402000, 551.040771,
              0.345500, 563.564453, 0.306000, 576.670593, 0.267625, 590.400818, 0.236000,
              604.800842, 0.212375, 619.920898, 0.194000, 635.816284, 0.177750, 652.548279,
              0.166000, 670.184753, 0.161000, 688.800964, 0.160000, 708.481018, 0.160875,
              729.318665, 0.164000, 751.419250, 0.169500, 774.901123, 0.176000, 799.897949,
              0.181375, 826.561157, 0.188000, 855.063293, 0.198125, 885.601257, 0.210000],
        "k": [298.757050, 1.920375, 302.400421, 1.920000, 306.133759, 1.918875, 309.960449,
              1.916000, 313.884003, 1.911375, 317.908142, 1.904000, 322.036835, 1.891375,
              326.274139, 1.878000, 330.624481, 1.868250, 335.092377, 1.860000, 339.682678,
              1.851750, 344.400482, 1.846000, 349.251221, 1.845250, 354.240509, 1.848000,
              359.374420, 1.852375, 364.659332, 1.862000, 370.102020, 1.883000, 375.709625,
              1.906000, 381.489777, 1.922500, 387.450562, 1.936000, 393.600555, 1.947750,
              399.948975, 1.956000, 406.505493, 1.959375, 413.280579, 1.958000, 420.285339,
              1.951375, 427.531647, 1.940000, 435.032196, 1.924500, 442.800629, 1.904000,
              450.851562, 1.875875, 459.200653, 1.846000, 467.864838, 1.814625, 476.862213,
              1.796000, 486.212463, 1.797375, 495.936707, 1.840000, 506.057861, 1.956500,
              516.600769, 2.120000, 527.592224, 2.326250, 539.061646, 2.540000, 551.040771,
              2.730625, 563.564453, 2.880000, 576.670593, 2.940625, 590.400818, 2.970000,
              604.800842, 3.015000, 619.920898, 3.060000, 635.816284, 3.070000, 652.548279,
              3.150000, 670.184753, 3.445812, 688.800964, 3.800000, 708.481018, 4.087687,
              729.318665, 4.357000, 751.419250, 4.610188, 774.901123, 4.860000, 799.897949,
              5.125813, 826.561157, 5.390000, 855.063293, 5.631250, 885.601257, 5.880000]
    },
    "Cu": {
        "n": [298.757050, 1.400313, 302.400421, 1.380000, 306.133759, 1.358438, 309.960449,
              1.340000, 313.884003, 1.329063, 317.908142, 1.325000, 322.036835, 1.332500,
              326.274139, 1.340000, 330.624481, 1.334375, 335.092377, 1.325000, 339.682678,
              1.317812, 344.400482, 1.310000, 349.251221, 1.300313, 354.240509, 1.290000,
              359.374420, 1.281563, 364.659332, 1.270000, 370.102020, 1.249062, 375.709625,
              1.225000, 381.489777, 1.200000, 387.450562, 1.180000, 393.600555, 1.174375,
              399.948975, 1.175000, 406.505493, 1.177500, 413.280579, 1.180000, 420.285339,
              1.178125, 427.531647, 1.175000, 435.032196, 1.172812, 442.800629, 1.170000,
              450.851562, 1.165312, 459.200653, 1.160000, 467.864838, 1.155312, 476.862213,
              1.150000, 486.212463, 1.142812, 495.936707, 1.135000, 506.057861, 1.131562,
              516.600769, 1.120000, 527.592224, 1.092437, 539.061646, 1.040000, 551.040771,
              0.950375, 563.564453, 0.826000, 576.670593, 0.645875, 590.400818, 0.468000,
              604.800842, 0.351250, 619.920898, 0.272000, 635.816284, 0.230813, 652.548279,
              0.214000, 670.184753, 0.209250, 688.800964, 0.213000, 708.481018, 0.216250,
              729.318665, 0.223000, 751.419250, 0.236500, 774.901123, 0.250000, 799.897949,
              0.254188, 826.561157, 0.260000, 855.063293, 0.280000, 885.601257, 0.300000],
        "k": [298.757050, 1.662125, 302.400421, 1.687000, 306.133759, 1.703313, 309.960449,
              1.720000, 313.884003, 1.744563, 317.908142, 1.770000, 322.036835, 1.791625,
              326.274139, 1.810000, 330.624481, 1.822125, 335.092377, 1.834000, 339.682678,
              1.851750, 344.400482, 1.872000, 349.251221, 1.894250, 354.240509, 1.916000,
              359.374420, 1.931688, 364.659332, 1.950000, 370.102020, 1.972438, 375.709625,
              2.015000, 381.489777, 2.121562, 387.450562, 2.210000, 393.600555, 2.177188,
              399.948975, 2.130000, 406.505493, 2.160063, 413.280579, 2.210000, 420.285339,
              2.249938, 427.531647, 2.289000, 435.032196, 2.326000, 442.800629, 2.362000,
              450.851562, 2.397625, 459.200653, 2.433000, 467.864838, 2.469187, 476.862213,
              2.504000, 486.212463, 2.535875, 495.936707, 2.564000, 506.057861, 2.589625,
              516.600769, 2.605000, 527.592224, 2.595562, 539.061646, 2.583000, 551.040771,
              2.576500, 563.564453, 2.599000, 576.670593, 2.678062, 590.400818, 2.809000,
              604.800842, 3.010750, 619.920898, 3.240000, 635.816284, 3.458187, 652.548279,
              3.670000, 670.184753, 3.863125, 688.800964, 4.050000, 708.481018, 4.239563,
              729.318665, 4.430000, 751.419250, 4.619563, 774.901123, 4.817000, 799.897949,
              5.034125, 826.561157, 5.260000, 855.063293, 5.485625, 885.601257, 5.717000]
    },
    "CuZn": {
        "n": [290, 1.358, 300, 1.388, 310, 1.419, 320, 1.446, 330, 1.473, 340, 1.494, 350, 1.504,
              360, 1.503, 370, 1.497, 380, 1.487, 390, 1.471, 400, 1.445, 410, 1.405, 420, 1.350,
              430, 1.278, 440, 1.191, 450, 1.094, 460, 0.994, 470, 0.900, 480, 0.816, 490, 0.745,
              500, 0.686, 510, 0.639, 520, 0.602, 530, 0.573, 540, 0.549, 550, 0.527, 560, 0.505,
              570, 0.484, 580, 0.468, 590, 0.460, 600, 0.450, 610, 0.452, 620, 0.449, 630, 0.445,
              640, 0.444, 650, 0.444, 660, 0.445, 670, 0.444, 680, 0.444, 690, 0.445, 700, 0.446,
              710, 0.448, 720, 0.450, 730, 0.452, 740, 0.455, 750, 0.457, 760, 0.458, 770, 0.460,
              780, 0.464, 790, 0.469, 800, 0.473, 810, 0.478, 820, 0.481, 830, 0.483, 840, 0.486,
              850, 0.490, 860, 0.494, 870, 0.500, 880, 0.507, 890, 0.515],
        "k": [290, 1.688, 300, 1.731, 310, 1.764, 320, 1.789, 330, 1.807, 340, 1.815, 350, 1.815,
              360, 1.815, 370, 1.818, 380, 1.818, 390, 1.813, 400, 1.805, 410, 1.794, 420, 1.786,
              430, 1.784, 440, 1.797, 450, 1.829, 460, 1.883, 470, 1.957, 480, 2.046, 490, 2.145,
              500, 2.250, 510, 2.358, 520, 2.464, 530, 2.568, 540, 2.668, 550, 2.765, 560, 2.860,
              570, 2.958, 580, 3.059, 590, 3.159, 600, 3.253, 610, 3.345, 620, 3.434, 630, 3.522,
              640, 3.609, 650, 3.695, 660, 3.778, 670, 3.860, 680, 3.943, 690, 4.025, 700, 4.106,
              710, 4.186, 720, 4.266, 730, 4.346, 740, 4.424, 750, 4.501, 760, 4.579, 770, 4.657,
              780, 4.737, 790, 4.814, 800, 4.890, 810, 4.965, 820, 5.039, 830, 5.115, 840, 5.192,
              850, 5.269, 860, 5.346, 870, 5.423, 880, 5.500, 890, 5.575]
    },
    "Fe": {
        "n": [301, 1.67, 311, 1.69, 320, 1.74, 332, 1.78, 342, 1.85,
              354, 1.93, 368, 2.02, 381, 2.12, 397, 2.24, 413, 2.35,
              431, 2.48, 451, 2.59, 471, 2.67, 496, 2.74, 521, 2.86,
              549, 2.95, 582, 2.94, 617, 2.88, 659, 2.92, 704, 2.86,
              756, 2.87, 821, 2.94, 892, 2.96],
        "k": [301, 2.00, 311, 2.06, 320, 2.12, 332, 2.19, 342, 2.27,
              354, 2.35, 368, 2.43, 381, 2.50, 397, 2.58, 413, 2.65,
              431, 2.71, 451, 2.77, 471, 2.82, 496, 2.88, 521, 2.91,
              549, 2.93, 582, 2.99, 617, 3.05, 659, 3.10, 704, 3.19,
              756, 3.28, 821, 3.39, 892, 3.56]
    },
    "Ti": {
        "n": [301, 1.45, 311, 1.50, 320, 1.55, 332, 1.61, 342, 1.72, 354, 1.82,
              368, 1.90, 381, 1.99, 397, 2.08, 413, 2.14, 431, 2.21, 451, 2.27,
              471, 2.32, 496, 2.36, 521, 2.44, 549, 2.54, 582, 2.60, 617, 2.67,
              659, 2.76, 704, 2.86, 756, 3.00, 821, 3.21, 892, 3.29],
        "k": [301, 2.46, 311, 2.57, 320, 2.66, 332, 2.74, 342, 2.82, 354, 2.87,
              368, 2.90, 381, 2.93, 397, 2.95, 413, 2.98, 431, 3.01, 451, 3.04,
              471, 3.10, 496, 3.19, 521, 3.30, 549, 3.43, 582, 3.58, 617, 3.72,
              659, 3.84, 704, 3.96, 756, 4.01, 821, 4.01, 892, 3.96]
    },
    "V": {
        "n": [301, 2.07, 311, 2.17, 320, 2.28, 332, 2.37, 342, 2.42, 354, 2.51,
              368, 2.68, 381, 2.87, 397, 3.07, 413, 3.31, 431, 3.52, 451, 3.59,
              471, 3.81, 496, 3.92, 521, 3.86, 549, 4.00, 582, 3.83, 617, 3.54,
              659, 3.25, 704, 3.18, 756, 3.20, 821, 3.16, 892, 3.12],
        "k": [301, 2.95, 311, 3.06, 320, 3.15, 332, 3.22, 342, 3.29, 354, 3.34,
              368, 3.40, 381, 3.45, 397, 3.48, 413, 3.49, 431, 3.49, 451, 3.46,
              471, 3.38, 496, 3.26, 521, 3.18, 549, 3.04, 582, 3.00, 617, 3.02,
              659, 3.09, 704, 3.15, 756, 3.20, 821, 3.25, 892, 3.34]
    },
    "VN": {
        "n": [310.0, 2.20E0, 354.2, 2.18E0, 413.3, 2.13E0, 495.9, 2.17E0,
              619.9, 2.35E0, 826.6, 2.73E0, 1239.9, 3.19E0],
        "k": [310.0, 1.54E0, 354.2, 1.58E0, 413.3, 1.70E0, 495.9, 1.98E0,
              619.9, 2.47E0, 826.6, 2.92E0, 1239.9, 3.66E0]
    },
    "Li": {
        "n": [359.37, 0.31009, 364.66, 0.30404, 370.10, 0.29531, 375.71, 0.28993, 381.49, 0.28191, 387.45, 0.27423,
              393.60, 0.26970, 399.95, 0.26258, 406.51, 0.25378, 413.28, 0.24549, 420.29, 0.23668, 427.53, 0.22763,
              435.03, 0.22207, 442.80, 0.21396, 450.85, 0.20635, 459.20, 0.19683, 467.86, 0.19016, 476.86, 0.18385,
              486.21, 0.17389, 495.94, 0.16838, 506.06, 0.16165, 516.60, 0.15539, 527.59, 0.14953, 539.06, 0.14601,
              551.04, 0.14359, 563.56, 0.14428, 576.67, 0.14585, 590.40, 0.14653, 604.80, 0.14817, 619.92, 0.14898,
              635.82, 0.15069, 652.55, 0.15243, 670.18, 0.15574, 688.80, 0.15828, 708.48, 0.16159, 729.32, 0.16422,
              751.42, 0.16954, 774.90, 0.17282, 799.90, 0.17926, 826.56, 0.18374, 855.06, 0.18995],
        "k": [359.37, 1.54795, 364.66, 1.57875, 370.10, 1.60848, 375.71, 1.63831, 381.49, 1.66718, 387.45, 1.69564,
              393.60, 1.72416, 399.95, 1.75184, 406.51, 1.79288, 413.28, 1.83310, 420.29, 1.85904, 427.53, 1.91097,
              435.03, 1.93631, 442.80, 1.98640, 450.85, 2.03533, 459.20, 2.08297, 467.86, 2.12983, 476.86, 2.17573,
              486.21, 2.24282, 495.94, 2.28656, 506.06, 2.35077, 516.60, 2.41333, 527.59, 2.47434, 539.06, 2.53403,
              551.04, 2.61163, 563.56, 2.66849, 576.67, 2.74249, 590.40, 2.83222, 604.80, 2.90206, 619.92, 2.98700,
              635.82, 3.08589, 652.55, 3.18170, 670.18, 3.27479, 688.80, 3.38010, 708.48, 3.49659, 729.32, 3.62312,
              751.42, 3.74550, 774.90, 3.87684, 799.90, 4.01648, 826.56, 4.16338, 855.06, 4.31695]
    }
}


def sample_metal_ior(w, wavelengths, v):
    assert wavelengths[0] <= w < wavelengths[-1]
    for i, l in enumerate(wavelengths):
        if w < l:
            lo, hi = wavelengths[i - 1], wavelengths[i]
            t = (w - lo) / (hi - lo)
            return (1 - t) * v[i - 1] + t * v[i]


def upsample_metal_ior(data):
    lambda_min = 360
    lambda_max = 830
    n = data["n"]
    k = data["k"]
    wn, n = n[0::2], n[1::2]
    wk, k = k[0::2], k[1::2]
    n = [sample_metal_ior(w, wn, n) for w in range(lambda_min, lambda_max + 1, 5)]
    k = [sample_metal_ior(w, wk, k) for w in range(lambda_min, lambda_max + 1, 5)]
    return n, k


def codegen(name, data):
    init_list = ", ".join(f"make_float2({ni:.10}f, {ki:.10}f)" for ni, ki in zip(*data)) + ",\n"
    print(f"std::array {name}{{\n{init_list}}};")


if __name__ == "__main__":
    converted = {
        name: upsample_metal_ior(data) for
        name, data in metal_data.items()
    }
    for name, data in converted.items():
        codegen(name, data)
