Dear Dr. I'm a Researcher from Cairo, Egypt. I installed the language programmer (Python) on my PC. I executed the following statements to read unformatted fortran data. I have the original program which I translate it to the Python language : pro rd_gadget, f=fname, d = data, h= hdr, swap=swap
;modified from Volker's read_snapshot_single.pro to be a free-standing ;program that reads fname, and returns data and header structures M-MML 6/16/06 ;added option to swap byte order to read Intel files on PowerPC ;11/8/06 M-MML if not keyword_set(fname) then fname="/home/vspringe/ICs/galaxy.dat.intel" npart=lonarr(6) massarr=dblarr(6) time=0.0D redshift=0.0D flag_sfr=0L flag_feedback=0L npartTotal=lonarr(6) bytesleft=256-6*4 - 6*8 - 8 - 8 - 2*4-6*4 la=intarr(bytesleft/2) openr,1,fname,/f77_unformatted, swap_endian = swap readu,1,npart,massarr,time,redshift,flag_sfr,flag_feedback,npartTotal,la hdr = { np: npart, mass: massarr, time: time, z: redshift, sfr: $ flag_sfr, fb: flag_feedback, nptot: npartTotal, la: la} N=total(npart) pos=fltarr(3,N) vel=fltarr(3,N) id=lonarr(N) ind=where((npart gt 0) and (massarr eq 0)) if ind(0) ne -1 then begin Nwithmass= total(npart(ind)) mass=fltarr(Nwithmass) endif else begin Nwithmass= 0 endelse nfield = 0 readu,1,pos nm = 'position' nfield = nfield + 1 readu,1,vel nm = [nm, 'velocity'] nfield = nfield + 1 readu,1,id nm = [nm, 'id'] nfield = nfield + 1 if Nwithmass gt 0 then begin readu,1,mass nm = [nm, 'mass'] nfield = nfield + 1 endif NGas=npart(0) if Ngas gt 0 then begin u=fltarr(Ngas) readu,1,u nm = [nm, 'gas specific energy'] nfield = nfield + 1 rho=fltarr(Ngas) readu,1,rho nm = [nm, 'gas density'] nfield = nfield + 1 endif close,1 if (nfield lt 3) or (nfield gt 6) then $ print,'RD_GADGET: Unexpected number of data fields, nfield = ',nfield $ else if nfield eq 3 then $ data = { nf: nfield, nm: nm, pos: pos, vel: vel, id: id } $ else if nfield eq 4 then $ data = { nf: nfield, nm: nm, pos: pos, vel: vel, id: id, mass: mass } $ else if nfield eq 6 then $ data = { nf: nfield, nm: nm, pos: pos, vel: vel, id: id, mass: mass, $ spe: u, den: rho } end Below you will find my attempt to translate the first part of this program to Python language import scipy.io.mio import Numeric from Numeric import * file_hdg = 'D:/mm/hdg' # Integer (Long) Arrays npart = array (6) # Floating point (double precision) array massarr = array(6) time=0.0 redshift=0.0 flag_sfr=0L flag_feedback=0L npartTotal=array(6) bytesleft=256-6*4 - 6*8 - 8 - 8 - 2*4-6*4 la=array(bytesleft/2) def readdata ( filePath ): fileHandle = scipy.io.mio.fopen( filePath, 'r') def fort_read(self,fmt,dtype=None): numberOfBlocks = fileHandle.fort_read( 1 , 'l' ) print numberOfBlocks readdata (file_hdg),npart,massarr,time,redshift,flag_sfr,flag_feedback,npartTotal,la All these commands are accepted, the result with the last command : readdata(file_hdg),npart,massarr,time,redshift,flag_sfr,flag_feedback,npartTotal,la Is (None, 6, 6, 0.0, 0.0, 0L, 0L, 6, 68) I will be very appreciated if you send me your opinion about this and what the ( None ) means in this result. Best Regards Magdy Sanad National Research Institute of Astronomy and Geophysics Astronomy Department Helwan - Cairo - Egypt --------------------------------- Looking for earth-friendly autos? Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
-- http://mail.python.org/mailman/listinfo/python-list