Optical constants of CO and CO2 in the IR/THz ranges and code to calculate the opacity of icy grains