c J. Kaluzny - 28 April, 2005
c The code is provided "as it is" without any guarantee.
c
c assumes EE80=2.0 arcsec; binning 2x2-> 0.28 arcsec/pixel scale
c slow mode rn=3.3 e/pixel; fast mode rn=5 e/pixel
	real*4 fac(5)
	character*1 mode,sky
	character*16 skyval
	write(*,*)' Slow (s) or fast (f) mode ?'
	read(*,'(a1)') mode
	write(*,*)'Bright(b) or Dark(d) time ?'
	read(*,'(a1)') sky
	if((sky.ne.'b') .and. (sky.ne.'d')) then
	  write(*,*)'Incorrect sky (d or b allowed)'
	  stop
	endif
	rn=-1.
	if(mode.eq.'s') rn=40.*3.3**2
	if(mode.eq.'f') rn=40.*5.**2
	if(rn.lt.0.) then
         write(*,*)' Invalid mode requested (S or F allowed)'
	  stop	
	endif
	write(*,*)'Enter magnitude'
	read(*,*) xmag
	write(*,*)'Enter EXPTIME in sec'
	read(*,*) exptime
	dm=(xmag-20.0)/-2.5
	dm=10.**dm
c fluxes from point source
	fu=420.*dm*exptime
	fb=2500.*dm*exptime
	fv=1800.*dm*exptime
	fr=2250.*dm*exptime
	fi=1650.*dm*exptime
c sky, dark time
	 su=132*exptime
	 sb=785*exptime
	 sv=1410*exptime
	 sr=3393*exptime
	 si=5702.*exptime
	 skyval='DARK  '
c for bright sky get multipying factor for UBVRI 
	if(sky.eq.'b') then
	 call  factor(fac)
	 su=su*fac(1)
	 sb=sb*fac(2)
	 sv=sv*fac(3)
	 sr=sr*fac(4)
	 si=si*fac(5)
	 skyval='BRIGHT FULL MOON'
	endif	 
c S/N
	snu=fu/sqrt(rn+su+fu)
	snb=fb/sqrt(rn+sb+fb)
	snv=fv/sqrt(rn+sv+fv)
	snr=fr/sqrt(rn+sr+fr)
	sni=fi/sqrt(rn+si+fi)
c
	write(*,*)'---------------------------'
	write(*,*)'UBVRI = ',xmag,'  EXPTIME = ',exptime,' SKY=',skyval
	write(*,*)' '
	write(*,*)'             U          B          V          R
     1         I'
	write(*,10)snu,snb,snv,snr,sni
	write(*,11)fu,fb,fv,fr,fi
	write(*,12)su,sb,sv,sr,si
	write(*,13)rn,rn,rn,rn,rn
10	format('SNR   ',5(1x,f10.0))
11	format('Star  ',5(1x,f10.0))
12	format('Sky   ',5(1x,f10.0))
13	format('CCD   ',5(1x,f10.0))
	stop
	end		
c
c This subroutine calculates scalling factor for the sky brighness
c For dark sky mag/arcsec^2  are adopted from the SALTICAM Web Page
c For bright (full moon) we assume U=17.8 B=18.3 V=18.3 R=18.2 I=17.8 
c mag/arcsec^2 
	subroutine factor(f)
	real*4 f(5)
	f(1)=10**( (22.5-17.8)/2.5)
	f(2)=10**((22.5-18.3)/2.5)
	f(3)=10**((21.5-18.3)/2.5)
	f(4)=10**((20.8-18.2)/2.5)
	f(5)=10**((19.9-17.8)/2.5)
	return
	end
