hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_file_close (x04ad)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_file_close (x04ad) closes a file associated with a given Fortran unit number.

Syntax

[ifail] = x04ad(iounit)
[ifail] = nag_file_close(iounit)

Description

nag_file_close (x04ad) is especially useful if the calling language is not Fortran. It closes a file associated with a given Fortran unit number.

References

None.

Parameters

Compulsory Input Parameters

1:     iounit int64int32nag_int scalar
The Fortran unit number which identifies the file to be closed.

Optional Input Parameters

None.

Output Parameters

1:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
Failure to close the file.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

None.

Example

This example program simply illustrates how to close a file once it has been opened for writing followed by how to close a file once it has been opened for reading.
function x04ad_example


fprintf('x04ad example results\n\n');

file = 'success.res';

% Associate unit number iounit=4 with filename success.res
iounit = int64(4);

% Open File for writing to
mode = int64(1);
[ifail] = x04ac(iounit, file, mode);

% write to file here via iounit using x04ba
fprintf('The file named %s was opened for writing on unit number %d\n', ...
        file,iounit);

rec = 'This file was successfully opened for writing';
x04ba(iounit,rec);
 
% Close File associated with unit number iounit=4
[ifail] = x04ad(iounit);
fprintf('Unit number %d has been closed\n\n', iounit);

% Open File for reading
mode = int64(0);
[ifail] = x04ac(iounit, file, mode);

% read from file here via iounit using x04bb
fprintf('The file named %s was opened for reading on unit number %d\n', ...
        file,iounit);

reclen = int64(50);
[rec, ifail] = x04bb(iounit, reclen);

fprintf('The following line was read from unit %d:\n----\n',iounit);
disp(rec);
fprintf('----\n');
 
% Close File associated with unit number iounit=4
[ifail] = x04ad(iounit);
fprintf('\nUnit number %d has been closed\n', iounit);

delete(file);


x04ad example results

The file named success.res was opened for writing on unit number 4
Unit number 4 has been closed

The file named success.res was opened for reading on unit number 4
The following line was read from unit 4:
----
This file was successfully opened for writing     
----

Unit number 4 has been closed

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015