C C Program to convert between various flux units C Evolved from the jancon and fmag programs, and some C code from Knox Long. C Chris Skinner @STScI, 01/03/1996. C Modified by Daniela Calzetti & Doris Daou @STScI, May 23 1996. C Modified Daniela Calzetti @STScI, July 07 1996, to include power-law spectra. C Modified by Daniela Calzetti @STScI, April 09 1997, to include AB mags and C to compactify the code. implicit none integer choice,ispectrum character*2 magtype character*15 units, iunits, ounits, eqsign character*20 infl_name, tsrc_name, wav_name real*4 influx, inwavel, tsource, outwavel real*4 f,themagnitude,sindex,sindex2,sindlambda,dnudlambda real*4 zerflux,fi,fnu,fo,xi,xo,bbody,c,h c=2.99793e+08 !speed of light in m/sec h=6.6262e-34 !Planck's constant in Js write(6,'('' INPUT FROM THE FORM IS '')') read(5,'(21x,a15)')iunits write(6,*) 'Input units = ', iunits read(5,'(22x,a15)')ounits write(6,*) 'Output units = ',ounits read(5,*)infl_name,eqsign,influx write(6,*) 'Input flux =', influx,' ',iunits read(5,*)wav_name,eqsign,inwavel read(5,*)wav_name,eqsign,outwavel c now reads the spectrum type 1=blackbody, 2=power-law in F(nu)=nu**alpha, and c 3=power-law in F(nu)=lambda**beta read(5,*)tsrc_name,eqsign,ispectrum if (ispectrum.eq.1) then read(5,*)tsrc_name,eqsign,tsource write(6,*) 'Temperature of the blackbody =', tsource elseif(ispectrum.eq.2) then read(5,*)tsrc_name,eqsign,sindex write(6,*) 'Index of the power-law spectrum as a function of frequency =', sindex sindlambda=-sindex-2. elseif(ispectrum.eq.3) then read(5,*)tsrc_name,eqsign,sindex2 write(6,*) 'Index of the power-law spectrum as a function of wavelength =', sindex2 sindlambda=sindex2-2. endif c To convert FROM: if(iunits.eq.'magnitude U ') then choice=9 magtype='U' zerflux=4.19e-02 inwavel=0.36 elseif(iunits.eq.'magnitude B ') then choice=9 magtype='B' zerflux=6.60e-02 inwavel=0.44 elseif(iunits.eq.'magnitude V ') then choice=9 magtype='V' zerflux=3.51e-02 inwavel=0.55 elseif(iunits.eq.'magnitude R ') then choice=9 magtype='R' zerflux=1.76e-02 inwavel=0.7 elseif(iunits.eq.'magnitude I ') then choice=9 magtype='I' zerflux=8.33e-03 inwavel=0.9 elseif(iunits.eq.'magnitude J ') then choice=9 magtype='J' zerflux=3.21e-03 inwavel=1.25 elseif(iunits.eq.'magnitude H ') then choice=9 magtype='H' zerflux=1.08e-03 inwavel=1.65 elseif(iunits.eq.'magnitude K ') then choice=9 magtype='K' zerflux=3.84e-04 inwavel=2.2 elseif(iunits.eq.'magnitude L ') then choice=9 magtype='L' zerflux=7.27e-05 inwavel=3.4 elseif(iunits.eq.'magnitude L1 ') then choice=9 magtype='L1' zerflux=5.40e-05 inwavel=3.74 elseif(iunits.eq.'magnitude M ') then choice=9 magtype='M' zerflux=1.95e-05 inwavel=4.8 elseif(iunits.eq.'magnitude N ') then choice=9 magtype='N' zerflux=1.09e-06 inwavel=10.1 elseif(iunits.eq.'magnitude Q ') then choice=9 magtype='Q' zerflux=7.50e-08 inwavel=20.0 endif if(choice.eq.9) then themagnitude=influx if (themagnitude.gt.35.0) then write(6,'('' Magnitude too faint. Get serious!'')') goto 100 elseif (themagnitude.lt.-15.0) then write(6,'('' Magnitude too bright. Get serious!'')') goto 100 endif f=(10.0**(-themagnitude/2.5))*zerflux endif write(6,*) 'INPUT wavelength = ', inwavel,' micron' if (inwavel.le.0.0) then write(6,'('' Negative wavelength. Try again!'')') goto 100 endif dnudlambda=c/(inwavel*1.0e-6)**2.0 if(iunits.eq.'Jy ') f=influx*1.0e-26*dnudlambda if(iunits.eq.'W/m2/Hz ') f=influx*dnudlambda if(iunits.eq.'W/m2/um ') f=influx*1.0e+06 if(iunits.eq.'W/cm2/um ') f=influx*1.0e+10 if(iunits.eq.'erg/cm2/s/Hz ') f=influx*1.0e-03*dnudlambda if(iunits.eq.'erg/cm2/s/A ') f=influx*1.0e+07 if(iunits.eq.'photons/m2/s/um') then f=influx*h*c/(inwavel*1.0e-06)*1.0e+06 endif if(iunits.eq.'photons/cm2/s/A') then f=influx*h*c/(inwavel*1.0e-06)*1.0e+14 endif if(iunits.eq.'AB magnitude ') then fnu=10.**(-(influx+48.57)/2.5) f=fnu*1.0e-03*dnudlambda endif if (f.le.1.0e-40.or.f.ge.1.0e+20) then write(6,'('' Flux too large or too small. Try again!'')') goto 100 endif C C We have just calculated the flux f in W/m2/m C Now we can convert it into whatever output was desired C c To convert TO: if(ounits.eq.'magnitude U ') then choice=8 magtype='U' outwavel=0.36 zerflux=4.19e-02 elseif(ounits.eq.'magnitude B ') then choice=8 magtype='B' outwavel=0.44 zerflux=6.60e-02 elseif(ounits.eq.'magnitude V ') then choice=8 magtype='V' outwavel=0.55 zerflux=3.51e-02 elseif(ounits.eq.'magnitude R ') then choice=8 magtype='R' outwavel=0.7 zerflux=1.76e-02 elseif(ounits.eq.'magnitude I ') then choice=8 magtype='I' outwavel=0.9 zerflux=8.33e-03 elseif(ounits.eq.'magnitude J ') then choice=8 magtype='J' outwavel=1.25 zerflux=3.21e-03 elseif(ounits.eq.'magnitude H ') then choice=8 magtype='H' outwavel=1.65 zerflux=1.08e-03 elseif(ounits.eq.'magnitude K ') then choice=8 magtype='K' outwavel=2.20 zerflux=3.84e-04 elseif(ounits.eq.'magnitude L ') then choice=8 magtype='L' outwavel=3.40 zerflux=7.27e-05 elseif(ounits.eq.'magnitude L1 ') then choice=8 magtype='L1' outwavel=3.74 zerflux=5.40e-05 elseif(ounits.eq.'magnitude M ') then choice=8 magtype='M' outwavel=4.80 zerflux=1.95e-05 elseif(ounits.eq.'magnitude N ') then choice=8 magtype='N' outwavel=10.10 zerflux=1.09e-06 elseif(ounits.eq.'magnitude Q ') then choice=8 magtype='Q' outwavel=20.00 zerflux=7.50e-08 endif write(6,*) 'OUTPUT wavelength = ', outwavel, ' micron' if (outwavel.le.0.0) then write(6,'('' Negative wavelength. Try again!'')') goto 100 endif if (ispectrum.eq.1) then if (tsource.ge.1.0e+07.or.tsource.le.10.0) then write(6,*)'Temperature too large or too small. Try again!' goto 100 endif xi=bbody(inwavel,tsource) xo=bbody(outwavel,tsource) fi=f*xo/xi elseif (ispectrum.eq.2 .or. ispectrum.eq.3) then if (sindlambda.gt.50.or.sindlambda.lt.-50.) then write(6,*)'Too large value of the power-law. Try again!' goto 100 endif fi=f*((outwavel/inwavel)**sindlambda) endif if (choice.eq.8) then themagnitude=2.5*(log10(zerflux)-log10(fi)) write(6,'(a2,''='',f6.2)')magtype,themagnitude elseif(ounits.eq.'AB magnitude ') then dnudlambda=c/(outwavel*1.0e-6)**2.0 fnu=fi/1.0e-03/dnudlambda fo=-2.5*alog10(fnu)-48.57 units='AB magnitude ' write(6,'(a15,''='',f6.2)')units,fo else dnudlambda=c/(outwavel*1.0e-6)**2.0 if(ounits.eq.'Jy ') then fo=fi*1.0e+26/dnudlambda units='Jy ' elseif(ounits.eq.'W/m2/Hz ') then fo=fi/dnudlambda units='W/m2/Hz ' elseif(ounits.eq.'W/m2/um ') then fo=fi*1.0e-06 units='W/m2/um ' elseif(ounits.eq.'W/cm2/um ') then fo=fi*1.0e-10 units='W/cm2/um ' elseif(ounits.eq.'erg/cm2/s/Hz ') then fo=fi*1.0e+03/dnudlambda units='erg/cm2/s/Hz ' elseif(ounits.eq.'erg/cm2/s/A ') then fo=fi*1.0e-07 units='erg/cm2/s/A ' elseif(ounits.eq.'photons/m2/s/um') then fo=fi*(outwavel*1.0e-06)/h/c*1.0e-06 units='photons/m2/s/um' elseif(ounits.eq.'photons/cm2/s/A') then fo=fi*(outwavel*1.0e-06)/h/c*1.0e-14 units='photons/cm2/s/A' endif write(6,'('' Flux='',1pg8.2,'' '',a15)')fo,units endif 100 end C C CALCULATION OF THE PLANK BLACK BODY EQUATION C C H Plank's constant in units Joule Sec C ch Plank's constant in units ergs sec C c units cm/sec C wlcm is wavelength in units of cm C kb boltzman constant units ergs/deg C wl Wavelength in microns C T Temperature in degrees Kelvin. C function bbody(wl,tbb) h=6.6262e-34 ch=6.6262e-27 c=3.0e10 bk=1.38062e-16 wlcm=wl*1.0e-4 wl4cm=wlcm**4.0 extest=ch*c/(wlcm*bk*tbb) if (extest.le.88.0) then bbody=(2.*h*c*c)/(wl4cm*wl)*(1./(exp(extest)-1.)) else bbody=0.0 end if return end