-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
2352 lines (1025 loc) · 72.7 KB
/
main.py
File metadata and controls
2352 lines (1025 loc) · 72.7 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 11 20:08:56 2020
While completing this academic project, we were restricted to using ONLY the numpy & sys libraries. Meaning, we could not use libraries such as Pandas to help us format
our output files.
This program is designed to analyse cascade circuits using the ABCD matrix analysis scheme. The program will read an input file of a specific format,
where the input file specifies an entire cascade circuit, including the number of and types of components, all component values, whether impedances are shunt or series
impedances, the source voltage, source impedance and a range of source frequencies.
My program will process the data from the input file, calculating the ABCD matrix of the circuit, and the ABCD matrix will then be used to calculate the values
of various quantities of the cascade circuit such as the output power, output voltage, voltage gain and many more quantities. The quantities will be calculated for various
source frequencies, they will then be formatted and displayed in an output file.
To run the program, you must use a command line argument. The program accepts two formats for the command line argument. The standard format is: python main.py test.net test.out
where main.py is this file, test.net is the input file and test.out is the output file. The extended command line format is: python main.py -i test -f
This format will also accept an input file of test.net and produce an output file test.out. The '-f' flag represents that the output data will be calculated and displayed in
the frequency domain. Change the flag to '-t' if you want to display the data in the time domain using IFFT.
If you are using Spyder, enter the command line options as either of these three options:
main.py -i test -f
main.py -i test -t
main.py test.net test.out
INPUT FILE FORMAT:
Please look at the example input file to see the formatting.
A '#' in the input file represents that the line is a comment and will be ignored.
n1 and n2 represent the two nodes attatched to a component. If n2=0, this component is a shunt component.
A norton or thevenin source can be specified in the <TERMS> block. The range of frequencies used will also be specificed in the <TERMS> block.
The units of the output quantities can be specified in the <OUTPUT> block. Unit prefixes can be used in ALL parts of the input file. dBV, dBW etc can be used to display a quantity in decibel/phase format.
Prefixes such as K, M, m etc can be used in the input file.
A logarithmic frequency sweep can also be used by changing 'Fstart' and 'Fend' to 'LFstart' and 'LFend' in the <TERMS> block.
"""
import numpy as np
import sys
import circuitsort
import ABCDmatrixcalc
import prefixcalc
import prefixcalcinv
import math
timeflag=0 # timeflag = 0 implies frequency response, timeflag = 1 implies time response
if sys.argv[2]=='-i': # extended command line format detected
f = open(sys.argv[3]+'.net',"r")
f1 =f.readlines()
f.close()
try:
if sys.argv[4]=='-t':
timeflag=1 # set timeflag = 1 to tell program that the output is a time response
except:
pass
else: # else standard command line format
f = open(sys.argv[2],"r")
f1 =f.readlines() #f1 is a list containing entire input file, each line is a string
f.close()
commentflag=0 # flag used to indicate that the current line of the input file is a comment, and to not import that line into the progam
arraypointer=0 # counter used to point at the required array indexes
logflag=0 # flag used to represent whether frequencies are logarithmic or linear
indcounter=-1 # counts how many inductors are in the circuit
capcounter=-1 # counts how many capacitors are in the circuit
indices=np.zeros((1,6), dtype = int) # array to store indices corresponding to each block in the input file
for i in range (0,len(f1)): #for loop to create indices corresponding to the start and end of each block, <CIRCUIT>, <TERMS> etc
if int ('<CIRCUIT>' in f1[i]) == 1:
indices[0,0]=i
if int ('</CIRCUIT>' in f1[i]) == 1:
indices[0,1]=i
if int ('<TERMS>' in f1[i]) == 1:
indices[0,2]=i
if int ('</TERMS>' in f1[i]) == 1:
indices[0,3]=i
if int ('<OUTPUT>' in f1[i]) == 1:
indices[0,4]=i
if int ('</OUTPUT>' in f1[i]) == 1:
indices[0,5]=i
circuit=np.zeros((0,0), dtype = complex)
terms=np.zeros((0,0), dtype = float) # create empty array for each block
output=np.zeros((0,0), dtype = object)
capindices=np.zeros((0,0), dtype = int)
inductindices=np.zeros((0,0), dtype = int) # arrays to store the indices corresponding to location of capacitors and inductors within the circuit array
units=np.zeros((0,0), dtype = object) # stores output data type and units from <OUTPUT> block
variables=np.zeros((0,0), dtype = object)
arraypointer=-1
for i in range (indices[0,0]+1,indices[0,1]): # for loop to fill the circuit array
commentflag=0 # needs to be 0 by default
if int('#' in f1[i]) == 1: # detects '#' substring to prevent comments being imported into array
commentflag=1 # commentflag = 1 skips importing data for 1 loop iteration
if commentflag!=1:
arraypointer+=1 # increment this every iteration to point at next locations in array to store data
p=f1[i]
tempslice=p[3:p.find(' ')]
tempslice = tempslice.strip()
try:
p=int(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
circuit=np.insert(circuit,3*arraypointer,p) # inserts the n1 values into circuit array
p=f1[i]
tempslice=p[(p.find('n2')+3):p.rfind(' ')]
tempslice = tempslice.strip()
try:
p=int(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
circuit=np.insert(circuit,(3*arraypointer)+1,p) # insert the n2 values into circuit array
#extract whether it's a resistor, capacitor, inductor or conductor
p=f1[i]
tempslice=p[(p.rfind(' ')+1):p.rfind('=')]
tempslice = tempslice.strip()
if tempslice == 'R': # if it's a resistor, get the resistance and plug it straight in the array
tempslice = p[(p.rfind('=')+1):(len(p)-1)]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice) # convert if there are any prefixes
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
circuit = np.insert(circuit,(3*arraypointer)+2,p)
elif tempslice == 'G': # if it's a conductor, invert the conductance to get resistance and store it
tempslice = p[(p.rfind('=')+1):(len(p)-1)]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
p=1/p
circuit = np.insert(circuit,(3*arraypointer)+2,p)
elif tempslice == 'L': # if it's an inductor, store the impedance for freq of 1 Hz
tempslice = p[(p.rfind('=')+1):(len(p)-1)]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice) # convert if there are any prefixes
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
p=complex(0,(2*math.pi*p))
circuit = np.insert(circuit,(3*arraypointer)+2,p)
indcounter += 1
inductindices = np.insert(inductindices,indcounter,(3*arraypointer)+2) # save the indices of where the inductor impedances are stored in the circuit array, needed later
elif tempslice == 'C': # else it must be a capacitor, store the impedance for a freq of 1 Hz
tempslice = p[(p.rfind('=')+1):(len(p)-1)]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
p=complex(0,(-1)/(2*math.pi*p))
circuit = np.insert(circuit,(3*arraypointer)+2,p)
capcounter+= 1
capindices = np.insert(capindices,capcounter,(3*arraypointer)+2)
else: # invalid circuit component
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
arraypointer=-1
for i in range (indices[0,2]+1,indices[0,3]): # for loop to fill the terms array
commentflag=0 # commentflag is 0 by default
if int('#' in f1[i]) == 1: # if a '#' is detected it's a comment in the input file, so skip this line
commentflag=1
if commentflag!=1:
arraypointer+=1 # increment to point at next location in array
p=f1[i]
if int('VT' in f1[i]) == 1: # stores both VT and RS in terms array as floats
tempslice = p[p.find('=')+1:p.find(' ')]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
terms = np.insert(terms,0,p) # store VT
p=f1[i]
tempslice = p[p.rfind('=')+1:len(p)-1]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
if int('GS' in f1[i]) == 1: # convert to resistance if a conductance is detected
p = 1/p
terms = np.insert(terms,1,p)
if int('IN' in f1[i]) == 1: # norton source detected, convert to thevenin source for ease of calculation
tempslice = p[p.find('=')+1:p.find(' ')]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
tempslice = f1[i][f1[i].rfind('=')+1:len(f1[i])-1]
tempslice = tempslice.strip()
try:
tempslice = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
if int('GS' in f1[i]) == 1: # convert conductance to resistance
tempslice = 1/tempslice
p = p * tempslice
terms = np.insert(terms,0,p)
terms = np.insert(terms,1,tempslice)
if int('RL' in f1[i]) == 1: # stores RL in terms array as float
p=f1[i]
tempslice = p[p.find('=')+1:len(p)-1]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
terms = np.insert(terms,2,p)
if int('GL' in f1[i]) == 1: # convert GL to RL and store in terms array
p=f1[i]
tempslice = p[p.find('=')+1:len(p)-1]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
p = 1/p
terms = np.insert(terms,2,p)
if int('Nfreqs' in f1[i]) == 1: # stores frequency data in terms array as floats
p=f1[i]
tempslice = p[p.find('=')+1:p.find(' ')]
tempslice = tempslice.strip()
freqprefix = tempslice[len(tempslice)-1:len(tempslice)]
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
terms = np.insert(terms,3,p)
p=f1[i]
tempslice = p[(p.index('=',p.find(' '),p.rfind(' '))) +1:p.rfind(' ')]
tempslice = tempslice.strip()
try:
p = prefixcalc.prefixcalc(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
terms = np.insert(terms,4,p)
p=f1[i]
tempslice = p[p.rfind('=')+1:len(p)-1]
tempslice = tempslice.strip()
try:
p=int(tempslice)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
terms = np.insert(terms,5,p)
if int('LFend' in f1[i]) == 1: # set logflag = 1 if logarithmic frequencies detected, logflag is used later when calculating the frequencies
logflag = 1
arraypointer=-1
for i in range (indices[0,4]+1,indices[0,5]): # for loop to fill the output, variables and units arrays
commentflag=0 # commentflag is 0 by default
if int('#' in f1[i]) == 1: # if a '#' is detected it's a comment in the input file, so skip this line
commentflag=1
if commentflag!=1:
arraypointer+=1 # increment to point at next location in array
output = np.insert(output,arraypointer,f1[i])
p = output[arraypointer]
if arraypointer==8 or arraypointer==9: # deal with units for gains Av and Ai
if int('dB' in output[arraypointer]) == 1:
units=np.insert(units,arraypointer,'dB')
tempslice = p[0:p.find(' ')]
tempslice = tempslice.strip()
variables = np.insert(variables,arraypointer,tempslice)
else:
units=np.insert(units,arraypointer,'L')
tempslice = p[0:p.find(' ')]
tempslice = tempslice.strip()
variables = np.insert(variables,arraypointer,tempslice)
else:
tempslice = p[0:p.find(' ')]
tempslice = tempslice.lstrip()
tempslice = tempslice.rstrip()
variables = np.insert(variables,arraypointer,tempslice)
tempslice = p[p.find(' ')+1:len(output[arraypointer])-1]
tempslice = tempslice.strip()
units = np.insert(units,arraypointer,tempslice)
data = np.zeros((0,0), dtype = object) # stores all the numerical output data as strings in format of output file
dataorig = np.zeros((0,0), dtype = complex) # stores all numercial output data as complex numbers with no formatting
indcounter = -11 # arraypointereeps tracarraypointer of what loop iteration program is on
nfreq = int(terms[5]) # the number of frequency points in the output file
increment = (terms[4]-terms[3])/(terms[5]-1) # the incremental frequency increase between frequency points in the output file
circuit2 = np.copy(circuit) # store a copy of the original circuit array, needed later
for i in range (1,nfreq+1): # loops over all frequencies, creating and storing output data
indcounter += 11
if logflag ==1: # calculate the logarithmic frequencies
end = np.log10(terms[4])
start = np.log10(terms[3])
increment = (end-start)/(terms[5]-1)
currentfreq = 10**(start + ((i-1)*increment))
else: # calculate the linear frequencies
currentfreq = terms[3] + ((i-1)*increment)
# re calculate the circuit array for the currentfreq
circuit = np.copy(circuit2) # return circuit array to original unsorted form, as can only update the impedances with the original unsorted circuit array
for j in range (0,len(inductindices)): # update the inductor impedances to match the current frequency
circuit[inductindices[j]] = circuit2[inductindices[j]]*currentfreq
for j in range (0,len(capindices)): # update the capacitor impedances to match the current frequency
circuit[capindices[j]] = circuit2[capindices[j]]/currentfreq
circuit = circuitsort.circuitsort(circuit) # sort the new circuit array so that component data is stored in the order that it appears in the circuit
ABCDmatrix = ABCDmatrixcalc.ABCDmatrixcalc(circuit) # get the ABCD matrix corresponding to this frequency
# calculate all the output data , considering prefixes
Zin = (((ABCDmatrix[0,0]*terms[2]) + ABCDmatrix[0,1])/((ABCDmatrix[1,0]*terms[2]) + ABCDmatrix[1,1]))
Zinstore = Zin
tempslice = units[7][0:1]
try:
Zin = prefixcalcinv.prefixcalcinv(tempslice,Zin)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
Zout = (((ABCDmatrix[1,1]*terms[1]) + ABCDmatrix[0,1])/((ABCDmatrix[1,0]*terms[1]) + ABCDmatrix[0,0]))
tempslice = units[5][0:1]
try:
Zout = prefixcalcinv.prefixcalcinv(tempslice,Zout)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
Iin = terms[0]/(terms[1]+Zinstore)
Iinstore = Iin
tempslice = units[2][0:1]
try:
Iin = prefixcalcinv.prefixcalcinv(tempslice,Iin)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
Vin = Zinstore * Iinstore
Vinstore = Vin
tempslice = units[0][0:1]
try:
Vin = prefixcalcinv.prefixcalcinv(tempslice,Vin)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
Av = (1/(ABCDmatrix[0,0] + (ABCDmatrix[0,1]/terms[2])))
Avstore = Av
tempslice = units[8][0:1]
try:
Av = prefixcalcinv.prefixcalcinv(tempslice,Av)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
Ai = (1/(ABCDmatrix[1,1] + (ABCDmatrix[1,0]*terms[2])))
Aistore = Ai
tempslice = units[9][0:1]
try:
Ai = prefixcalcinv.prefixcalcinv(tempslice,Ai)
except: # error detected
if sys.argv[2] == '-i': # detect extended command line format
f = open(sys.argv[3]+'.out',"w+") # write blank file
else: # else it's the standard command line format
f = open(sys.argv[3],"w+") # write blank file
f.close()
sys.exit()
Pin = Vinstore * np.conj(Iinstore)
Pinstore = Pin
tempslice = units[4][0:1]
try:
Pin = prefixcalcinv.prefixcalcinv(tempslice,Pin)
except: # error detected