cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
depth_table.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 #include "cddefines.h"
4 
5 #include "depth_table.h"
6 #include "thirdparty.h"
7 
8 double DepthTable::tabval(double r0,
9  double depth) const
10 {
11  double tabden_v,
12  x;
13 
14  DEBUG_ENTRY( "DepthTable::tabval()" );
15  /*interpolate on table of points for density with dlaw table command, by K Volk
16  *each line is log radius and H density per cc. */
17 
18  /*begin sanity check */
19  if( r0 <= 0. || depth <= 0. )
20  {
21  fprintf( ioQQQ, " dense_tabden called with insane depth, radius, =%10.2e%10.2e\n",
22  depth, r0 );
23  }
24  /*end sanity check */
25 
26  /* interpolate on radius or depth? */
27  if( lgDepth )
28  {
29  /* depth key appeared = we want depth */
30  x = log10(depth);
31  }
32  else
33  {
34  /* use radius */
35  x = log10(r0);
36  }
37 
38  /* set to impossible value, will crash if not reset */
39  tabden_v = -DBL_MAX;
40 
41  if( x < dist[0] || x >= dist[nvals-1] )
42  {
43  fprintf( ioQQQ, " requested radius outside range of dense_tabden\n" );
44  fprintf( ioQQQ, " radius was%10.2e min, max=%10.2e%10.2e\n",
45  x, dist[0], dist[nvals-1] );
47  }
48  else
49  {
50  tabden_v = linint(get_ptr(dist),get_ptr(val),nvals,x);
51  }
52 
53  /* got it, now return value, not log of density */
54  tabden_v = exp10(tabden_v);
55  return( tabden_v );
56 }
long int nvals
Definition: depth_table.h:17
double exp10(double x)
Definition: cddefines.h:1368
T * get_ptr(T *v)
Definition: cddefines.h:1109
FILE * ioQQQ
Definition: cddefines.cpp:7
bool lgDepth
Definition: depth_table.h:11
#define EXIT_FAILURE
Definition: cddefines.h:168
#define cdEXIT(FAIL)
Definition: cddefines.h:482
double tabval(double r0, double depth) const
Definition: depth_table.cpp:8
vector< double > dist
Definition: depth_table.h:13
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
vector< double > val
Definition: depth_table.h:14
double linint(const double x[], const double y[], long n, double xval)
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121