def run_accc(path_to_case, case_name, sub_file, mon_file, con_file,
             subsystem_name, accc_outfile, overload_summary_file,
             nonconvergence_summary_file, accc_folder_results):

    #os.chdir(accc_folder_results)

    load_case(path_to_case, case_name)

    psspy.dfax_2([1, 1, 0], sub_file, mon_file, con_file, accc_outfile)

    #psspy.accc_with_dsp_3( 0.5,[0,0,0,1,1,2,0,0,0,0,0],subsystem_name,accc_outfile + ".dfx",accc_outfile,"","","")

    psspy.accc_parallel_2(0.5, [0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0],
                          subsystem_name, accc_outfile + ".dfx", accc_outfile,
                          "", "", "")

    #generate overload report
    psspy.report_output(2,
                        accc_folder_results + overload_summary_file + ".txt",
                        0)
    psspy.accc_single_run_report_4([0, 1, 2, 1, 1, 0, 1, 0, 0, 0, 0, 0],
                                   [0, 0, 0, 0, 6000],
                                   [0.5, 5.0, 100.0, 0.0, 0.0, 0.0, 99999.],
                                   accc_outfile)

    #generate non-convergence report
    psspy.report_output(
        2, accc_folder_results + nonconvergence_summary_file + ".txt", 0)
    psspy.accc_single_run_report_4([5, 1, 2, 1, 1, 0, 1, 0, 0, 0, 0, 0],
                                   [0, 0, 0, 0, 6000],
                                   [0.5, 5.0, 100.0, 0.0, 0.0, 0.0, 99999.],
                                   accc_outfile)

    return
Exemple #2
0
    def __init__(self):
        # psse
        self._psspy = psspy
        psspy.psseinit(0)
        psspy.report_output(6, '', [])
        psspy.progress_output(6, '', [])
        psspy.alert_output(6, '', [])
        psspy.prompt_output(6, '', [])

        return None
Exemple #3
0
def run_TLTG(list_DFAX):

   list_output=[]

   for fichero_dfax in list_DFAX:
      #se guarda en un fichero de texto la salida del TLTG
      ruta_output = fichero_dfax.replace('.dfx', '.txt')
      list_output.append(ruta_output)
      psspy.report_output(2, ruta_output, options=[0, 1])
      # ierr = tltg(options, values, labels, dfxfile)
      options=[1,2,1,0,0,0,0,0,0,0,0,1,1,0,1,10000,1]
      values=[ 1.1, 100.0, 5000.0, 0.05, 1.0, 0.03, 300.0]
      ierr=psspy.tltg(options, values,[r"""S.ESTUDIO""", r"""S.OPUESTO""", "", "", "", "", "", ""],fichero_dfax)
      if ierr != 0:
         print('Error al lanzar el TLTG del fichero ' + str(fichero_dfax) + ', ierr=' + str(ierr))

   return list_output
import numpy
import math
import matplotlib as mpl
import matplotlib.pyplot as plt
import dyntools

# OPEN PSS
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
_s = psspy.getdefaultchar()
redirect.psse2py()
psspy.psseinit(50000)

ierr = psspy.progress_output(6, ' ', [0, 0])  # disable output
ierr = psspy.prompt_output(6, ' ', [0, 0])  # disable output
ierr = psspy.report_output(6, ' ', [0, 0])  # disable output

# Set Simulation Path.
LoadScenario = "SimplifiedSystem"
ClauseName = "5.2.5.1 Reactive Power Capability"
ProgramPath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/P_SimulationProgram/"
GridInfoPath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/NEM_files/" + LoadScenario + "/"
HuaweiModelPath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/D_HuaweiModels/34"
OutputFilePath = ProgramPath + "SimulationOutput.out"
FigurePath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/R_Results/"

PowerFlowFileName = 'NEOEN Western Downs Solar Farm_C3WV_3.raw'

# Initialize
psspy.read(0, GridInfoPath + PowerFlowFileName)
Exemple #5
0
# Select working path ##########################################################
#os.chdir(r"C:\Users\bikiran_remote\Desktop\NewCAPECleanOld")
################################################################################
# Local imports
import redirect
import psspy
import dyntools
import csv

planningRaw = 'hls18v1dyn_1219.raw'
psse_log = 'log_planning_multTFLoad.txt'
redirect.psse2py()
psspy.psseinit(buses=80000)
# Silence all psse outputs
psspy.report_output(2, psse_log, [0, 0])
psspy.progress_output(6, psse_log, [0, 0])  #ignored
psspy.alert_output(6, psse_log, [0, 0])  #ignored
psspy.prompt_output(6, psse_log, [0, 0])  #ignored
##############################

ierr = psspy.read(0, planningRaw)

# File:"C:\Users\bikiran_remote\Desktop\report_bus_data.py", generated on MON, MAR 05 2018  19:33, release 33.03.00
for bus in LoadSet:
    ierr = psspy.bsys(1, 0, [0.0, 0.0], 0, [], 1, [int(bus)], 0, [], 0,
                      [])  # PAGE 1373 of API book
    ierr = psspy.lamp(1, 0)  # page 258 of API book
"""
with open(psse_log,'r') as f:
    filecontent = f.read()
Exemple #6
0
#add the the above line 


#Here is the macro script
import psspy
import redirect
_i=psspy.getdefaultint()
_f=psspy.getdefaultreal()
_s=psspy.getdefaultchar()
redirect.psse2py()
import pssdb
psspy.psseinit(80000)
psspy.case(r"""psse.sav""")
psspy.resq(r""" psse.seq""")
psspy.lines_per_page_one_device(1,60)
psspy.report_output(2,r"""report.txt""",[0,0])
psspy.flat([1,1,1,0],[0.0,0.0])
psspy.seqd([0,0])
psspy.sequence_network_setup(0)
psspy.scmu(1,[0,0,0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0],"")
psspy.scmu(2,[7,1082,0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0],"")
psspy.scmu(3,[7,1082,0,0,0,0,0],[0.0,0.0,0.0,0.0,0.0],"")
psspy.sequence_network_setup(0)
#end of script

# add below line to show the report
f=open("report.txt",'r')
for line in f.readlines():
	print line
Exemple #7
0
            continue
        totalSims += 2

totalSims = totalSims * len(RawFileList)
''' Drives a PSS/E Dynamic simulation and returns values '''

##### Get everything set up on the PSSE side
redirect.psse2py()

#output = StringIO.StringIO()
with silence():
    psspy.psseinit(buses=80000)
    _i = psspy.getdefaultint()
    _f = psspy.getdefaultreal()
    _s = psspy.getdefaultchar()
"""
# Redirect any psse outputs to psse_log
psspy.report_output(2,psse_log,[0,0])
psspy.progress_output(2,psse_log,[0,0]) #ignored
psspy.alert_output(2,psse_log,[0,0]) #ignored
psspy.prompt_output(2,psse_log,[0,0]) #ignored
"""

k = 1
for rawFile in RawFileList:

    # get the percentage loading from the raw file name
    if rawFile == 'savnw_conp.raw':
        PL = '100'
    else:
        rawFileName = rawFile.replace('.raw', '')
    def runSimulation(self):
        """Runs the simulation by crating an instance of psspy, loading the raw and dyr data, applying the disturbance and controling PEV output power. Finally plots in native PSS/E or export to matlab."""
        sufix = str(self._disturbance) + "_" + str(self._control)
        conec_file = trash_dir + "\\CC1_" + sufix + ".out"
        conet_file = trash_dir + "\\CT1_" + sufix + ".out"
        compile_file = trash_dir + "\\compile_" + sufix + ".out"

        psspy.psseinit(49)

        #suppress output if required, else redirect it to python
        if self._suppress_output:
            psspy.report_output(6, "", [0, 0])
            psspy.progress_output(6, "", [0, 0])
            #psspy.progress_output(2,r"""pot.txt""",[0,0])
        else:
            #redirect psse output to python
            import redirect
            redirect.psse2py()

        #----------------------
        #read in case data
        psspy.read(0, self._power_system_object._raw_filename)

        #solve the power flow
        psspy.fdns([0, 0, 0, 1, 1, 1, 99, 0])

        #----------------------
        #convert all generators
        psspy.cong(0)

        #----------------------
        #conv_standard_loads
        #change the vector of numbers to get constant current, admittance or power conversion
        utils.convertLoads([0.0, 100.0, 0.0, 100.0])

        #convert the PEVs to constant power loads
        utils.convertPEVs()

        #----------------------------------------
        #read in dynamics data

        psspy.dyre_new([1, 1, 1, 1], self._power_system_object._dyr_filename,
                       "", "", "")

        #solve power flow with dynamics tysl - and fact devices (was in tutorial) - not sure if we need it though
        psspy.fact()
        psspy.tysl(1)

        #set up pre designated channels
        self._channels.setUpChannels()

        #designate channel output_file
        psspy.strt(0, self._channels._channel_file)

        self._performDynamicSimulation()

        if self._plot:
            self._channels.plot(self._channels._channels_to_include)

        if self._export_to_matlab:
            description = sufix.replace(" ",
                                        "_").replace(".",
                                                     "_").replace("=", "__")
            self._channels.exportToMatlab(
                matlab_dir + "\\" + description + ".m", description, True,
                True, self._export_figures)
            if self._export_figures:
                import win32com.client
                h = win32com.client.Dispatch('matlab.application')
                h.Execute("cd('" + os.getcwd() + "\\" + matlab_dir + "');")
                h.Execute(description)

        #clean up
        try:
            os.remove(conec_file)
        except:
            pass
        try:
            os.remove(conet_file)
        except:
            pass
        try:
            os.remove(compile_file)
        except:
            pass

        return self._channels
Exemple #9
0
def changeLoad(raw, start, end, step, newdir):
    """ 
        New raw files are created for each percentage step in [start,end]. 
        The current step defines the percentage scaling up (or down) factor for load and generation
    """

    # convert the raw file to another one where all the load is constant power
    raw_conp = raw.replace('.raw', '') + '_conp.raw'
    redirect.psse2py()
    psspy.psseinit(buses=80000)

    # ignore the output
    psspy.report_output(6, '', [0, 0])
    psspy.progress_output(6, '', [0, 0])
    psspy.alert_output(6, '', [0, 0])
    psspy.prompt_output(6, '', [0, 0])

    # read the raw file and convert all the loads to constant power
    ierr = psspy.read(0, raw)

    # multi-line command to convert the loads to 100% constant power
    psspy.conl(0, 1, 1, [1, 0], [0.0, 0.0, 0.0, 0.0])
    psspy.conl(0, 1, 2, [1, 0], [0.0, 0.0, 0.0, 0.0])
    psspy.conl(0, 1, 3, [1, 0], [0.0, 0.0, 0.0, 0.0])
    ierr = psspy.rawd_2(0, 1, [1, 1, 1, 0, 0, 0, 0], 0, raw_conp)
    # run change Load on the constant power load raw file

    rawBusDataDict = getBusData(raw_conp)
    # create a new directory to put the files in
    currentdir = os.getcwd()

    if not os.path.exists(newdir):
        os.mkdir(newdir)
    output_dir = currentdir + '/' + newdir
    #genDiscount = 0.90 # ratio of the actual increase in generation
    genDiscount = 1.0
    lossRatio = 0.0  # gen scale-up factor: (scalePercent + (scalePercent-100)*lossRatio)/100
    ############################################

    # create new raw files with scaled up loads and generation
    for scalePercent in range(start, end + step, step):
        scalePercent = float(
            scalePercent)  # float is needed, otherwise 101/100 returns 1

        scalePercentInt = int(
            scalePercent)  # integer value needed to append to filename
        scalePercentStr = str(scalePercentInt)

        # variables to store load data
        loadBusList = []  # list of load buses (string)
        loadPList = []  # list of Pload values (string)
        loadQList = []  # list of Qload values (string)
        loadPListInt = []  # list of Pload values (float)
        loadQListInt = []  # list of Qload values (float)
        #loadBusListInt = [] # list of load buses (int)

        # variables to store gen data
        genBusList = []
        #genBusListInt = []
        genPList = []
        genMVAList = []
        genMVAListInt = []
        genPListInt = []

        raw_name = raw_conp.replace('.raw', '')
        out_file = raw_name + scalePercentStr + '.raw'  # output file
        out_path = output_dir + '/' + out_file
        impLoadBuses = [
        ]  # enter specified load buses to scale, if empty all loads are scaled
        incLoss = (
            scalePercent - 100
        ) * lossRatio  # Additional percentage increase in Pgen (to account for losses)
        #############################################

        #Read raw file
        with open(raw_conp, 'r') as f:
            filecontent = f.read()
            filelines = filecontent.split('\n')

            ## Get start and end indices of load and gen info
            #########################################
            loadStartIndex = filelines.index(
                '0 / END OF BUS DATA, BEGIN LOAD DATA') + 1
            loadEndIndex = filelines.index(
                '0 / END OF LOAD DATA, BEGIN FIXED SHUNT DATA')

            genStartIndex = filelines.index(
                '0 / END OF FIXED SHUNT DATA, BEGIN GENERATOR DATA') + 1
            genEndIndex = filelines.index(
                '0 / END OF GENERATOR DATA, BEGIN BRANCH DATA')
            ##############################################################################

            totalPincr = 0.0
            totalQincr = 0.0
            percentIncr = (scalePercent -
                           100.0) / 100  # increment in percentage

            newPConList = []
            newQConList = []
            newIPList = []
            newIQList = []
            newZPList = []
            newZQList = []
            # Extract load info
            for i in range(loadStartIndex, loadEndIndex):
                words = filelines[i].split(',')
                loadBus = words[0].strip()
                #loadBusList.append(words[0].strip())
                loadPCon = float(words[5].strip())
                loadQCon = float(words[6].strip())
                loadIP = float(words[7].strip())
                loadIQ = float(words[8].strip())
                loadZP = float(words[9].strip())
                loadZQ = float(words[10].strip())

                # calculate the total MW (MVAr) increase in load
                loadBusVolt = float(rawBusDataDict[loadBus].voltpu)

                Pincr = percentIncr * (
                    loadPCon + loadIP * loadBusVolt + loadZP * loadBusVolt**2
                )  # this equation is provided in PAGV1 page 293
                Qincr = percentIncr * (loadQCon + loadIQ * loadBusVolt +
                                       loadZQ * loadBusVolt**2)
                totalPincr += Pincr
                totalQincr += Qincr
                ###

                # new load values
                newPConList.append(loadPCon * scalePercent / 100)
                newQConList.append(loadQCon * scalePercent / 100)
                newIPList.append(loadIP * scalePercent / 100)
                newIQList.append(loadIQ * scalePercent / 100)
                newZPList.append(loadZP * scalePercent / 100)
                newZQList.append(loadZQ * scalePercent / 100)
                """
                loadPList.append(words[5].strip()) # adding P value (constant power)
                loadQList.append(words[6].strip()) # adding Q value (constant power)
                loadIPList.append(words[7].strip()) # constant current P
                loadIQList.append(words[7].strip()) # constant current Q
                loadZPList.append(words[9].strip()) # adding P value (constant admittance)
                loadZQList.append(words[10].strip()) # adding Q value (constant admittance)
                """

            # get total MW gen
            totalGenMW = 0.0  # total generation excluding the swing bus
            for i in range(genStartIndex, genEndIndex):
                words = filelines[i].split(',')
                GenBus = words[0].strip()
                if rawBusDataDict[GenBus].type == '3':
                    continue
                PGen = float(words[2].strip())
                totalGenMW += PGen

            # get new MW Gen
            GenMWDict = {}  # dictionary to hold new PGen values
            for i in range(genStartIndex, genEndIndex):
                words = filelines[i].split(',')
                Bus = words[0].strip()
                if rawBusDataDict[Bus].type == '3':
                    continue
                macID = words[1].strip()
                key = Bus + macID
                PGen = float(words[2].strip())
                genIncr = PGen / totalGenMW * totalPincr
                newPGen = (PGen + genIncr) * genDiscount
                GenMVA = float(words[8].strip())
                if newPGen < GenMVA:
                    GenMWDict[key] = newPGen
                else:
                    GenMWDict[key] = GenMVA

        #  generate the new raw file
        with open(out_path, 'w') as f:
            # copy everything before load data
            for i in range(loadStartIndex):
                f.write(filelines[i])
                f.write('\n')

            # modify the load data
            j = 0
            for i in range(loadStartIndex, loadEndIndex):
                words = filelines[i].split(',')

                # change the constant MVA values
                words[5] = '%.3f' % newPConList[j]
                words[6] = '%.3f' % newQConList[j]
                words[5] = words[5].rjust(10)
                words[6] = words[6].rjust(10)

                # change the constant current values
                words[7] = '%.3f' % newIPList[j]
                words[8] = '%.3f' % newIQList[j]
                words[7] = words[7].rjust(10)
                words[8] = words[8].rjust(10)

                # change the constant impedance values
                words[9] = '%.3f' % newZPList[j]
                words[10] = '%.3f' % newZQList[j]
                words[9] = words[9].rjust(10)
                words[10] = words[10].rjust(10)

                # construct a whole string by inserting commas between the words list
                filelines[i] = reconstructLine2(words)
                f.write(filelines[i])
                f.write('\n')
                # increment the load list index
                j += 1

            # copy the shunt data, which is in between the load and gen data
            for i in range(loadEndIndex, genStartIndex):
                f.write(filelines[i])
                f.write('\n')

            # update and write the gen data
            for i in range(genStartIndex, genEndIndex):
                words = filelines[i].split(',')
                Bus = words[0].strip()

                if rawBusDataDict[Bus].type == '3':
                    f.write(filelines[i])
                    f.write('\n')
                    continue
                macID = words[1].strip()
                key = Bus + macID
                newPGen = GenMWDict[key]

                words[2] = '%.3f' % newPGen
                words[2] = words[2].rjust(10)

                # construct a whole string by inserting commas between the words list
                filelines[i] = reconstructLine2(words)
                f.write(filelines[i])
                f.write('\n')

                # copy the rest of the raw data
            for i in range(genEndIndex, len(filelines)):
                f.write(filelines[i])
                f.write('\n')

    # solves each of the newly generated raw files and saves them
    output_dir = currentdir + '/' + newdir
    NewRawFiles = os.listdir(output_dir)
    PathList = [(output_dir + '/' + f) for f in NewRawFiles]

    redirect.psse2py()
    psspy.psseinit(buses=80000)

    _i = psspy.getdefaultint()
    _f = psspy.getdefaultreal()
    _s = psspy.getdefaultchar()

    for i in range(len(PathList)):
        #Settings. CONFIGURE THIS
        settings = {
            # use the same raw data in PSS/E and TS3ph #####################################
            'filename':
            PathList[i],  #use the same raw data in PSS/E and TS3ph
            ################################################################################
            'dyr_file':
            '',
            'out_file':
            'output2.out',
            'pf_options': [
                0,  #disable taps
                0,  #disable area exchange
                0,  #disable phase-shift
                0,  #disable dc-tap
                0,  #disable switched shunts
                0,  #do not flat start
                0,  #apply var limits immediately
                0,  #disable non-div solution
            ]
        }

        psse_log = output_dir + '/' + 'log' + NewRawFiles[i].replace(
            '.raw', '.txt')
        psspy.report_output(2, psse_log, [0, 0])
        psspy.progress_output(2, psse_log, [0, 0])
        psspy.alert_output(2, psse_log, [0, 0])
        psspy.prompt_output(2, psse_log, [0, 0])

        print "\n Reading raw file:", settings['filename']
        ierr = psspy.read(0, settings['filename'])
        ierr = psspy.fnsl(settings['pf_options'])
        converge = psspy.solved()
        if converge == 0:
            ierr = psspy.rawd_2(0, 1, [1, 1, 1, 0, 0, 0, 0], 0, PathList[i])
        else:  # file does not converge, remove raw file, keep log file
            os.remove(PathList[i])
        """
    def runSimulation(self):
        """Runs the simulation by crating an instance of psspy, loading the raw and dyr data, applying the disturbance and controling PEV output power. Finally plots in native PSS/E or export to matlab."""
        sufix = str(self._disturbance)+"_"+str(self._control)
        conec_file = trash_dir+"\\CC1_"+sufix+".out"
        conet_file = trash_dir+"\\CT1_"+sufix+".out"
        compile_file = trash_dir+"\\compile_"+sufix+".out"
    
        psspy.psseinit(49)
        
        #suppress output if required, else redirect it to python
        if self._suppress_output:
            psspy.report_output(6,"",[0,0])
            psspy.progress_output(6,"",[0,0])
            #psspy.progress_output(2,r"""pot.txt""",[0,0])
        else:
            #redirect psse output to python
            import redirect
            redirect.psse2py()
    
        #----------------------
        #read in case data
        psspy.read(0,self._power_system_object._raw_filename)

        #solve the power flow
        psspy.fdns([0,0,0,1,1,1,99,0])

        #----------------------
        #convert all generators
        psspy.cong(0)

        #----------------------
        #conv_standard_loads
        #change the vector of numbers to get constant current, admittance or power conversion
        utils.convertLoads([0.0,100.0,0.0,100.0])

        #convert the PEVs to constant power loads
        utils.convertPEVs()
        
        #----------------------------------------
        #read in dynamics data

        psspy.dyre_new([1,1,1,1],self._power_system_object._dyr_filename,"","","")

        #solve power flow with dynamics tysl - and fact devices (was in tutorial) - not sure if we need it though
        psspy.fact()
        psspy.tysl(1)
    
        #set up pre designated channels
        self._channels.setUpChannels()
    
    
        #designate channel output_file
        psspy.strt(0,self._channels._channel_file)
        
        self._performDynamicSimulation()
        
        if self._plot:
            self._channels.plot(self._channels._channels_to_include)
            
        if self._export_to_matlab:
            description = sufix.replace(" ","_").replace(".","_").replace("=","__")
            self._channels.exportToMatlab(matlab_dir+"\\"+description+".m",description,True,True,self._export_figures)
            if self._export_figures:
                import win32com.client
                h = win32com.client.Dispatch('matlab.application')
                h.Execute ("cd('"+os.getcwd()+"\\"+matlab_dir+"');")
                h.Execute (description)
            
            
        #clean up
        try:
            os.remove(conec_file)
        except:
            pass
        try:
            os.remove(conet_file)
        except:
            pass
        try:
            os.remove(compile_file)
        except:
            pass
            
        return self._channels
Exemple #11
0
ierr, ctpsg7 = psspy.gendat(44025)
ierr, ctpsg8 = psspy.gendat(44026)
ierr, mtpsg5 = psspy.gendat(44024)
ierr, mtpsg6 = psspy.gendat(44027)
with open('output.txt', 'a') as fout:
    fout.write('CTPS Gen7 loaded to %s \n' % round(ctpsg7.real, 3))
    fout.write('CTPS Gen8 loaded to %s \n' % round(ctpsg8.real, 3))
    fout.write('MTPS Gen5 loaded to %s \n' % round(mtpsg5.real, 3))
    fout.write('MTPS Gen6 loaded to %s \n' % round(mtpsg6.real, 3))
    fout.write('\n')

with open('output.txt', 'a') as fout:
    fout.write(add_data())
    fout.write('\n\n')

psspy.report_output(islct=2, filarg="./output.txt", options=[2])
psspy.asys(sid=1, num=1, areas=4)
psspy.ties(1, 0)
psspy.report_output(islct=2, options=[0])
with open('output.txt', 'a') as fout:
    fout.write('\n\n')

flowarr = [['KLYN-MTHNPG L1', 7.6], ['KLYN-MTHNPG L2', 7.6],
           ['DHN-MTHNPG L1', 45], ['DHN-MTHNPG L2', 45], ['CTPS-DHN L1', 45.6],
           ['CTPS-DHN L2', 45.6], ['CTPS-KLYN L1', 141.8],
           ['CTPS-KLYN L2', 141.8], ['MTPS-BRNPR L1', 58.23],
           ['KLYN-BRNPR L1', 22], ['KLYN-MTPS L1', 55], ['KLYN-MTPS L2', 79.2],
           ['KLYN-MTPS L3', 79.2], ['PARU-DGPPG L1', 1], ['PARU-DGPPG L2', 1],
           ['DGPDVC-PARU L1', 16.5], ['DGPDVC-PARU L2', 16.5],
           ['DTPS-PARU L1', 22], ['DTPS-PARU L2', 22],
           ['MTPS-DGPDVC L1', 31.45], ['MTPS-DGPDVC L2', 31.45],
ierr, ctpsg7 = psspy.gendat(44025)
ierr, ctpsg8 = psspy.gendat(44026)
ierr, mtpsg5 = psspy.gendat(44024)
ierr, mtpsg6 = psspy.gendat(44027)
with open('output.txt','a') as fout:
    fout.write('CTPS Gen7 loaded to %s \n' % round(ctpsg7.real, 3))
    fout.write('CTPS Gen8 loaded to %s \n' % round(ctpsg8.real, 3))
    fout.write('MTPS Gen5 loaded to %s \n' % round(mtpsg5.real, 3))
    fout.write('MTPS Gen6 loaded to %s \n' % round(mtpsg6.real, 3))
    fout.write('\n')

with open('output.txt','a') as fout:
    fout.write(add_data())
    fout.write('\n\n')

psspy.report_output(islct=2, filarg="./output.txt", options=[2])
psspy.asys(sid=1,num=1,areas=4)
psspy.ties(1,0)
psspy.report_output(islct=2, options=[0])
with open('output.txt','a') as fout:
    fout.write('\n\n')


flowarr=[['KLYN-MTHNPG L1',7.6],['KLYN-MTHNPG L2',7.6],['DHN-MTHNPG L1',45],['DHN-MTHNPG L2',45],
         ['CTPS-DHN L1',45.6],['CTPS-DHN L2',45.6],['CTPS-KLYN L1',141.8],['CTPS-KLYN L2',141.8],
         ['MTPS-BRNPR L1',58.23],['KLYN-BRNPR L1',22],['KLYN-MTPS L1',55],['KLYN-MTPS L2',79.2],
         ['KLYN-MTPS L3',79.2],['PARU-DGPPG L1',1],['PARU-DGPPG L2',1],['DGPDVC-PARU L1',16.5],
         ['DGPDVC-PARU L2',16.5],['DTPS-PARU L1',22],['DTPS-PARU L2',22],['MTPS-DGPDVC L1',31.45],
         ['MTPS-DGPDVC L2',31.45],['MTPS-DTPS L1',42],['MTPS-DTPS L2',42]]

import psspy
from psspy import _i
# MakeCnvSnp_.py
# VARs definition
study     = 'ieee39_flat'
mysav     = 'ieee39_v33'
mydyr     = 'ieee39.dyr'
simtime   =  10.0
title1    = 'ieee39'
title2    = 'flatstart'
conl      = 'Conl.idv'
channels  = 'channels.idv'
mylog = '%s.log'%study
#
psspy.progress_output(2,mylog,[0,0])
psspy.report_output(2,mylog,[0,0])
psspy.progress(' \n')
psspy.progress('***************************************\n')
psspy.progress('*            MakeCnvSnp %s \n'%study)
psspy.progress('*\n')
psspy.progress('***************************************\n')

psspy.case(mysav)
#psspy.runrspnsfile(re_add)			#adds RE topology
psspy.runrspnsfile(conl)
psspy.fnsl((_i,0,_i,_i,_i,_i,_i,0))
psspy.cong(0)
psspy.ordr(0)
psspy.fact()
psspy.tysl(0)
psspy.tysl(0)