You just need to know how the chi binning works. For non-prolines, 1 is 60 degrees +/- 60; 2 is 180 degrees +/- 60, and 3 is -60 degrees +/- 60. For proline chi 1 it’s 1 is 90 degrees +/- 90 degrees, and 2 is -90 degrees +/ 90. (This is rotamer library dependent: the values I give are for the current default dun10 rotamer library. The older dun02 library has different cutoffs.)
This may or may not be what you want – one particular complication is that certain residues are semi-rotameric, in the sense that all but the terminal chi is rotameric, but the terminal chi is represented continuously. Honestly, give your stated goal (” find the closest rotamer to each residue in a protein and then obtain the chi angles for each of those closest rotamers”) you might be better off explicitly instantiating the vector of rotamers, and then searching through it for the rotamer which is closest (by whatever sense you want) to the rotamer of interest.