cloudy trunk
Loading...
Searching...
No Matches
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
12static char chElement[NPUNLM][5];
13static long int nColdenEntered;
14static 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 */
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*/
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
FILE * ioQQQ
Definition cddefines.cpp:7
const int INPUT_LINE_LENGTH
Definition cddefines.h:254
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
#define MAX2
Definition cddefines.h:782
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
int cdColm(const char *chLabel, long int ion, double *theocl)
Definition cddrive.cpp:636
bool getline(void)
Definition parser.cpp:164
double FFmtRead(void)
Definition parser.cpp:353
int strcmp(const char *s2)
Definition parser.h:177
bool lgEOL(void) const
Definition parser.h:98
NORETURN void NoNumb(const char *chDesc) const
Definition parser.cpp:233
bool m_lgEOF
Definition parser.h:42
string getCommand(long i)
Definition parser.h:215
t_colden colden
Definition colden.cpp:5
const realnum SMALLFLOAT
Definition cpu.h:191
void save_colden(FILE *ioPUN)
#define NPUNLM
static long int nColdenEntered
void parse_save_colden(Parser &p, char chHeader[])
static long int ionstage[NPUNLM]
static char chElement[NPUNLM][5]