| United States-English |
|
|
|
![]() |
HP OpenVMS Systems Documentation |
HP Fortran for OpenVMS
|
| Previous | Contents | Index |
The DELETE statement allows you to delete records from an indexed file. The DELETE and REWRITE statements are similar; a record must first be locked by a READ statement before it can be operated on.
The following Fortran code segment deletes the second record in the file with ITEM_NUMBER 375 (refer to previous examples):
READ (UNIT=10,KEY=375,KEYID=2,IOSTAT=IOS,ERR=9999)
READ (UNIT=10,IOSTAT=IOS,ERR=9999) FILE_REC
IF (FILE_REC.ITEM_NUMBER .EQ. 375) THEN
DELETE (UNIT=10, IOSTAT=IOS, ERR=9999)
ELSE
PRINT *, 'There is no second record.'
END IF
|
Deletion removes a record from all defined indexes in the file.
12.7 Current Record and Next Record Pointers
The RMS file system maintains two pointers into an open indexed file:
You can expect to encounter certain exception conditions when using indexed files. The two most common of these conditions involve valid attempts to read locked records and invalid attempts to create duplicate keys. Provisions for handling both of these situations should be included in a well-written program.
When an indexed file is shared by several users, any read operation may result in a "specified record locked" error. One way to recover from this error condition is to ask if the user would like to reattempt the read. If the user's response is positive, then the program can go back to the READ statement. For example:
INCLUDE '($FORIOSDEF)'
.
.
.
100 READ (UNIT=10,IOSTAT=IOS) DATA
IF (IOS .EQ. FOR$IOS_SPERECLOC) THEN
TYPE *, 'That record is locked. Press RETURN'
TYPE *, 'to try again, or Ctrl/Z to discontinue'
READ (UNIT=*,FMT=*,END=900)
GO TO 100
ELSE IF (IOS .NE. 0) THEN
CALL ERROR (IOS)
END IF
|
You should avoid looping back to the READ statement without first providing some type of delay (caused by a request to try again, or to discontinue, as in this example). If your program reads a record but does not intend to modify the record, you should place an UNLOCK statement immediately after the READ statement. This technique reduces the time that a record is locked and permits other programs to access the record.
The second exception condition, creation of duplicate keys, occurs when your program tries to create a record with a key field value that is already in use. When duplicate key field values are not desirable, you might have your program prompt for a new key field value whenever an attempt is made to create a duplicate. For example:
INCLUDE '($FORIOSDEF)'
200 WRITE (UNIT=10,IOSTAT=IOS) KEY_VAL, DATA
IF (IOS .EQ. FOR$IOS_INCKEYCHG) THEN
TYPE *, 'This key field value already exists. Please'
TYPE *, 'enter a different key field value, or press'
TYPE *, 'Ctrl/Z to discontinue this operation.'
READ (UNIT=*,FMT=300,END=999) KEY_VAL
GO TO 200
ELSE IF (IOS .NE. 0) THEN
CALL ERROR (IOS)
END IF
|
This chapter describes how to exchange and share data between local and remote processes:
Local processes involve a single OpenVMS processor, and remote
processes involve separate processors that are interconnected by means
of DECnet.
13.1 HP Fortran Program Section Usage
You may need to change program section attributes to allow shared access to an installed shareable image.
The storage required by an HP Fortran program unit is allocated in contiguous areas called program sections (PSECTs). The HP Fortran compiler implicitly declares these PSECTs:
Each common block you declare causes allocation of a PSECT with the same name as the common block. (The unnamed common block PSECT is named $BLANK.) Memory allocation and sharing are controlled by the linker according to the attributes of each PSECT; PSECT names and attributes are listed in Table 13-1.
Each procedure in your program is named according to the name specified in the PROGRAM, BLOCK DATA, FUNCTION, or SUBROUTINE statement used in creating the object module. The defaults applied to PROGRAM and BLOCK DATA statements are source-file-name$MAIN and source-file-name$DATA, respectively.
| PSECT Name | Use | Attributes |
|---|---|---|
| $CODE$ | Executable code | PIC, CON, REL, LCL, SHR, EXE, NORD, NOWRT, OCTA |
| $LINK$ | Linkage information (procedure descriptors, linkage pairs, and literals) | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, NOWRT, OCTA |
| $DATA$ | Initialized user local static variables and compiler temporary variables | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT, OCTA |
| $BSS$ | Uninitialized user local variables and compiler temporary variables | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT, OCTA |
| $LITERAL$ | Literals used in FORMAT statements | NOPIC, CON, REL, LCL, NOSHR, NOEXE, RD, WRT, OCTA |
| $BLANK | Blank common block | NOPIC, OVR, REL, GBL, NOSHR, NOEXE, RD, WRT, OCTA |
| names | Named common blocks | NOPIC, OVR, REL, GBL, NOSHR, NOEXE, RD, WRT, OCTA |
You can use the cDEC$ PSECT (such as !DEC$ PSECT) directive or use a linker options file to change some of the attributes of a common block.
Table 13-2 describes the meanings of HP Fortran PSECT attributes.
| Attribute | Meaning |
|---|---|
| PIC/NOPIC | Position independent or position dependent code |
| CON/OVR | Concatenated or overlaid |
| REL/ABS | Relocatable or absolute |
| GBL/LCL | Global or local scope |
| SHR/NOSHR | Shareable or nonshareable |
| EXE/NOEXE | Executable or nonexecutable |
| RD/NORD | Readable or nonreadable (reserved by HP) |
| WRT/NOWRT | Writable or nonwritable |
| LONG/QUAD/OCTA | Longword, quadword, or octaword alignment |
When the linker constructs an executable image, it divides the executable image into sections. Each image section contains PSECTs that have the same attributes. By arranging image sections according to PSECT attributes, the linker is able to control memory allocation. The linker allows you to allocate memory to your own specification by means of commands you include in an options file that is input to the linker.
Interprocess communication mechanisms provided for local processes include the following capabilities:
These capabilities are discussed in the sections that follow.
VOLATILE declarations are required when you use certain run-time features of the operating system, including values that can be read or written by methods other than direct assignment, or during a routine call.
If a variable can be accessed using rules in addition to those provided by the standard Fortran 90/95 language, declare the variable as VOLATILE. For example, if a variable in COMMON can change value by means of an OpenVMS AST routine or condition handler, you must declare that common block variable or the entire COMMON block as volatile.
Consider the following uses of variables as candidates for a VOLATILE declaration if asynchronous access might occur:
If you have a routine that is invoked by more than one program, you should consider establishing it as a shareable image and installing it on your system.
Establishing a routine as a shareable image provides the following benefits:
Installing a shareable image as shared (INSTALL command, /SHARED qualifier) can also save memory.
The steps to creating and installing a shareable image are:
Any programs that access a shareable image must be linked with that image. When performing the link operation, you must specify one of the following items on your LINK command:
The resulting executable image contains the contents of each object
module and a pointer to each shareable image.
13.2.2 Sharing Data in Installed Common Areas
Sharing the same data among two or more processes can be done using installed common areas.
Typically, you use an installed common area for interprocess
communication or for two or more processes to access the same data
simultaneously.
13.2.2.1 Creating and Installing the Shareable Image Common Area
To communicate between processes using a common area, first install the common area as a shareable image:
COMMON /WORK_AREA/ WORK_ARRAY(8192) END |
$ FORTRAN/ALIGN=COMMONS=NATURAL/GRANULARITY=LONGWORD INC_COMMON.F90 |
$ LINK/SHAREABLE INC_COMMON ,SYS$INPUT/OPTION SYMBOL_VECTOR=(WORK_AREA=PSECT) PSECT_ATTR=WORK_AREA,SHR [Ctrl/Z] |
$ LINK/SHAREABLE INC_COMMON ,SYS$INPUT/OPTION SYMBOL_VECTOR=(WORK_AREA=PSECT) [Ctrl/Z] |
!DEC$ PSECT /INC_COMMON/ SHR |
$ COPY/LOG DISK$:[INCOME.DEV]INC_COMMON.EXE SYS$SHARE:*.*/PROTECTION=G:RWE |
$ INSTALL INSTALL> CREATE SYS$SHARE:INC_COMMON/WRITABLE/SHARED INSTALL> EXIT $ |
After the common area has been installed as a shareable image, use the following steps to access the data from any executable program:
$ FORTRAN/ALIGN=COMMONS=NATURAL/GRANULARITY=LONGWORD INCOME.F90 $ FORTRAN/ALIGN=COMMONS=NATURAL/GRANULARITY=LONGWORD REPORT.F90 |
$ LINK INCOME, INCOME/OPTION $ LINK REPORT, INCOME/OPTION |
INC_COMMON/SHAREABLE PSECT_ATTR=WORK_AREA, SHR |
INC_COMMON/SHAREABLE |
!DEC$ PSECT /INC_COMMON/ SHR |
| Previous | Next | Contents | Index |
| ** About PDF files: The PDF files on this Web site can be read online or printed using Adobe® Acrobat® Reader. If you do not have this software installed on your system, you may download it from the Adobe Web site. | ||
|
|||||||||||||||