• Aucun résultat trouvé

OPEN 'MTO:ABC ' FOR OUTPUT AS FILE N%, MODE M%

Dans le document RSTS/E Programming Manual (Page 37-40)

100 OPEN ·MTO:FIDO· FOR INPUT AS FILE NX, RECORQSIZE M%

10 OPEN 'MTO:ABC ' FOR OUTPUT AS FILE N%, MODE M%

The system associates magtape unit 0 with the internal channel designated by N% and searches for the file ABC on the current account according to the value M% in the MODE specification.

If the file is not found, the system writes a magtape label record for the file at the logical end of tape and leaves the unit open with write access only. A PUT statement subsequently executed on channel N% writes the channel's buffer to the magtape. Since the me is open solely for output, a GET statement executed on channel N% generates the PROTECTION VIOLATION error (ERR = 10).

The search is successful when the specified file is located. The value of M% in the MODE specification determines how the system searches for the file and acts upon the file when it is found. The meanings shown in Table 2-3 can be at-tached to the MODE values used in an OPEN FOR OUTPUT statement. The MODE value used can be the sum of any combination of these single values, as long as they are not mutually exclusive.

Table 2-3 Magtape OPEN FOR OUTPUT MODE Values

MODE Meaning

0% Read record at current tape position.

2% Do not rewind tape when system searches for the magtape me.

16% Write over existing me. (Destroy any subsequent mes cur-rently on the tape.)

32% Rewind tape before searching for the magtape me.

64% Rewind tape upon executing the CLOSE statement.

128% Open for append.

512% Write new fue label group without searching.

16384% Search for a DOS formatted label.

24576% Search for an ANSI formatted label.

2-4

2.2.1 Searching for a Label

Omitting the MODE specification or using a MODE 0% specification reads the tape at its current position. The sys-tem expects the label format to be the syssys-tem wide default unless the format was changed when the unit was assigned to the job. If the label format differs, the system generates the BAD DIRECTORY FOR DEVICE error (ERR = 1).

If the system fmds a label record and its file name and account match those of the fue specified in the OPEN state-ment, the system generates the NAME OR ACCOUNT NOW EXISTS error (ERR = 16). No match causes the system to rewind the tape and to check successive magtape label records until either a match is made or until the logical end of tape is detected. If the system detects the logical end of tape, the search is unsuccessful. As a result, the system backspaces over the logical end of tape, writes a label record for the fue, and allows write access to the file. The sys-tem does not rewind the tape when the program executes a CLOSE stasys-tement on channel N%.

2.2.2 Writing a Label

As mentioned before, a search is successful when the system finds the specified me on the magtape. The NAME OR ACCOUNT NOW EXISTS error occurs when this happens. This is a precaution to prevent the user from writing a file at this point. (Doing so will write over the current file and erase all subsequent files on the tape.) A value of 16% induded in the MODE specification suppresses this error message and causes the system to write over an exist-ing file on magtape.

NOTE

MODE 16% causes any files following the overwritten file to be lost.

When 16% appears alone in the MODE specification, the system initially reads the magtape at its current position. If the system finds a label record and the file name in the label record matches the file name in the OPEN FOR OUT-PUT statement, it backspaces over the label record, writes a new label record over the existing label and allows the user program write access to the me. If the logical end of tape is at the current position, the system backspaces one record and writes a new label record and allows write access to the me. No match causes the system to rewind the tape and to check label records until either the file is located or until the logical end of tape is detected. Detecting the logical end of tape before locating the file causes the system to backspace one record and write a tape label for the file and to allow the user write access to the file.

A CLOSE statement for a magtape open with MODE 16% writes trailing EOF records, backspaces two records, but does not rewind the tape unless 64% was included in the MODE value.

When 512% is included in the value for the MODE option, the system writes a label record at the current tape posi-tion. No label record reading occurs. The system simply wntes a new label record, erasing all subsequent files on the tape. Only the value 32%, which causes the tape to rewind (see Section 2.2.4), takes precedence over 512%. There-fore, when 512% hi used in conjunction with any combination of values, not including 32%, the system writes a rec-ord label at the current cape position.

2.2.3 Extending a File

NOTE

Any MODE value which includes 512% causes files follow-ing an overwritten file to be lost. The overwritten file is al-ways the one at which the tape is currently positioned ex-cept when 32% is also included in the MODE value.

When 128% is included in the value for the MODE option, the system attempts to open an existing fue and append it does not exist, a CAN'T FIND FILE OR ACCOUNT error (ERR =

2.2.4 Rewinding the Tape

As mentioned before, MODE 0% reads the tape at its current position. If the fIle name specified in the OPEN state-ment does not match the record label, the system automatically rewinds the tape to the first record label and begins reading labels me by file.

To override this automatic rewind feature, include tHe MODE value 2% in the OPEN statement. In this case, the sys-tem reads the tape from its current position and, if no match occurs, continues reading label records from that posi.;

tion forward until either the search is successful or until the logical end of tape is detected. The system does not re-wind the tape when it performs a CLOSE operation. MODE 32% rere-winds the tape to the first record label before reading any label. Once again, no match causes the system to check successive label records until the fue is found or until the logical end of tape is detected. The system does not rewind the tape when it performs the CLOSE operation . on channel N%.

Finally, including MODE value 64% rewinds the tape when a CLOSE statement is executed on- channel N%.

2.2.5 DOS and ANSI Format Labels

Including MODE 16384% in the OPEN FOR OUTPUT statement searches for a magtape me whose file name is speci-fied. In addition, the file must be written in DOS format (Le., preceded by a DOS label) for the search to be considered successful.

When the user omits the MODE value 16384%, the system assumes record labels on the tape, either DOS or ANSI, are in the default format either specified by the system manager when he starts time~sharing or specified by the user when he' reserves the unit to the current job (ASSIGN or MOUNT). The MODE value overrides any current defaults for labeliIig.

Including MODE 24576% in the OPEN FOR OUTPUT statement searches for the magtape me whose fIle name is specified. In this case, the fIle must be written in ANSI format (Le., preceded by an ANSI label) for the search to be considered successful. If the format in which the tape is written differs from that used in the search, the system gener-ates the BAD DIRECTORY FOR DEVICE error (ERR = 1). If the me is found, the system returns the NAME OR ACCOUNT NOW EXISTS error (ERR = 16).

The system reads the tape from its current position. If the fIle is not found, it rewinds the tape and reads label by label until it finds the correct file. If the logical end of tape is detected, the system automatically backspaces over two EOF records, writes an ANSI label record for the me, and allows write access to the fIle.

Once again, omitting the MODE values 16384% or 24576% in the OPEN FOR OUTPUT statement assumes record labels are in the system-wide or job-related default format.

2.2.6 Processing DOS Magtape Files

If the tape being processed is in DOS format, the RECORDSIZE option in the OPEN FOR OUTPUT statement desig-nates the block length. Omitting the RECORDSIZE option from the OPEN FOR OUTPUT statement is equivalent to specifying RECORDSIZE O. That is, BASIC-PLUS creates a 512-byte buffer, the default for DOS magtape proc-essing. PUT statements write blocks on tape equal to the buffer size - 512 bytes.

To write blocks larger than 512 bytes, simply specify an even value equal to or greater than 512 in the RECORDSIZE option. If the value is odd, BASIC-PLUS rounds down the buffer size to make it even.

To write blocks smaller than 512 bytes; the program can create a buffer smaller than 512 bytes. To create a buffer smaller than 512 bytes, specify 32767%+1% plus an even value equal to or greater than 14 in the RECORDSIZE op-tion. Fourteen bytes is the minimum length the magtape hardware can handle. The 32767%+1% value sets the sign bit and tells BASIC-PLUS to use the value specified rather than the default value of 512.1f the sign bit is not set, a 512-byte buffer is created. If the value given is odd (and the sign bit is set), the buffer size is rounded down to make it even. PUT statements without the COUNT option write blocks on tape equal to the buffer size. The COUNT op-tion can be used to write tape blocks smaller than the buffer size but not less than the minimum of 14 bytes.

2-6

2.2.7- Processing ANSI Magtape Fnes

If the tape being processed is in ANSI format, the CLUSTERSIZE and FILESIZE options in the OPEN FOR OUT-PUT statement designate record format and length, me characteristics, and block length. The FILESIZE and CLUSTERSIZE options have effect only when the tape being processed is in ANSI format. The general form of the statement with options is:

Dans le document RSTS/E Programming Manual (Page 37-40)