HP OpenVMS Systems Documentation
OpenVMS Programming Concepts Manual
This part describes the I/O operations, and the system and programming
routines used by run-time libraries and system services.
|Logical Name||User Mode||Equivalence Device or File|
|SYS$INPUT||Interactive||Terminal at which the user is logged in|
|Batch job||Data lines following the invocation of the program|
|Command procedure||Data lines following the invocation of the program|
|SYS$OUTPUT||Interactive||Terminal at which the user is logged in|
|Batch job||Batch log file|
|Command procedure||Terminal at which the user is logged in|
Generally, use of SYS$INPUT and SYS$OUTPUT as the primary input and output devices is recommended. A user of the program can redefine SYS$INPUT and SYS$OUTPUT to redirect input and output as desired. For example, the interactive user might redefine SYS$OUTPUT as a file name to save output in a file rather than display it on the terminal.
22.2.2 Reading and Writing to Alternate Devices and External Files
Alternatively, you can design your program to read input from and write
output to a file or a device other than the user's terminal. Files may
be useful for writing large amounts of data, for writing data that the
user might want to save, and for writing data that can be reused as
input. If you use files or devices other than SYS$INPUT and SYS$OUTPUT,
you should provide the names of the files or devices (best form is to
use logical names) and any conventions for their use. You can specify
such information by having the program write it to the terminal, by
creating a help file, or by providing user documentation.
22.3 Working with Simple User I/O
Usually, you can request information from or provide information to the user with little regard for formatting. For such simple I/O, use either LIB$GET_INPUT and LIB$PUT_OUTPUT or the I/O statements for your programming language.
The LIB$GET_INPUT and LIB$PUT_OUTPUT routines read from SYS$INPUT and
write to SYS$OUTPUT, respectively. The logical names SYS$INPUT and
SYS$OUTPUT are implicit to the routines, because you need only call the
routine to access the I/O unit (device or file) associated with
SYS$INPUT and SYS$OUTPUT. You cannot use these routines to access an
I/O unit other than the one associated with SYS$INPUT or SYS$OUTPUT.
22.3.2 Getting a Line of Input
A read operation transfers one record from the input unit to a variable or variables of your choice. At a terminal, the user ends a record by pressing a terminator. The terminators are the ASCII characters NUL through US (0 through 31) except for LF, VT, FF, TAB, and BS. The usual terminator is CR (carriage return), which is generated by pressing the Return key.
If you are reading character data, LIB$GET_INPUT is a simple way of prompting for and reading the data. If you are reading noncharacter data, programming language I/O statements are preferable since they allow you to translate the data to a format of your choice.
For example, Fortran offers the ACCEPT statement, which reads data from SYS$INPUT, and the READ statement, which reads data from an I/O unit of your choice.
Make sure the variables that you specify can hold the largest number of characters the user of your program might enter, unless you want to truncate the input deliberately. Overflowing the input variable using LIB$GET_INPUT causes the fatal error LIB$_INPSTRTRU (defined in $LIBDEF); overflowing the input variable using language I/O statements may not cause an error but does truncate your data.
LIB$GET_INPUT places the characters read in a variable of your choice. You must define the variable type as a character. Optionally, LIB$GET_INPUT places the number of characters read in another variable of your choice. For input at a terminal, LIB$GET_INPUT optionally writes a prompt before reading the input. The prompt is suppressed automatically for an operation not taking place at a terminal.
Example 22-1 uses LIB$GET_INPUT to read a line of input.
|Example 22-1 Reading a Line of Data|
INTEGER*4 STATUS, 2 LIB$GET_INPUT INTEGER*2 INPUT_SIZE CHARACTER*512 INPUT STATUS = LIB$GET_INPUT (INPUT, ! Input value 2 'Input value: ', ! Prompt (optional) 2 INPUT_SIZE) ! Input size (optional) IF (.NOT. STATUS) CALL LIB$SIGNAL (%VAL (STATUS))
The usual technique for obtaining a variable number of input records---either values for which you are prompting or data records from a file---is to read and process records until the end-of-file. End-of-file means one of the following:
Example 22-2 uses a Fortran READ statement in a loop to read a sequence of integers from SYS$INPUT.
|Example 22-2 Reading a Varying Number of Input Records|
! Return status and error codes INTEGER STATUS, 2 IOSTAT, 3 STATUS_OK, 4 IOSTAT_OK PARAMETER (STATUS_OK = 1, 2 IO_OK = 0) INCLUDE '($FORDEF)' ! Data record read on each iteration INTEGER INPUT_NUMBER ! Accumulated data records INTEGER STORAGE_COUNT, 2 STORAGE_MAX PARAMETER (STORAGE_MAX = 255) INTEGER STORAGE_NUMBER (STORAGE_MAX) ! Write instructions to interactive user TYPE *, 2 'Enter values below. Press CTRL/Z when done.' ! Get first input value WRITE (UNIT=*, 2 FMT='(A,$)') ' Input value: ' READ (UNIT=*, 2 IOSTAT=IOSTAT, 2 FMT='(BN,I)') INPUT_NUMBER IF (IOSTAT .EQ. IO_OK) THEN STATUS = STATUS_OK ELSE CALL ERRSNS (,,,,STATUS) END IF ! Process each input value until end-of-file DO WHILE ((STATUS .NE. FOR$_ENDDURREA) .AND. (STORAGE_COUNT .LT. STORAGE_MAX)) ! Keep repeating on conversion error DO WHILE (STATUS .EQ. FOR$_INPCONERR) WRITE (UNIT=*, 2 FMT='(A,$)') ' Try again: ' READ (UNIT=*, 2 IOSTAT=IOSTAT, 2 FMT='(BN,I)') INPUT_NUMBER IF (IOSTAT .EQ. IO_OK) THEN STATUS = STATUS_OK ELSE CALL ERRSNS (,,,,STATUS) END IF END DO ! Continue if end-of-file not entered IF (STATUS .NE. FOR$_ENDDURREA) THEN ! Status check on last read IF (.NOT. STATUS) CALL LIB$SIGNAL (%VAL (STATUS)) ! Store input numbers in input array STORAGE_COUNT = STORAGE_COUNT + 1 STORAGE_NUMBER (STORAGE_COUNT) = INPUT_NUMBER ! Get next input value WRITE (UNIT=*, 2 FMT='(A,$)') ' Input value: ' READ (UNIT=*, 2 IOSTAT=IOSTAT, 2 FMT='(BN,I)') INPUT_NUMBER IF (IOSTAT .EQ. IO_OK) THEN STATUS = STATUS_OK ELSE CALL ERRSNS (,,,,STATUS) END IF END IF END DO
You can use LIB$PUT_OUTPUT to write character data. If you are writing noncharacter data, programming language I/O statements are preferable because they allow you to translate the data to a format of your choice.
LIB$PUT_OUTPUT writes one record of output to SYS$OUTPUT. Typically, you should avoid writing records that exceed the device width. The width of a terminal is 80 or 132 characters, depending on the setting of the physical characteristics of the device. The width of a line printer is 132 characters. If your output record exceeds the width of the device, the excess characters are either truncated or wrapped to the next line, depending on the setting of the physical characteristics.
You must define a value (a variable, constant, or expression) to be written. The value must be expressed in characters. You should specify the exact number of characters being written and not include the trailing portion of a variable.
INTEGER*4 STATUS, 2 LIB$PUT_OUTPUT CHARACTER*40 ANSWER INTEGER*4 ANSWER_SIZE . . . STATUS = LIB$PUT_OUTPUT ('Answer: ' // ANSWER (1:ANSWER_SIZE)) IF (.NOT. STATUS) CALL LIB$SIGNAL (%VAL (STATUS))
The following sections present Compaq DECwindows Motif for OpenVMS
(DECwindows Motif), and the SMG$ run-time library routines that enable
complex screen display I/O.
22.4.1 Compaq DECwindows Motif
The Compaq DECwindows Motif environment provides a consistent user interface for developing software applications. It also includes an extensive set of programming libraries and tools. The following Compaq DECwindows Motif software allows you to build a graphical user interface:
Compaq DECwindows Motif environment also makes available the LinkWorks
services for creating, managing, and traversing informational links
between different application-specific data. Along with the LinkWorks
Manager application, LinkWorks services help organize information into
a hyperinformation environment. LinkWorks Developer's Tools provide a
development environment for creating, modifying, and maintaining
184.108.40.206 DECwindows Server Height or Width Exceeding 32767 (VAX Only)
On OpenVMS VAX systems, when an X application sends the display server a width or height greater than 32767, the application may terminate with a BadValue error similar to the following:
X error event received from server: BadValue (integer parameter out of range for operation) Major opcode of failed request: 61 (X_ClearArea) Value in failed request: 0xffff**** Serial number of failed request: ### Current serial number in output stream: ###
The following calls can cause this problem:
This is due to the width and height being defined as a signed word by the display server when it should be defined as an unsigned word (CARD16) that allows for values up to 65536.
To modify the default operation, perform the following steps:
$DEFINE/TABLE=DECW$SERVER0_TABLE DECW$CARD16_VALIDATE TRUE
To make this a permanent change, add the command from step 1 to the
220.127.116.11 SET DISPLAY Used to Create WSA Pseudo Workstation Devices
When creating WSA pseudo workstation devices using the SET DISPLAY command, be careful not to create WSA devices that are never destroyed. For example, this DCL command procedure is wrong:
$LOOP: $ SET DISPLAY/CREATE/NODE=remote $ RUN SYS$SYSTEM:DECW$CLOCK $ IF $STATUS THEN GOTO DONE $ WAIT 0:0:5 $ GOTO LOOP $DONE:
If the clock cannot be started for some reason, one WSA device will be created for each failed attempt. These WSA devices will use up non-paged dynamic memory, and eventually the process will exceed its BYTLM quota and enter a resource wait state (if resource waiting is enabled, as it is by default).
A better version of this command procedure is the following:
$ SET DISPLAY/CREATE/NODE=remote $LOOP: $ RUN SYS$SYSTEM:DECW$CLOCK $ IF $STATUS THEN GOTO DONE $ WAIT 0:0:5 $ GOTO LOOP $DONE: $ SET DISPLAY/DELETE 'F$TRNLNM("DECW$DISPLAY")'
The SET DISPLAY/DELETE command deletes the WSA device that was created at the beginning of the command procedure; the logical name DECW$DISPLAY contains the name of the WSA device that was created.
For information about using OpenVMS Compaq DECwindows Motif, see the
Overview of DECwindows Motif for OpenVMS Documentation and the DECwindows Motif Guide to Application Programming.
22.4.2 SMG$ Run-Time Routines
The SMG$ run-time library routines provide a simple, device-independent
interface for managing the appearance of the terminal screen. The SMG$
routines are primarily for use with video terminals; however, they can
be used with files or hardcopy terminals.
To use the screen management facility for output, do the following:
Example 22-3 associates a pasteboard with the terminal, creates a virtual display the size of the terminal screen, and pastes the display to the pasteboard. When text is written to the virtual display, the text appears on the terminal screen.
|Example 22-3 Associating a Pasteboard with a Terminal|
. . . ! Screen management control structures INTEGER*4 PBID, ! Pasteboard ID 2 VDID, ! Virtual display ID 2 ROWS, ! Rows on screen 2 COLS ! Columns on screen ! Status variable and routines called as functions INTEGER*4 STATUS, 2 SMG$CREATE_PASTEBOARD, 2 SMG$CREATE_VIRTUAL_DISPLAY, 2 SMG$PASTE_VIRTUAL_DISPLAY ! Set up SYS$OUTPUT for screen management ! and get the number of rows and columns on the screen STATUS = SMG$CREATE_PASTEBOARD (PBID, ! Return value 2 'SYS$OUTPUT', 2 ROWS, ! Return value 2 COLUMNS) ! Return value IF (.NOT. STATUS) CALL LIB$SIGNAL (%VAL (STATUS)) ! Create virtual display that pastes to the full screen size STATUS = SMG$CREATE_VIRTUAL_DISPLAY (ROWS, 2 COLUMNS, 2 VDID) ! Return value IF (.NOT. STATUS) CALL LIB$SIGNAL (%VAL (STATUS)) ! Paste virtual display to pasteboard STATUS = SMG$PASTE_VIRTUAL_DISPLAY (VDID, 2 PBID, 2 1, ! Starting at row 1 and 2 1) ! column 1 of the screen IF (.NOT. STATUS) CALL LIB$SIGNAL (%VAL (STATUS)) . . .
To use the SMG$ routines for input, you associate a virtual keyboard with a physical device or file using the SMG$CREATE_VIRTUAL_KEYBOARD routine. The SMG$ input routines can be used alone or with the output routines. This section assumes that you are using the input routines with the output routines. Section 22.5 describes how to use the input routines without the output routines.
The screen management facility keeps an internal representation of the screen contents; therefore, it is important that you do not mix SMG$ routines with other forms of terminal I/O. The following subsections contain guidelines for using most of the SMG$ routines; for more details, see the OpenVMS RTL Screen Management (SMG$) Manual.