cloudy  trunk
prt_columns.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 /*PrtColumns print column densities of all elements */
4 #include "cddefines.h"
5 #include "cddrive.h"
6 #include "dense.h"
7 #include "elementnames.h"
8 #include "h2.h"
9 #include "save.h"
10 #include "taulines.h"
11 #include "molcol.h"
12 #include "prt.h"
13 
15  /* this is stream used for io, is stdout when called by final,
16  * is save unit when save output generated */
17  FILE *ioMEAN ,
18  /* PRETTY for nice looking table in main output
19  * TABLE for table for save column density output, feeding into post processors
20  */
21  const char *chType ,
22  /* index of save in save array */
23  long int ioPun )
24 {
25  long int i,
26  nelem;
27 
28  double aa;
29 
30  DEBUG_ENTRY( "PrtColumns()" );
31 
32  if( strcmp( chType , "PRETTY")==0 )
33  {
34  /* print molecular element column densities */
35  molcol("PRIN" , ioMEAN);
36 
37  fprintf( ioMEAN, "\n" );
38 
39  fprintf( ioMEAN, "\n " );
40  for( i=1; i <= 17; i++ )
41  {
42  fprintf( ioMEAN, "%7ld", i );
43  }
44  fprintf( ioMEAN, "\n\n" );
45 
46  /* ionization column densities */
47  for( nelem=0; nelem < LIMELM; nelem++ )
48  {
49  if( dense.lgElmtOn[nelem] )
50  {
51  bool lgDONE = false;
52 
53  fprintf( ioMEAN, " %10.10s", elementnames.chElementName[nelem] );
54 
55  i = 1;
56  while( !lgDONE )
57  {
58  if( cdColm(
59  /* return value is zero if all ok, 1 if errors happened */
60  /* 4-char + eol string that is first
61  * 4 char of element name as spelled by cloudy */
63 
64  /* integer stage of ionization, 1 for atom, 0 for CO or H2 */
65  i,
66 
67  /* the theoretical column density derived by the code */
68  &aa ) )
69  TotalInsanity();
70 
71  if( aa == 0. )
72  {
73  aa = -30.;
74  }
75  else if( aa > 0. )
76  {
77  aa = log10(aa);
78  }
79 
80  if( i == 18 )
81  {
82  fprintf( ioMEAN, "\n" );
83  }
84  fprintf( ioMEAN, "%7.3f", aa );
85 
86  /* increment counter and check if at upper limit */
87  ++i;
88  /* MAX2 is to include H2 in H array */
89  if( i > MAX2(3,nelem+2) )
90  lgDONE = true;
91 
92  /* print title for this info if we are done with hydrogen */
93  if( nelem==ipHYDROGEN && lgDONE )
94  fprintf(ioMEAN," (H2) Log10 Column density (cm^-2)");
95  }
96 
97  fprintf( ioMEAN, "\n" );
98  }
99  }
100 
101  /* only print excited state column densities if level2 lines are included
102  * since they populated the upper level by UV pumping. This process
103  * is not included if level2 lines are not considered, by introducing
104  * the "no level2" command */
105  if( nWindLine>0 )
106  {
107  const int nEXCIT_COL = 12;
108  // use strings instead of char[][] to avoid bogus errors with PGCC bounds checking
109  string strExcit_Col[nEXCIT_COL]={
110  "He1*","CII*","C11*","C12*","C13*","O11*","O12*","O13*","Si2*","C30*","C31*","C32*"};
111  long int nprt = 0;
112  /* print excited level column densities */
113  fprintf(ioMEAN," Exc state ");
114  nprt = 12;
115  for(i=0; i<nEXCIT_COL; ++i )
116  {
117  ASSERT( strExcit_Col[i].size() <= 4 );
118  if( cdColm(
119  /* return value is zero if all ok, 1 if errors happened */
120  /* 4-char + eol string that is first
121  * 4 char of element name as spelled by cloudy */
122  strExcit_Col[i].c_str(),
123  /* integer stage of ionization, 1 for atom, 0 for CO, OH, CII*, or H2 */
124  0,
125  /* the theoretical column density derived by the code */
126  &aa ) )
127  TotalInsanity();
128 
129  if( nprt > 120 )
130  {
131  fprintf(ioMEAN,"\n ");
132  nprt = 0;
133  }
134  fprintf(ioMEAN," %s%7.3f",
135  strExcit_Col[i].c_str(),
136  log10(SDIV(aa) ));
137  nprt += 14;
138  }
139  fprintf(ioMEAN,"\n");
140  }
141 
142  /* print column densities for H2 */
143  h2.H2_Prt_column_density(ioMEAN);
144 
145  fprintf(ioMEAN,"\n");
146  }
147  else if( strcmp( chType , "TABLE")==0 )
148  {
149  ASSERT( ioPun>=0 );
150  if( save.lgPunHeader[ioPun] )
151  {
152  fprintf(ioMEAN,"#Column densities %s",
153  mole_global.list[0]->label.c_str() );
154  for( i=1; i < mole_global.num_calc; i++ )
155  {
156  fprintf(ioMEAN,"\t%s",
157  mole_global.list[i]->label.c_str() );
158  }
159  fprintf(ioMEAN,"\n");
160  save.lgPunHeader[ioPun] = false;
161  }
162  fprintf(ioMEAN,"%.3e",
163  mole.species[0].column );
164  for( i=1; i < mole_global.num_calc; i++ )
165  {
166  fprintf(ioMEAN,"\t%.3e",
167  mole.species[i].column );
168  }
169  fprintf(ioMEAN,"\n");
170  }
171  else
172  TotalInsanity();
173  return;
174 }
t_elementnames::chElementName
char chElementName[LIMELM][CHARS_ELEMENT_NAME]
Definition: elementnames.h:17
PrtColumns
void PrtColumns(FILE *ioMEAN, const char *chType, long int ioPun)
Definition: prt_columns.cpp:14
h2
diatomics h2("h2", 4100., &hmi.H2_total, Yan_H2_CS)
dense
t_dense dense
Definition: dense.cpp:24
elementnames.h
elementnames
t_elementnames elementnames
Definition: elementnames.cpp:5
nWindLine
long nWindLine
Definition: cdinit.cpp:19
cdColm
int cdColm(const char *chLabel, long int ion, double *theocl)
Definition: cddrive.cpp:636
t_dense::lgElmtOn
bool lgElmtOn[LIMELM]
Definition: dense.h:146
t_mole_global::list
MoleculeList list
Definition: mole.h:317
SDIV
sys_float SDIV(sys_float x)
Definition: cddefines.h:952
ASSERT
#define ASSERT(exp)
Definition: cddefines.h:578
ipHYDROGEN
const int ipHYDROGEN
Definition: cddefines.h:305
cddrive.h
dense.h
mole
t_mole_local mole
Definition: mole.cpp:7
cddefines.h
TotalInsanity
NORETURN void TotalInsanity(void)
Definition: service.cpp:886
molcol
void molcol(const char *chLabel, FILE *ioMEAN)
Definition: molcol.cpp:12
MAX2
#define MAX2
Definition: cddefines.h:782
LIMELM
const int LIMELM
Definition: cddefines.h:258
save.h
t_elementnames::chElementNameShort
char chElementNameShort[LIMELM][CHARS_ELEMENT_NAME_SHORT]
Definition: elementnames.h:21
prt.h
molcol.h
diatomics::H2_Prt_column_density
void H2_Prt_column_density(FILE *ioMEAN)
Definition: mole_h2_io.cpp:395
taulines.h
t_mole_local::species
valarray< class molezone > species
Definition: mole.h:398
h2.h
t_save::lgPunHeader
bool lgPunHeader[LIMPUN]
Definition: save.h:246
mole_global
t_mole_global mole_global
Definition: mole.cpp:6
t_mole_global::num_calc
int num_calc
Definition: mole.h:314
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684
save
t_save save
Definition: save.cpp:5