home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.update.uu.se
/
ftp.update.uu.se.2014.03.zip
/
ftp.update.uu.se
/
pub
/
rainbow
/
msdos
/
decus
/
RB101
/
timinc.for
< prev
next >
Wrap
Text File
|
1995-05-19
|
3KB
|
141 lines
$STORAGE: 2
$NOFLOATCALLS
Subroutine TIMINC(Line,Incmod)
C ROUTINE TO ADD OR SUBTRACT TIME
character LINE(84)
INTEGER INCMOD
integer khar
C INCMOD = 1 FOR DAY
C = 2 FOR WEEK
C = 3 FOR MONTH
C = 4 FOR YEAR
C FORMAT IS
C +NN OR -NN : ADD/SUBTRACT NN DEFAULT UNITS
C +/- NNU (U=D,W,M,Y) TO ADD/SUBT THAT UNIT
INTEGER IDYR,IDMO,IDDY
COMMON/DEFDAT/IDYR,IDMO,IDDY
C OUTPUT IN DEFDAT
INTEGER ML(14)
C LENGTH OF MONTHS
INTEGER L(12)
EQUIVALENCE(L(1),ML(2))
DATA ML/31,31,28,31,30,31,30,31,31,30,31,30,31,31/
C ML IS 14 LONG TO ALLOW REFS OUT OF BOUNDS TO L FOR NO.
C DAYS IN MONTH...
ISIGN=1
IF(LINE(1).EQ.'-')ISIGN=-1
IF(LINE(1).EQ.'-'.OR.LINE(1).EQ.'+')LINE(1)=' '
C SQUASH LINE DOWN AND MAKE SURE UPPER CASE
C DO 1 N=1,83
C LL=KHAR(LINE(N+1))
C IF(LL.GT.97.AND.LL.LT.255)LL=LL-32
C1 LINE(N)=LL
LINE(84)=0
C SCAN FOR D,W,M,Y FOR UNITS
DO 2 N=1,80
IF(LINE(N).EQ.'D'.OR.LINE(N).EQ.'d')THEN
INCMOD=1
LINE(N)=0
GOTO 3
ELSE IF (line(n).eq.'w'.or.LINE(N).EQ.'W')THEN
INCMOD=2
LINE(N)=0
GOTO 3
ELSE IF (line(n).eq.'m'.or.LINE(N).EQ.'M')THEN
INCMOD=3
LINE(N)=0
GOTO 3
ELSE IF (line(n).eq.'y'.or.LINE(N).EQ.'Y')THEN
INCMOD=4
LINE(N)=0
GOTO 3
END IF
2 CONTINUE
3 CONTINUE
C NOW GRAB OFF DIGITS...
MAGN=0
C MAGN GETS MAGNITUDE TO GRAB
DO 4 N=1,80
LL=KHAR(LINE(N))
IF(LL.EQ.32)GOTO 4
IF(LL.GE.48.AND.LL.LE.57) THEN
MAGN=10*MAGN+(LL-48)
ELSE
GOTO 5
END IF
4 CONTINUE
5 CONTINUE
IF(MAGN.EQ.0)MAGN=1
C MAGN NOW HAS MAGNITUDE, ISIGN HAS SIGN AND INCMOD HAS TYPE OF
C INCREMENT.
IF(INCMOD.LE.2) THEN
INCTYP=1
ELSE
INCTYP=INCMOD-1
END IF
C INCTYP IS 1 FOR DAY OR WEEK, 2 FOR MONTH, 3 FOR YEAR
IF(INCMOD.EQ.2)MAGN=MAGN*7
C ADJUST WEEKS AS BEING 7 * DAYS AND TREAT TOGETHER
IF(INCTYP.EQ.1)THEN
IDDY=IDDY+ISIGN*MAGN
C LOOP POINT IF WE MOVE FORWARD
100 IF(IDDY.GT.L(IDMO)) THEN
LYD=0
C ACCOUNT FOR LEAP YEARS WHERE FEBRUARY IS 29 DAYS LONG...
IF(4*(IDYR/4).EQ.IDYR.AND.IDMO.EQ.2)LYD=1
IDDY=IDDY-L(IDMO)-LYD
IDMO=IDMO+1
IF(IDMO.GT.12)THEN
IDMO=1
IDYR=IDYR+1
END IF
GOTO 100
END IF
C LOOP POINT IF WE MOVE BACK
110 IF(IDDY.LE.0)THEN
C ACCOUNT FOR LEAP YEARS. NOTE ML IS PREV MONTH SO CHECK DEF MO=3
LYD=0
IF(4*(IDYR/4).EQ.IDYR.AND.IDMO.EQ.3)LYD=1
IDDY=IDDY+ML(IDMO)+LYD
IDMO=IDMO-1
IF(IDMO.LE.0)THEN
IDMO=12
IDYR=IDYR-1
END IF
GOTO 110
END IF
ELSE IF(INCTYP.EQ.2)THEN
IDMO=IDMO+ISIGN*MAGN
200 IF(IDMO.GT.12)THEN
IDMO=IDMO-12
IDYR=IDYR+1
GOTO 200
END IF
300 IF(IDMO.LE.0)THEN
IDMO=IDMO+12
IDYR=IDYR-1
GOTO 300
END IF
ELSE IF(INCTYP.EQ.3)THEN
IDYR=IDYR+ISIGN*MAGN
END IF
RETURN
END
FUNCTION KHAR(CHAR)
integer khar
CHARACTER CHAR
INTEGER*2 II,I255
LOGICAL*2 LL,L255
EQUIVALENCE(II,LL),(I255,L255)
DATA I255/127/
c mask off all but 7 bits
C RETURN INTEGER VALUE OF CHARACTER IN ARGUMENT
C MASK OFF OTHER BYTE.
II=CHAR
LL=LL.AND.L255
KHAR=II
RETURN
END