OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
getorbit.f
Go to the documentation of this file.
1  subroutine getorbit(iyr,iday,msec,iorbno,pdsec,
2  . inorad,cline1,cline2)
3 c
4 c $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $
5 c $Log: getorbit.f,v $
6 c Revision 1.3 1996/04/24 20:30:48 seawifsd
7 c comments out 4 lines using 'd'(instead of 'c') based on the recommendation
8 c from Bob that the orbit number returned by this function will be consistent
9 c with the orbit number in the schedule file.
10 c
11 c Revision 1.2 1996/01/05 20:12:34 seawifsd
12 c Corrected element-file search to handle year boundaries
13 c
14 c Revision 1.1 1995/01/17 23:02:17 seawifsd
15 c Initial revision
16 c
17 c Revision 1.1 1994/08/30 20:53:29 seawifsd
18 c Initial revision
19 c
20 c Revision 1.1 1994/07/13 19:07:24 seawifst
21 c Initial revision
22 c
23 c Revision 1.3 1994/05/23 20:08:16 seawifst
24 c New version from Watson. <Mark>
25 c
26 c Revision 1.3 1994/04/18 17:10:13 seawifst
27 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ $Log: getorbit.f,v $
28 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.4/swfnav/getorbit.f,v 1.2 1996/01/05 20:12:34 seawifsd Exp seawifsd $ Revision 1.3 1996/04/24 20:30:48 seawifsd
29 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.4/swfnav/getorbit.f,v 1.2 1996/01/05 20:12:34 seawifsd Exp seawifsd $ comments out 4 lines using 'd'(instead of 'c') based on the recommendation
30 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.4/swfnav/getorbit.f,v 1.2 1996/01/05 20:12:34 seawifsd Exp seawifsd $ from Bob that the orbit number returned by this function will be consistent
31 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.4/swfnav/getorbit.f,v 1.2 1996/01/05 20:12:34 seawifsd Exp seawifsd $ with the orbit number in the schedule file.
32 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.4/swfnav/getorbit.f,v 1.2 1996/01/05 20:12:34 seawifsd Exp seawifsd $
33 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Revision 1.2 1996/01/05 20:12:34 seawifsd
34 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Corrected element-file search to handle year boundaries
35 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $
36 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Revision 1.1 1995/01/17 23:02:17 seawifsd
37 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Initial revision
38 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $
39 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Revision 1.1 1994/08/30 20:53:29 seawifsd
40 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Initial revision
41 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $
42 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Revision 1.1 1994/07/13 19:07:24 seawifst
43 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $ Initial revision
44 c Added $Header: /app/shared/RCS/irix-5.2/seawifsd/src/mops/mopsV4.5/swfnav/getorbit.f,v 1.3 1996/04/24 20:30:48 seawifsd Exp seawifsd $
45 c Revision 1.3 1994/05/23 20:08:16 seawifst
46 c New version from Watson. <Mark>
47 c
48 c Orbit number fraction is computed by first computing true
49 c anomaly instead of mean anomaly, and adding to the argument
50 c of perigee.
51 c
52 c Revision 1.4 1994/07/28 20:08:16 seawifst
53 c New version from Watson. <Mark>
54 c
55 c NORAD Two-line elements are returned from the subroutine.
56 c They are as character*69.
57 c
58 c
59 c.......................................................................
60 c Originally: rdnor.f - 20 August 92
61 c
62 c Altered and revised to: rnorad.f
63 c Kenneth S. Lambert
64 c Sea Grant - University of Maryland
65 c 15 July 1993
66 c
67 c Altered and revised to: getorbit.f
68 c Watson Gregg
69 c Code 902.3
70 c NASA/GSFC
71 c December 1993
72 c Modified for better orbit number calculation, using argument
73 c of perigee and mean anomaly, 4/18/94, WWG
74 c
75 c Modified to compute and use true anomaly in orbit number
76 c calculation, 5/93, Robert Woodward, GSC
77 c
78 c NORAD Two-line elements are returned from the subroutine.
79 c They are as character*69, 7/28/94, WWG
80 c
81 c Corrected element-file search to handle year boundaries
82 c 1/3/96, BAF
83 c
84 c Given year, day of year, and time (GMT, in milliseconds), computes
85 c orbit number for SeaStar/SeaWiFS, for use by the SeaWiFS Data
86 c Processing System. Requires a recent NORAD Two-Line Element
87 c File for SeaStar. I recommend that the element file be no more
88 c than 1 week old, but if the file is updated monthly only a few (1-3)
89 c minutes of error should result. A few minutes is of no
90 c consequence to HRPT stations, since the error occurs at the
91 c crossing of the equator on ascending node (always night), but
92 c may result in error of lunar calibration files created by the
93 c SDPS.
94 c
95 c
96 c Calling argument list:
97 c Input
98 c iyr (I4,1) - year of data
99 c iday (I4,1) - day of year of data
100 c msec (I4,1) - time of day in milliseconds (GMT) of data
101 c Output
102 c iorbno (I4,1) - orbit number for the data file
103 c inorad (I4,1) - error return flag:
104 c .eq. 0 - proper return
105 c .ne. 0 - error reading input format
106 c cline1 (A69) - first line of NORAD Two-Line Elements
107 c cline2 (A69) - second line of NORAD Two-Line Elements
108 c
109 c Local Variables
110 c ifound (I4,1) - flag describing whether satellite was found
111 c iepyr (I4,1) - four digit epoch year of element set
112 c epday (R8,1) - epoch day (day of year & fraction: XXX.XXXXXXXX)
113 c elem (R8,6) - element array:
114 c (1) semi-major axis (km)
115 c (2) eccentricity
116 c (3) inclination (deg)
117 c (4) right ascension of ascending node (deg)
118 c (5) argument of perigee (deg)
119 c (6) mean anomaly (deg)
120 c iorbit (i4,1) - orbit number (revolution number) for epoch
121 c pi (R8,1) - Pi
122 c radeg (R8,1) - Radians to degrees conversion factor
123 c re (R8,1) - Earth equatorial radius (km)
124 c gm (R8,1) - Earth gravitational constant (km3/s2)
125 c bj2 (R8,1) - 2nd Spherical Harmonic Term
126 c
127 c.......................................................................
128 
129  implicit real*8 (a-h,o-z)
130  save !required for IRIX compilers
131  parameter(maxfilesrch=30)
132  logical*1 found
133  character*69 cline1,cline2
134  character*128 noradf
135  real*8 elem(6)
136  real*8 rmanom8,reanom8,dkeplr
137  data isatnum/24883/
138  data imon/1/
139 
140 c Constants
141  pi = dacos(-1.0d0)
142  re = 6378.137d0
143  radeg = 180.0d0/pi
144  gm = 398600.5d0
145  bj2 = 1082.63d-6
146 c
147 c Variable declarations
148  pi2 = 2.0d0*pi ! 2*pi
149  inorad = 0 ! error flag
150 
151 c Open NORAD Two-Line Element file; search back in time to find
152 c most recent file
153 
154  jyr = iyr
155  jday = iday
156  icnt = 0 ! Count of number of days searched
157  found = .false.
158 
159 c !
160 c ! Begin search
161 c !
162  do while ( (icnt .lt. maxfilesrch) .and. (.not. found) )
163 
164  icnt = icnt+1
165 
166 c !
167 c ! If the file day goes to zero, convert to previous year
168 c !
169  if (jday .lt. 1) then
170 
171  jyr = iyr-1
172 
173 c !
174 c ! Check for leap year before setting new day number
175 c !
176  rlp = jyr/4.0
177  ilp = rlp
178  rchk = rlp - ilp
179 
180  if (rchk .eq. 0.0) then
181  jday = 366 ! leap year
182  else
183  jday = 365 ! non-leap year
184  endif
185 
186  endif
187 
188 c !
189 c ! Try to open the file
190 c !
191  call selfilnm(jyr,jday,noradf)
192  open(4,file=noradf,status='old',form='formatted',err=300)
193  found = .true.
194 300 continue
195 
196  jday = jday-1
197 
198  enddo
199 
200 c !
201 c ! Verify that a file was found. Exit on error.
202 c !
203  if (.not. found) then
204 
205  write(6,*)
206  write(6,*)' ERROR '
207  write(6,*)
208  write(6,*)' RECENT NORAD TWO LINE ELEMENT FILE NOT FOUND'
209  write(6,*)' FOR SEASTAR: '
210  write(6,*)' File does not exist or most recent file'
211  write(6,*)' exceeds 1 month old'
212  write(6,*)' Obtain updated element file'
213 
214  inorad = 1
215  return
216 
217  endif
218 
219 c !
220 c ! Search through file and read two line elements. look for satellite no.
221 c !
222  ieof = 0
223  ifound = 0
224  do while ((ieof .eq. 0) .and. (ifound .eq. 0))
225  read(4,'(a)',end=100,err=101) cline1
226  if (cline1(1:1) .eq. '1') then
227  read(4,'(a)',end=100,err=101) cline2
228  if (cline2(1:1) .eq. '2') then
229  read(cline1(3:7),'(i5)') isat
230  if (isat .eq. isatnum) ifound = 1
231  read(cline1(10:11),'(i2)') idyr
232  read(cline1(19:32),'(i2,f12.8)') iepyr2, epday
233  read(cline1(34:43),'(f9.8)')rndot2
234  read(cline2(8:63),'(2f9.4,i8,2f9.4)') elem(3),elem(4),
235  . iecc,
236  . elem(5),elem(6)
237  read(cline2(52:63),'(f12.8)') xmm
238  read(cline2(64:68),'(i5)') iorbit
239  else
240  backspace(4)
241  endif
242  endif
243 
244  enddo
245 
246 c Satellite found
247  if (ifound .eq. 1) then
248 
249 c Convert integer eccentricity (from assumed decimal) to real.
250  elem(2) = dble(iecc)*1.0d-7
251 
252 c Compute semi-major axis using method of SGP4
253  if (xmm .gt. 1.0d-10) then !trap for divide by zero
254  xno = xmm*pi2/1440.0d0 !mean motion in radians/min
255  tothrd = 2.0d0/3.0d0
256  xincl = elem(3)/radeg !inclination
257  eo = elem(2)
258  ck2 = abs(0.5d0*bj2) !1/2*j2*ae**2
259  xke = sqrt(gm/re**3)*60.0d0
260  a1 = (xke/xno)**tothrd
261  cosio = cos(xincl)
262  theta2 = cosio*cosio
263  x3thm1 = 3.0d0*theta2-1.0d0
264  eosq = eo*eo
265  betao2 = 1.0d0-eosq
266  betao = sqrt(betao2)
267  del1 = 1.5d0*ck2*x3thm1/(a1*a1*betao*betao2)
268  ao = a1*(1.0d0-del1*(0.5d0*tothrd+del1*
269  * (1.0d0+134.0d0/81.0d0*del1)))
270  delo = 1.5d0*ck2*x3thm1/(ao*ao*betao*betao2)
271  xnodp = xno/(1.0d0+delo)
272  aodp = ao/(1.0d0-delo) !semi-major axis in Earth radii
273  elem(1) = aodp*re !semi-major axis in km
274  else
275  inorad = 2
276  endif
277 c write(6,*)'semi-major axis = ',elem(1)
278 c Compute period using method of Casey and Way, 1991 (IEEE Trans.
279 c Geoscience and Remote Sensing)
280  dsma2 = elem(1)*elem(1)
281  dsma3 = dsma2*elem(1)
282  classpd = 2.0*pi*sqrt(dsma3/gm) !classical period
283  cosarg = 4.0d0*cosio*cosio - 1.0
284  pcorr = 1.0 - 3.0/2.0*bj2*re*re/dsma2*cosarg
285  pdsec = classpd*pcorr
286 c
287 c Output iepyr as four digits, keep within range of 1950 - 2049
288  if (iepyr2 .lt. 50) then
289  iepyr = 2000 + iepyr2
290  else
291  iepyr = 1900 + iepyr2
292  endif
293 c
294 c Convert to Julian day
295 c Compute floating point days since Jan 1.5, 2000
296 c Note that the Julian day starts at noon on the specified date
297  sec = msec*0.001d0
298  tdata = jd(iyr,imon,iday) - 2451545.0d0
299  * + (sec-43200.d0)/86400.d0
300 c write(6,*)'iyr,iday,msec,sec,tdata = ',iyr,iday,msec,sec,tdata
301  iepday = epday
302  fracday = epday - iepday
303  sec = fracday*86400.0d0
304  tepoch = jd(iepyr,imon,iepday) - 2451545.0d0
305  * + (sec-43200.d0)/86400.d0
306 c Compute orbit number as function of time difference
307 c New as of May, 1994 -- use true anomaly instead of mean anomaly
308 c fracorb = (elem(5) + elem(6))/360.0D0
309  rmanom8 = elem(6)/radeg !mean anomaly in radians
310  reanom8 = dkeplr(rmanom8,elem(2)) !eccentric anomaly
311  a = ((1-elem(2))/(1+elem(2)))**0.5
312  rtanom = 2.0 * datan(dtan((reanom8/2.0)/a)) * radeg !true anom.
313  if (rtanom .lt. .0)rtanom = rtanom + 360.0
314  fracorb = (elem(5) + rtanom)/360.0d0
315 c if (fracorb .ge. 1.0D0)then
316 c rorbit = iorbit + (fracorb-1.0D0)
317 c else
318  rorbit = iorbit + fracorb
319 c endif
320  diff = (tdata-tepoch)*86400.0d0
321  rorb = diff/pdsec + rorbit
322  iorbno = rorb
323  else !SeaStar satellite number not found in NORAD TLE file
324  print *, 'SeaStar not found in NORAD TLE file...'
325  inorad = 1
326  endif
327  go to 400
328 
329 
330 100 ieof = 1
331  print *, 'SeaStar not found in NORAD TLE file...'
332  inorad = 1
333  go to 400
334 
335 101 print *, 'Error reading ',radfilnm
336  goto 400
337 
338 400 close(4)
339  return
340  end
341 c
342 c ******************************************************************
343  subroutine selfilnm(myr,idoy,fnme)
344 c
345 c Given year, day of year, returns appropriate file name for
346 c daily NORAD Two-Line Element file for SeaStar.
347 c
348  character*128 fnme
349  character cday1*1,cday2*2,cday3*3,cday*3,c1*1,cyr*2
350  character*10 chead
351  character*4 cdat
352  character*1 zero
353 c
354 c chead = '/ftp/pub/mission-ops/sel'
355  chead = '$NORAD/sel'
356  cdat = '.dat'
357  zero = '0'
358 c
359 c Convert day
360  jday = idoy
361  if (jday .lt. 10)then
362  write(cday1,'(i1)')jday
363  cday = zero//zero//cday1
364  else if (jday .lt. 100)then
365  write(cday2,'(i2)')jday
366  cday = zero//cday2
367  else
368  write(cday3,'(i3)')jday
369  cday = cday3
370  endif
371 c
372 c Convert year
373  if (myr .le. 1999)then
374  itmp = myr - 1900
375  write(cyr,'(i2)')itmp
376  else if (myr .eq. 2000)then
377  cyr = zero//zero
378  else if (myr .lt. 2010)then
379  itmp = myr - 2000
380  write(c1,'(i1)')itmp
381  cyr = zero//c1
382  else
383  itmp = myr - 2000
384  write(cyr,'(i2)')itmp
385  endif
386 c
387 c File name
388  fnme = chead//cday//cyr//cdat
389  call filenv(fnme,fnme)
390 c
391  return
392  end
393 c
394 c
395 C ******************************************************************
396  FUNCTION dkeplr(M,E)
397  IMPLICIT REAL*8(a-h,o-z)
398  SAVE ! REQUIRED FOR IRIX
399  real*8 m,pi2/6.283185307179586d0/,tol/0.5d-15/
400 C
401 C SUBROUTINE TO SOLVE KEPLER'S EQUATION
402 C KEPLER'S EQUATION RELATES GEOMETRY OR POSITION IN ORBIT PLANE
403 C TO TIME.
404 C
405 C M - MEAN ANOMALY (O<M<2PI)
406 C E - ECCENTRICITY
407 C EA - ECCENTRIC ANOMALY
408 C
409  ea=0
410  IF(m)1,2,1
411  1 ea=m + e*dsin(m)
412  DO 22 i=1,12
413  oldea=ea
414  fe=ea-e*dsin(ea)-m
415  ea=ea-fe/(1-e*dcos(ea-0.5d0*fe))
416 C TEST FOR CONVERGENCE
417  delea=dabs(ea-oldea)
418  IF(delea.LE.tol)GO TO 2
419  22 CONTINUE
420  2 ea=dmod(ea,pi2)
421  dkeplr=ea
422  RETURN
423  END
424 C
function dkeplr(M, E)
Definition: getorbit.f:401
int32_t jday(int16_t i, int16_t j, int16_t k)
Definition: jday.c:4
#define real
Definition: DbAlgOcean.cpp:26
subroutine filenv(infil, outfil)
Definition: filenv.f:2
README for MOD_PR03(V6.1.0) 2. POINTS OF CONTACT it can be either SDP Toolkit or MODIS Packet for Terra input files The orbit validation configuration parameter(LUN 600281) must be either "TRUE" or "FALSE". It needs to be "FALSE" when running in Near Real Time mode
#define re
Definition: l1_czcs_hdf.c:701
Definition: jd.py:1
subroutine diff(x, conec, n, dconecno, dn, dconecmk, units, u, inno, i, outno, o, input, deriv)
Definition: ffnet.f:205
#define pi
Definition: vincenty.c:23
subroutine selfilnm(myr, idoy, fnme)
Definition: getorbit.f:349
subroutine getorbit(iyr, iday, msec, iorbno, inorad, cline1, cline2)
Definition: getorbit.f:2
#define abs(a)
Definition: misc.h:90