Re: incorrect header format: python

From: Jaime Perea <>
Date: Wed, 23 May 2012 19:24:20 +0200

On Miércoles, 23 de mayo de 2012 16:18:50 escribió:
> Hi everyone,
> I installed GADGET2 and it is running perfectly with the examples
> provided by GADGET itself and with the example provided by Nathan
> Goldbaum at astrobites.
> So now I'm creating my initial conditions script but I decided to
> create it in python. However, I always get the 'incorrect header
> format' message and I have no idea why. So what did I do?:
> in order to create the header I used c_type structures as follows:
> class Create_Header(Structure):
> SixDoubles=c_double*6
> SixInts=c_int*6
> OneDouble=c_double*1
> _fields_ = [("npart",SixInts),
> ("massarr",SixDoubles),
> ("time", c_float ),
> ("redshift", c_float),
> ...
> ("bytes",c_byte*(256- 6*4- ...))] #here I force the
> header to have 256 bytes
> where for each of the fields I assign a list of values or a value(eg:
> header.time=0.0).
> Later on I have to convert it to binary format, for that I'm using
> pack.struct(),like:
> p =
> struct.pack("iiiiiiffffffffiiiiiiiiiiffffiiiiiiiiiiif",header.npart[0],\
> header.npart[1],header.npart[2],header.npart[3],\
> header.npart[4],header.npart[5]...)
> I'm sure the header has 256 bytes: I checked using sizeof(header).
> This way of packing seems fine: I checked using struct.unpack.
> basically I have no idea what I am missing... do you have any ideas?
> I also tried to read my header in the IC script provided in
> astrobites, using 'readu' and then save it using writeu, turns out
> that GADGET stops working again... so I used the TRANSFER_COUNT while
> writing this header into the file and I always get:TRANSFER_COUNT=1,
> even if I change the variables or size of the header... I don't really
> know much of IDL, so I was wondering that maybe you could have some
> idea of what I am doing wrong...
> In attach I send you a simple example based on my script, where I show
> how I'm creating and saving the header so you can have a clear picture
> of what I'm doing with it...
> Thanks in advance,
> Joana.
Dear Joana

We made a long time ago a few scripts for handling the gadget2 file format,
it's not complete since I decided to leave the task of handling file and file
conversion to some ad-hoc fortran modules parsed with f2py.

Search for the read_gfile method in the attached script


           Jaime D. Perea Duarte.
             Linux registered user #10472
           Dep. Astrofisica Extragalactica.
           Instituto de Astrofisica de Andalucia (CSIC)
           Apdo. 3004, 18080 Granada, Spain.

Received on 2012-05-23 19:24:26

This archive was generated by hypermail 2.3.0 : 2023-01-10 10:01:31 CET