Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def loadout():
- # This is the working directory to load files. I'll add an option to change this via console input.
- dir = "/home/bradley/Desktop/BradSim/drop-6.00-3/"
- list = []
- # Changes the directory to the specified cwd
- os.chdir(dir)
- # Iterates through the files to determine how many .bin files exist, storing that counter into an array
- for files in glob.glob("*.bin"):
- list.append(int(files[11:][:-4]))
- list.sort()
- list = list[:-1]
- tot = len(list)
- # Hex size of a double
- dubs = calcsize('d')
- # Empty arrays to fill when the work's being done
- vcube = []
- ccube = []
- rcube = []
- # Iterate through all .bin files in the directory
- for z in range(tot):
- print(z)
- # Iterate opening the files and reading them into an array, converting the first value (an int) from hex to a usable format as 'num'
- f = open("CartAndRad."+str(list[z])+".bin", "rb").read()
- num = unpack("I", f[:4])
- num = num[0]
- # Hex size of an int. This will be used as a running length counter to read through the full binary file
- i = calcsize('I')
- # Empty arrays to fill up.
- # pcoord: particle coordinates for the file
- # pvel: particle velocities for the file
- # rad: particle radii for the file
- pcoord = []
- pvel = []
- rad = []
- cube = []
- # Index counter for adding absolute particle IDs with their coordinates for later tracking
- c = 0
- # Iterate through every particle in the file
- for y in range(num):
- # Empty the the array for each particle, it will temporarily hold the coordinates for that particle
- particle = []
- # Iterate through the coordinates (x,y,z,vx,vy,vz) of each particle
- for x in range(6):
- #Unpack convert each coordinate to a double and append it to the particle array
- temp = unpack('d', f[i:dubs+i])
- particle.append(temp[0])
- # Add on the hex length of a double to the running counter to then read the next double in the .bin
- i += dubs
- # Checks if the particle is above the "ground" (z = 0.25), ie, has it flown in an appreciable arc
- if particle[2]>=0.25:
- #print("Jerry, hello!")
- # Append the first three coordinate values (x,y,z) to the pcoord array
- pcoord.append(particle[:3])
- # Append the particle ID after the coordinates
- pcoord[c].append(y)
- # Append the last three coordinate values (vx,vy,vz) to the pvel array
- pvel.append(particle[3:])
- # Append, you guessed it, the particle ID afterwards
- pvel[c].append(y)
- # Increment the counter for the particle arrays
- c += 1
- # Iterates through the particles to store the radii as well. I really don't think I'll need this,
- # but it could be useful for rough momenta calculations.
- for y in range(num):
- temp = unpack('d', f[i:dubs+i])
- # Store the data if the particle is above z = 0.25
- if particle[2]>=0.25:
- rad.append(temp)
- # Incremement the running hex read counter
- i += dubs
- # Append all the coordinates to the great big inefficient data cubes
- ccube.append(pcoord)
- vcube.append(pvel)
- rcube.append(rad)
- # Return it all
- return ccube, vcube, rcube
Add Comment
Please, Sign In to add comment