F90 module for conversion between (RA,dec) and (az,el)?

 Posts: 59
 Joined: September 25 2004
 Affiliation: ITA, University of Oslo
 Contact:
F90 module for conversion between (RA,dec) and (az,el)?
Hi! I need an F90 (or plain Fortran) module for conversion between (RA,dec) and (az,el), both ways. Does anybody know about a publicly available module for this? I'd prefer a single small file over a big library (for portability and ease of installation). So, before writing one myself, I figured I'd check if somebody already have one lying around, that I could adopt.. Thanks! :)

 Posts: 183
 Joined: September 24 2004
 Affiliation: Brookhaven National Laboratory
 Contact:
F90 module for conversion between (RA,dec) and (az,el)?
Depends a lot of how accurate positioning you need: for real pointing needs one needs to take into account all the gory details about earth precession, shape, etc. to convert ra dec in say j2000 to az,el at a given point in time, etc.
If you need something rough, then the easiest thing would be to extract e.g SLA_DE2H from the SLALIB  that is just a bunch of sines and coses...
a
If you need something rough, then the easiest thing would be to extract e.g SLA_DE2H from the SLALIB  that is just a bunch of sines and coses...
a

 Posts: 8
 Joined: December 29 2004
 Affiliation: University of Chicago
F90 module for conversion between (RA,dec) and (az,el)?
Hi HansKristian 
If you're desperate (or lazy), feel free to copy & paste the following (from the TopHat analysis package). All standard caveats about bugs & accuracy & other bad things apply.
Cheers,
Tom
! rewrite celestial2horizon.pro (JB rewrite of A. Balbi radec2azel.pro)
subroutine cel2hor(az,el,ra,dec,lst,lat,npts3)
integer, intent(in) :: npts3
double precision, dimension(npts3), intent(in) :: ra, dec, lst, lat
double precision, dimension(npts3) :: az, el,arg, rel
!working out elevation
arg = sin(dec*dtor)*sin(lat*dtor)+cos(dec*dtor)* &
cos(lst*2.*pi/24.d0ra*15.d0*dtor)*cos(lat*dtor)
! arg = arg  dim(arg,1.)
! arg = arg + dim(arg,1.)
rel=asin( arg )
el=rel*radeg
!working out azimuth
az=atan2(cos(dec*dtor)*sin(lst*2.*pi/24.d0ra*15.d0*dtor), &
sin(dec*dtor)*cos(lat*dtor)+cos(dec*dtor)* &
cos(lst*2.*pi/24.d0ra*15.d0*dtor)*sin(lat*dtor))
az=az*radeg + 180.d0
end subroutine cel2hor
! rewrite horizon2celestial.pro (JB rewrite of A. Balbi azel2radec.pro)
subroutine hor2cel(az,el,ra,dec,lst,lat,npts4)
integer, intent(in) :: npts4
double precision, dimension(npts4), intent(in) :: az, el, lst, lat
double precision, dimension(npts4) :: ra, dec, arg, rdec, ha
! working out declination
arg = sin(el*dtor)*sin(lat*dtor)cos(el*dtor)*cos((az180.)*dtor)* &
cos(lat*dtor)
rdec = asin( arg )
! working out right ascension
ha = atan2(cos(el*dtor)*sin((az180.)*dtor), sin(el*dtor)* &
cos(lat*dtor)+cos(el*dtor)*cos((az180.)*dtor)*sin(lat*dtor))
ha = 24.*ha/2./pi
ra = lstha
ra = pmod(ra,24.d0,npts4)
dec = rdec*radeg
end subroutine hor2cel
If you're desperate (or lazy), feel free to copy & paste the following (from the TopHat analysis package). All standard caveats about bugs & accuracy & other bad things apply.
Cheers,
Tom
! rewrite celestial2horizon.pro (JB rewrite of A. Balbi radec2azel.pro)
subroutine cel2hor(az,el,ra,dec,lst,lat,npts3)
integer, intent(in) :: npts3
double precision, dimension(npts3), intent(in) :: ra, dec, lst, lat
double precision, dimension(npts3) :: az, el,arg, rel
!working out elevation
arg = sin(dec*dtor)*sin(lat*dtor)+cos(dec*dtor)* &
cos(lst*2.*pi/24.d0ra*15.d0*dtor)*cos(lat*dtor)
! arg = arg  dim(arg,1.)
! arg = arg + dim(arg,1.)
rel=asin( arg )
el=rel*radeg
!working out azimuth
az=atan2(cos(dec*dtor)*sin(lst*2.*pi/24.d0ra*15.d0*dtor), &
sin(dec*dtor)*cos(lat*dtor)+cos(dec*dtor)* &
cos(lst*2.*pi/24.d0ra*15.d0*dtor)*sin(lat*dtor))
az=az*radeg + 180.d0
end subroutine cel2hor
! rewrite horizon2celestial.pro (JB rewrite of A. Balbi azel2radec.pro)
subroutine hor2cel(az,el,ra,dec,lst,lat,npts4)
integer, intent(in) :: npts4
double precision, dimension(npts4), intent(in) :: az, el, lst, lat
double precision, dimension(npts4) :: ra, dec, arg, rdec, ha
! working out declination
arg = sin(el*dtor)*sin(lat*dtor)cos(el*dtor)*cos((az180.)*dtor)* &
cos(lat*dtor)
rdec = asin( arg )
! working out right ascension
ha = atan2(cos(el*dtor)*sin((az180.)*dtor), sin(el*dtor)* &
cos(lat*dtor)+cos(el*dtor)*cos((az180.)*dtor)*sin(lat*dtor))
ha = 24.*ha/2./pi
ra = lstha
ra = pmod(ra,24.d0,npts4)
dec = rdec*radeg
end subroutine hor2cel

 Posts: 59
 Joined: September 25 2004
 Affiliation: ITA, University of Oslo
 Contact:
Re: F90 module for conversion between (RA,dec) and (az,el)?
Thanks! However, I ended up writing my own version after all, which is quite similar to this one. One difference, though, is that I output the general rotation matrix, rather than convert a single point. So if anybody is interested in that, please let me know, and I'll post/send it.Tom Crawford wrote: If you're desperate (or lazy), feel free to copy & paste the following (from the TopHat analysis package). All standard caveats about bugs & accuracy & other bad things apply.