/* This file is part of Cloudy and is copyright (C)1978-2006 by Gary J. Ferland
 * For conditions of distribution and use see copyright notice in license.txt */
/*ParseF_nu parse intensity command parameters */
#include "cddefines.h"
#include "physconst.h"
#include "rfield.h"
#include "radius.h"
#include "parse.h"

void ParseF_nu(
  char *chCard, 
  long int *nqh, 
  float *ar1, 
  const char *chType, 
  int lgNU2)
{
	int lgEOL;
	long int i;
	double fr;

#	ifdef DEBUG_FUN
	fputs( "<+>ParseF_nu()\n", debug_fp );
#	endif

	/* flux density of this continuum source, at optional frequency */
	i = 5;

	strcpy( rfield.chRSpec[*nqh], chType );

	rfield.totpow[*nqh] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);

	/* large luminosity but per sq cm */
	if( rfield.totpow[*nqh] > 37. && 
		strcmp(rfield.chRSpec[*nqh],"SQCM") == 0 )
	{
		fprintf( ioQQQ, " This intensity is VERY large.  Problems?  Was luminosity intended??\n" );
	}

	if( lgEOL )
	{
		NoNumb(chCard);
	}

	strcpy( rfield.chSpNorm[*nqh], "FLUX" );

	/* this is optional frequency in Rydbergs */
	rfield.range[*nqh][0] = FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);

	/* >>chng 96 dec 18, was 1 changed to H mass nuc ryd
	 * if( lgEOL ) range(nqh,1) = 1. */
	if( lgEOL )
	{
		rfield.range[*nqh][0] = HIONPOT;
	}

	if( rfield.range[*nqh][0] <= 0. )
	{
		rfield.range[*nqh][0] = pow(10.,rfield.range[*nqh][0]);
	}

	if( lgNU2 )
	{
		/* range is now freq in ryd, totpow is log of product nu*f_nu */
		fr = log10(rfield.range[*nqh][0]*FR1RYD);
		rfield.totpow[*nqh] -= fr;
	}

	/* set R to large value in case R not specified (per sq cm)
	 * and this is per unit area */
	if( strcmp(chType,"SQCM") == 0 && radius.Radius == 0. )
	{
		/* RDFALT in BLOCK DATA SCALAR, is 25 */
		*ar1 = (float)radius.rdfalt;
		radius.Radius = pow(10.,radius.rdfalt);
	}

	++*nqh;
	if( *nqh >= LIMSPC )
	{
		fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" );
		puts( "[Stop in ParseF_nu]" );
		cdEXIT(EXIT_FAILURE);
	}

#	ifdef DEBUG_FUN
	fputs( " <->ParseF_nu()\n", debug_fp );
#	endif
	return;
}

