Formation and reactivity of nitrides II. Calcium and magnesium nitrides and calcium cyanamide