From 3698671bed07ac9b473bca80314c371a0b6a43fc Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Mon, 30 Jan 2012 16:04:17 -0500 Subject: [PATCH] * Added: fortran_bin_file.peek_next_rec_len() to fetch the next record length while not advancing the read pointer to that record yet. --- iofmt/fortbin.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/iofmt/fortbin.py b/iofmt/fortbin.py index 103c3c0..0e3940d 100644 --- a/iofmt/fortbin.py +++ b/iofmt/fortbin.py @@ -220,6 +220,15 @@ class fortran_bin_file(object): self.write_vals(*vals, **opts) + def peek_next_rec_len(self): + """Fetches the length of the next record, while preserving + the position of the file read pointer. + """ + filepos = self.F.tell() + reclen = numpy.fromfile(self.F, self.record_marker_type, 1) + self.F.seek(filepos) + return reclen[0] + def array_major_dim(arr): """Tests whether a numpy array is column or row major.