/home66/gary/public_html/cloudy/c08_branch/source/parse_grid.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 /*ParseGrid parse the grid command lines */
00004 #include "cddefines.h"
00005 #include "optimize.h"
00006 #include "grid.h"
00007 
00008 /* ParseGrid - called from ParseCommands if GRID command found */
00009 void ParseGrid(
00010         /* command line, which was changed to all caps in main parsing routine */
00011         char *chCard)
00012 {
00013         bool lgEOL;
00014         long int i;
00015 
00016         DEBUG_ENTRY( "ParseGrid()" );
00017 
00018         /* RP fake optimizer to run a grid of calculations, also accepts
00019          * keyword XSPEC */
00020         strcpy( optimize.chOptRtn, "XSPE" );
00021         grid.lgGrid = true;
00022 
00023         if( nMatch("REPE",chCard) )
00024         {
00025                 /* just keep repeating, don't actually change the values in the grid.
00026                  * useful for debugging unintentional crosstalk */
00027                 grid.lgStrictRepeat = true;
00028         }
00029 
00030         /* 06 aug 22, change to accept three parameters: lower and upper limit and number of points. */
00031         /* scan off range for the previously selected variable */
00032         if( optimize.nparm > 0 )
00033         {
00034                 realnum highvalue;
00035                 long numPoints=0;
00036 
00037                 ASSERT( optimize.nparm < LIMPAR );
00038 
00039                 i = 5;
00040                 optimize.varang[optimize.nparm-1][0] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
00041                 optimize.varang[optimize.nparm-1][1] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
00042                 grid.paramIncrements[optimize.nparm-1] = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
00043 
00044                 if( grid.paramIncrements[optimize.nparm-1] <= 0. )
00045                 {
00046                         fprintf( ioQQQ," The increment (third parameter) must be a positive number.\n" );
00047                         fprintf( ioQQQ," Sorry.\n" );
00048                         cdEXIT( EXIT_FAILURE );
00049                 }
00050 
00051                 if( grid.paramIncrements[optimize.nparm-1] > ( optimize.varang[optimize.nparm-1][1] - optimize.varang[optimize.nparm-1][0] ) )
00052                 {
00053                         fprintf( ioQQQ," The increment (third parameter) must not be greater than the difference between the limits (first and second parameters.\n" );
00054                         fprintf( ioQQQ," Sorry.\n" );
00055                         cdEXIT( EXIT_FAILURE );
00056                 }
00057 
00058                 if( lgEOL )
00059                 {
00060                         fprintf( ioQQQ," This command has changed since the definition given in Porter et al. 2006, PASP, 118, 920.\n" );
00061                         fprintf( ioQQQ," The grid command now requires three parameters: lower limit, upper limit, and increment.\n" );
00062                         fprintf( ioQQQ," The keywords RANGE and STEPS are no longer necessary.\n" );
00063                         fprintf( ioQQQ," Sorry.\n" );
00064                         cdEXIT( EXIT_FAILURE );
00065                 }
00066                 else
00067                 {
00068                         ++optimize.nRangeSet;
00069                 }
00070 
00071                 /* Swap if second range parameter is less than the first. */
00072                 if( optimize.varang[optimize.nparm-1][1] < optimize.varang[optimize.nparm-1][0] )
00073                 {
00074                         realnum temp = optimize.varang[optimize.nparm-1][0];
00075                         optimize.varang[optimize.nparm-1][0] = optimize.varang[optimize.nparm-1][1];
00076                         optimize.varang[optimize.nparm-1][1] = temp;
00077                 }
00078 
00079                 ASSERT( optimize.varang[optimize.nparm-1][1] - optimize.varang[optimize.nparm-1][0] > 0. );
00080 
00081                 {
00082                         realnum integer, tempNumPoints = (optimize.varang[optimize.nparm-1][1] - 
00083                                 optimize.varang[optimize.nparm-1][0])/grid.paramIncrements[optimize.nparm-1];
00084                         realnum fraction = modf( tempNumPoints, &integer );
00085 
00086                         if( fraction > 0.99f || fraction < 0.01f )
00087                         {
00088                                 optimize.varang[optimize.nparm-1][1] += 0.01f * grid.paramIncrements[optimize.nparm-1];
00089                                 fprintf( ioQQQ,"\n NOTE The range is very nearly (or exactly) an integer multiple of the increment.\n" );
00090                                 fprintf( ioQQQ," NOTE The upper limit has been increased by a small fraction of the increment to ensure that\n" );
00091                                 fprintf( ioQQQ," NOTE the specified upper limit is included in the grid.\n\n" );
00092                         }
00093                 }
00094 
00095                 numPoints = 0;
00096                 highvalue = optimize.varang[optimize.nparm-1][0];
00097                 /* find the number of parameter values by incrementing from the lower limit up to the upper limit. */
00098                 while( highvalue <= optimize.varang[optimize.nparm-1][1] )
00099                 {
00100                         ++numPoints;
00101                         highvalue += grid.paramIncrements[optimize.nparm-1];
00102                 }
00103 
00104                 grid.numParamValues[optimize.nparm-1] = numPoints;
00105 
00106                 if( grid.numParamValues[optimize.nparm-1] < 2 )
00107                 {
00108                         fprintf( ioQQQ, " NOTE must have at least two grid points\n" );
00109                 }
00110                 else if( grid.numParamValues[optimize.nparm-1] > 20 )
00111                 {
00112                         fprintf( ioQQQ, " NOTE There are %li grid points.  Are you "
00113                                 "sure you want that many?\n" ,
00114                                 grid.numParamValues[optimize.nparm-1]);
00115                 }
00116 
00117                 grid.numParamValues[optimize.nparm-1] = MAX2( 2, grid.numParamValues[optimize.nparm-1] );
00118         }
00119 
00120         return;
00121 }

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