ccp4_general.c File Reference

General library functions and utilities. More...

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdarg.h>
#include "ccp4_fortran.h"
#include "ccp4_utils.h"
#include "ccp4_parser.h"
#include "ccp4_general.h"
#include "ccp4_program.h"
#include "cmtzlib.h"
#include "csymlib.h"
#include "ccp4_errno.h"

Functions

int ccperror (int ierr, const char *message)
int ccperror_noexit (int ierr, const char *message)
int ccp4printf (int level, char *format,...)
int ccp4fyp (int argc, char **argv)
int ccp4setenv (char *logical_name, char *value, char **envname, char **envtype, char **envext, int *ienv, int no_overwrt)
int ccpexists (char *filename)
int ccpputenv (char *logical_name, char *file_name)
void ccp4_banner (void)


Detailed Description

General library functions and utilities.

Author:
Peter Briggs et al.

Function Documentation

void ccp4_banner ( void   ) 

int ccp4fyp ( int  argc,
char **  argv 
)

Initialise environment for CCP4 programs and parse command line arguments.

This function processes the command line arguments supplied via the argv array, and performs initialisations of the CCP4 environment within the program based on these arguments.

CCP4 programs which use ccp4fyp should be called with the following syntax:

<progname> [switches] <logical_name1> <value1> <logical_name2> <value2>...

The command switches all start with a hyphen (-) and immediately follow the program name. The remainer of the arguments are logical name-value pairs.

On successful completion ccp4fyp returns 0 (zero). On encountering an error, ccp4fyp registers the error condition via ccp4_signal and returns a non-zero value.

Parameters:
[in] argc number of command line arguments passed to main
[in] argv array of command line parameters passed to main

References CCP4_MAXLINE, CCP4_MAXNAMES, CCP4_MAXTOKS, ccp4_parse(), ccp4_parse_delimiters(), ccp4_parse_end(), ccp4_parse_reset(), ccp4_parse_start(), ccp4_prog_vers(), ccp4_signal(), ccp4_utils_basename(), ccp4_utils_joinfilenames(), ccp4_utils_malloc(), ccp4_utils_pathname(), ccp4_utils_realloc(), ccp4printf(), ccp4ProgramName(), ccp4ProgramTime(), ccp4setenv(), ccp4VerbosityLevel(), ccpputenv(), CCP4PARSERTOKEN::fullstring, GPP4_VERSION_NO, strtoupper(), and CCP4PARSERARRAY::token.

int ccp4printf ( int  level,
char *  format,
  ... 
)

Wrapper for vprintf

A wrapper for vprintf - acts like printf with an additional argument which is checked against the reference verbosity level.

If the supplied message is less than or equal to the reference verbosity level then the format string and remaining arguments are passed to vprintf to be printed on stdout. Otherwise nothing is printed.

The format string has the same format as the format strings passed to printf, with the remaining arguments being the values (if any) to be inserted into placeholders in the format string.

Returns:
Returns the number of bytes printed, or zero if no printing was performed, or a negative number for an error from vprintf.

References ccp4VerbosityLevel().

Referenced by ccp4fyp(), and ccperror_noexit().

int ccp4setenv ( char *  logical_name,
char *  value,
char **  envname,
char **  envtype,
char **  envext,
int *  ienv,
int  no_overwrt 
)

Set environment variables

Set up file names and associate with logical_name in environment.

Associates logical_name with value. It is passed arrays of name, type and extension for ienv number of name lines read from environ.def, which may be used to modify the value before assignment.

If no_overwrt is true then any existing logical_names are not redefined.

ccp4setenv returns 0 on sucess, non-zero values on failure. In the case of failure an error code is registered with ccp4_signal and a non-zero value is returned to the calling subprogram.

References CCP4_MAXNAMES, CCP4_MODULO, ccp4_signal(), ccp4_utils_basename(), ccp4_utils_extension(), ccp4_utils_malloc(), ccp4_utils_pathname(), ccp4_utils_realloc(), ccp4ProgramName(), ccpexists(), ccpputenv(), and strmatch().

Referenced by ccp4fyp().

int ccperror ( int  ierr,
const char *  message 
)

Error reporting and program termination

ccperror is called with a message level ierr and a message string. The exact behaviour is determined by the value of ierr:

  • 0 : normal termination and stop
  • 1 : fatal error and stop
  • 2 : report severe warning
  • 3 : report information
  • 4 : report from library

ierr=-1 also reports last system error and terminates. The text in message is sent to standard output, and to standard error for ierr=1 (or -1).

Parameters:
[in] ierr error message level
[in] message text to be displayed
See also:
ccperror_noexit

References ccperror_noexit().

int ccperror_noexit ( int  ierr,
const char *  message 
)

Error reporting without program termination

ccperror_noexit is called with a message level ierr and a message string, The exact behaviour is determined by the value of ierr:

  • 0 : normal termination
  • 1 : fatal error message
  • 2 : report severe warning
  • 3 : report information
  • 4 : report from library

Parameters:
[in] ierr error message level
[in] message text to be displayed
See also:
ccperror

References ccp4printf(), ccp4ProgramName(), ccp4ProgramTime(), html_log_output(), and summary_output().

Referenced by ccperror().

int ccpexists ( char *  filename  ) 

Check if named file exists and can be opened for reading

The check is performed by attempting to fopen the file for read only, then immediately closing the file. If this method proves to be unsatisfactory then it may be necessary to investigate using access or stat instead.

Returns:
Returns 1 if the file can be opened for read (=exists), 0 otherwise.

Referenced by ccp4setenv().

int ccpputenv ( char *  logical_name,
char *  file_name 
)

Wrapper for the ccp4_utils_setenv command.

Set environment variable logical_name to have value file_name. It must be supplied with a logical name (the name of a variable which will be set in the environment) and a file name (the value which will be assigned to that variable).

Returns 1 if successful and 0 otherwise.

Notes:

  1. Platform-dependency is encoded in ccp4_utils_setenv.
  2. Dynamically allocated strings passed to ccpputenv should be freed by the calling subprogram to avoid memory leaks.

References ccp4_utils_malloc(), and ccp4_utils_setenv().

Referenced by ccp4fyp(), and ccp4setenv().


Generated on Wed Oct 29 21:05:08 2008 for gpp4 by  doxygen 1.5.6