/home66/gary/public_html/cloudy/c08_branch/source/punch_colden.cpp

Go to the documentation of this file.
00001 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
00002  * others.  For conditions of distribution and use see copyright notice in license.txt */
00003 /*punch_colden parse punch column density command, or actually do the punch lines output */
00004 #include "cddefines.h"
00005 #include "cddrive.h"
00006 #include "input.h"
00007 #include "punch.h"
00008 /* this is the limit to the number of lines we can store */
00009 #define NPUNLM  100L
00010 
00011 /*punch_colden parse punch column density command, or actually do the punch lines output */
00012 void punch_colden(
00013   /* the header for the file, a list of identifications */
00014   char chHeader[] ,
00015   /* the file we will write to */
00016   FILE * ioPUN, 
00017   /* the job we shall do - one of READ or PUNS */
00018   const char *chDo )
00019 {
00020         char chCAP[INPUT_LINE_LENGTH], 
00021           chCard[INPUT_LINE_LENGTH];
00022         char chTemp[INPUT_LINE_LENGTH];
00023 
00024         bool lgEOF, 
00025           lgEOL;
00026         long int i;
00027         static char chElement[NPUNLM][5];
00028         static long int nColdenEntered;
00029         static long int ionstage[NPUNLM];
00030 
00031         DEBUG_ENTRY( "punch_colden()" );
00032 
00033         if( strcmp(chDo,"READ") == 0 )
00034         {
00035                 /* very first time this routine is called, chDo is "READ" and we read
00036                  * in lines from the input stream.  The line labels and wavelengths
00037                  * are store locally, and output in later calls to this routine */
00038 
00039                 /* number of lines we will save */
00040                 nColdenEntered = 0;
00041 
00042                 /* get the next line, and check for eof */
00043                 input_readarray(chCard,&lgEOF);
00044                 if( lgEOF )
00045                 {
00046                         fprintf( ioQQQ, 
00047                                 " Hit EOF while reading line list; use END to end list.\n" );
00048                         cdEXIT(EXIT_FAILURE);
00049                 }
00050 
00051                 /* convert line to caps */
00052                 strcpy( chCAP, chCard );
00053                 caps(chCAP);
00054 
00055                 while( strncmp(chCAP, "END" ,3 ) != 0 )
00056                 {
00057                         if( nColdenEntered >= NPUNLM )
00058                         {
00059                                 fprintf( ioQQQ, 
00060                                         " Too many lines have been entered; the %ld limit is.  Increase variable NPUNLM in routine punch_colden.\n", 
00061                                   NPUNLM );
00062                                 cdEXIT(EXIT_FAILURE);
00063                         }
00064 
00065                         /* order on line is label (col 1-4), ionstage */
00066                         strncpy( chElement[nColdenEntered], chCard , 4 );
00067 
00068                         /* null terminate the string*/
00069                         chElement[nColdenEntered][4] = 0;
00070 
00071                         /* now get ionstage - 1 for atom, 2 for first ion, etc */
00072                         i = 5;
00073                         ionstage[nColdenEntered] = (long)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
00074                         if( lgEOL )
00075                                 NoNumb( chCard );
00076 
00077                         /* this is total number stored so far */
00078                         ++nColdenEntered;
00079 
00080                         /* get next line and check for eof */
00081                         input_readarray(chCard,&lgEOF);
00082                         if( lgEOF )
00083                         {
00084                                 fprintf( ioQQQ, " Hit EOF while reading line list; use END to end list.\n" );
00085                                 cdEXIT(EXIT_FAILURE);
00086                         }
00087 
00088                         /* convert it to caps */
00089                         strcpy( chCAP, chCard );
00090                         caps(chCAP);
00091                 }
00092 
00093                 /*fprintf( ioPUN, "%li lines were entered, they were;\n", 
00094                   nColdenEntered );*/
00095                 /* give header line */
00096 
00097                 sprintf( chHeader , "#colden %s %3li", chElement[0] , ionstage[0] );
00098                 for( i=1; i < nColdenEntered; i++ )
00099                 {
00100                         sprintf( chTemp, "\t%s %3li", chElement[i] , ionstage[i] );
00101                         strcat( chHeader, chTemp );
00102                 }
00103                 strcat( chHeader, "\n" );
00104         }
00105 
00106         else if( strcmp(chDo,"PUNS") == 0 )
00107         {
00108                 /* punch some column densities  */
00109                 double colden;
00110                 /* punch some column column densities command */
00111                 for( i=0; i < nColdenEntered; i++ )
00112                 {
00113                         if( i )
00114                                 fprintf(ioPUN,"\t");
00115                         /* get column density, returns 0 if all ok */
00116                         if( cdColm(
00117                                 /* four char string, null terminated, giving the element name */
00118                                 chElement[i], 
00119                                 /* IonStage is ionization stage */
00120                                 ionstage[i], 
00121                                 /* will be column density */
00122                                 &colden) )
00123                         {
00124                                 fprintf( ioQQQ, 
00125                                         "\n PROBLEM punch_colden could not find a column density for "
00126                                         "the species with label %s %li \n\n",
00127                                         chElement[i] , ionstage[i] );
00128                                 colden = 1.;
00129                         }
00130                         fprintf( ioPUN, "%.4f", log10( MAX2(SMALLFLOAT , colden ) ) );
00131                 }
00132                 fprintf( ioPUN, "\n" );
00133         }
00134 
00135         else
00136         {
00137                 fprintf( ioQQQ, 
00138                         " unrecognized key for punch_colden=%4.4s\n", 
00139                   chDo );
00140                 cdEXIT(EXIT_FAILURE);
00141         }
00142 
00143         return;
00144 }

Generated on Mon Feb 16 12:01:27 2009 for cloudy by  doxygen 1.4.7