cloudy  trunk
save_colden.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 /*save_colden parse save column density command, or actually do the save lines output */
4 #include "cddefines.h"
5 #include "cddrive.h"
6 #include "input.h"
7 #include "save.h"
8 #include "parser.h"
9 /* this is the limit to the number of lines we can store */
10 #define NPUNLM 100L
11 
12 static char chElement[NPUNLM][5];
13 static long int nColdenEntered;
14 static long int ionstage[NPUNLM];
15 
16 /*save_colden parse save column density command, or actually do the save lines output */
18  Parser &p,
19  /* the header for the file, a list of identifications */
20  char chHeader[] )
21 {
22  char chTemp[INPUT_LINE_LENGTH];
23 
24  long int i;
25 
26  DEBUG_ENTRY( "parse_save_colden()" );
27 
28  /* very first time this routine is called, chDo is "READ" and we read
29  * in lines from the input stream. The line labels and wavelengths
30  * are store locally, and output in later calls to this routine */
31 
32  /* number of lines we will save */
33  nColdenEntered = 0;
34 
35  /* get the next line, and check for eof */
36  p.getline();
37  if( p.m_lgEOF )
38  {
39  fprintf( ioQQQ,
40  " Hit EOF while reading line list; use END to end list.\n" );
42  }
43 
44  while( p.strcmp( "END" ) != 0 )
45  {
46  if( nColdenEntered >= NPUNLM )
47  {
48  fprintf( ioQQQ,
49  " Too many lines have been entered; the %ld limit is. Increase variable NPUNLM in routine save_colden.\n",
50  NPUNLM );
52  }
53 
54  /* order on line is label (col 1-4), ionstage */
55  strncpy( chElement[nColdenEntered], p.getCommand(4).c_str() , 4 );
56 
57  /* null terminate the string*/
58  chElement[nColdenEntered][4] = 0;
59 
60  /* now get ionstage - 1 for atom, 2 for first ion, etc */
61  ionstage[nColdenEntered] = (long)p.FFmtRead();
62  if( p.lgEOL() )
63  p.NoNumb("ion stage");
64 
65  /* this is total number stored so far */
67 
68  /* get next line and check for eof */
69  p.getline();
70  if( p.m_lgEOF )
71  {
72  fprintf( ioQQQ, " Hit EOF while reading line list; use END to end list.\n" );
74  }
75 
76  }
77 
78  /*fprintf( ioPUN, "%li lines were entered, they were;\n",
79  nColdenEntered );*/
80  /* give header line */
81 
82  sprintf( chHeader , "#colden %s %3li", chElement[0] , ionstage[0] );
83  for( i=1; i < nColdenEntered; i++ )
84  {
85  sprintf( chTemp, "\t%s %3li", chElement[i] , ionstage[i] );
86  strcat( chHeader, chTemp );
87  }
88  strcat( chHeader, "\n" );
89 }
90 
91 /*save_colden parse save column density command, or actually do the save lines output */
93  /* the file we will write to */
94  FILE * ioPUN )
95 {
96  long int i;
97 
98  DEBUG_ENTRY( "save_colden()" );
99 
100  /* save some column densities */
101  double colden;
102  /* save some column column densities command */
103  for( i=0; i < nColdenEntered; i++ )
104  {
105  if( i )
106  fprintf(ioPUN,"\t");
107  /* get column density, returns 0 if all ok */
108  if( cdColm(
109  /* four char string, null terminated, giving the element name */
110  chElement[i],
111  /* IonStage is ionization stage */
112  ionstage[i],
113  /* will be column density */
114  &colden) )
115  {
116  fprintf( ioQQQ,
117  "\n PROBLEM save_colden could not find a column density for "
118  "the species with label %s %li \n\n",
119  chElement[i] , ionstage[i] );
120  colden = 1.;
121  }
122  fprintf( ioPUN, "%.4f", log10( MAX2(SMALLFLOAT , colden ) ) );
123  }
124  fprintf( ioPUN, "\n" );
125 }
126 
Parser::FFmtRead
double FFmtRead(void)
Definition: parser.cpp:353
chElement
static char chElement[NPUNLM][5]
Definition: save_colden.cpp:12
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
save_colden
void save_colden(FILE *ioPUN)
Definition: save_colden.cpp:92
nColdenEntered
static long int nColdenEntered
Definition: save_colden.cpp:13
cdColm
int cdColm(const char *chLabel, long int ion, double *theocl)
Definition: cddrive.cpp:636
Parser::m_lgEOF
bool m_lgEOF
Definition: parser.h:42
cddrive.h
EXIT_FAILURE
#define EXIT_FAILURE
Definition: cddefines.h:140
Parser::NoNumb
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:233
Parser
Definition: parser.h:31
Parser::getline
bool getline(void)
Definition: parser.cpp:164
cddefines.h
NPUNLM
#define NPUNLM
Definition: save_colden.cpp:10
colden
t_colden colden
Definition: colden.cpp:5
MAX2
#define MAX2
Definition: cddefines.h:782
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
Parser::lgEOL
bool lgEOL(void) const
Definition: parser.h:98
save.h
INPUT_LINE_LENGTH
const int INPUT_LINE_LENGTH
Definition: cddefines.h:254
parser.h
parse_save_colden
void parse_save_colden(Parser &p, char chHeader[])
Definition: save_colden.cpp:17
ionstage
static long int ionstage[NPUNLM]
Definition: save_colden.cpp:14
Parser::strcmp
int strcmp(const char *s2)
Definition: parser.h:177
input.h
Parser::getCommand
string getCommand(long i)
Definition: parser.h:215
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684
SMALLFLOAT
const realnum SMALLFLOAT
Definition: cpu.h:191