-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixed_width_1.py
More file actions
executable file
·32 lines (32 loc) · 1.14 KB
/
fixed_width_1.py
File metadata and controls
executable file
·32 lines (32 loc) · 1.14 KB
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
def read_weather_data(r):
'''Read weather data from reader r in fixed-width format.
The fields are:
1 8 YYYYMMDD (date)
9 14 DDMMSS (latitude)
15 20 DDMMSS (longitude)
21 26 FF.FFF (temp, deg. C)
27 32 FF.FFF (humidity, %)
33 38 FF.FFF (pressure, kPa)
The result is a list of tuples of tuples,
where each tuple of tuples is of the form:
((Yr, Mo, Day), (Deg, Min, Sec), (Deg, Min, Sec), (Temp, Hum, Press))
'''
result = []
for line in r:
year = int(line[0:4])
month = int(line[4:6])
day = int(line[6:8])
lat_deg = int(line[8:10])
lat_min = int(line[10:12])
lat_sec = int(line[12:14])
long_deg = int(line[14:16])
long_min = int(line[16:18])
long_sec = int(line[18:20])
temp = float(line[20:26])
hum = float(line[26:32])
press = float(line[32:38])
result.append(((year, month, day),
(lat_deg, lat_min, lat_sec),
(long_deg, long_min, long_sec),
(temp, hum, press)))
return result