Bonjour,
J'ai un fichier binaire qui a ce format :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
71 int np float np float np float np float np float
"np float" étant un ceratin nombre de floats, ici np = 52428800.
J'ai fait le code suivant pour le lire, mais je ne sais pas pourquoi, ça ne marche pas, il semble pas bien lire les données....
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #! /use/bin/env python import numpy as np import struct as st filename = '/ou/mes/donnees/sont/fichier.dat' nbpart = 0 file = open(filename,"rb") nbpart=np.fromfile(filename,dtype='int32',count=1) print nbpart x = np.fromfile(file, np.float32, nbpart[0]) y = np.fromfile(file, np.float32, nbpart[0]) vx = np.fromfile(file, np.float32, nbpart[0]) vy = np.fromfile(file, np.float32, nbpart[0]) vz = np.fromfile(file, np.float32, nbpart[0]) print x.min(), x.max() print y.min(), y.max() file.close()
voici ce que ça m'affiche :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 me@here:~/code/visu/particules$ python derive_z.py [52428800] 4.70197740329e-37 280.0 7.68104314375e-07 275.521087646
alors que ça devrait m'afficher :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 [52428800] 1e-6 280.0 1e-6 40.0
Merci si vous pouvez m'aiguiller :-)
Partager