Update rlib.cpp for calibration