OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
check_polarwander.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 """
3 Verify validity of USNO polar wander file
4 Format description: http://maia.usno.navy.mil/ser7/readme.finals2000A
5 """
6 
7 import re
8 import sys
9 
10 
11 def isValidLine(line):
12  valid = True
13  ipflag = re.compile("^[IP]$") # IERS (I) or Prediction (P) flag
14 
15  try:
16 
17  int(line[0:2]) # year
18  int(line[2:4]) # month number
19  int(line[4:6]) # day of month
20  float(line[6:16]) # fractional Modified Julian Date (MJD UTC)
21 
22  valid &= ipflag.match(line[16]) is not None
23  # IP flag for Bull. A polar motion values
24  float(line[17:27]) # Bull. A PM-x (sec. of arc)
25  float(line[27:36]) # error in PM-x (sec. of arc)
26  float(line[36:46]) # Bull. A PM-y (sec. of arc)
27  float(line[46:57]) # error in PM-y (sec. of arc)
28 
29  valid &= ipflag.match(line[57]) is not None
30  # IP flag for Bull. A UT1-UTC values
31  float(line[58:68]) # Bull. A UT1-UTC (sec. of time)
32  float(line[68:78]) # error in UT1-UTC (sec. of time)
33 
34  if len(line[78:95].split()) > 0: # optional section
35  float(line[78:86]) # Bull. A LOD (msec. of time)
36  float(line[86:95]) # error in LOD (msec. of time)
37 
38  if len(line[95:134].split()) > 0: # optional section
39  valid &= ipflag.match(line[95]) is not None
40  # IP flag for Bull. A nutation values
41  float(line[96:106]) # Bull. A dX wrt IAU2000A Nutation (msec. of arc)
42  float(line[106:115]) # error in dX (msec. of arc)
43  float(line[115:125]) # Bull. A dY wrt IAU2000A Nutation (msec. of arc)
44  float(line[125:134]) # error in dY (msec. of arc)
45 
46  if len(line[134:].split()) > 0: # optional section
47  float(line[134:144]) # Bull. B PM-x (sec. of arc)
48  float(line[144:154]) # Bull. B PM-y (sec. of arc)
49  float(line[154:165]) # Bull. B UT1-UTC (sec. of time)
50  float(line[165:175]) # Bull. B dX wrt IAU2000A Nutation (msec. of arc)
51  float(line[175:185]) # Bull. B dY wrt IAU2000A Nutation (msec. of arc)
52 
53  except (ValueError, IndexError):
54  return False
55  except Exception as e:
56  print('Unexpected Exception: {:}'.format(e))
57  return False
58 
59  return valid
60 
61 
62 if __name__ == '__main__':
63 
64  if len(sys.argv) != 2:
65  print('Checks a USNO Polar Wander file for validity.')
66  print('Exits with status = 1 upon first invalid line.')
67  callseq = sys.argv[0] + ' filename'
68  print('Usage:', callseq)
69  sys.exit(1)
70 
71  infile = open(sys.argv[1], 'r')
72  for line in infile:
73  if not isValidLine(line):
74  print('Format error in line:')
75  print(line)
76  infile.close()
77  sys.exit(1)
78 
79  infile.close()
80  sys.exit(0)