Lib can be found here http://bildr.org/2012/02/hmc5883l_arduino/
Adafruit lib : https://github.com/adafruit/Adafruit_HMC5883_Unified
Calibration : http://diydrones.com/profiles/blogs/advanced-hard-and-soft-iron-magnetometer-calibration-for-dummies
More info