Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import string
- from operator import add
- from math import floor
- class MyFormatter(string.Formatter):
- def format_field(self, value, format_spec):
- #print(value)
- #print(format_spec)
- ss = string.Formatter.format_field(self,value,format_spec)
- a,b = format_spec.split('.');
- newA = str(int(a)-1)
- #print(a)
- #print(newA)
- newSpec = "{}.{}".format(newA,b)
- #print(newSpec)
- ssNew = string.Formatter.format_field(self,value,newSpec)
- #print(ssNew)
- if format_spec.endswith('E'):
- if ( 'E' in ss):
- mantissa, exp = ss.split('E')
- num=int(exp[1:])
- if num >= 0 and num < 100:
- mantissa, exp = ssNew.split('E')
- return mantissa + 'E' + exp[0] + '0' + exp[1:]
- elif num > 100:
- return mantissa + 'E' + exp
- else :
- print("the exponential out of range")
- return mantissa + 'E' + exp
- return ss
- def writeData(filename,data):
- xmin=1
- ymin=1
- zmin=1
- xmax=data.shape[0]+xmin-1
- ymax=data.shape[1]+ymin-1
- zmax=data.shape[2]+zmin-1
- file=open(filename,"wb")
- dimension="{:6d}{:6d}{:6d}".format(xmax-xmin+1,ymax-ymin+1,zmax-zmin+1)
- file.write(dimension+" \n")
- FORMAT='{0:16.7E}'
- for i in range(xmin-1,xmax):
- for j in range(ymin-1,ymax):
- for k in range(zmin-1,zmax):
- position="{:6d}{:6d}{:6d}".format(i+2-xmin,j+2-ymin,k+2-zmin)
- value='{:>16}{:>16}{:>16}'.format(MyFormatter().format(FORMAT,data[i,j,k,0]),MyFormatter().format(FORMAT,data[i,j,k,1]),MyFormatter().format(FORMAT,data[i,j,k,2]))
- file.write('{}{}{} \n'.format(position,value,value))
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement