2 fixes for the calibration submission

Described in a comment to the original pull request:
1. math library must be explicitly included on Linux
2. Double close in write_ori.