10
10
class UMFileException (Exception ):
11
11
pass
12
12
13
- # Integer header pointers
14
- LBLREC = 14
15
- LBPACK = 20
16
- LBEGIN = 28
13
+
14
+ # Lookup header pointers
15
+ LBLREC = 14 # Length of data record (including any extra data)
16
+ LBPACK = 20 # Packing method indicator
17
+ LBEGIN = 28 # Disk address/Start Record
18
+
17
19
18
20
class File :
19
21
"""A class for a UM file that gives a view of the file including
@@ -286,21 +288,21 @@ def __init__(
286
288
287
289
@classmethod
288
290
def from_file_and_offsets (
289
- cls , file , header_offset , data_offset = None , disk_length = None
291
+ cls , file , hdr_offset , data_offset = None , disk_length = None
290
292
):
291
293
"""Instantiate a `Rec` object from the `File` object and the
292
294
header and data offsets.
293
295
294
- The headers are read in, and also the record object is ready for
295
- calling `get_data`.
296
+ The lookup header are read in immediately , and the returned
297
+ record object is ready for calling `get_data`.
296
298
297
299
:Parameters:
298
300
299
301
file: `File`
300
302
A view of a file including sets of PP records combined
301
303
into variables.
302
304
303
- header_offset : `int`
305
+ hdr_offset : `int`
304
306
The file start address of the header, in bytes.
305
307
306
308
data_offset: `int`, optional
@@ -311,7 +313,7 @@ def from_file_and_offsets(
311
313
disk_length: `int`
312
314
The length in bytes of the data in the file. If
313
315
`None`, the default, then the disk length will be
314
- calculated from the integer header .
316
+ calculated from the integer.
315
317
316
318
:Returns:
317
319
@@ -321,32 +323,33 @@ def from_file_and_offsets(
321
323
c = file ._c_interface
322
324
word_size = file .word_size
323
325
int_hdr , real_hdr = c .read_header (
324
- file .fd , header_offset , file .byte_ordering , word_size
326
+ file .fd , hdr_offset , file .byte_ordering , word_size
325
327
)
326
328
327
329
if data_offset is None :
328
330
# Calculate the data offset from the integer header
329
331
if file .fmt == "PP" :
330
332
# We only support 64-word headers, so the data starts
331
- # 66 words after the header_offset, i.e. 64 words of the
332
- # header, plus 2 block control words.
333
- data_offset = header_offset + 66 * word_size
333
+ # 66 words after the header_offset, i.e. after 64
334
+ # words of the header, plus 2 block control words.
335
+ data_offset = hdr_offset + 66 * word_size
334
336
else :
335
337
# Fields file
336
338
data_offset = int_hdr [LBEGIN ] * word_size
337
339
338
340
if disk_length is None :
339
341
# Calculate the disk length from the integer header
342
+ disk_length = int_hdr [LBLREC ]
340
343
if int_hdr [LBPACK ] % 10 == 2 :
341
344
# Cray 32-bit packing
342
- disk_length = int_hdr [ LBLREC ] * 4
345
+ disk_length = disk_length * 4
343
346
else :
344
- disk_length = int_hdr [ LBLREC ] * word_size
347
+ disk_length = disk_length * word_size
345
348
346
349
return cls (
347
350
int_hdr ,
348
351
real_hdr ,
349
- header_offset ,
352
+ hdr_offset ,
350
353
data_offset ,
351
354
disk_length ,
352
355
file = file ,
@@ -360,8 +363,8 @@ def read_extra_data(self):
360
363
`numpy.ndarray`
361
364
362
365
"""
363
- c = self .file ._c_interface
364
366
file = self .file
367
+ c = file ._c_interface
365
368
366
369
(
367
370
extra_data_offset ,
@@ -424,17 +427,18 @@ def get_data(self):
424
427
`numpy.ndarray`
425
428
426
429
"""
427
- c = self .file ._c_interface
428
430
file = self .file
429
- data_type , nwords = c .get_type_and_num_words (self .int_hdr )
431
+ c = file ._c_interface
432
+ int_hdr = self .int_hdr
433
+ data_type , nwords = c .get_type_and_num_words (int_hdr )
430
434
431
435
return c .read_record_data (
432
436
file .fd ,
433
437
self .data_offset ,
434
438
self .disk_length ,
435
439
file .byte_ordering ,
436
440
file .word_size ,
437
- self . int_hdr ,
441
+ int_hdr ,
438
442
self .real_hdr ,
439
443
data_type ,
440
444
nwords ,
0 commit comments