Ask Your Question
1

output starting channel index

asked 2020-01-16 13:38:08 -0500

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.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-01-17 07:41:08 -0500

perolofl gravatar image

updated 2020-03-16 05:57:42 -0500

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')
edit flag offensive delete link more

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 ( 2020-03-15 17:09:20 -0500 )edit

See update above!

perolofl gravatar imageperolofl ( 2020-03-16 05:58:05 -0500 )edit

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 ( 2020-03-16 08:50:01 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2020-01-16 13:38:08 -0500

Seen: 860 times

Last updated: Mar 16 '20