Spicity is defined as a thermodynamic variable whose isopleths are 'perpendicular” to those of density in the (T, S) diagram. A new set of Matlab codes are defined based on the following criteria: First, the isopleths of spicity should be orthogonal to those of density. Second, the ocean is vertically separated into many pressure levels, and the zero point of spicity is set for the water mass with the mean salinity and temperature at each pressure level. This new definition of spicity can provide more accurate information of the water mass properties for the study of thermohaline perturbations.