|
Bsoft
2.1.0
Bernard's software package
|
Header file for general utilities. More...
#include <stdio.h>#include <string.h>#include <ctype.h>#include <unistd.h>#include <pwd.h>#include <math.h>#include <climits>#include <cfloat>#include <algorithm>#include <iostream>#include <iomanip>#include <vector>#include <tuple>#include <ctime>#include "Bstring.h"Go to the source code of this file.
Macros | |
| #define | BVERSION "2.0.7-20200917" |
| #define | MAXLINELEN 1024 |
| #define | SMALLFLOAT 1e-30 |
| #define | MIN_SIZE_FOR_THREADING 100000 |
| #define | TRIGPRECISION 1e-30 |
| #define | PLANCK 6.626070E-34 |
| #define | ECHARGE 1.602177E-19 |
| #define | EMASS 9.109384E-31 |
| #define | LIGHTSPEED 299792458 |
| #define | AVOGADRO 6.02214076e23 |
| #define | M_PI 3.14159265358979323846264338327950288 |
| #define | M_PI_2 1.57079632679489661923132169163975144 |
| #define | M_PI_4 0.785398163397448309615660845819875721 |
| #define | TWOPI 6.28318530717958647692528676655900576 |
| #define | MIN2PI -6.28318530717958647692528676655900576 |
| #define | GOLDEN 1.61803398874989484820458683436563811772 |
| #define | RHO 0.81 |
| #define | VERB_NONE 0 |
| #define | VERB_RESULT 1 |
| #define | VERB_LABEL 2 |
| #define | VERB_PROCESS 4 |
| #define | VERB_STATS 8 |
| #define | VERB_FULL 16 |
| #define | VERB_TIME 32 |
| #define | VERB_MEMORY 64 |
| #define | VERB_DEBUG 128 |
| #define | VERB_DEBUG_STAR 256 |
| #define | VERB_DEBUG_XML 512 |
| #define | VERB_DEBUG_DM 1024 |
| #define | _systype_ |
| #define | _datatype_ |
| #define | FILL_USER 0 |
| #define | FILL_AVERAGE 1 |
| #define | FILL_BACKGROUND 2 |
| #define | FILL_MIN 3 |
| #define | FILL_MAX 4 |
Enumerations | |
| enum | SysType { Unknown_System = 0, BigIEEE = 1, BigOther = 5, LittleIEEE = 6, LittleAlpha = 7, LittleVAX = 8, LittleOther = 10 } |
| enum | DataType { Unknown_Type = 0, Bit = 1, UCharacter = 2, SCharacter = 3, UShort = 4, Short = 5, UInteger = 6, Integer = 7, ULong = 8, Long = 9, Float = 10, Double = 11 } |
| Base data type specifier. More... | |
Functions | |
| ostream & | tab (ostream &out) |
| int | cmd_line (int argc, char **argv) |
| Reconstructs the command line as a global string. More... | |
| Bstring | command_line () |
| Returns the command line. More... | |
| Bstring | command_line_time () |
| Returns the command line and time in a string. More... | |
| string | get_user_name () |
| Returns the user name. More... | |
| void | usage (const char **use, int all) |
| Prints usage information. More... | |
| SysType | systype (int show) |
| Finds the system type - mostly just for byte order. More... | |
| size_t | system_processors () |
| Returns the number of processors. More... | |
| long | system_memory () |
| Returns system memory size. More... | |
| int | memory_check (long mem_required) |
| Checking if there is enough memory, abort if not. More... | |
| int | bexit (int value) |
| Exit function for cleanup and debugging. More... | |
| DataType | getdatatype (char letter) |
| Get the data type indicated by a single letter code. More... | |
| int | select_numbers (Bstring &string, int n, int *numsel) |
| Converts a string with a selection specification into an integer array. More... | |
| 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. More... | |
| int | get_integer (char *ptr, int len) |
| Converts a defined length string into an integer. More... | |
| float | get_float (char *ptr, int len) |
| Converts a defined length string into a floating point number. More... | |
| void | swapbytes (unsigned char *v, size_t n) |
| Swaps bytes. More... | |
| void | swapbytes (size_t size, unsigned char *v, size_t n) |
| Swaps bytes. More... | |
| void | vax2ieee (unsigned char *v, int sb) |
| Converts VAX floating point format to IEEE floating point format. More... | |
| double | angle_set_negPI_to_PI (double angle) |
| Returns an angle between -PI and PI. More... | |
| float | remove_negative_zeros (float value0, float threshold) |
| Prevent a negative sign from being placed in front of zero value in a text file. More... | |
| size_t | get_chunk_size (size_t datasize) |
| Returns the chunk size per thread. More... | |
| size_t | get_chunk_size (size_t datasize, size_t c) |
| Returns the chunk size per thread. More... | |
| int | error_show (string message, string file, int line) |
| Displays the error with file and line reference. More... | |
Header file for general utilities.
Definition in file utilities.h.
| #define _datatype_ |
Definition at line 164 of file utilities.h.
| #define _systype_ |
Definition at line 140 of file utilities.h.
| #define AVOGADRO 6.02214076e23 |
Definition at line 55 of file utilities.h.
| #define BVERSION "2.0.7-20200917" |
Definition at line 9 of file utilities.h.
| #define ECHARGE 1.602177E-19 |
Definition at line 52 of file utilities.h.
| #define EMASS 9.109384E-31 |
Definition at line 53 of file utilities.h.
| #define FILL_AVERAGE 1 |
Definition at line 177 of file utilities.h.
| #define FILL_BACKGROUND 2 |
Definition at line 178 of file utilities.h.
| #define FILL_MAX 4 |
Definition at line 180 of file utilities.h.
| #define FILL_MIN 3 |
Definition at line 179 of file utilities.h.
| #define FILL_USER 0 |
Definition at line 176 of file utilities.h.
| #define GOLDEN 1.61803398874989484820458683436563811772 |
Definition at line 85 of file utilities.h.
| #define LIGHTSPEED 299792458 |
Definition at line 54 of file utilities.h.
| #define M_PI 3.14159265358979323846264338327950288 |
Definition at line 63 of file utilities.h.
| #define M_PI_2 1.57079632679489661923132169163975144 |
Definition at line 66 of file utilities.h.
| #define M_PI_4 0.785398163397448309615660845819875721 |
Definition at line 69 of file utilities.h.
| #define MAXLINELEN 1024 |
Definition at line 45 of file utilities.h.
| #define MIN2PI -6.28318530717958647692528676655900576 |
Definition at line 75 of file utilities.h.
| #define MIN_SIZE_FOR_THREADING 100000 |
Definition at line 47 of file utilities.h.
| #define PLANCK 6.626070E-34 |
Definition at line 51 of file utilities.h.
| #define RHO 0.81 |
Definition at line 95 of file utilities.h.
| #define SMALLFLOAT 1e-30 |
Definition at line 46 of file utilities.h.
| #define TRIGPRECISION 1e-30 |
Definition at line 48 of file utilities.h.
| #define TWOPI 6.28318530717958647692528676655900576 |
Definition at line 72 of file utilities.h.
| #define VERB_DEBUG 128 |
Definition at line 116 of file utilities.h.
| #define VERB_DEBUG_DM 1024 |
Definition at line 119 of file utilities.h.
| #define VERB_DEBUG_STAR 256 |
Definition at line 117 of file utilities.h.
| #define VERB_DEBUG_XML 512 |
Definition at line 118 of file utilities.h.
| #define VERB_FULL 16 |
Definition at line 113 of file utilities.h.
| #define VERB_LABEL 2 |
Definition at line 110 of file utilities.h.
| #define VERB_MEMORY 64 |
Definition at line 115 of file utilities.h.
| #define VERB_NONE 0 |
Definition at line 108 of file utilities.h.
| #define VERB_PROCESS 4 |
Definition at line 111 of file utilities.h.
| #define VERB_RESULT 1 |
Definition at line 109 of file utilities.h.
| #define VERB_STATS 8 |
Definition at line 112 of file utilities.h.
| #define VERB_TIME 32 |
Definition at line 114 of file utilities.h.
| enum DataType |
Base data type specifier.
This determines what simple data type is used in an image.
| Enumerator | |
|---|---|
| Unknown_Type | |
| Bit | |
| UCharacter | |
| SCharacter | |
| UShort | |
| Short | |
| UInteger | |
| Integer | |
| ULong | |
| Long | |
| Float | |
| Double | |
Definition at line 150 of file utilities.h.
| enum SysType |
| Enumerator | |
|---|---|
| Unknown_System | |
| BigIEEE | |
| BigOther | |
| LittleIEEE | |
| LittleAlpha | |
| LittleVAX | |
| LittleOther | |
Definition at line 131 of file utilities.h.
| double angle_set_negPI_to_PI | ( | double | angle | ) |
Returns an angle between -PI and PI.
| angle | input angle. |
Reference: Derived from CCP4 code
Definition at line 558 of file utilities.cpp.
| int bexit | ( | int | value | ) |
Exit function for cleanup and debugging.
| value | exit value. |
Definition at line 280 of file utilities.cpp.
| int cmd_line | ( | int | argc, |
| char ** | argv | ||
| ) |
Reconstructs the command line as a global string.
| argc | the number of command line arguments. |
| **argv | the command line arguments. |
Concatenates the command line arguments into one string.
Definition at line 36 of file utilities.cpp.
| Bstring command_line | ( | ) |
Returns the command line.
This is designed to pack the command line into a string.
Definition at line 58 of file utilities.cpp.
| Bstring command_line_time | ( | ) |
Returns the command line and time in a string.
This is designed to pack the command line into a string followed by a second string for the time.
Definition at line 71 of file utilities.cpp.
| int error_show | ( | string | message, |
| string | file, | ||
| int | line | ||
| ) |
Displays the error with file and line reference.
| *message | a string to be included. |
| *file | the file name (should be FILE). |
| line | the line number (should be LINE). |
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 719 of file utilities.cpp.
| int findNextPowerOf | ( | int | startNumber, |
| int | powerOf | ||
| ) |
Finds the next greatest number that is a power of a given number.
| startNumber | number to begin from. |
| powerOf | power of this number is the number returned. |
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 397 of file utilities.cpp.
| size_t get_chunk_size | ( | size_t | datasize | ) |
Returns the chunk size per thread.
| datasize | size of data to be divided into chunks. |
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 609 of file utilities.cpp.
| size_t get_chunk_size | ( | size_t | datasize, |
| size_t | c | ||
| ) |
Returns the chunk size per thread.
| datasize | size of data to be divided into chunks. |
| c | channel size to align chunk to. |
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 643 of file utilities.cpp.
| float get_float | ( | char * | ptr, |
| int | len | ||
| ) |
Converts a defined length string into a floating point number.
| *ptr | pointer to the string. |
| len | length to be scanned. |
The string is copied, 0-terminated, and scanned for a floating point number.
Definition at line 446 of file utilities.cpp.
| int get_integer | ( | char * | ptr, |
| int | len | ||
| ) |
Converts a defined length string into an integer.
| *ptr | pointer to the string. |
| len | length to be scanned. |
The string is copied, 0-terminated, and scanned for an integer.
Definition at line 423 of file utilities.cpp.
| string get_user_name | ( | ) |
Returns the user name.
It uses getpwuid_r (thread safe) to find the user in the password file.
Definition at line 92 of file utilities.cpp.
| DataType getdatatype | ( | char | letter | ) |
Get the data type indicated by a single letter code.
| letter | letter indicating data type. |
This function is used in optional command-line arguments to indicate a new data type for an image.
Definition at line 295 of file utilities.cpp.
| int memory_check | ( | long | mem_required | ) |
Checking if there is enough memory, abort if not.
| mem_required | memory required. |
Definition at line 255 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.
| value0 | input value to be tested |
| threshold | a small negative number |
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 586 of file utilities.cpp.
| vector<int> select_numbers | ( | Bstring & | string, |
| int | n | ||
| ) |
Definition at line 342 of file utilities.cpp.
| int select_numbers | ( | Bstring & | string, |
| int | n, | ||
| int * | numsel | ||
| ) |
Converts a string with a selection specification into an integer array.
| &string | string. |
| n | length of integer array. |
| *numsel | pre-allocated integer array. |
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 335 of file utilities.cpp.
| void swapbytes | ( | size_t | size, |
| unsigned char * | v, | ||
| size_t | n | ||
| ) |
Swaps bytes.
| 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 489 of file utilities.cpp.
| void swapbytes | ( | unsigned char * | v, |
| size_t | n | ||
| ) |
Swaps bytes.
| *v | a pointer to the bytes. |
| n | number of bytes to swap. Byte swapping is done in place. |
Definition at line 468 of file utilities.cpp.
| long system_memory | ( | ) |
| size_t system_processors | ( | ) |
Returns the number of processors.
Definition at line 193 of file utilities.cpp.
| SysType systype | ( | int | show | ) |
Finds the system type - mostly just for byte order.
| show | a flag to indicate if the result should be shown. |
Test the byte order of an arbitrary byte sequence by interpreting it as an integer or a floating point number.
Definition at line 151 of file utilities.cpp.
| ostream& tab | ( | ostream & | out | ) |
Definition at line 22 of file utilities.cpp.
| void usage | ( | const char ** | use, |
| int | all | ||
| ) |
Prints usage information.
| **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 126 of file utilities.cpp.
| void vax2ieee | ( | unsigned char * | v, |
| int | sb | ||
| ) |
Converts VAX floating point format to IEEE floating point format.
| *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 valuesReference: Derived from CCP4 code |
Definition at line 512 of file utilities.cpp.