|
» |
|
|
|
The user is asked to enter a language. All date
and time formatting and conversion
is done by using the language entered by the user.
The time and date used in the examples is the current
system time obtained by calling the HP 3000 system
intrinsics CALENDAR and CLOCK.
1 $CONTROL USLINIT
2 PROGRAM EXAMPLE
3 LOGICAL LANGUAGE(8)
4 CHARACTER *16 BLANGUAGE
5 C
6 LOGICAL LERROR(2)
7 INTEGER IERROR(2)
8 C
9 CHARACTER *13 BCUSTOMDATE
10 CHARACTER *28 BDATE
11 CHARACTER *18 BCALENDAR
12 CHARACTER *8 BCLOCK
13 C
14 LOGICAL LWEEKDAYS(42)
15 CHARACTER *12 BWEEKDAYS(7)
16 C
17 LOGICAL LMONTHS(72)
18 CHARACTER *12 BMONTHS(12)
19 C
20 EQUIVALENCE (LANGUAGE, BLANGUAGE)
21 EQUIVALENCE (LWEEKDAYS,BWEEKDAYS)
22 EQUIVALENCE (LMONTHS, BMONTHS)
23 EQUIVALENCE (LERROR, IERROR)
24 LOGICAL DATE
25 INTEGER *4 TIME
26 INTEGER LANGNUM, LGTH, WEEKDAY, MONTH
27 SYSTEM INTRINSIC CLOCK, CALENDAR, ALMANAC, NLINFO,
28 # NLFMTCLOCK, QUIT, NLCONVCLOCK, NLFMTDATE,
29 # NLFMTCALENDAR, NLFMTCUSTDATE, NLCONVCUSTDATE
30 C
31 1001 FORMAT (1X,A12)
32 1002 FORMAT (1X,A13)
33 1003 FORMAT (1X,A18)
34 1004 FORMAT (1X,A8)
35 1005 FORMAT (1X,A28)
36 2001 FORMAT (A16)
37 2002 FORMAT (A1)
38 C
39 1 WRITE (6,*)
40 #"ENTER A LANGUAGE NAME OR NUMBER (MAX. 16 CHARACTERS):"
41 READ (5, 2001) BLANGUAGE
42 C
43 C NLINFO item 22 returns the corresponding
44 C lang number in integer format for this language.
45 C
46 CALL NLINFO (22, LANGUAGE, LANGNUM, LERROR)
47 IF (IERROR(1) .EQ. 0) GO TO 400
48 C
49 C
50 100 IF (IERROR(1) .NE. 1) GO TO 200
51 C
52 WRITE (6, *) "NLS IS NOT INSTALLED"
53 CALL QUIT (1001)
54 C
55 200 IF (IERROR(1) .NE. 2) GO TO 300
56 C
57 WRITE (6, *) "THIS LANGUAGE IS NOT CONFIGURED"
58 CALL QUIT (1002)
59 C
60 300 CALL QUIT (1000 + IERROR(1))
61 C
62 C This obtains the machine internal clock and calendar
63 C formats, which are provided by the HP 3000 intrinsics.
64 C
65 400 TIME = CLOCK
66 DATE = CALENDAR
67 C
68 C Call ALMANAC and convert the machine internal
69 C date format into numeric values, which will be used
70 C as indices into the name tables.
71 C
72 CALL ALMANAC(DATE, LERROR, , MONTH, ,WEEKDAY)
73 IF (IERROR(1) .NE. 0) CALL QUIT (2000 + IERROR(1))
74 C
75 C Call the tables for month and weekday names and
76 C display todays day name and the current month's name.
77 C
78 CALL NLINFO(5, LMONTHS, LANGNUM, LERROR)
79 IF (IERROR(1) .NE. 0) CALL QUIT (3000 + IERROR(1))
80 C
81 WRITE (6, 1001) BMONTHS (MONTH)
82 C
83 CALL NLINFO(7, LWEEKDAYS, LANGNUM, LERROR)
84 IF (IERROR(1) .NE. 0) CALL QUIT (4000 + IERROR(1))
85 C
86 WRITE (6, 1001) BWEEKDAYS (WEEKDAY)
87 C
88 C Format the machine internal date format
89 C into the custom date format (short version).
90 C The result will be displayed.
91 C
92 CALL NLFMTCUSTDATE (DATE, BCUSTOMDATE, LANGNUM, LERROR)
93 IF (IERROR(1) .NE. 0) CALL QUIT (5000 + IERROR(1))
94 C
95 WRITE (6,*) "CUSTOM DATE:"
96 WRITE (6,1002) BCUSTOMDATE
97 C
98 C Use the output of NLFMTCUSTDATE as input for
99 C NLCONVCUSTDATE and convert back to the internal format.
100 C
101 DATE = NLCONVCUSTDATE(BCUSTOMDATE, 13, LANGNUM, LERROR)
102 IF (IERROR(1) .NE. 0) CALL QUIT (6000 + IERROR(1))
103 C
104 C Format the machine internal date format into the
105 C date format (long format) according to the language.
106 C The result will be displayed.
107 C
108 CALL NLFMTCALENDAR(DATE, BCALENDAR, LANGNUM, LERROR)
109 IF (IERROR(1) .NE. 0) CALL QUIT (7000 + IERROR(1))
110 C
111 WRITE (6,*) "DATE FORMAT:"
112 WRITE (6,1003) BCALENDAR
113 C
114 C Format the machine internal time format into the
115 C language-dependent clock format.
116 C The result will be displayed.
117 C
118 CALL NLFMTCLOCK(TIME, BCLOCK, LANGNUM, LERROR)
119 IF (IERROR(1) .NE. 0) CALL QUIT (8000 + IERROR(1))
120 C
121 WRITE (6,*) "TIME FORMAT:"
122 WRITE (6,1004) BCLOCK
123 C
124 C Use the output of NLFMTCLOCK as input for
125 C NLCONVCLOCK and convert back to the internal format.
126 C
127 TIME = NLCONVCLOCK(BCLOCK, 8, LANGNUM, LERROR)
128 IF (IERROR(1) .NE. 0) CALL QUIT (9000 + IERROR(1))
129 C
130 C Format the machine internal time and date format
131 C into the language dependent format.
132 C The result will be displayed.
133 C
134 CALL NLFMTDATE(DATE, TIME, BDATE, LANGNUM, LERROR)
135 IF (IERROR(1) .NE. 0) CALL QUIT (10000 + IERROR(1))
136 C
137 WRITE (6,*) "DATE AND TIME FORMAT:"
138 WRITE (6, 1005) BDATE
139 C
140 C
141 STOP
142 END
|
Executing the program gives the following result:
:RUN PROGRAM
ENTER A LANGUAGE NAME OR NUMBER (MAX. 16 CHARACTERS):
NATIVE-3000
JANUARY
TUESDAY
CUSTOM DATE:
01/31/84
DATE FORMAT:
TUE, JAN 31, 1984
TIME FORMAT:
5:15 PM
DATE AND TIME FORMAT:
TUE, JAN 31, 1984, 5:15 PM
END OF PROGRAM
:RUN PROGRAM
ENTER A LANGUAGE NAME OR NUMBER (MAX. 16 CHARACTERS):
8
January
Dienstag
CUSTOM DATE:
31.01.84
DATE FORMAT:
Di., 31. Jan. 1984
TIME FORMAT:
17:15
DATE AND TIME FORMAT:
Di., 31. Jan. 1984, 17:15
END OF PROGRAM
:
|
|