cloudy trunk
Loading...
Searching...
No Matches
flux.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
4#include "cddefines.h"
5#include "physconst.h"
6#include "energy.h"
7#include "flux.h"
8
9
10Flux::fu_bits Flux::p_InternalFluxUnitNoCheck(const string& unit, size_t& len) const
11{
12 DEBUG_ENTRY( "Flux::p_InternalFluxUnitNoCheck()" );
13
14 len = 0;
15 fu_bits bits;
16 if( unit == "Jy" )
17 {
18 len = 2;
19 bits.set(FU_JY);
20 }
21 else if( unit == "mJy" )
22 {
23 len = 3;
24 bits.set(FU_MJY);
25 }
26 else if( unit == "MJy/sr" )
27 {
28 len = 6;
29 bits.set(FU_MJY_SR);
30 }
31 else
32 {
33 if( unit.substr(len,5) == "erg/s" )
34 {
35 len += 5;
36 bits.set(FU_ERG_S);
37 }
38 else if( unit.substr(len,1) == "W" )
39 {
40 len += 1;
41 bits.set(FU_W);
42 }
43 if( unit.substr(len,4) == "/cm2" )
44 {
45 len += 4;
46 bits.set(FU_CM2);
47 }
48 else if( unit.substr(len,3) == "/m2" )
49 {
50 len += 3;
51 bits.set(FU_M2);
52 }
53 if( unit.substr(len,2) == "/A" )
54 {
55 len += 2;
56 bits.set(FU_A);
57 }
58 if( unit.substr(len,3) == "/nm" )
59 {
60 len += 3;
61 bits.set(FU_NM);
62 }
63 else if( unit.substr(len,7) == "/micron" )
64 {
65 len += 7;
66 bits.set(FU_MU);
67 }
68 else if( unit.substr(len,3) == "/Hz" )
69 {
70 len += 3;
71 bits.set(FU_HZ);
72 }
73 if( unit.substr(len,3) == "/sr" )
74 {
75 len += 3;
76 bits.set(FU_SR);
77 }
78 else if( unit.substr(len,8) == "/arcsec2" )
79 {
80 len += 8;
81 bits.set(FU_SQAS);
82 }
83 }
84 return bits;
85}
86
87Flux::fu_bits Flux::p_InternalFluxUnit(const string& unit) const
88{
89 DEBUG_ENTRY( "Flux::p_InternalFluxUnit()" );
90
91 size_t p;
92 fu_bits bits = p_InternalFluxUnitNoCheck( unit, p );
93 if( p != unit.length() || !p_ValidFluxUnit(bits) )
94 {
95 fprintf( ioQQQ, " insane units in Flux::InternalFluxUnit: \"%s\"\n", unit.c_str() );
97 }
98 return bits;
99}
100
102{
103 DEBUG_ENTRY( "Flux::p_ValidFluxUnit()" );
104
105 if( bits.none() )
106 return false;
107
108 if( bits[FU_JY] )
109 bits.reset(FU_JY);
110 else if( bits[FU_MJY] )
111 bits.reset(FU_MJY);
112 else if( bits[FU_MJY_SR] )
113 bits.reset(FU_MJY_SR);
114 else
115 {
116 if( bits[FU_ERG_S] )
117 bits.reset(FU_ERG_S);
118 else if( bits[FU_W] )
119 bits.reset(FU_W);
120 else
121 return false;
122 if( bits[FU_CM2] )
123 bits.reset(FU_CM2);
124 else if( bits[FU_M2] )
125 bits.reset(FU_M2);
126 else
127 return false;
128 if( bits[FU_A] )
129 bits.reset(FU_A);
130 else if( bits[FU_NM] )
131 bits.reset(FU_NM);
132 else if( bits[FU_MU] )
133 bits.reset(FU_MU);
134 else if( bits[FU_HZ] )
135 bits.reset(FU_HZ);
136 if( bits[FU_SR] )
137 bits.reset(FU_SR);
138 else if( bits[FU_SQAS] )
139 bits.reset(FU_SQAS);
140 }
141 return bits.none();
142}
143
144double Flux::p_get(fu_bits bits) const
145{
146 DEBUG_ENTRY( "Flux::p_get()" );
147
148 /* internal units are erg/cm^2/s (into 4pi sr in the case of an intensity) */
149 double val = p_flux;
150 if( bits[FU_W] )
151 val /= 1.e7;
152 if( bits[FU_M2] )
153 val *= 1.e4;
154 if( bits[FU_A] )
155 val /= p_energy.Angstrom();
156 if( bits[FU_NM] )
157 val /= p_energy.nm();
158 if( bits[FU_MU] )
159 val /= p_energy.micron();
160 if( bits[FU_HZ] )
161 val /= p_energy.Hz();
162 if( bits[FU_SR] )
163 val /= PI4;
164 if( bits[FU_SQAS] )
165 val /= SQAS_SKY;
166 if( bits[FU_JY] )
167 val *= 1.e23/p_energy.Hz();
168 if( bits[FU_MJY] )
169 val *= 1.e26/p_energy.Hz();
170 if( bits[FU_MJY_SR] )
171 val *= 1.e17/(PI4*p_energy.Hz());
172 return val;
173}
174
175void Flux::p_set(Energy e, double value, fu_bits bits)
176{
177 DEBUG_ENTRY( "Flux::p_set()" );
178
179 /* internal units are erg/cm^2/s (into 4pi sr in the case of an intensity) */
180 p_energy = e;
181 p_flux = value;
182 p_userunits = bits;
183 if( bits[FU_W] )
184 p_flux *= 1.e7;
185 if( bits[FU_M2] )
186 p_flux /= 1.e4;
187 if( bits[FU_A] )
188 p_flux *= p_energy.Angstrom();
189 if( bits[FU_NM] )
190 p_flux *= p_energy.nm();
191 if( bits[FU_MU] )
192 p_flux *= p_energy.micron();
193 if( bits[FU_HZ] )
194 p_flux *= p_energy.Hz();
195 if( bits[FU_SR] )
196 p_flux *= PI4;
197 if( bits[FU_SQAS] )
198 p_flux *= SQAS_SKY;
199 if( bits[FU_JY] )
200 p_flux /= 1.e23/p_energy.Hz();
201 if( bits[FU_MJY] )
202 p_flux /= 1.e26/p_energy.Hz();
203 if( bits[FU_MJY_SR] )
204 p_flux /= 1.e17/(PI4*p_energy.Hz());
205}
206
207string StandardFluxUnit(const char* chCard)
208{
209 DEBUG_ENTRY( "StandardFluxUnit()" );
210
211 if( nMatch(" JY ",chCard) || nMatch("JANS",chCard) )
212 return "Jy";
213 else if( nMatch("MJY/SR",chCard) )
214 return "MJy/sr";
215 else if( nMatch(" MJY",chCard) )
216 return "mJy";
217
218 string str;
219 if( nMatch("ERG/S/",chCard) )
220 str = "erg/s";
221 else if( nMatch("W/SQ",chCard) )
222 str = "W";
223 else
224 return "";
225
226 if( nMatch("/SQCM",chCard) )
227 str += "/cm2";
228 else if( nMatch("/SQM",chCard) )
229 str += "/m2";
230 else
231 return "";
232
233 if( nMatch("/A ",chCard) || nMatch("/A/",chCard) )
234 str += "/A";
235 else if( nMatch("/NM",chCard) )
236 str += "/nm";
237 else if( nMatch("/MICR",chCard) )
238 str += "/micron";
239 else if( nMatch("/HZ",chCard) )
240 str += "/Hz";
241
242 if( nMatch("/SR",chCard) )
243 str += "/sr";
244 else if( nMatch("/SQAS",chCard) )
245 str += "/arcsec2";
246
247 if( !ValidFluxUnit(str) )
248 {
249 fprintf( ioQQQ, " No valid flux unit was recognized on this line:\n %s\n\n", chCard );
250 fprintf( ioQQQ, " See Hazy for details.\n" );
252 }
253
254 return str;
255}
256
257string Flux::uu() const
258{
259 DEBUG_ENTRY( "Flux::uu()" );
260
262
263 if( p_userunits[FU_JY] )
264 return "Jy";
265 else if( p_userunits[FU_MJY] )
266 return "mJy";
267 else if( p_userunits[FU_MJY_SR] )
268 return "MJy/sr";
269
270 string str;
271 if( p_userunits[FU_ERG_S] )
272 str = "erg/s";
273 else if( p_userunits[FU_W] )
274 str = "W";
275
276 if( p_userunits[FU_CM2] )
277 str += "/cm2";
278 else if( p_userunits[FU_M2] )
279 str += "/m2";
280
281 if( p_userunits[FU_A] )
282 str += "/A";
283 else if( p_userunits[FU_NM] )
284 str += "/nm";
285 else if( p_userunits[FU_MU] )
286 str += "/micron";
287 else if( p_userunits[FU_HZ] )
288 str += "/Hz";
289
290 if( p_userunits[FU_SR] )
291 str += "/sr";
292 else if( p_userunits[FU_SQAS] )
293 str += "/arcsec2";
294
295 return str;
296}
FILE * ioQQQ
Definition cddefines.cpp:7
#define ASSERT(exp)
Definition cddefines.h:578
long nMatch(const char *chKey, const char *chCard)
Definition service.cpp:451
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
Definition energy.h:8
fu_bits p_InternalFluxUnitNoCheck(const string &unit, size_t &len) const
Definition flux.cpp:10
fu_bits p_userunits
Definition flux.h:19
@ FU_M2
Definition flux.h:13
@ FU_MJY_SR
Definition flux.h:12
@ FU_W
Definition flux.h:12
@ FU_MU
Definition flux.h:13
@ FU_JY
Definition flux.h:12
@ FU_A
Definition flux.h:13
@ FU_NM
Definition flux.h:13
@ FU_SQAS
Definition flux.h:13
@ FU_SR
Definition flux.h:13
@ FU_MJY
Definition flux.h:12
@ FU_HZ
Definition flux.h:13
@ FU_CM2
Definition flux.h:12
@ FU_ERG_S
Definition flux.h:12
Energy p_energy
Definition flux.h:17
string uu() const
Definition flux.cpp:257
void p_set(Energy e, double value, fu_bits bits)
Definition flux.cpp:175
double p_get(fu_bits bits) const
Definition flux.cpp:144
fu_bits p_InternalFluxUnit(const string &unit) const
Definition flux.cpp:87
double p_flux
Definition flux.h:18
bool p_ValidFluxUnit(fu_bits) const
Definition flux.cpp:101
bitset< FU_TOP > fu_bits
Definition flux.h:15
string StandardFluxUnit(const char *chCard)
Definition flux.cpp:207
bool ValidFluxUnit(const string &unit)
Definition flux.h:71
UNUSED const double PI4
Definition physconst.h:35
UNUSED const double SQAS_SKY
Definition physconst.h:135