Function MAGLAT.PRO [message #6063] |
Tue, 02 April 1996 00:00 |
zawodny
Messages: 121 Registered: August 1992
|
Senior Member |
|
|
Hi,
Awhile back (like Jan 1993!) I posted a function to convert
geographic latitude and longitude to geomagnetic coordinates. Is has
been so popular that someone found an obvious bug in the program just
this morning ;-). The routine that follows here is the latest release
of MAGLAT.PRO.
;+
; NAME: MAGLAT
;
; PURPOSE: Convert geographic latitude and longitude to magnetic
; latitude and longitude.
;
; CATEGORY: Coordinate transformation
;
; CALLING SEQUENCE:
; mlat = MAGLAT(lat,lon,mlon)
; INPUTS:
; Lat A scalar or vector of geographic latitudes
; Lon A scalar or vector of geographic longitudes
;
; OUTPUTS:
; Mlat Primary result, a scalar/vector of magnetic latitudes
; Mlon Optional result, a scalar/vector of magnetic longitudes
;
; COMMON BLOCKS: None
;
; SIDE EFFECTS: None
;
; RESTRICTIONS: Latitude should be -90 <= lat <= 90.
;
; PROCEDURE:
; STRAIGHTFORWARD (seems to be the default value of this field).
; MODIFICATION HISTORY:
; Version 1.1, Jan 1993 by J.M.Zawodny NASA LaRC
; Version 1.2, Apr 1996 by J.M.Zawodny NASA LaRC (Fixed bug in Mag. Lon.)
; j.m.zawodny@larc.nasa.gov
;-
function MAGLAT,glat,glon,mlon
; Convert to radians
a117 = 11.7/!radeg
alat = glat/!radeg
;v1.1 alon = (glon-291.)/!radeg
alon = (291.-glon)/!radeg
; Calculate the latitude
slat = sin(alat)*cos(a117) + cos(alat)*sin(a117)*cos(alon)
mlat = asin(slat)
; If user wants geomagnetic longitude as well
if(n_params(0) eq 3) then begin
ylon = cos(alat)*sin(alon)
xlon = sin(alat)*sin(a117) - cos(alat)*cos(alon)*cos(a117)
mlon = atan(ylon,xlon)*!radeg
endif
; Return the geomagnetic latitude (in degrees)
return,mlat*!radeg
end
--
Work: Dr. Joseph M. Zawodny Play: Joe Zawodny
NASA Langley Research Center Ham Radio KO4LW
E-mail: J.M.Zawodny@LaRC.NASA.gov zawodny@exis.net
|
|
|