NAG CL Interface
x04acc (open)

1 Purpose

x04acc opens a file for reading, writing or appending, and returns an associated file identifier.

2 Specification

#include <nag.h>
void  x04acc (const char *filename, Integer mode, Nag_FileID *fileid, NagError *fail)
The function may be called by the names: x04acc, nag_file_open or nag_open_file.

3 Description

x04acc opens a file for reading, writing or appending and returns an associated file identifier. This function is intended for use by callers of certain functions in Chapters E04 and F12 which use the file identifier for input or output of data.

4 References

None.

5 Arguments

1: filename const char * Input
On entry: the name of the file to be opened. As special cases, an empty string or null pointer may be used to associate fileid with standard input or standard output. See the description of mode below.
Constraint: must contain a valid filename for the computer system being used.
2: mode Integer Input
On entry: specifies whether the file is to be opened for reading, writing or appending.
mode=0
The file is to be opened for reading.
If filename is an empty string or null pointer then fileid becomes associated with standard input.
mode=1
The file is to be opened for writing.
If filename is an empty string or null pointer then fileid becomes associated with standard output.
mode=2
The file is to be opened for appending.
If filename is an empty string or null pointer then fileid becomes associated with standard output.
Constraint: 0mode2.
3: fileid Nag_FileID * Output
On exit: an identifier associated with the file to be read from, written to or appended to. This identifier will typically be passed to other NAG C Library functions.
4: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_INT
On entry, mode=value.
Constraint: 0mode2.
NE_NOT_APPEND_FILE
Cannot open file value for appending.
NE_NOT_READ_FILE
Cannot open file value for reading.
NE_NOT_WRITE_FILE
Cannot open file value for writing.

7 Accuracy

Not applicable.

8 Parallelism and Performance

x04acc is not threaded in any implementation.

9 Further Comments

None.

10 Example

This example illustrates how to open a file for writing, write a line to the file using x04bac and close the file using x04adc. The file is then reopened, the line read back using x04bbc, and closed again.

10.1 Program Text

Program Text (x04acce.c)

10.2 Program Data

None.

10.3 Program Results

Program Results (x04acce.r)