character*50 function astofs(ASTRNG, UPTOLW)
c
c    Convert Aldes string ASTRNG to a Fortran string.
c    IF UPTOLW then convert upper to lower case (e.g. to make Unix filename).
c
        integer ASTRNG, FIRST, RED, F, BETA, i, LCODE, ichar, index, c
        logical UPTOLW, UCLET
        character char
        common/ZBETA/BETA
        common/ZLCODE/LCODE(156)
        astofs = ""
        i = 1
        F=ASTRNG
        if (F.EQ.BETA) return
1       c = FIRST(F)
        index = LCODE(c+1)
        UCLET = c.GE.10.AND.c.LE.35
c ... convert upper to lower case
        if (UPTOLW.AND.UCLET) index = index+ichar('a')-ichar('A')
        astofs(i:i) = char(index)
        i = i + 1
        F = RED(F)
        if (F.NE.BETA) go to 1
        return
        end