Read Julian Date

#!/bin/ksh93

let JULIAN=$1

# Sets a month/day pair for comparison

if  [[ `leapyear $2` != true ]]
        then
        JULIANSTR="12.334 11.304 10.273 9.243 8.212 7.181 6.151 5.120 4.90 3.59 2.31 1.0"
        LASTDAY=365
        else
        JULIANSTR="12.335 11.305 10.274 9.244 8.213 7.182 6.152 5.121 4.91 3.60 2.31 1.0"
        LASTDAY=366
fi

# Exists if the Julian Date is invalid

if [[ $JULIAN -gt $LASTDAY ]]
        then
        exit
        fi

# Main loop, only prints on a match

for MONJUL in $JULIANSTR
        do
        echo $MONJUL | sed 's/\./\ /g' | read MON JUL
        if [[ $JULIAN -gt $JUL ]]
        then
        let DAY=JULIAN-JUL
        echo "$MON/$DAY/$2"
        exit
        fi
done

Leave a Reply

Your email address will not be published. Required fields are marked *