nag_example_file_io (x04aec) (PDF version)
x04 Chapter Contents
x04 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_example_file_io (x04aec)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

nag_example_file_io (x04aec) reads command-line arguments and returns either a file pointer or a file name depending on the argument flag specified in argv.

2  Specification

#include <nag.h>
#include <nagx04.h>
FILE *  nag_example_file_io (int argc, const char *argv[], const char *flag, char **fname)

3  Description

nag_example_file_io (x04aec) returns either a FILE pointer or the name of a file depending on the argument flag specified in argv. If the argument flag is either "-data" or "-results", a FILE pointer is returned for data input or output respectively. If the argument flag is "-options", "-nag_write" or "-nag_read", a char pointer is returned in fname to hold the name of an options file, a data output or a data input file.

4  References

None.

5  Arguments

1:     argcintInput
On entry: the number of command-line arguments.
2:     argv[argc]const char *Input
On entry: the argument vector.
3:     flagconst char *Input
On entry: indicates which file pointer or file name will be returned by the function. nag_example_file_io (x04aec) searches the command-line arguments contained in argv for flag. If it is found, in say argv[i-1], the function examines argv[i] and if it is a filename the function returns either a file pointer or the filename as follows:
flag="-data"
If argv[i] is a filename it specifies the data file to be opened for reading and a FILE pointer to that file is returned. Otherwise a FILE pointer to stdin is returned.
flag="-results"
If argv[i] is a filename it specifies the results file to be opened for writing and a FILE pointer to that file is returned. Otherwise a FILE pointer to stdout is returned.
flag="-options"
If argv[i] is a filename it specifies a file containing optional arguments to be opened for reading and this filename is returned in fname. Otherwise a default filename comprising the stem of the program name with a file extension of .opt (e.g., e04ucce.opt) is returned in fname. Note that memory is allocated internally to fname using NAG_ALLOC. It can be freed using NAG_FREE.
flag="-nag_write"
If argv[i] is a filename it specifies a file to be opened for library output and this filename is returned in fname. Otherwise a NULL is returned in fname.
flag="-nag_read"
If argv[i] is a filename it specifies a file to be opened for reading library input and this filename is returned in fname. Otherwise a NULL is returned in fname.
Constraint: flag= "-data", "-results", "-options", "-nag_write" or "-nag_read".
4:     fnamechar **Input
On exit: if the flag specified is "-options", "-nag_write" or "-nag_read", fname contains the name of the file for reading or writing.

6  Error Indicators and Warnings

None.

7  Accuracy

Not applicable.

8  Parallelism and Performance

Not applicable.

9  Further Comments

None.

10  Example

This program illustrates the use of nag_example_file_io (x04aec) to check for input and output file names on the command line, before making a call to nag_1d_aitken_interp (e01aac).

10.1  Program Text

Program Text (x04aece.c)

10.2  Program Data

None.

10.3  Program Results

Program Results (x04aece.r)


nag_example_file_io (x04aec) (PDF version)
x04 Chapter Contents
x04 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2014