First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
1

output starting channel index

asked Jan 16 '0

Ascegan gravatar image

Is there an API to output the starting channel index in v33? It's displayed, along with CONS, STATES, etc under "elements restored" after RSTR, and I know many functions use "-1" to automatically write to the next channel #, but I'd like to obtain the channel value itself.

1 answer

Sort by » oldest newest most voted
0

answered Jan 17 '0

perolofl gravatar image

updated Mar 16 '0

There is no API in PSSE for that. I have written my own "API", as shown below:

def get_last_channel():
    """ Returns last used channel number.
    """
    for n in range(1,999999):
        ierr, rval = psspy.chnval(n)
        if ierr == 9:
            print 'Dynamics data not present in working memory'
            return None
        if ierr > 0: break
    return n-1

You can get the number of channels with:

nchan = get_last_channel()

EDIT: Below there is a self-made API to return the last used index in CON, STATE, VAR and ICON vector as well as the number of channels.

def get_dyn_index(type='VARS'):
    """ Returns number of used index in ICON, CON, STATE, VAR or CHANNEL vector
    type: index to be returned ('ICONS', 'CONS', 'STATES', 'VARS' or 'CHANNELS'
    """
    import os
    d = {'CONS':1,'STATES':2,'VARS':3,'ICONS':4,'CHANNELS':5}
    type = type.upper()
    if type not in d:
        print 'Invalid value of type (%s)' % type
        return None
    filnamn = "get_dyn_index_dummy_file.dat"
    psspy.report_output(2,filnamn,[1,0])
    psspy.size_ds()
    psspy.report_output(1,"",[0,0])
    with open(filnamn) as f: lines = f.readlines()
    if type == 'CHANNELS': line = lines[11].split()
    else: line = lines[5].split()
    os.remove(filnamn)
    return int(line[d[type]])

For example, the last VAR is returned with

get_dyn_index('VARS')
link

Comments

Excellent logic. Is the same logic applicable to get the number of VARs? PSSE does not provide API to get the number of VARs in the case. I tried to apply the same logic using: ierr, rval = dsrval('VAR', indx) However, ierr is alwyas zero even indx value is bigger than the total VAR in the case.

yunzhi cheng gravatar imageyunzhi cheng (Mar 15 '0)

See update above!

perolofl gravatar imageperolofl (Mar 16 '0)

Thanks. I used the similar way like this: reading log file while loading DYR data. Your way is much nicer with a defined function. However, I think there should be an API to do this. Reading log/report file is a little weird.

yunzhi cheng gravatar imageyunzhi cheng (Mar 16 '0)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: Jan 16 '0

Seen: 943 times

Last updated: Mar 16 '20