cloudy  trunk
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
punch_colden.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*punch_colden parse punch column density command, or actually do the punch lines output */
4 #include "cddefines.h"
5 #include "cddrive.h"
6 #include "input.h"
7 #include "punch.h"
8 /* this is the limit to the number of lines we can store */
9 #define NPUNLM 100L
10 
11 /*punch_colden parse punch column density command, or actually do the punch lines output */
13  /* the header for the file, a list of identifications */
14  char chHeader[] ,
15  /* the file we will write to */
16  FILE * ioPUN,
17  /* the job we shall do - one of READ or PUNS */
18  const char *chDo )
19 {
20  char chCAP[INPUT_LINE_LENGTH],
21  chCard[INPUT_LINE_LENGTH];
22  char chTemp[INPUT_LINE_LENGTH];
23 
24  bool lgEOF,
25  lgEOL;
26  long int i;
27  static char chElement[NPUNLM][5];
28  static long int nColdenEntered;
29  static long int ionstage[NPUNLM];
30 
31  DEBUG_ENTRY( "punch_colden()" );
32 
33  if( strcmp(chDo,"READ") == 0 )
34  {
35  /* very first time this routine is called, chDo is "READ" and we read
36  * in lines from the input stream. The line labels and wavelengths
37  * are store locally, and output in later calls to this routine */
38 
39  /* number of lines we will save */
40  nColdenEntered = 0;
41 
42  /* get the next line, and check for eof */
43  input_readarray(chCard,&lgEOF);
44  if( lgEOF )
45  {
46  fprintf( ioQQQ,
47  " Hit EOF while reading line list; use END to end list.\n" );
48  cdEXIT(EXIT_FAILURE);
49  }
50 
51  /* convert line to caps */
52  strcpy( chCAP, chCard );
53  caps(chCAP);
54 
55  while( strncmp(chCAP, "END" ,3 ) != 0 )
56  {
57  if( nColdenEntered >= NPUNLM )
58  {
59  fprintf( ioQQQ,
60  " Too many lines have been entered; the %ld limit is. Increase variable NPUNLM in routine punch_colden.\n",
61  NPUNLM );
62  cdEXIT(EXIT_FAILURE);
63  }
64 
65  /* order on line is label (col 1-4), ionstage */
66  strncpy( chElement[nColdenEntered], chCard , 4 );
67 
68  /* null terminate the string*/
69  chElement[nColdenEntered][4] = 0;
70 
71  /* now get ionstage - 1 for atom, 2 for first ion, etc */
72  i = 5;
73  ionstage[nColdenEntered] = (long)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
74  if( lgEOL )
75  NoNumb( chCard );
76 
77  /* this is total number stored so far */
78  ++nColdenEntered;
79 
80  /* get next line and check for eof */
81  input_readarray(chCard,&lgEOF);
82  if( lgEOF )
83  {
84  fprintf( ioQQQ, " Hit EOF while reading line list; use END to end list.\n" );
85  cdEXIT(EXIT_FAILURE);
86  }
87 
88  /* convert it to caps */
89  strcpy( chCAP, chCard );
90  caps(chCAP);
91  }
92 
93  /*fprintf( ioPUN, "%li lines were entered, they were;\n",
94  nColdenEntered );*/
95  /* give header line */
96 
97  sprintf( chHeader , "#colden %s %3li", chElement[0] , ionstage[0] );
98  for( i=1; i < nColdenEntered; i++ )
99  {
100  sprintf( chTemp, "\t%s %3li", chElement[i] , ionstage[i] );
101  strcat( chHeader, chTemp );
102  }
103  strcat( chHeader, "\n" );
104  }
105 
106  else if( strcmp(chDo,"PUNS") == 0 )
107  {
108  /* punch some column densities */
109  double colden;
110  /* punch some column column densities command */
111  for( i=0; i < nColdenEntered; i++ )
112  {
113  if( i )
114  fprintf(ioPUN,"\t");
115  /* get column density, returns 0 if all ok */
116  if( cdColm(
117  /* four char string, null terminated, giving the element name */
118  chElement[i],
119  /* IonStage is ionization stage */
120  ionstage[i],
121  /* will be column density */
122  &colden) )
123  {
124  fprintf( ioQQQ,
125  "\n PROBLEM punch_colden could not find a column density for "
126  "the species with label %s %li \n\n",
127  chElement[i] , ionstage[i] );
128  colden = 1.;
129  }
130  fprintf( ioPUN, "%.4f", log10( MAX2(SMALLFLOAT , colden ) ) );
131  }
132  fprintf( ioPUN, "\n" );
133  }
134 
135  else
136  {
137  fprintf( ioQQQ,
138  " unrecognized key for punch_colden=%4.4s\n",
139  chDo );
140  cdEXIT(EXIT_FAILURE);
141  }
142 
143  return;
144 }

Generated for cloudy by doxygen 1.8.4