incorrect header format: python

From: <joana.figueira_at_upc.edu>
Date: Wed, 23 May 2012 16:18:50 +0200

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.
...so 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.




Received on 2012-05-23 16:30:02

This archive was generated by hypermail 2.3.0 : 2022-09-01 14:03:42 CEST