fork download
  1. import sys
  2.  
  3. #Time for gschem unit in ns
  4. XU = 10.0
  5. #Voltage for unit for ch 1 and 2 in mV
  6. YU1 = 1.0
  7. YU2 = 10.0
  8. #Resistors 2 and 3 resistances in ohms
  9. R2 = 983.0
  10. R3 = 99.4
  11. #Frequency in Hz
  12. F = 30303.0
  13.  
  14. def getlist(list, x0, y0, invert):
  15. for i in range(len(list)):
  16. list[ i ][0] -= x0
  17. list[ i ][2] -= x0
  18. if (invert):
  19. list[ i ][1] = y0 - list[ i ][1]
  20. list[ i ][3] = y0 - list[ i ][3]
  21. else:
  22. list[ i ][1] -= y0
  23. list[ i ][3] -= y0
  24. return list
  25.  
  26. def gety(list, i, t):
  27. lx = float(list[ i ][2] - list[ i ][0])
  28. ly = float(list[ i ][3] - list[ i ][1])
  29. dx = float(t - list[ i ][0])
  30. dy = ly * abs(dx / lx)
  31. return list[ i ][1] + dy
  32.  
  33. def output(s, e):
  34. #Energy in uJ
  35. e *= XU / 10 / 1000000
  36. print("%s power was %.3f uW" % (s, F * e))
  37.  
  38. lines = []
  39. for s in sys.stdin:
  40. l = []
  41. i1 = -1
  42. if (s[0] != "L"): continue
  43. for j in range(5):
  44. if (i1 == len(s)): break
  45. i0 = i1 + 1
  46. i1 = i0 + s[i0:].find(" ")
  47. if (s[i0:].find(" ") == -1): i1 = len(s)
  48. if (j and s[i0:i1].isdigit()): l.append(int(s[i0:i1]))
  49. lines.append(l)
  50.  
  51. x0 = lines[0][0]
  52. y0 = lines[-2][1]
  53. lines.pop()
  54. lines.pop()
  55. i1 = map(lambda l: l[1] <= y0, lines).index(True)
  56. i2 = map(lambda l: l[0] == x0, lines[1 : ]).index(True) + 1
  57. ilist = getlist(lines[: i1], x0, y0, False)
  58. olist = getlist(lines[i1 : i2], lines[i1][0], y0, True)
  59. ch2list = getlist(lines[i2 : ], lines[i2][0], lines[-1][3], False)
  60.  
  61. e = 0.0
  62. i1 = i2 = 0
  63. for t in range(0, ilist[-1][2], 10):
  64. if (t >= ilist[i1][2]): i1 += 1;
  65. if (t >= ch2list[i2][2]): i2 += 1;
  66. ilr = gety(ch2list, i2, t) * YU2 / R2
  67. vlr = gety(ilist, i1, t) * YU1
  68. plr = ilr * vlr / 1000
  69. pr = vlr * vlr / R3 / 1000
  70. pl = plr - pr
  71. e += pl
  72. output("Input", e)
  73.  
  74. e = 0.0
  75. i1 = 0
  76. for t in range(0, olist[-1][2], 10):
  77. if (t >= olist[i1][2]): i1 += 1;
  78. vlr = gety(olist, i1, t) * YU1
  79. pr = vlr * vlr / R3 / 1000
  80. e += pr
  81. output("Output", e)
  82.  
Success #stdin #stdout 0s 23296KB
stdin
v 20130925 2
L 60500 42500 60900 41900 3 0 0 0 -1 -1
L 60900 41900 61300 41700 3 0 0 0 -1 -1
L 61300 40500 61600 41000 3 0 0 0 -1 -1
L 61600 41000 62000 41300 3 0 0 0 -1 -1
L 62000 41300 62400 41400 3 0 0 0 -1 -1
L 62400 41400 63800 41500 3 0 0 0 -1 -1
L 60500 40000 61300 40100 3 0 0 0 -1 -1
L 61300 40100 61300 39000 3 0 0 0 -1 -1
L 60300 41500 64000 41500 3 0 0 0 -1 -1
L 60300 39000 64000 39000 3 0 0 0 -1 -1
stdout
Input power was 5.277 uW
Output power was 7.500 uW