Logo Tesseroids 1.0: User Manual and API Documentation

src/c/utils.c File Reference

Set of misc utilities and data structures. More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "constants.h"
#include "logger.h"
#include "utils.h"

Functions

void split_tess (TESSEROID tess, TESSEROID *split)
 Split a tesseroid into 8.
double tess_total_mass (TESSEROID *model, int size)
 Calculate the total mass of a tesseroid model.
double tess_range_mass (TESSEROID *model, int size, double low_dens, double high_dens)
 Calculate the mass of a tesseroid model within a density range.
void tess2prism (TESSEROID tess, PRISM *prism)
 Convert a tesseroid into a rectangular prism of equal volume (Wild-Pfeiffer, 2008).
void tess2sphere (TESSEROID tess, SPHERE *sphere)
 Convert a tesseroid into a sphere of equal volume.
void prism2sphere (PRISM prism, double lonc, double latc, double rc, SPHERE *sphere)
 Convert a rectangular prism into a sphere of equal volume.
double tess_volume (TESSEROID tess)
 Calculate the volume of a tesseroid.
double sphere_volume (SPHERE sphere)
 Calculate the volume of a sphere.
double prism_volume (PRISM prism)
 Calculate the volume of a prism.
void strstrip (char *str)
 Strip trailing spaces and newlines from the end of a string.
int gets_tess (const char *str, TESSEROID *tess)
 Read a single tesseroid from a string.
TESSEROIDread_tess_model (FILE *modelfile, int *size)
 Read tesseroids from an open file and store them in an array.
int gets_prism (const char *str, PRISM *prism)
 Read a single rectangular prism from a string.
PRISMread_prism_model (FILE *modelfile, int *size)
 Read rectangular prisms from an open file and store them in an array.

Detailed Description

Set of misc utilities and data structures.

Defines the TESSEROID, SPHERE and PRISM structures.

Author:
Leonardo Uieda
Date:
25 Jan 2011

Function Documentation

int gets_prism ( const char *  str,
PRISM prism 
)

Read a single rectangular prism from a string.

Parameters:
str string with the tesseroid parameters
prism used to return the read prism
Returns:
0 if all went well, 1 if failed to read.

Todo:
Catch wrong order of model inputs, ie. x1 > x2 etc
Todo:
Read the position of the prism from the string

int gets_tess ( const char *  str,
TESSEROID tess 
)

Read a single tesseroid from a string.

Parameters:
str string with the tesseroid parameters
tess used to return the read tesseroid
Returns:
0 if all went well, 1 if failed to read.

Todo:
Catch wrong order of model inputs, ie. w > e or s > n or top < bottom

void prism2sphere ( PRISM  prism,
double  lonc,
double  latc,
double  rc,
SPHERE sphere 
)

Convert a rectangular prism into a sphere of equal volume.

Parameters:

Parameters:
prism prism to convert
lonc longitude of the desired center of the sphere, in degrees
latc latitude of the desired center of the sphere, in degrees
rc radial coordinate of the desired center of the sphere, in SI units
sphere sphere with equal volume of the prism (used to return)
double prism_volume ( PRISM  prism  ) 

Calculate the volume of a prism.

Parameters:
prism the prism whose volume will be calculated
Returns:
the volume in the respective units
PRISM* read_prism_model ( FILE *  modelfile,
int *  size 
)

Read rectangular prisms from an open file and store them in an array.

Allocates memory. Don't forget to free 'model'!

Parameters:
modelfile open FILE for reading with the model
size used to return the size of the model read
Returns:
pointer to array with the model. NULL if there was an error
TESSEROID* read_tess_model ( FILE *  modelfile,
int *  size 
)

Read tesseroids from an open file and store them in an array.

Allocates memory. Don't forget to free 'model'!

Parameters:
modelfile open FILE for reading with the tesseroid model
size used to return the size of the model read
Returns:
pointer to array with the model. NULL if there was an error
double sphere_volume ( SPHERE  sphere  ) 

Calculate the volume of a sphere.

Parameters:
sphere the sphere whose volume will be calculated
Returns:
the volume in the respective units
void split_tess ( TESSEROID  tess,
TESSEROID split 
)

Split a tesseroid into 8.

Parameters:
tess tesseroid that will be split
split array of 8 tesseroids with memory allocated. Used to return.
void strstrip ( char *  str  ) 

Strip trailing spaces and newlines from the end of a string.

Done IN PLACE!

Parameters:
str string to strip
void tess2prism ( TESSEROID  tess,
PRISM prism 
)

Convert a tesseroid into a rectangular prism of equal volume (Wild-Pfeiffer, 2008).

\[ \Delta x = \frac{r_1 + r_2}{2} \Delta \phi, \]

\[ \Delta y = \frac{r_1 + r_2}{2} \cos\left(\frac{\phi_1 + \phi_2}{2}\right) \Delta\lambda, \]

\[ \Delta z = \Delta r, \]

References

  • Wild-Pfeiffer, F. (2008). A comparison of different mass elements for use in gravity gradiometry. Journal of Geodesy, 82(10), 637-653.
Parameters:
tess tesseroid to convert
prism prism with equal volume of the tesseroid (used to return)
void tess2sphere ( TESSEROID  tess,
SPHERE sphere 
)

Convert a tesseroid into a sphere of equal volume.

Parameters:

Parameters:
tess tesseroid to convert
sphere sphere with equal volume of the tesseroid (used to return)
double tess_range_mass ( TESSEROID model,
int  size,
double  low_dens,
double  high_dens 
)

Calculate the mass of a tesseroid model within a density range.

Give all in SI units and degrees!

Parameters:
model array of tesseroids
size size of the model
low_dens lower bound of the density range
high_dens upper bound of the density range
Returns:
The calculated mass
double tess_total_mass ( TESSEROID model,
int  size 
)

Calculate the total mass of a tesseroid model.

Give all in SI units and degrees!

Parameters:
model array of tesseroids
size size of the model
Returns:
The calculated mass
double tess_volume ( TESSEROID  tess  ) 

Calculate the volume of a tesseroid.

Parameters:
tess the tesseroid whose volume will be calculated
Returns:
the volume in the respective units
Generated on Tue Apr 26 12:17:07 2011 for Tesseroids 1.0: User manual and API documentation by doxygen 1.6.3