OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
genutils.h File Reference
#include <stdint.h>
#include <stdio.h>
#include "passthebuck.h"
Include dependency graph for genutils.h:

Go to the source code of this file.

Macros

#define EARTH_CIRCUMFERENCE   40075016.6856
 
#define BAD_FLT   -32767.0
 
#define BAD_INT   -32767
 
#define BAD_UINT   65535
 
#define BAD_BYTE   -128
 
#define BAD_UBYTE   255
 

Functions

int endianess (void)
 
void parse_file_name (const char *inpath, char *outpath)
 
int swapc_bytes (char *in, int nbyte, int ntime)
 
int swapc_bytes2 (const char *in, char *out, int nbyte, int ntime)
 
size_t fread_swap (int little_endian, void *ptr, size_t size, size_t nmemb, FILE *stream)
 
size_t fwrite_swap (int little_endian, const void *ptr, size_t size, size_t nmemb, FILE *stream)
 
void spline (float[], float[], int, float, float, float[])
 
void splint (float[], float[], float[], int, float, float *)
 
void lspline (float xin[], float yin[], int32_t nin, float xout[], float yout[], int32_t nout)
 
float linterp (float xin[], float yin[], int32_t nin, float xout)
 
float bioBandShift (float xin[], float yin[], float chl, int32_t nin, float xout)
 
int32_t filesize_ (const char *filename)
 
int32_t filesize (const char *filename)
 
int getlut_file (char *lut_file, short *rlut, short *glut, short *blut)
 
char * lowcase (char *instr)
 
char * upcase (char *instr)
 
int isValidInt (const char *str)
 
void * allocateMemory (size_t numBytes, const char *name)
 
void trimBlanks (char *str)
 
char * trimBlanksDup (const char *str)
 
int getFileFormatIndex (const char *str)
 
const char * getFileFormatName (const char *str)
 
const char * getFileFormatExtension (const char *str)
 
char * replace_ocroots (const char *inStr)
 
double str2resolution (char const *resolutionStr)
 
const char * resolution2str (double resolution)
 
double resolution2degrees (double resolution)
 
double degrees2resolution (double degrees)
 

Variables

int want_verbose
 

Detailed Description

This is a bunch of useful general utilities.

Definition in file genutils.h.

Macro Definition Documentation

◆ BAD_BYTE

#define BAD_BYTE   -128

Definition at line 25 of file genutils.h.

◆ BAD_FLT

#define BAD_FLT   -32767.0

Define a few useful BAD values

Definition at line 22 of file genutils.h.

◆ BAD_INT

#define BAD_INT   -32767

Definition at line 23 of file genutils.h.

◆ BAD_UBYTE

#define BAD_UBYTE   255

Definition at line 26 of file genutils.h.

◆ BAD_UINT

#define BAD_UINT   65535

Definition at line 24 of file genutils.h.

◆ EARTH_CIRCUMFERENCE

#define EARTH_CIRCUMFERENCE   40075016.6856

Definition at line 10 of file genutils.h.

Function Documentation

◆ allocateMemory()

void* allocateMemory ( size_t  numBytes,
const char *  name 
)

Definition at line 7 of file allocateMemory.c.

◆ bioBandShift()

float bioBandShift ( float  xin[],
float  yin[],
float  chl,
int32_t  nin,
float  xout 
)

◆ degrees2resolution()

double degrees2resolution ( double  degrees)

Pixel resolution degrees to meters.

Parameters
degreesresolution in degrees
Returns
double in meters

Definition at line 93 of file resolution_utils.cpp.

◆ endianess()

int endianess ( void  )

determine endianess

Is this machine little endian

Returns
0 for BIG_ENDIAN machines, 1 for LITTLE_ENDIAN mahcines

Determines if the host calling this routine is a big or little endian machine.

Returns
A 0 for BIG_ENDIAN machines, 1 for LITTLE_ENDIAN mahcines.

Definition at line 10 of file endianess.c.

◆ filesize()

int32_t filesize ( const char *  filename)

Definition at line 93 of file swl0_utils.c.

◆ filesize_()

int32_t filesize_ ( const char *  filename)

Definition at line 19 of file filesize.c.

◆ fread_swap()

size_t fread_swap ( int  little_endian,
void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)

read a binary file and swap bytes if necessary

Parameters
little_endianset to 0 for big endian files, 1 for little endian files
ptrmemory to read into
sizesize of object to read in bytes
nmembnumber of objects to read
streamfile to read from
Returns
number of objects read

Definition at line 4 of file fread_swap.c.

◆ fwrite_swap()

size_t fwrite_swap ( int  little_endian,
const void *  ptr,
size_t  size,
size_t  nmemb,
FILE *  stream 
)

write a binary file and swap bytes if necessary

Parameters
little_endianset to 0 for big endian files, 1 for little endian files
ptrmemory to write
sizesize of object to write in bytes
nmembnumber of objects to write
streamfile to write to
Returns
number of objects written

Definition at line 15 of file fread_swap.c.

◆ getFileFormatExtension()

const char* getFileFormatExtension ( const char *  str)

convert the input string to the file format extension. Input string can be index, name or extension Formats are defined in $OCDATAROOT/common/file_formats.txt

Parameters
strinput string
Returns
pointer to internal string holding the file format extension

Definition at line 221 of file fileFormatUtils.c.

◆ getFileFormatIndex()

int getFileFormatIndex ( const char *  str)

convert the input string to the file format index. Input string can be index, name or extension Formats are defined in $OCDATAROOT/common/file_formats.txt

Parameters
strinput string
Returns
index associated with the file format

Definition at line 188 of file fileFormatUtils.c.

◆ getFileFormatName()

const char* getFileFormatName ( const char *  str)

convert the input string to the normalized file format name. Input string can be index, name or extension Formats are defined in $OCDATAROOT/common/file_formats.txt

Parameters
strinput string
Returns
pointer to internal string holding the normalized format string, or NULL

Definition at line 205 of file fileFormatUtils.c.

◆ getlut_file()

int getlut_file ( char *  lut_file,
short *  rlut,
short *  glut,
short *  blut 
)

Definition at line 8 of file getlut_file.c.

◆ isValidInt()

int isValidInt ( const char *  str)

check if a string is a valid integer

Parameters
strstring to check
Returns
1 if valid int, 0 if not

Definition at line 9 of file isValidInt.c.

◆ linterp()

float linterp ( float  xin[],
float  yin[],
int32_t  nin,
float  xout 
)

Definition at line 59 of file lspline.c.

◆ lowcase()

char* lowcase ( char *  instr)

Definition at line 10 of file lowcase.c.

◆ lspline()

void lspline ( float  xin[],
float  yin[],
int32_t  nin,
float  xout[],
float  yout[],
int32_t  nout 
)

Definition at line 20 of file lspline.c.

◆ parse_file_name()

void parse_file_name ( const char *  inpath,
char *  outpath 
)

This function parses a path name. It removes extra /'s, translates any environment variables, translates ~users, and also handles "." and ".."

Parameters
inpathfile name to be translated
outpathpointer to enough space for the translated file path

Definition at line 23 of file parse_file_name.c.

◆ replace_ocroots()

char* replace_ocroots ( const char *  inStr)

allocate a new string with environment variable names substituted for the values for: OCVARROOT, OCDATAROOT and OCSSWROOT

Parameters
inStrstring to do substitutions on
Returns
sanitized string that must be freed by the caller.

Definition at line 37 of file replace_ocroots.cpp.

◆ resolution2degrees()

double resolution2degrees ( double  resolution)

Pixel resolution meters to degrees.

Parameters
resolutionin meters
Returns
double in degrees

Definition at line 89 of file resolution_utils.cpp.

◆ resolution2str()

const char* resolution2str ( double  resolution)

Pixel resolution meters to string.

Parameters
resolutionin meters
Returns
const char* resolution as a string with units

Definition at line 84 of file resolution_utils.cpp.

◆ spline()

void spline ( float  [],
float  [],
int  ,
float  ,
float  ,
float  [] 
)

Definition at line 35 of file nr_spline.c.

◆ splint()

void splint ( float  [],
float  [],
float  [],
int  ,
float  ,
float *   
)

Definition at line 78 of file nr_spline.c.

◆ str2resolution()

double str2resolution ( char const resolutionStr)

Pixel resolution string to meters.

Parameters
resolutionStrresolution string
Returns
double in meters

Definition at line 79 of file resolution_utils.cpp.

◆ swapc_bytes()

int swapc_bytes ( char *  in,
int  nbyte,
int  ntime 
)

Swap bytes in place

Parameters
inpointer to memory to byte swap
nbytesize of object to reverse
ntimenumber of objects to swap
Returns
0 always

Definition at line 4 of file swapc_bytes.c.

◆ swapc_bytes2()

int swapc_bytes2 ( const char *  in,
char *  out,
int  nbyte,
int  ntime 
)

Swap bytes from in to out. in and out should not be overlapping memory

Parameters
inpointer to source memory to byte swap
outpointer to destination memory
nbytesize of object to reverse
ntimenumber of objects to swap
Returns
0 always

Definition at line 24 of file swapc_bytes.c.

◆ trimBlanks()

void trimBlanks ( char *  str)

trim white space off of beginning and end of string.

Parameters
strstring to modify

Definition at line 10 of file trimBlanks.c.

◆ trimBlanksDup()

char* trimBlanksDup ( const char *  str)

Allocate a string without beginning and ending white space.

Parameters
strstring to use as source (left unmodified)
Returns
pointer to newly allocated string without whitespace on ends

Definition at line 58 of file trimBlanks.c.

◆ upcase()

char* upcase ( char *  instr)

Definition at line 10 of file upcase.c.

Variable Documentation

◆ want_verbose

int want_verbose

Do we want to print out extra info to stdout

Definition at line 3 of file genutils_globals.c.