1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
!
! Astrometry related transformations
!
!
! Copyright © 2011-3, 2015 F.Hroch (hroch@physics.muni.cz)
!
! This file is part of Munipack.
!
! Munipack is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! Munipack is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with Munipack. If not, see <http://www.gnu.org/licenses/>.
!
module astrotrafo
implicit none
integer, parameter, private :: dbl = selected_real_kind(15)
real(dbl), parameter, private :: rad = 57.295779513082322865_dbl
! Transformation and projection:
!
! type ... type of projection (GNOMONIC,..)
! ... mostly affine transformation ...
! scale... scale [deg/pixel]
! rot ... rotation angle [deg]
! acen ... center projection in alpha [deg]
! dcen ... center projection in delta [deg]
! xcen ... horizontal center projection [pixel]
! ycen ... vertical center projection [pixel]
! refl ... -1 for reflected frame
! err ... typical statistical error of acen, dcen [deg]
type AstroTrafoProj
character(len=80) :: type
real(dbl) :: acen,dcen,xcen,ycen,ucen,vcen,scale,rot,err,refl
real(dbl), dimension(2,2) :: mrot,smat,mat,mat1
real(dbl), dimension(2) :: xy0,uv0
end type AstroTrafoProj
interface trafo
module procedure trafo_point, trafo_array
end interface trafo
interface invtrafo
module procedure invtrafo_point, invtrafo_array
end interface invtrafo
interface affine
module procedure affine_point, affine_array
end interface affine
interface invaffine
module procedure invaffine_point, invaffine_array
end interface invaffine
interface proj
module procedure proj_point, proj_array
end interface proj
interface invproj
module procedure invproj_point, invproj_array
end interface invproj
private :: trafo_point, trafo_array,invtrafo_point, invtrafo_array, &
affine_point, affine_array, invaffine_point, invaffine_array, &
proj_point, proj_array, invproj_point, invproj_array, &
gproj, invgproj
contains
! --- init ---
subroutine trafo_init(t,type,acen,dcen,xcen,ycen,ucen,vcen,scale,rot,refl,err)
type(AstroTrafoProj), intent(out) :: t
character(len=*), intent(in), optional :: type
real(dbl), intent(in), optional :: acen,dcen,xcen,ycen,ucen,vcen,scale,rot,err,refl
t%type = 'GNOMONIC'
t%acen = 0.0_dbl
t%dcen = 0.0_dbl
t%xcen = 0.0_dbl
t%ycen = 0.0_dbl
t%ucen = 0.0_dbl
t%vcen = 0.0_dbl
t%scale= 1.0_dbl
t%rot = 0.0_dbl
t%refl = 1.0_dbl
t%err = epsilon(t%err)
if( present(type) ) t%type = type
if( present(acen) ) t%acen = acen
if( present(dcen) ) t%dcen = dcen
if( present(xcen) ) t%xcen = xcen
if( present(ycen) ) t%ycen = ycen
if( present(ucen) ) t%ucen = ucen
if( present(vcen) ) t%vcen = vcen
if( present(scale)) t%scale= scale
if( present(rot) ) t%rot = rot
if( present(refl) ) t%refl = refl
if( present(err) ) t%err = err
call trafo_refresh(t)
end subroutine trafo_init
subroutine trafo_refresh(t)
type(AstroTrafoProj), intent(inout) :: t
real(dbl), dimension(2,2) :: m
real(dbl) :: f,c,s,det
! construct affine projection matrix
f = t%rot / rad
c = cos(f)
s = sin(f)
t%smat(1,:) = (/ t%scale * t%refl, 0.0_dbl /)
t%smat(2,:) = (/ 0.0_dbl, t%scale /)
t%mrot(1,:) = (/c,-s/)
t%mrot(2,:) = (/s, c/)
t%mat = matmul(t%mrot,t%smat)
m = t%mat
det = m(1,1)*m(2,2) - m(1,2)*m(2,1)
t%mat1(1,:) = (/ m(2,2),-m(1,2) /) / det
t%mat1(2,:) = (/-m(2,1), m(1,1) /) / det
t%xy0 = (/t%xcen, t%ycen/)
t%uv0 = (/t%ucen, t%vcen/)
end subroutine trafo_refresh
! --- trafo ---
subroutine trafo_point(t, a, d, x,y)
type(AstroTrafoProj), intent(in) :: t
real(dbl), intent(in) :: a,d
real(dbl), intent(out) :: x,y
real(dbl), dimension(1) :: xx,yy
call trafo(t, (/a/), (/d/), xx,yy)
x = xx(1)
y = yy(1)
end subroutine trafo_point
subroutine trafo_array(t, a, d, x,y)
type(AstroTrafoProj), intent(in) :: t
real(dbl), dimension(:), intent(in) :: a,d
real(dbl), dimension(:), intent(out) :: x,y
real(dbl), dimension(:), allocatable :: u,v
integer :: n
n = size(a)
allocate(u(n),v(n))
call proj(t,a,d,u,v)
call affine(t,u,v,x,y)
deallocate(u,v)
end subroutine trafo_array
! --- invtrafo ---
subroutine invtrafo_point(t,x,y,a,d)
type(AstroTrafoProj), intent(in) :: t
real(dbl), intent(in) :: x,y
real(dbl), intent(out) :: a,d
real(dbl), dimension(1) :: aa,dd
call invtrafo(t,(/x/),(/y/),aa,dd)
a = aa(1)
d = dd(1)
end subroutine invtrafo_point
subroutine invtrafo_array(t,x,y,a,d)
use projections
type(AstroTrafoProj), intent(in) :: t
real(dbl), dimension(:), intent(in) :: x,y
real(dbl), dimension(:), intent(out) :: a,d
real(dbl), dimension(:), allocatable :: u,v
integer :: n
n = size(a)
allocate(u(n),v(n))
call invaffine(t,x,y,u,v)
call invproj(t,u,v,a,d)
deallocate(u,v)
end subroutine invtrafo_array
! --- proj ---
subroutine proj_array(t,a,d,u,v)
use projections
type(AstroTrafoProj), intent(in) :: t
real(dbl), dimension(:), intent(in) :: a,d
real(dbl), dimension(:), intent(out) :: u,v
if( t%type == "GNOMONIC" ) then
call gproj(gnomond,t%acen,t%dcen,a,d,u,v)
else if( t%type == " " ) then
call gproj(identity,t%acen,t%dcen,a,d,u,v)
end if
end subroutine proj_array
subroutine proj_point(t,a,d,u,v)
type(AstroTrafoProj), intent(in) :: t
real(dbl), intent(in) :: a,d
real(dbl), intent(out) :: u,v
real(dbl), dimension(1) :: uu,vv
call proj(t,(/a/),(/d/),uu,vv)
u = uu(1)
v = vv(1)
end subroutine proj_point
! --- invproj ---
subroutine invproj_array(t,u,v,a,d)
use projections
type(AstroTrafoProj), intent(in) :: t
real(dbl), dimension(:), intent(in) :: u,v
real(dbl), dimension(:), intent(out) :: a,d
if( t%type == "GNOMONIC" ) then
call invgproj(invgnomond,t%acen,t%dcen,u,v,a,d)
else if( t%type == " " ) then
call invgproj(invidentity,t%acen,t%dcen,u,v,a,d)
end if
end subroutine invproj_array
subroutine invproj_point(t,u,v,a,d)
type(AstroTrafoProj), intent(in) :: t
real(dbl), intent(in) :: u,v
real(dbl), intent(out) :: a,d
real(dbl), dimension(1) :: aa,dd
call invproj(t,(/u/),(/v/),aa,dd)
a = aa(1)
d = dd(1)
end subroutine invproj_point
! --- invaffine ---
subroutine invaffine_point(t,x,y,u,v,g,h)
type(AstroTrafoProj), intent(in) :: t
real(dbl), intent(in) :: x,y
real(dbl), intent(out) :: u,v
real(dbl), intent(out), optional :: g,h
real(dbl), dimension(1) :: uu,vv,gg,hh
if( present(g) .and. present(h) ) then
call invaffine(t,(/x/),(/y/),uu,vv,gg,hh)
u = uu(1)
v = vv(1)
g = gg(1)
h = hh(1)
else
call invaffine(t,(/x/),(/y/),uu,vv)
u = uu(1)
v = vv(1)
end if
end subroutine invaffine_point
subroutine invaffine_array(t,x,y,u,v,g,h)
type(AstroTrafoProj), intent(in) :: t
real(dbl), dimension(:), intent(in) :: x,y
real(dbl), dimension(:), intent(out) :: u,v
real(dbl), dimension(:), intent(out), optional :: g,h
real(dbl), dimension(2) :: r,s
integer :: i
do i = 1,size(x)
r = (/x(i),y(i)/) - t%xy0
s = matmul(t%mat,r) + t%uv0
u(i) = s(1)
v(i) = s(2)
if( present(g) .and. present(h) ) then
s = matmul(t%mrot,r)
g(i) = s(1)
h(i) = s(2)
end if
end do
end subroutine invaffine_array
! --- affine ---
subroutine affine_point(t,u,v,x,y)
type(AstroTrafoProj), intent(in) :: t
real(dbl), intent(in) :: u,v
real(dbl), intent(out) :: x,y
real(dbl), dimension(1) :: xx,yy
call affine(t,(/u/),(/v/),xx,yy)
x = xx(1)
y = yy(1)
end subroutine affine_point
subroutine affine_array(t,u,v,x,y)
type(AstroTrafoProj), intent(in) :: t
real(dbl), dimension(:), intent(in) :: u,v
real(dbl), dimension(:), intent(out) :: x,y
real(dbl), dimension(2) :: r,s
integer :: i
do i = 1,size(u)
s = (/u(i),v(i)/) - t%uv0
r = matmul(t%mat1,s) + t%xy0
x(i) = r(1)
y(i) = r(2)
end do
end subroutine affine_array
! --- projections ---
subroutine gproj(proj, acen,dcen, a, d, u,v)
interface
subroutine proj(a,d,a0,d0,u,v)
implicit none
integer, parameter :: dp = selected_real_kind(15)
real(dp),intent(in) :: a,d,a0,d0
real(dp),intent(out) :: u,v
end subroutine proj
end interface
real(dbl), intent(in) :: acen,dcen
real(dbl), dimension(:),intent(in) :: a,d
real(dbl), dimension(:),intent(out) :: u,v
integer :: i
do i = 1, size(a)
call proj(a(i),d(i),acen,dcen,u(i),v(i))
end do
end subroutine gproj
subroutine invgproj(invproj, acen,dcen, u, v, a,d)
interface
subroutine invproj(a,d,a0,d0,u,v)
implicit none
integer, parameter :: dp = selected_real_kind(15)
real(dp),intent(in) :: a,d,a0,d0
real(dp),intent(out) :: u,v
end subroutine invproj
end interface
real(dbl), intent(in) :: acen,dcen
real(dbl), dimension(:),intent(in) :: u,v
real(dbl), dimension(:),intent(out) :: a,d
integer :: i
do i = 1, size(a)
call invproj(u(i),v(i),acen,dcen,a(i),d(i))
end do
end subroutine invgproj
end module astrotrafo
|