SlideShare a Scribd company logo
1 of 19
Basic Scientific Programming
File Processing
File Processing






Applications involving large data sets can be
processed more conveniently if the data is
stored in a file.
The data in the file to be used as an input file
must be arranged in a form suitable for
reading by a read statement.
These values are read during program
execution, just like data entered by the user
from the keyboard.
Opening Files


form OPEN ( open_list )
opens the file associated with specified
unit number so that Input/Output can
take place.
Open List


Open_list includes:
1) a unit specifier indicating a unit
number connected to the file being
opened. The unit specifier has the form
described for the write statement.
2) FILE = Character_expression giving
the name of the file being opened.
Open List


3) Status = character_expression where
character expression is one of the following
“old”,”new”, or “replace”.
*Old means the file already exists.
*New means the file does not yet exist and is
being created.
*Replace creates a new file, replacing the old
one if one already exists, and changes its
status to old
Open List


Action = i-o-action
where i-o-action is a character expression
whose value is one of the following:
“Read”: file opened for reading only
“Write”: file opened for writing only
“Readwrite”: file opened for both reading and
writing.
Open List


Position = character_expression
where the character expression is on of
“Rewind”: position the file at its initial point.
“Append”: position the file at the end of file.
“ASIS”: leaves the position unchanged..
Open List


IOSTAT = Status_variable
where status variable is an integer
variable to which the value zero is
assigned if the file is opened
successfully and a positive value is
assigned otherwise.
Ex:


To open a file named info.dat from which data
values are to be read:
open(unit=12,FILE=“info.dat”,status=“old”,&
action=“read”, Position=“rewind”,&
IOSTAT = OpenStauts)

where openstatus is an integer variable equal to zero
if the file is successfully opened or some positive
value if the file cannot be open.


If the program is to used with various data
files, it’s better not to assign the file name
directly but to use a character variable.
Character(12):: filename
Write(*,’(1X,A)’,ADVANCE=“NO”) &
“Enter name of data file”
read *, filename
open(unit=12,FILE=filename,status=“old”,&
action=“read”, Position=“rewind”,&
IOSTAT = OpenStauts)




To open a new file named Report to
which values are to be written;
open(unit=13,File=“Report”,status=“new”,&
action=“write”, IOSTAT= openstatus)
To write values to the file, we use the write
statement
Write(13,’(1X,I3)’) Code
Closing Files


The CLOSE statement has a function
opposite that of the OPEN statement
and is used to disconnect a file from its
unit number.

Form

close (unit_number)
Notes




After a close statement is executed, the
closed file may be reopened by using an
open statement; the same unit number may
be connected to it or a different on may be
used.
All files that are not explicitly closed by means
of a close statement are automatically closed
when and End or Stop statement is executed.
File Input/Output




Once a file has been connected to a
unit number, data can be written to or
form that file using the general WRITE
and READ statements.
A general read statement may contain
an IOSTAT= clause to detect an end-offile condition or an input error.



IOSTAT = status_variable,
Status_variable is assigned





A positive value if an input error occurs.
A negative value if the end of data is
encountered but no input errors occurs.
Zero if neither an input error not the end of
data occurs.
Ex:


Do
Read(12,*,IOSTAT= Instat) pressure
if (Instat >0) stop “ input error”
if (Instat <0) exit !end of file
! Otherwise continue processing data
sum = sum + pressure
End Do


An alternative method of detecting an
end-of-file condition is to use an
END=clause in the control list of a
general read statement.

Form END= statement_number.
Ex:


Do
Read(12,*,End=20) pressure
sum = sum + pressure
End Do
20 Continue
.
.
.
File Positioning Statements




Rewind Statement:
Rewind unit_number
positions the file at the beginning.
Backspace Statement:
Backspace unit_number
positions the file at the beginning of the
preceding line.

More Related Content

What's hot (18)

Using serials solutions overlap analysis to identify print rev
Using serials solutions overlap analysis  to identify print revUsing serials solutions overlap analysis  to identify print rev
Using serials solutions overlap analysis to identify print rev
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Rozalia alik math3 (newone)
Rozalia alik  math3 (newone)Rozalia alik  math3 (newone)
Rozalia alik math3 (newone)
 
shs-adcppt1
shs-adcppt1shs-adcppt1
shs-adcppt1
 
Filter
FilterFilter
Filter
 
SHS-ADC(Hyperlinks)
SHS-ADC(Hyperlinks)SHS-ADC(Hyperlinks)
SHS-ADC(Hyperlinks)
 
Dynamic Web Pages Ch 4 V1.0
Dynamic Web Pages Ch 4 V1.0Dynamic Web Pages Ch 4 V1.0
Dynamic Web Pages Ch 4 V1.0
 
Lecture12 abap on line
Lecture12 abap on lineLecture12 abap on line
Lecture12 abap on line
 
TLE
TLETLE
TLE
 
CS215 - Lec 7 managing records collection
CS215 - Lec 7  managing records collectionCS215 - Lec 7  managing records collection
CS215 - Lec 7 managing records collection
 
Database Basics
Database BasicsDatabase Basics
Database Basics
 
SPSS
SPSSSPSS
SPSS
 
Introduction To .Net
Introduction To .NetIntroduction To .Net
Introduction To .Net
 
Rozalia alik math3 (latest)
Rozalia alik  math3 (latest)Rozalia alik  math3 (latest)
Rozalia alik math3 (latest)
 
Hira
HiraHira
Hira
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
M02 un05 p02
M02 un05 p02M02 un05 p02
M02 un05 p02
 
Introduction to linking
Introduction to linkingIntroduction to linking
Introduction to linking
 

Viewers also liked

Introduction to storage
Introduction to storageIntroduction to storage
Introduction to storagesagaroceanic11
 
ファイルアクセス方式 - オペレーティングシステム
ファイルアクセス方式 - オペレーティングシステムファイルアクセス方式 - オペレーティングシステム
ファイルアクセス方式 - オペレーティングシステム金沢工業高等専門学校
 
ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~
ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~
ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~Brocade
 
IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)
IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)
IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)IIJ
 

Viewers also liked (6)

Ch08
Ch08Ch08
Ch08
 
Introduction to storage
Introduction to storageIntroduction to storage
Introduction to storage
 
ファイルアクセス方式 - オペレーティングシステム
ファイルアクセス方式 - オペレーティングシステムファイルアクセス方式 - オペレーティングシステム
ファイルアクセス方式 - オペレーティングシステム
 
ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~
ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~
ストレージ管理者が今、押さえておくべきネットワーク基本の「キ」 ~必要なのは性能とシンプルさ。その極意とは?~
 
Kernel ext4
Kernel ext4Kernel ext4
Kernel ext4
 
IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)
IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)
IIJ GIOアカデミー / ハイブリッドクラウド(基礎編)
 

Similar to Scientific Programming File Processing

Read write program
Read write programRead write program
Read write programAMI AMITO
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSFILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSVenugopalavarma Raja
 
FILE HANDLING in python to understand basic operations.
FILE HANDLING in python to understand basic operations.FILE HANDLING in python to understand basic operations.
FILE HANDLING in python to understand basic operations.ssuser00ad4e
 
Programming in C
Programming in CProgramming in C
Programming in Csujathavvv
 
Data Structure Using C - FILES
Data Structure Using C - FILESData Structure Using C - FILES
Data Structure Using C - FILESHarish Kamat
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'eShikshak
 
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handlingRai University
 

Similar to Scientific Programming File Processing (20)

Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptx
 
FILE HANDLING.pptx
FILE HANDLING.pptxFILE HANDLING.pptx
FILE HANDLING.pptx
 
Satz1
Satz1Satz1
Satz1
 
Read write program
Read write programRead write program
Read write program
 
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUSFILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
FILE HANDLING IN C++. +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
 
FILE HANDLING in python to understand basic operations.
FILE HANDLING in python to understand basic operations.FILE HANDLING in python to understand basic operations.
FILE HANDLING in python to understand basic operations.
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Programming in C
Programming in CProgramming in C
Programming in C
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Data Structure Using C - FILES
Data Structure Using C - FILESData Structure Using C - FILES
Data Structure Using C - FILES
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
File handling C program
File handling C programFile handling C program
File handling C program
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
 
Savitch Ch 06
Savitch Ch 06Savitch Ch 06
Savitch Ch 06
 
Savitch Ch 06
Savitch Ch 06Savitch Ch 06
Savitch Ch 06
 
Files.pptx
Files.pptxFiles.pptx
Files.pptx
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 

More from fyjordan9

More from fyjordan9 (17)

17recursion
17recursion17recursion
17recursion
 
16 subroutine
16 subroutine16 subroutine
16 subroutine
 
15 functions
15 functions15 functions
15 functions
 
14 arrays
14 arrays14 arrays
14 arrays
 
13 arrays
13 arrays13 arrays
13 arrays
 
12 doloops
12 doloops12 doloops
12 doloops
 
11 doloops
11 doloops11 doloops
11 doloops
 
10 examples for if statement
10 examples for if statement10 examples for if statement
10 examples for if statement
 
9 case
9 case9 case
9 case
 
8 if
8 if8 if
8 if
 
6 read write
6 read write6 read write
6 read write
 
5 format
5 format5 format
5 format
 
4 design
4 design4 design
4 design
 
3 in out
3 in out3 in out
3 in out
 
2 int real
2 int real2 int real
2 int real
 
1 arithmetic
1 arithmetic1 arithmetic
1 arithmetic
 
PHYS303
PHYS303PHYS303
PHYS303
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 

Scientific Programming File Processing

  • 2. File Processing    Applications involving large data sets can be processed more conveniently if the data is stored in a file. The data in the file to be used as an input file must be arranged in a form suitable for reading by a read statement. These values are read during program execution, just like data entered by the user from the keyboard.
  • 3. Opening Files  form OPEN ( open_list ) opens the file associated with specified unit number so that Input/Output can take place.
  • 4. Open List  Open_list includes: 1) a unit specifier indicating a unit number connected to the file being opened. The unit specifier has the form described for the write statement. 2) FILE = Character_expression giving the name of the file being opened.
  • 5. Open List  3) Status = character_expression where character expression is one of the following “old”,”new”, or “replace”. *Old means the file already exists. *New means the file does not yet exist and is being created. *Replace creates a new file, replacing the old one if one already exists, and changes its status to old
  • 6. Open List  Action = i-o-action where i-o-action is a character expression whose value is one of the following: “Read”: file opened for reading only “Write”: file opened for writing only “Readwrite”: file opened for both reading and writing.
  • 7. Open List  Position = character_expression where the character expression is on of “Rewind”: position the file at its initial point. “Append”: position the file at the end of file. “ASIS”: leaves the position unchanged..
  • 8. Open List  IOSTAT = Status_variable where status variable is an integer variable to which the value zero is assigned if the file is opened successfully and a positive value is assigned otherwise.
  • 9. Ex:  To open a file named info.dat from which data values are to be read: open(unit=12,FILE=“info.dat”,status=“old”,& action=“read”, Position=“rewind”,& IOSTAT = OpenStauts) where openstatus is an integer variable equal to zero if the file is successfully opened or some positive value if the file cannot be open.
  • 10.  If the program is to used with various data files, it’s better not to assign the file name directly but to use a character variable. Character(12):: filename Write(*,’(1X,A)’,ADVANCE=“NO”) & “Enter name of data file” read *, filename open(unit=12,FILE=filename,status=“old”,& action=“read”, Position=“rewind”,& IOSTAT = OpenStauts)
  • 11.   To open a new file named Report to which values are to be written; open(unit=13,File=“Report”,status=“new”,& action=“write”, IOSTAT= openstatus) To write values to the file, we use the write statement Write(13,’(1X,I3)’) Code
  • 12. Closing Files  The CLOSE statement has a function opposite that of the OPEN statement and is used to disconnect a file from its unit number. Form close (unit_number)
  • 13. Notes   After a close statement is executed, the closed file may be reopened by using an open statement; the same unit number may be connected to it or a different on may be used. All files that are not explicitly closed by means of a close statement are automatically closed when and End or Stop statement is executed.
  • 14. File Input/Output   Once a file has been connected to a unit number, data can be written to or form that file using the general WRITE and READ statements. A general read statement may contain an IOSTAT= clause to detect an end-offile condition or an input error.
  • 15.   IOSTAT = status_variable, Status_variable is assigned    A positive value if an input error occurs. A negative value if the end of data is encountered but no input errors occurs. Zero if neither an input error not the end of data occurs.
  • 16. Ex:  Do Read(12,*,IOSTAT= Instat) pressure if (Instat >0) stop “ input error” if (Instat <0) exit !end of file ! Otherwise continue processing data sum = sum + pressure End Do
  • 17.  An alternative method of detecting an end-of-file condition is to use an END=clause in the control list of a general read statement. Form END= statement_number.
  • 18. Ex:  Do Read(12,*,End=20) pressure sum = sum + pressure End Do 20 Continue . . .
  • 19. File Positioning Statements   Rewind Statement: Rewind unit_number positions the file at the beginning. Backspace Statement: Backspace unit_number positions the file at the beginning of the preceding line.