cloudy trunk
Loading...
Searching...
No Matches
dense_tabden.cpp
Go to the documentation of this file.
1/* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2 * others. For conditions of distribution and use see copyright notice in license.txt */
3/*dense_tabden interpolate on table of points for density with dlaw table command, by K Volk */
4#include "cddefines.h"
5#include "dense.h"
6
7double dense_tabden(double r0,
8 double depth)
9{
10 bool lgHit;
11 long int j;
12 double frac,
13 tabden_v,
14 x;
15
16 DEBUG_ENTRY( "dense_tabden()" );
17 /*interpolate on table of points for density with dlaw table command, by K Volk
18 *each line is log radius and H density per cc. */
19
20 /*begin sanity check */
21 if( r0 <= 0. || depth <= 0. )
22 {
23 fprintf( ioQQQ, " dense_tabden called with insane depth, radius, =%10.2e%10.2e\n",
24 depth, r0 );
25 }
26 /*end sanity check */
27
28 /* interpolate on radius or depth? */
29 if( dense.lgDLWDepth )
30 {
31 /* depth key appeared = we want depth */
32 x = log10(depth);
33 }
34 else
35 {
36 /* use radius */
37 x = log10(r0);
38 }
39
40 /* set to impossible value, will crash if not reset */
41 tabden_v = -DBL_MAX;
42
43 if( x < dense.frad[0] || x >= dense.frad[dense.nvals-1] )
44 {
45 fprintf( ioQQQ, " requested radius outside range of dense_tabden\n" );
46 fprintf( ioQQQ, " radius was%10.2e min, max=%10.2e%10.2e\n",
47 x, dense.frad[0], dense.frad[dense.nvals-1] );
49 }
50 else
51 {
52 lgHit = false;
53 j = 1;
54
55 while( !lgHit && j <= dense.nvals - 1 )
56 {
57 if( dense.frad[j-1] <= (realnum)x && dense.frad[j] > (realnum)x )
58 {
59 frac = (x - dense.frad[j-1])/(dense.frad[j] -
60 dense.frad[j-1]);
61 tabden_v = dense.fhden[j-1] + frac*(dense.fhden[j] -
62 dense.fhden[j-1]);
63 lgHit = true;
64 }
65 j += 1;
66 }
67
68 if( !lgHit )
69 {
70 fprintf( ioQQQ, " radius outran dlaw table scale, requested=%6.2f largest=%6.2f\n",
71 x, dense.frad[dense.nvals-1] );
73 }
74 }
75
76 /* got it, now return value, not log of density */
77 tabden_v = pow(10.,tabden_v);
78 return( tabden_v );
79}
FILE * ioQQQ
Definition cddefines.cpp:7
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
float realnum
Definition cddefines.h:103
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
t_dense dense
Definition dense.cpp:24
double dense_tabden(double r0, double depth)