Layers
Diffusion in heterogeneous environments
Functions
io.c File Reference

Input/output functions that are useful for 3layer. More...

#include "header.h"
Include dependency graph for io.c:

Go to the source code of this file.

Functions

void get_filename (char *in, char *out)
 Make sure that the filename is not too long. More...
 
void get_io_filenames (char *argstring, const char *inf_extension, const char *outf_extension, char *infilename, char *outfilename)
 Determine the input filename and the default output file name. More...
 
int assemble_command (int argc, char *argv[], char *command)
 Create a string containing the command used to run the program. More...
 
double read_source_parameter (char *string, int nsource)
 Read a parameter from the string argument to the additional_sources option. More...
 

Detailed Description

Input/output functions that are useful for 3layer.

Author
David Lewis, CABI, NKI
Date
2012-2013

Definition in file io.c.

Function Documentation

int assemble_command ( int  argc,
char *  argv[],
char *  command 
)

Create a string containing the command used to run the program.

It can be very useful for the program's output file to have a comment line that contains the command used to run the program. This function assembles that command into a string from the argc and argv parameters so it can be added to the output file.

Parameters
[in]argcArgument count (parameter passed to main)
[in]argvArgument vector (parameter passed to main)
[out]commandString containing the command line
Returns
Number of elements on the command line

Definition at line 91 of file io.c.

void get_filename ( char *  in,
char *  out 
)

Make sure that the filename is not too long.

If the input string is not to big, copy it to the output string. Otherwise, exit with an error message. This function is used to check that the user input filename is not too long.

Parameters
[in]inInput string = the user input filename (or base filename)
[out]outOutput string = the input string, if not too long

Definition at line 25 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void get_io_filenames ( char *  argstring,
const char *  inf_extension,
const char *  outf_extension,
char *  infilename,
char *  outfilename 
)

Determine the input filename and the default output file name.

From the last argument on the command line, determine the input file name and the default output file name. (If the output file name is specified on the command line, it will be used instead of the default output file name determined here.)

If the argument has an extension, it is the input filename; remove the extension to get the basename and add the default output filename extension to get the default output filename.

If the argument has no extension, it is the basename; then add the default extensions to get the input filename and the default output filename.

Parameters
[in]argstringFinal command-line argument
[in]inf_extensionDefault extension for input file
[in]outf_extensionDefault extension for output file
[out]infilenameName of input file
[out]outfilenameName of output file

Definition at line 60 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

double read_source_parameter ( char *  string,
int  nsource 
)

Read a parameter from the string argument to the additional_sources option.

The additional_sources option to 3layer takes several arguments. (The total number of arguments depends on the number of extra sources.) The getopt_long function (used in the main() function to parse 3layer's options) takes only one argument per option, so for additional_sources's argument use a string that contains the several arguments that additional_sources needs.

This function uses strtok to parse the string to obtain the next parameter. The two arguments for this function are used only for diagnostic purposes – if there is an error, the function aborts with an error message that lists these two arguments.

The first element of the string (the number of extra sources) was previously obtained with the first call to strtok, and subsequent calls to strtok (via this function) use NULL rather than the name of the string.

Parameters
[in]stringString containing the type of parameter to be read
[out]nsourceThe number of the source whose parameter is being read
Returns
Value of the parameter that is read

Definition at line 153 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function: