integer testnymd,testnhms,testndpm
testndpm = ndpm(month0)
if( month0.eq.2 .and. mod(year0,4).eq.0) testndpm = 29
if(day0.gt.testndpm) then
testnymd = testnymd - testndpm
day0 = day0 - testndpm