-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseHDSu.py
56 lines (52 loc) · 1.46 KB
/
parseHDSu.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 4 19:28:01 2019
@author: marius
"""
import numpy as np
import os
def parseHDSu(fn: str=None) -> np.array:
fSize = os.path.getsize(fn)
print(fSize)
ofst = 0
HDS = {}
while ofst < fSize:
dtmeta = np.dtype([
('kstp', 'i4'),
('kper', 'i4'),
('pertim', 'f4'),
('totim', 'f4'),
('text', 'S16'),
('nstrt', 'i4'),
('nndlay', 'i4'),
('ilay', 'i4')
])
meta = np.memmap(fn, mode='r', dtype=dtmeta, offset=ofst, shape=1)[0]
print('debug message', meta)
nstrt = meta['nstrt']
nndlay = meta['nndlay']
kper = meta['kper']
kstp = meta['kstp']
ilay = meta['ilay']
if ilay == 1:
h = np.empty(0)
n = nndlay - nstrt + 1
dt = np.dtype([
('kstp', 'i4'),
('kper', 'i4'),
('pertim', 'f4'),
('totim', 'f4'),
('text', 'S16'),
('nstrt', 'i4'),
('nndlay', 'i4'),
('ilay', 'i4'),
('data', 'f4', n)
])
arr = np.memmap(fn, mode='r', dtype=dt, offset=ofst, shape=1)[0]
h = np.concatenate((h, arr['data']))
ofst += dt.itemsize
HDS[kper, kstp] = h
return HDS
fName = 'data/biscayne.hds'
hds = parseHDSu(fName)