1

output starting channel index

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.

Ascegan's avatar
11
Ascegan
asked 2020-01-16 13:38:08 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

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')
perolofl's avatar
3.8k
perolofl
answered 2020-01-17 07:41:08 -0500, updated 2020-03-16 05:57:42 -0500
edit flag offensive 0 remove flag delete 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's avatar yunzhi cheng (2020-03-15 17:09:20 -0500) edit

See update above!

perolofl's avatar perolofl (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's avatar yunzhi cheng (2020-03-16 08:50:01 -0500) edit
add a comment see more comments

Your Answer

Login/Signup to Answer