import sys

#------------------------
# User defined parameters
#------------------------

# Filename of .nc file containing the IVCurve analysis
fname = 'device_120.nc'

# The maximum temperature in K
Tmax = 400.0 

# The minimum temperature in K
Tmin = 250.0

#-----------
# Load files
#-----------

iv = nlread(fname, IVCurve)[0]
transmission_spectra = iv.transmissionSpectra()

# Consider positive bias only
pos_spectra = []
for t in transmission_spectra:
  if float(t.bias()) > 0:
    pos_spectra.append(t)

#---------------------------------
# Calculate the IT-characteristics
#---------------------------------

# Loop through voltages
for spectrum in pos_spectra:
  temp = numpy.arange(Tmin,Tmax,1)
  currents = []

  # Loop through temperatures
  for t in temp:
    current = spectrum.current(electrode_temperatures=[t,t]*Kelvin)
    currents.append(current)

  bias = spectrum.bias()

  IvsT = open('IvsT'+str(float(bias))+'.dat','w')
  for i in range(len(temp)):
    IvsT.write("%6.0f %s\n"%(temp[i], currents[i]))
