IanLambley
Joined: 17 Dec 2006 Posts: 506 Location: Sunderland
|
Posted: Fri Feb 10, 2012 4:49 pm Post subject: |
|
|
What you have to do is locate all occurances of the open and close statements and determine what each is being used for. Then if they are file usage, and they are a unit less than say 10, change them to a higher number. It is best to allocate an integaer variable and transfer it via subroutine call statements or common blocks for example. All read and write statements between these open and close statements should also be made to match the appropriate unit number. Note, read(*,*) and write(*,*) & Print * are probably intended to refer to keyboard and screen respectively.
Basically you need to determine the structure of your program's input/output and adjust the unit numbers.
Note on some very old computers, the unit numbers are assigned to the files and other devices using operating system commands rather than Fortran open and close statements. and example could be:
Code: |
program io_example
!include these two lines in all subroutines/functions where reads and writes occur
!also in main program or an initialisation routine to set their values
integer*4 keyboard_unit, Screen_unit, input_file_unit,output_file_unit
common/io_units/ keyboard_unit, Screen_unit,input_file_unit,output_file_unit
!allocate units
keyboard_unit = 5
Screen_unit = 6
input_file_unit = 10
output_file_unit = 11
.
.
.
call input_routine
call output routine
.
.
end
subroutine input_routine
integer*4 keyboard_unit, Screen_unit, input_file_unit,output_file_unit
common/io_units/ keyboard_unit, Screen_unit,input_file_unit,output_file_unit
common/data/a,b,c
character*256 input,output
!prompt or input file name
write(screen_unit,*)'Input file'
read(keyboard_unit,'(a)')input
!if not blank, then open file
if(input .ne. ' ')then
open(unit=input_file_unit,file=input,status='unknown')
!read some input data
read(input_file_unit,*)a,b,c
close(unit=input_file_unit)
!prompt for output file name
write(screen_unit,*)'Output file'
read(keyboard_unit,'(a)')output
!open the file
open(unit=output_file_unit,file=output,status='unknown')
else
stop
endif
end
subroutine output_routine
integer*4 keyboard_unit, Screen_unit, input_file_unit,output_file_unit
common/io_units/ keyboard_unit,Screen_unit,input_file_unit,output_file_unit
common/data/a,b,c
write(output_file_unit,*)'Input data'
write(output_file_unit,*)a,b,c
write(output_file_unit,*)'Output data'
write(output_file_unit,*)a+b*c
close(unit=output_file_unit)
end
|
|
|