function dv = trimdv(dv, integersec)

if argn(2)==1
  integersec = 0;
end

if size(dv, 2)==6 then
  if integersec
    dv(:, 6) = round(dv(:, 6));
  else
    err = ceil(dv(:, 6))-dv(:, 6);
    errindex = err>0 & err<0.000005;
    dv(errindex, 6) = dv(errindex, 6) + 0.000005; // 0 to 5 microsec
  end
  minadd = floor(dv(:, 6)/60);
  dv(:, 5) = dv(:, 5) + minadd;      
  dv(:, 6) = dv(:, 6) - minadd*60;
end
if size(dv, 2)>4 then
  hhadd = floor(dv(:, 5)/60);
  dv(:, 4) = dv(:, 4) + hhadd;      
  dv(:, 5) = dv(:, 5) - hhadd*60;

  ddadd = floor(dv(:, 4)/24);
  dv(:, 3) = dv(:, 3) + ddadd;      
  dv(:, 4) = dv(:, 4) - ddadd*24;
end

eday = eomday(dv(:,1), dv(:,2));
decmon = find(dv(:, 3) < 1);              // newmon
dv(decmon, 2) = dv(decmon, 2) - 1;

incmon = find(dv(:, 3) > eday);
dv(incmon, 3) = dv(incmon, 3) - eday(incmon);
dv(incmon, 2) = dv(incmon, 2) + 1;

decyr = find(dv(:, 2) < 1);
dv(decyr, 2) = dv(decyr, 2) + 12;
dv(decyr, 1) = dv(decyr, 1) - 1;
incyr = find(dv(:, 2) > 12);
dv(incyr, 2) = dv(incyr, 2) - 12;
dv(incyr, 1) = dv(incyr, 1) + 1;

dv(decmon, 3) = dv(decmon, 3) + eomday(dv(decmon,1), dv(decmon,2));

endfunction
