/Users/bernard/b20/bsoft/src/util/utilities.cpp(3)

NAME
/Users/bernard/b20/bsoft/src/util/utilities.cpp - Library functions useful in all the package.

SYNOPSIS

#include <errno.h>
#include <sys/sysctl.h>
#include <stdio.h>
#include 'utilities.h'
#include <iostream>

  Macros
#define MAX_GET_LEN 32

  Functions
int verbose (0)
ostream & tab (ostream &out)
string get_cmd_line (int argc, char **argv)
Returns the command line as a string.
Bstring command_line_time (int n, char **strings)
Returns a set of strings and time in a string.
string get_user_name ()
Returns the user name.
void usage (const char **use, int all)
Prints usage information.
SysType systype (int show)
Finds the system type - mostly just for byte order.
size_t system_processors ()
Returns the number of processors.
long system_memory ()
Returns system memory size.
int memory_check (long mem_required)
Checking if there is enough memory, abort if not.
int bexit (int value)
Exit function for cleanup and debugging.
DataType getdatatype (char letter)
Get the data type indicated by a single letter code.
int select_numbers (Bstring &string, int n, int *numsel)
Converts a string with a selection specification into an integer array.
vector< int > select_numbers (Bstring &string, int n)
int findNextPowerOf (int startNumber, int powerOf)
Finds the next greatest number that is a power of a given number.
int get_integer (char *ptr, int len)
Converts a defined length string into an integer.
float get_float (char *ptr, int len)
Converts a defined length string into a floating point number.
void swapbytes (unsigned char *v, size_t n)
Swaps bytes.
void swapbytes (size_t size, unsigned char *v, size_t n)
Swaps bytes.
void vax2ieee (unsigned char *v, int sb)
Converts VAX floating point format to IEEE floating point format.
double angle_set_negPI_to_PI (double angle)
Returns an angle between -PI and PI.
float remove_negative_zeros (float value0, float threshold)
Prevent a negative sign from being placed in front of zero value in a text file.
size_t get_chunk_size (size_t datasize)
Returns the chunk size per thread.
size_t get_chunk_size (size_t datasize, size_t c)
Returns the chunk size per thread.
int error_show (const char *message, const char *file, int line)
Displays the error with file and line reference.
int error_show (string message, string file, int line)
Displays the error with file and line reference.

Detailed Description

Library functions useful in all the package.

Author:
    Bernard Heymann

Date:
    Created: 19990722

    Modified: 20190109

Definition in file utilities.cpp.

Macro Definition Documentation

  #define MAX_GET_LEN 32

Definition at line 16 of file utilities.cpp.

Function Documentation

  double angle_set_negPI_to_PI (double angle)

Returns an angle between -PI and PI.

Parameters:
    angle input angle.

Returns:
    double angle between -PI and PI.

Reference: Derived from CCP4 code

Definition at line 594 of file utilities.cpp.

  int bexit (int value)

Exit function for cleanup and debugging.

Parameters:
    value exit value.

Returns:
    int given value.

Definition at line 273 of file utilities.cpp.

  Bstring command_line_time (int n, char ** strings)

Returns a set of strings and time in a string.

Parameters:
    n the number of strings.
    **strings an array of strings.

Returns:
    Bstring new string.

    This is designed to pack the command line into a string followed by
    a second string for the time.

Definition at line 60 of file utilities.cpp.

  int error_show (const char * message, const char * file, int line)

Displays the error with file and line reference.

Parameters:
    *message a string to be included.
    *file the file name (should be FILE).
    line the line number (should be LINE).

Returns:
    int error number.

    The function uses perror() to display a message containing the source
    file and line number where it originated.

     Reference: Derived from CCP4 code

Definition at line 716 of file utilities.cpp.

  int error_show (string message, string file, int line)

Displays the error with file and line reference.

Parameters:
    *message a string to be included.
    *file the file name (should be FILE).
    line the line number (should be LINE).

Returns:
    int error number.

    The function uses perror() to display a message containing the source
    file and line number where it originated.

     Reference: Derived from CCP4 code

Definition at line 755 of file utilities.cpp.

  int findNextPowerOf (int startNumber, int powerOf)

Finds the next greatest number that is a power of a given number.

Author:
    Dan Krainak

Parameters:
    startNumber number to begin from.
    powerOf power of this number is the number returned.

Returns:
    int the next greatest power (i.e. 128) or 0 on error.

    Loop through the powerOf variable, multiplying it each successive
    iteration until it is greater than the starting number.
    Eg., the next greatest power of 2 starting at 100 is 128.

Definition at line 433 of file utilities.cpp.

  size_t get_chunk_size (size_t datasize)

Returns the chunk size per thread.

Parameters:
    datasize size of data to be divided into chunks.

Returns:
    long chunk size.

    If multiple processors are used, the chunk size is set to the data size
    divided by the number of processors.
    Otherwise, the chunk size is equal to the data size.

     Reference: Derived from CCP4 code

Definition at line 645 of file utilities.cpp.

  size_t get_chunk_size (size_t datasize, size_t c)

Returns the chunk size per thread.

Parameters:
    datasize size of data to be divided into chunks.
    c channel size to align chunk to.

Returns:
    long chunk size.

    If multiple processors are used, the chunk size is set to the data size
    divided by the number of processors.
    Otherwise, the chunk size is equal to the data size.

     Reference: Derived from CCP4 code

Definition at line 679 of file utilities.cpp.

  string get_cmd_line (int argc, char ** argv)

Returns the command line as a string.

Parameters:
    argc the number of command line arguments.
    **argv the command line arguments.

Returns:
    string the command line string.

    Concatenates the command line arguments into one string. The string
    receiving the command line must be at least 1024 bytes long.

Definition at line 36 of file utilities.cpp.

  float get_float (char * ptr, int len)

Converts a defined length string into a floating point number.

Parameters:
    *ptr pointer to the string.
    len length to be scanned.

Returns:
    float the floating point number.

    The string is copied, 0-terminated, and scanned for a floating point number.

Definition at line 482 of file utilities.cpp.

  int get_integer (char * ptr, int len)

Converts a defined length string into an integer.

Parameters:
    *ptr pointer to the string.
    len length to be scanned.

Returns:
    int the integer.

    The string is copied, 0-terminated, and scanned for an integer.

Definition at line 459 of file utilities.cpp.

  string get_user_name ()

Returns the user name.

Returns:
    string user name.

    It uses getpwuid_r (thread safe) to find the user in the password file.

Definition at line 85 of file utilities.cpp.

  DataType getdatatype (char letter)

Get the data type indicated by a single letter code.

Parameters:
    letter letter indicating data type.

Returns:
    DataType data type (defined in rwimg.h).

    This function is used in optional command-line arguments to indicate
    a new data type for an image.

Definition at line 288 of file utilities.cpp.

  int memory_check (long mem_required)

Checking if there is enough memory, abort if not.

Parameters:
    mem_required memory required.

Returns:
    int 1 if enough.

Definition at line 248 of file utilities.cpp.

  float remove_negative_zeros (float value0, float threshold)

Prevent a negative sign from being placed in front of zero value in a text file.

Author:
    David Belnap

Parameters:
    value0 input value to be tested
    threshold a small negative number

Returns:
    float 'Corrected' or input value

    This function is intended to be used when obvious zero values are set
    to a very small negative number.  Input value is set to zero if
                  value0 > threshold  and  value0 < 0
    If so, the value is reset to zero.  Otherwise, the input value is
    returned.

     Reference: Derived from CCP4 code

Definition at line 622 of file utilities.cpp.

  int select_numbers (Bstring & string, int n, int * numsel)

Converts a string with a selection specification into an integer array.

Parameters:
    &string string.
    n length of integer array.
    *numsel pre-allocated integer array.

Returns:
    int number of levels.

    The integer array must be allocated to a length that would accommodate
    the highest number in the selection.
    If the string length is zero, all elements are selected.
    Multiple subsets are separated by colons

Definition at line 328 of file utilities.cpp.

  vector<int> select_numbers (Bstring & string, int n)

Definition at line 378 of file utilities.cpp.

  void swapbytes (unsigned char * v, size_t n)

Swaps bytes.

Parameters:
    *v a pointer to the bytes.
    n number of bytes to swap.

    Byte swapping is done in place.

Definition at line 504 of file utilities.cpp.

  void swapbytes (size_t size, unsigned char * v, size_t n)

Swaps bytes.

Parameters:
    size size of the block to be swapped.
    *v a pointer to the bytes.
    n number of bytes to swap.

    Byte swapping is done in place.

Definition at line 525 of file utilities.cpp.

  long system_memory ()

Returns system memory size.

Returns:
    long memory size.

Definition at line 204 of file utilities.cpp.

  size_t system_processors ()

Returns the number of processors.

Returns:
    long number of processors.

Definition at line 186 of file utilities.cpp.

  SysType systype (int show)

Finds the system type - mostly just for byte order.

Parameters:
    show a flag to indicate if the result should be shown.

Returns:
    SysType an enumerated type.

    Test the byte order of an arbitrary byte sequence by interpreting it as
    an integer or a floating point number.

Definition at line 144 of file utilities.cpp.

  ostream& tab (ostream & out)

Definition at line 21 of file utilities.cpp.

  void usage (const char ** use, int all)

Prints usage information.

Parameters:
    **use the string array.
    all flag to output all usage information.

    The usage information must be written into an array of srings, with each
    string a line and following a specific convention for the Bsoft package.
    The first line with non-space characters must start with "Usage:"
    followed by the command-line syntax. The next lines should describe the
    program. The options are indicated by lines strating with "-".
    The options are categorized as "Actions", "Parameters", "Input",
    and "Output". This constitutes the brief form.
    An additional section can be added as "Examples", that is shown
    only when the "all" argument is set.

Definition at line 119 of file utilities.cpp.

  void vax2ieee (unsigned char * v, int sb)

Converts VAX floating point format to IEEE floating point format.

Parameters:
    *v four-byte array holding the floating point value
    sb flag to swap bytes before conversion

    Swap bytes prior to conversion if the swap flag is set.
    Handle special cases of zero, infinity, NaN or normalized values
    Otherwise assign the new byte values

     Reference: Derived from CCP4 code

Definition at line 548 of file utilities.cpp.

  int verbose (0)

Author

Generated automatically by Doxygen for Bsoft from the source code.