Re: incorrect header format: python

From: <joana.figueira_at_upc.edu>
Date: Thu, 24 May 2012 13:09:08 +0200

Hi everyone,

so the problem was in the way I was storing the data. I didn't realize
that I needed to store 4byte integers in between each data block.

Thanks so much for all your help!

Cheers,
Joana.

Quoting Florian Bürzle <florian.buerzle_at_uni-konstanz.de>:

>
> Dear Joana,
>
> I haven't investigated this in detail, but you define the floating
> point variables as 'c_float' whereas (according to the GADGET
> documentation) they should be 'c_double'. Then, you need to
> re-calculate the number of bytes within your header and to modify
> the struct format string accordingly (i. e. change every 'f' to 'd').
>
> Hope this helps!
>
> Cheers
> Florian
>
> Am 23.05.2012 um 16:18 schrieb joana.figueira_at_upc.edu:
>
>> 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.
>>
>> <setup_IC.py>
>> -----------------------------------------------------------
>>
>> If you wish to unsubscribe from this mailing, send mail to
>> minimalist_at_MPA-Garching.MPG.de with a subject of: unsubscribe gadget-list
>> A web-archive of this mailing list is available here:
>> http://www.mpa-garching.mpg.de/gadget/gadget-list
>
> -----------------------------------------------------------------------------------------------------------
> Florian Bürzle
> University of Konstanz
> Department of Physics, Group Prof. Nielaba
> Universitätsstr. 10
> 78464 Konstanz, Germany
> tel: +49 7531 88 3790
> web: http://cms.uni-konstanz.de/physik/nielaba/mitarbeiter/florian-buerzle/
> -----------------------------------------------------------------------------------------------------------
>
>
>
>
> -----------------------------------------------------------
>
> If you wish to unsubscribe from this mailing, send mail to
> minimalist_at_MPA-Garching.MPG.de with a subject of: unsubscribe gadget-list
> A web-archive of this mailing list is available here:
> http://www.mpa-garching.mpg.de/gadget/gadget-list
>
Received on 2012-05-24 13:09:11

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