Collisions in Logical Unit Numbers

| SimCon Home | fpt Reference Manual Home |

Why Are Logical Unit Numbers a Problem?

The logical unit numbers (LUNs) used in Fortran file handling are simple integers. They may be written in the code as Fortran parameters (And this is good practice) but nothing prevents two named LUNs from having the same integer value. Contrast this behaviour with the file pointers used in C, where the name of the pointer uniquely defines it.

If a file is opened on a LUN which is already in use, the file already open is silently closed and the new file is opened. There is no run-time diagnostic. If any file accesses intended for the original file are made, they operate on the new file. There is a real risk of collisions between LUNs and we have observed this in several codes.

Can Collisions be Detected?

fpt can list the LUNs used in a program. The listing shows the keywords used with each LUN (OPEN, CLOSE, READ, WRITE etc.) with their arguments, and the parameterised names if any are used. The command is:

SHOW LOGICAL UNITS

At present, users must inspect this listing to look for problems. It might be useful to provide an automatic search for LUNs which are opened more than once or which have two or more parameterised names. This will be considered for future development.

The end of the listing for the control system of a tracking radar is shown below. The listing ends with a summary of the number of LUNs and the use of keywords.

Logical Unit: 87 ---------------- Symbol(s): Name Scope Use/COMMON Address Type Size Value/Bounds ---- ----- ---------- ------- ---- ---- ------------ p_joy_lun open_history_file,get_mission_files,urpma125,urpm_prd,urpm_123, urpm_122,read_joy_cal,read_axes_cal,read_zoom_cal,urt_wvco,urvc_upd, urvc_par... Parameter INTEGER *4 87 READ and ACCEPT, number of occurrences: 2, Keywords: (fmt=...) BACKSPACE, number of occurrences: 1, Keywords: () CLOSE, number of occurrences: 2, Keywords: () OPEN, number of occurrences: 1, Keywords: (err=..., file=..., status='old') Units which are run-time variables ---------------------------------- Symbol(s): Name Scope Use/COMMON Address Type Size Value/Bounds ---- ----- ---------- ------- ---- ---- ------------ acilun wwrite,wread,acl_app_bda,acwrit,actral,acstpt,acsend,acrept,acprpt, acpron,acpass,acpars... /acl_ncm/ 8 INTEGER *4 iluna skip_comments Formal Input Argument INTEGER *4 lun acinop Local INTEGER *4 df READ and ACCEPT, number of occurrences: 3, Keywords: (fmt=...) WRITE, TYPE, PRINT and DISPLAY, number of occurrences: 2, Keywords: (fmt=...) BACKSPACE, number of occurrences: 1, Keywords: () CLOSE, number of occurrences: 3, Keywords: () OPEN, number of occurrences: 2, Keywords: (err=..., file=..., status='unknown') Total Counts of External I/O Statements ======================================= READ and ACCEPT 161 REWRITE 0 WRITE, TYPE, PRINT and DISPLAY 709 BACKSPACE 4 CLOSE 85 DELETE 0 ENDFILE 0 OPEN 89 REWIND 0 UNLOCK 0 *******************************************************************************

Copyright ©1995 to 2024 Software Validation Ltd. All rights reserved.