def write_block(f, block, parttype, data): part_name="PartType"+str(parttype) if (hdf5lib.Contains(f, "", part_name)==False): group=hdf5lib.CreateGroup(f, part_name) else: group=hdf5lib.GetGroup(f, part_name) if (datablocks.has_key(block)): block_name=datablocks[block][0] dim2=datablocks[block][1] if (hdf5lib.ContainsGroup(group, block_name)==False): hdf5lib.CreateArray(f, group, block_name, data) else: print("I/O block already written") sys.stdout.flush() else: print("Unknown I/O block") sys.stdout.flush()
def writeheader(f, header): group_header=hdf5lib.CreateGroup(f, "Header") hdf5lib.SetAttr(group_header, "NumPart_ThisFile", header.npart) hdf5lib.SetAttr(group_header, "NumPart_Total", header.nall) hdf5lib.SetAttr(group_header, "NumPart_Total_HighWord", header.nall_highword) hdf5lib.SetAttr(group_header, "MassTable", header.massarr) hdf5lib.SetAttr(group_header, "Time", header.time) hdf5lib.SetAttr(group_header, "Redshift", header.redshift) hdf5lib.SetAttr(group_header, "BoxSize", header.boxsize) hdf5lib.SetAttr(group_header, "NumFilesPerSnapshot", header.filenum) hdf5lib.SetAttr(group_header, "Omega0", header.omega0) hdf5lib.SetAttr(group_header, "OmegaLambda", header.omegaL) hdf5lib.SetAttr(group_header, "HubbleParam", header.hubble) hdf5lib.SetAttr(group_header, "Flag_Sfr", header.sfr) hdf5lib.SetAttr(group_header, "Flag_Cooling", header.cooling) hdf5lib.SetAttr(group_header, "Flag_StellarAge", header.stellar_age) hdf5lib.SetAttr(group_header, "Flag_Metals", header.metals) hdf5lib.SetAttr(group_header, "Flag_Feedback", header.feedback) hdf5lib.SetAttr(group_header, "Flag_DoublePrecision", header.double)
def write_block(f, block, parttype, data, data_name=None ): print("writing block!") part_name="PartType"+str(parttype) if (hdf5lib.Contains(f, "", part_name)==False): group=hdf5lib.CreateGroup(f, part_name) else: group=hdf5lib.GetGroup(f, part_name) if data_name!=None: for block in datablocks: # print block # print datablocks[block] if datablocks[block][0] == data_name: break #dim2=datablocks[block][1] #if (hdf5lib.ContainsGroup(group, block_name)==False): # hdf5lib.CreateArray(f, group, block_name, data) #else: # print "I/O block already written" # sys.stdout.flush() # sys.exit() # print block if (datablocks.has_key(block)): block_name=datablocks[block][0] dim2=datablocks[block][1] if (hdf5lib.ContainsGroup(group, block_name)==False): hdf5lib.CreateArray(f, group, block_name, data) else: print("I/O block already written") sys.stdout.flush() else: print("Unknown I/O block") sys.stdout.flush()