-- $Id: mono-point_02.lua,v 1.4 1999/02/01 20:16:21 tibbetts Exp dj $ -- -- raygen specification for multiple monochromatic point sources -- at different energies. -- the override function must set the following global variable: -- -- energy -> one of the following options: -- -- - single energy, e.g. energy=1.49. flux is set to the -- default value (see below). -- -- - lua table of energies, e.g. energy={1.49,4.51}. fluxes -- are set to the default value (see below) -- -- - lua table of tables of energies and photon fluxes, -- e.g. energy={{1.49,0.5},{4.51,1.25}} -- -- - a filename of an rdb table containing energies and, -- optionally, fluxes. the column containing energies -- defaults to 'energy'. it can be specified with the -- energy_colname variable. if fluxes are specified in -- the rdb table, the flux_colname variable should be set -- to the name of the column. otherwise, fluxes are -- set to the default value (see below). -- -- -- The following global variables are optional; -- optional global variables are applied to each point source; -- defaults are set by raygen: -- -- flux -> the user specified default flux. this will be used if -- fluxes are not specified with energies. if flux is not -- specified the default default flux is 1. -- z -> the position of the source. 0 is at CAP datum A, -- z increases from the source to the focal plane -- theta -> the radial position of the source in the sky, in -- minutes of arc -- phi -> the azimuthal angle of the source, in degrees $debug AXAF_ROOT = getenv( 'AXAF_ROOT' ) dofile( AXAF_ROOT .. '/simul/lib/lua/RDB.lua' ) override( ) function mono_point( ) local pfx = 'mono-point_02.lua: ' local local_flux = 1 local attrs = {} local deg2rad = 3.14159265358979/180.0 local arcsec2rad = deg2rad / 3600 local arcmin2rad = deg2rad / 60 if ( "nil" == type( energy ) ) then error( pfx .. "energy not specified" ) end -- if user didn't define flux, set it to the default if ( nil == flux ) then flux = local_flux end if ( nil ~= z ) then attrs['z'] = z end if ( nil ~= theta ) then attrs['theta'] = theta * arcmin2rad end if ( nil ~= phi ) then attrs['phi'] = phi * deg2rad end if ( "table" == type( energy ) ) then local i = nil local e = nil -- loop through the table putting index in i and value in e i, e = next( energy, i ) while ( nil ~= i ) do -- if value is a table then look for a flux if ( "table" == type( e ) ) then e = energy[i][1] -- if flux is not defined in table, default to flux if ( nil == energy[i][2] ) then local_flux = flux -- else use the flux given else local_flux = energy[i][2] end -- else default to flux else local_flux = flux end begin_source( "s"..e ) mono( "mono", e, local_flux ) point( "source", attrs ) end_source( "s"..e ) i, e = next( energy, i ) end -- elseif energy is just a number, use default flux elseif ( "number" == type( energy ) ) then begin_source( "s" .. tostring( energy ) ) mono( "mono", energy, flux ) point( "source", attrs ) end_source( "s" .. tostring( energy ) ) -- elseif energy is a string, it's the name of an rdb file elseif ( "string" == type( energy ) ) then -- open rdb file rdb, msg = RDB:new( energy ) if ( nil == rdb ) then error( pfx .. energy .. ': ' .. msg ) end -- see if energy column name was specified via override() if ( nil == energy_colname ) then energy_colname = 'energy' end -- check that the energy column exists if ( nil == rdb:pos( energy_colname ) ) then error( pfx .. "column `" .. energy_colname .. "' doesn\'t exist in rdb file " .. energy ) end -- if flux column is specified, then check that if ( nil ~= flux_colname and nil == rdb:pos( flux_colname ) ) then error( pfx .. "column `" .. flux_colname .. "' doesn\'t exist in rdb file " .. energy ) end -- now, loop through rdb table and create the sources local data data = rdb:read( ) while data do energy = data[energy_colname] if ( nil ~= flux_colname ) then flux = data[flux_colname] end begin_source( "s" .. tostring( energy ) ) mono( "mono", energy, flux ) point( "source", attrs ) end_source( "s" .. tostring( energy ) ) data = rdb:read( ) end -- else energy is an unexpected type else error( pfx .. "unexpected type: energy = `" .. energy .. "'" ) end end function source( ) mono_point( ) end