Ah, and R_decl.from_euler(0.0f, 0.0f, mag_decl); should be calculated not in the if..else, but below after both, as its needed in both cases.