gain calibration code completed