[mesa-users] Profile name zero padding

Josiah Schwab jwschwab at berkeley.edu
Fri Dec 5 12:08:39 EST 2014


Hi Ehsan,

> I would like to ask for a new feature regarding the profile names. 
> I find it a bit inconvenient that profile names are not zero padded
> from left, because when listing the stored profiles in the LOGS
> directory with “ls” command, or when using “glob” in python to fetch
> the list of available files, they are no longer returned in the order
> by which they were produced. E.g. profile11.data will appear after
> profile1.data, but before profile2.data. Left zero padding resolves
> this. This makes life easier (and happier :-D) when plotting profiles
> in sequential order.

As Bill said, the number in the profile isn't a meaningful ordering, so
from a design standpoint, it makes sense to leave things as is.

But when I'm doing something quick and dirty, I do cheat sometimes and
use the profile number as a proxy for model order.  But it's easy enough
to sort things in non-lexicographic order that you may not even need to
bother with zero-padding.  Since software versions are numbered without
leading zeros, most tools have options for this kind of sort.

When using ls, check out the `-v' option:

    -v     natural sort of (version) numbers within text

which gives you what you want.  If you have an old version of ls that
doesn't support that, you could reverse sort by timestamp `-tr'

In the case of python glob, the order is arbitrary, so you have to sort
it anyways.  You can use "version" sorting here too, or do something
simple on your own.

    import distutils
    files = glob.glob('profile*.data')
    sorted(files, key=distutils.version.LooseVersion)

But of course, the best advice is still to always get the order from
profiles.index.

Hope that helps,
Josiah








More information about the Mesa-users mailing list