-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_nrg_x.py
executable file
·56 lines (51 loc) · 1.91 KB
/
get_nrg_x.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
import sys
def get_nrg0(suffix,nspec=2,ncols=10):
print( 'Getting data from nrg file')
time=np.empty(0,dtype='float')
nrgi=np.empty((0,ncols),dtype='float')
nrge=np.empty((0,ncols),dtype='float')
if nspec == 1:
print( "nspec =", nspec)
print( "Assume the kinetic species to be electrons.")
if nspec == 2:
print( "nspec =", nspec)
print( "Species order: first: ions, second: electrons.")
if nspec==3:
nrgz=np.empty((0,ncols),dtype='float')
print( "nspec =", nspec)
print( "Species order: first: ions, second: electrons, third: impurity.")
if nspec>=4:
print( "nspec=",nspec)
sys.exit("nspec must be 1, 2 or 3")
f=open('nrg'+suffix,'r')
nrg_in = f.read()
nrg0 = np.empty((1,ncols))
nrg_in_lines = nrg_in.split('\n')
for j in range(len(nrg_in_lines)):
if nrg_in_lines[j] and j % (nspec+1) == 0:
time = np.append(time,float(nrg_in_lines[j]))
elif nrg_in_lines[j] and j % (nspec+1) == 1:
nline = nrg_in_lines[j].split()
for i in range(ncols):
nrg0[0,i] = nline[i]
if nspec == 1:
nrge=np.append(nrge,nrg0,axis=0)
else:
nrgi=np.append(nrgi,nrg0,axis=0)
elif nspec>=2 and nrg_in_lines[j] and j % (nspec+1) ==2:
nline=nrg_in_lines[j].split()
for i in range(ncols):
nrg0[0,i]=nline[i]
nrge=np.append(nrge,nrg0,axis=0)
elif nspec==3 and nrg_in_lines[j] and j % (nspec+1) ==3:
nline=nrg_in_lines[j].split()
for i in range(ncols):
nrg0[0,i]=nline[i]
nrgz = np.append(nrgz,nrg0,axis=0)
if nspec==1:
return time,nrge
elif nspec==2:
return time,nrgi,nrge
else:
return time,nrgi,nrge,nrgz