I succeed in extracting all of the header information, and then only a portion of the data. The data section is 123,410 doubles, but after retrieving 62 of the numbers, I can not go further, struct.unpack indicates that the string argument is the wrong length. I set up a loop to get the numbers one at a time, and it stops at the same place. The file is not corrupt, and will open in the original software. Does anyone have suggestions for figuring out the problem? -
import struct, string, os
-
-
bf = "F:/Junker/TestT/TU_TSA.grd"
-
wbf = open(bf).read() # "rb")
-
start, stop = 0, struct.calcsize('<7l8d2l')
-
-
#Retrieve the header information
-
try:
-
TheadID,TheadSize,HSver,TgridID,TgridSize,nRow,nCol,xLL,yLL,xSize,ySize,zMin,zMax,\
-
Rotation,BlankVal,TdataID,TdataSize = struct.unpack('<7l8d2l', wbf[start:stop])
-
except:
-
print "Problem reading Header"
-
print "TheadID ", TheadID, "\n ", "TheadSize ",TheadSize,"\n ","HSver ", HSver,"\n ","TheadID ",TgridID,"\n ","TgridSize ",TgridSize,"\n ","nRow ",nRow,"\n ","nCol ",nCol,"\n ","xLL ",xLL,"\n ","yLL ",yLL,"\n ","xSize ",xSize,"\n ","ySize ",ySize,"\n ","zMin ",zMin,"\n ","zMax ",zMax,"\n ","Rotation ",Rotation,"\n ","BlankVal ",BlankVal,"\n ","TdataID ",TdataID,"\n ","TdataSize",TdataSize
-
-
#Retrieve the data
-
try:
-
x = nCol * nRow
-
while x:
-
start, stop = stop, stop + struct.calcsize('<d')
-
DataBlock = struct.unpack('<d', wbf[start:stop])
-
print DataBlock, " start ",start, " stop ",stop
-
-
except:
-
print "Failed at: start ",start, " stop ",stop
-
-
del TheadID,TheadSize,HSver,TgridID,TgridSize,nRow,nCol,xLL,yLL,xSize,ySize,zMin,zMax,\
-
Rotation,BlankVal,TdataID,TdataSize,start,stop
-
3 2336
Test the length of "wbf" and see if it is approximately the same size as the file. Also it is not being read in binary mode: - ## should be
-
wbf = open(bf, "rb").read() # "rb")
That is just embarrassing, I changed this so many times and tried so many things, that at some point I commented out the read binary mode, and never put it back. Grrrrrr.
Thank you for pointing out what I was too close to see.
The answer is usually embarrassingly simple _after_ you know it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jesse Noller |
last post by:
The problem: I am writing a file uploading utility in python that uses
the walk() function to parse a directory, finding any file under that
directory, and upload it to a remote server using the...
|
by: john_phx |
last post by:
I'm trying to increase the performance of a program that concatenates binary file parts into a single file. Each of the parts is contained in a binary file. The existing app simply takes the first...
|
by: Shmurthy |
last post by:
I have a binary file. How do i search for a string (pattern) and replace dynamically with new data.
Thank
Shmurthy
|
by: maxwell |
last post by:
I used to program in matlab
An read an image file with :
fread(a,,0)
which gave me a matrix of 256*256 full of numbers which were the pidxel
values from 0 to 256.
How do i do the same in c++
...
|
by: spike |
last post by:
Im trying to write a program that should
read through a binary file searching for the character sequence "\name\"
Then it should read the characters following the "\name\" sequence
until a NULL...
|
by: chinthamani |
last post by:
Hai,
I want to read from a particular point of the file not from the
beginning of the file. It may be from the second line or the third or from
any position, so how is it possible for me to reach...
|
by: cooldisk |
last post by:
Is it possible at all to read a binary file larger than 2GB on a 32-
bit system? I tried the following:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char...
|
by: =?ISO-8859-1?Q?Hans_M=FCller?= |
last post by:
Good morning folks,
I cannot read a binary file into a mysql database. Everything I tried did not succeed.
What I tried (found from various google lookups...) is this:
con =...
|
by: Sunny |
last post by:
Hi,
Can someone tell me how to get the content of entire xml file in
Firefox?
I am using this code to load the xml file.
if (document.implementation && document.implementation.createDocument)
{...
|
by: tom thomas |
last post by:
Dear sir,
i am very new to c# and i request you to... please look into the problem
The following is the code(please see the code below:) which i uses to open the binary file,currently it works...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |