A mean-field scaling method for first- and second-order phase transition ferromagnets and its application in magnetocaloric studies