cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
prt.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 /*SetPrintLineCol set some parameters for the main line block & wl format */
4 /*prt_LineLabels save all labels and wavelengths for emission line array */
5 /*sprt_wl write wavelength to string - must be kept parallel with prt_wl */
6 /*prt_wl - print floating wavelength in Angstroms, in output format */
7 /* prt_line print the line label, followed by the line wl, and the wavelength of the closest match, if given */
8 /* prt_line_inlist print line suitable for output list, label not enclosed in quotation marks */
9 #include "cddefines.h"
10 #include "lines.h"
11 #include "prt.h"
12 #include "generic_state.h"
13 
16 
18 {
19  DEBUG_ENTRY( "t_line_col::zero()" );
20  /* set the format of the main output line list */
21  absint_len = 8;
22  relint_len = 9;
23  col_gap_len = 6;
24 }
25 
26 
27 /*SetPrintLineCol set some parameters for the main line block & wl format */
29 {
30  LineSave.wl_length = (int) LineSave.sig_figs + 2;
31 
32  /* set the format of the main output line list */
33  prt_linecol.column_len = (NCHLAB-1) + LineSave.wl_length + prt_linecol.absint_len + prt_linecol.relint_len + 3;
34 
35  prt_linecol.col_gap.assign( prt_linecol.col_gap_len, ' ' );
36  prt_linecol.relint_outrange.assign( prt_linecol.relint_len , '*' );
37 
38  return;
39 }
40 
41 
42 
43 /*prt_wl print floating wavelength in Angstroms, in output format */
44 void prt_wl( FILE *ioOUT , realnum wl )
45 {
46  char chString[100];
47  DEBUG_ENTRY( "prt_wl()" );
48 
49  sprt_wl( chString , wl );
50 
51  fprintf(ioOUT, "%.*s", LineSave.wl_length, chString );
52  return;
53 }
54 
55 /* write wavelength to string */
56 void sprt_wl( char *chString , realnum wl )
57 {
58  char chUnits[10];
59 
60  DEBUG_ENTRY( "sprt_wl()" );
61 
62  /* print in A unless > 1e4, then use microns */
63  if( wl > 1e8 )
64  {
65  /* centimeters */
66  strcpy( chUnits , "c" );
67  wl /= 1e8;
68  }
69  else if( wl > 1e4 )
70  {
71  /* microns */
72  strcpy( chUnits , "m" );
73  wl /= 1e4;
74  }
75  else if( wl == 0. )
76  {
77  strcpy( chUnits , " " );
78  }
79  else
80  {
81  /* Angstroms units */
82  strcpy( chUnits , "A" );
83  }
84 
85  /* want total of LineSave.sig_figs sig figs */
86  if( wl==0. )
87  {
88  sprintf(chString, "%*i", LineSave.wl_length-1, 0 );
89  }
90  else
91  {
92  int n = LineSave.sig_figs - 1 - (int)log10(wl);
93  if( n > 0 )
94  {
95  sprintf( chString, "%*.*f", (int)LineSave.sig_figs+1, n, wl );
96  }
97  else if (wl < (realnum)INT_MAX)
98  {
99  sprintf(chString, "%*i", (int)LineSave.sig_figs+1, (int)wl );
100  }
101  else
102  {
103  sprintf(chString, "%*c", (int)LineSave.sig_figs+1, '*' );
104  }
105  }
106 
107  strcat( chString , chUnits );
108  return;
109 }
110 
111 /*prt_LineLabels save all labels and wavelengths for emission line array */
113  /* io file handle */
114  FILE * ioOUT ,
115  /* print all if true, if false then do not print parts of
116  * transferred lines */
117  bool lgPrintAll )
118 {
119  long int i;
120 
121  DEBUG_ENTRY( "prt_LineLabels()" );
122 
123  for( i=0; i < LineSave.nsum; i++ )
124  {
125  if( LineSave.lines[i].isSeparator() )
126  {
127  /*fprintf( ioOUT, "%s ", LineSave.lines[i].chALab );*/
128  fprintf( ioOUT, "####\t%s",LineSave.chHoldComments[(int)LineSave.lines[i].wavelength()] );
129  }
130  else
131  {
132  if( !lgPrintAll &&
133  ( LineSave.lines[i].isInward() ||
134  LineSave.lines[i].isCollisional() ||
135  LineSave.lines[i].isPump() ||
136  LineSave.lines[i].isHeat() )
137  )
138  /* option to do not print lots of redundant labels
139  * lgPrintAll is false by default set true with LONG option
140  * on save line labels command */
141  continue;
142  /* this format chosen to be identical to that used by final */
143  fprintf( ioOUT, "%li\t%s\t",
144  i,
145  LineSave.lines[i].label().c_str() );
146  /* skip over leading spaces - a formatting problem */
147  long int j = 0;
148  string comment = LineSave.lines[i].chComment();
149  while( comment[j]!='\0' && comment[j]==' ')
150  ++j;
151  /* comment entered when line intensity generated */
152  fprintf( ioOUT , "\t# %s" , comment.substr(j).c_str() );
153  }
154  fprintf( ioOUT, "\n" );
155  }
156  return;
157 }
158 
159 /* prt_line_err produce an error message containing the line label and wavelength,
160  * followed, if given, by the wavelength of the closest line of the same label */
161 void prt_line_err ( FILE *ioOUT, const char *label, realnum wvlng )
162 {
163  fprintf( ioOUT, "with label (between quotes) \"%s\" and wavelength ", label );
164  prt_wl ( ioOUT, wvlng );
165  fprintf( ioOUT, ".\n" );
166 
167  return;
168 }
169 
170 
171 
172 /* prt_line_inlist print line suitable for output list, label not enclosed in quotation marks */
173 void prt_line_inlist ( FILE *ioOUT, const char *label, realnum wvlng )
174 {
175  fprintf( ioOUT, "%-*s\t", NCHLAB-1, label );
176  prt_wl ( ioOUT, wvlng );
177 
178  return;
179 }
180 
181 
183 {
184  DEBUG_ENTRY( "t_prt_matrix::zero()" );
185 
186  for( int i = 0; i < CHARS_SPECIES; ++i )
187  {
188  species[ i ] = '\0';
189  speciesLevels[ i ] = '\0';
190  }
191 }
192 
193 void t_prt_matrix::setSpecies( const string &sspec )
194 {
195  DEBUG_ENTRY( "t_prt_matrix::setSpecies()" );
196 
197  strncpy( species, sspec.c_str(), CHARS_SPECIES-1 );
198  species[CHARS_SPECIES-1] = '\0';
199  char *p = strchr( species, '[' );
200  char *p1 = p;
201  // Erase levels specification, e.g., "[*:*]", if any
202  if( p != NULL )
203  *p = '\0';
204 
205  strncpy( speciesLevels, sspec.c_str(), CHARS_SPECIES-1 );
206  speciesLevels[CHARS_SPECIES-1] = '\0';
207  if( p1 == NULL )
208  {
209  if( strlen( speciesLevels ) + 3 < CHARS_SPECIES )
210  {
211  strcat( speciesLevels, "[:]" );
212  fprintf( ioQQQ, "NOTE: Converted '%s' to '%s'\n",
213  species, speciesLevels );
214  }
215  else
216  {
217  fprintf( ioQQQ, "PROBLEM: Cannot convert '%s' to '%s[:]'. Species label too wide.\n",
218  species, speciesLevels );
219  cdEXIT( EXIT_FAILURE );
220  }
221  }
222 }
223 
225 {
226  DEBUG_ENTRY( "t_prt_matrix::`resolveSpecies()" );
227 
228  if( strlen( speciesLevels ) == 0 )
229  return;
230 
232 }
233 
234 void t_prt_matrix::prtRates( const long nlevels_local, const multi_arr<double,2,C_TYPE> &a,
235  valarray<double> &b )
236 {
237  DEBUG_ENTRY( "t_prt_matrix::prtRates()" );
238 
239  if( speciesLevelList.size() == 0 )
240  return;
241 
242  fprintf( ioQQQ, "'%s' lvl / creation /=>rates", species);
243  for( vector<long>::iterator ipLo = speciesLevelList.begin();
244  ipLo != speciesLevelList.end(); ++ipLo )
245  {
246  if( ipLo == speciesLevelList.begin() )
247  fprintf( ioQQQ, "\t%3ld", *ipLo+1 );
248  else
249  fprintf( ioQQQ, "\t%11ld", *ipLo+1 );
250  }
251  fprintf( ioQQQ, "\n" );
252 
253  for( vector<long>::iterator ipLo = speciesLevelList.begin();
254  ipLo != speciesLevelList.end(); ++ipLo )
255  {
256  if( *ipLo >= nlevels_local )
257  continue;
258  fprintf( ioQQQ, "%3ld\t %.4e", *ipLo+1, b[ *ipLo ] );
259  for( vector<long>::iterator ipHi = speciesLevelList.begin();
260  ipHi != speciesLevelList.end(); ++ipHi )
261  {
262  fprintf( ioQQQ, "\t%11.4e", a[ *ipLo ][ *ipHi ] );
263  }
264  fprintf( ioQQQ, "\n" );
265  }
266 }
void prt_wl(FILE *ioOUT, realnum wl)
Definition: prt.cpp:44
t_line_col prt_linecol
Definition: prt.cpp:15
void prt_LineLabels(FILE *ioOUT, bool lgPrintAll)
Definition: prt.cpp:112
void prtRates(const long nlevels_local, const multi_arr< double, 2, C_TYPE > &a, valarray< double > &b)
Definition: prt.cpp:234
t_LineSave LineSave
Definition: lines.cpp:10
string relint_outrange
Definition: prt.h:332
int col_gap_len
Definition: prt.h:329
char speciesLevels[CHARS_SPECIES]
Definition: prt.h:117
FILE * ioQQQ
Definition: cddefines.cpp:7
int wl_length
Definition: lines.h:114
vector< LinSv > lines
Definition: lines.h:132
void prt_line_err(FILE *ioOUT, const char *label, realnum wvlng)
Definition: prt.cpp:161
void zero()
Definition: prt.cpp:182
float realnum
Definition: cddefines.h:124
#define EXIT_FAILURE
Definition: cddefines.h:168
int relint_len
Definition: prt.h:321
#define cdEXIT(FAIL)
Definition: cddefines.h:482
const molezone * getLevelsGeneric(const char *chLabel, bool lgValidate, vector< long > &LevelList)
void resolveLevels()
Definition: prt.cpp:224
vector< long > speciesLevelList
Definition: prt.h:118
long int sig_figs
Definition: lines.h:109
t_prt prt
Definition: prt.cpp:14
void zero()
Definition: prt.cpp:17
string col_gap
Definition: prt.h:335
Definition: prt.h:127
void sprt_wl(char *chString, realnum wl)
Definition: prt.cpp:56
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
void setSpecies(const string &sspec)
Definition: prt.cpp:193
const int NCHLAB
Definition: cddefines.h:304
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
void prt_line_inlist(FILE *ioOUT, const char *label, realnum wvlng)
Definition: prt.cpp:173
int absint_len
Definition: prt.h:318
long int nsum
Definition: lines.h:87
char chHoldComments[NHOLDCOMMENTS][INPUT_LINE_LENGTH]
Definition: lines.h:99
void SetPrintLineCol()
Definition: prt.cpp:28
int column_len
Definition: prt.h:325