1. Converting C

I have a C program that calculates stardates in several different
ways. It came in source only and I can get the darn thing to compile.
(It might help if I had the docs for the compiler and knew what I was
doing =>). Is there anyone here who could convert the program to
Euphoria for me? It is more or less ANSI C (I think). If you can
please respond via private mail at joe at cyber-wizard.com Thanks.


~~>Joseph Martin
~~>E-mail:  joe at cyber-wizard.com
~~>URL: http://users.exis.net/~jam/

new topic     » topic index » view message » categorize

2. Re: Converting C

On Mon, 9 Jun 1997 21:39:45 -0500 Joseph Martin <jam at MAILHUB.EXIS.NET>
writes:

>I have a C program that calculates stardates in several different
>ways. It came in source only and I can get the darn thing to compile.
>(It might help if I had the docs for the compiler and knew what I was
>doing =>). Is there anyone here who could convert the program to
>Euphoria for me?

I did not convert his source from C but I did find a couple of C
algorithms that calculated Scalar, Julian and Papal calendar dates and
converted them. If you need to do some date calculations these might
help.

Larry D. Poos
-[USMC (Retar{bks}{bks}ired) Havelock, NC]-
- Programming and System Consultant, LTAD Enterprises -
e-mail: ldpoos at juno.com
Fido: 1:3629/101.6

-- begin code
-- ******************************************************************
--
-- Filename:           Dates.ex
-- Author:             Larry D. Poos
-- Enviormemt:         Euphouia
-- Date:               Thu 06-12-1997
-- Date Last Modified: Fri 06-13-1997
-- Remarks:
-- some date functions converted from c++ files
--
-- ******************************************************************
function isleap(atom yr)
    -- leap years are years divisible evenly by 4 unless they are the
    -- last year of a century (end in 00). If they are the last year of a
    -- century they must be divisible by 400 to be a leap year.
    atom Leap
    Leap= remainder(yr,400)=0 or (remainder(yr,100)!=0 and
remainder(yr,4)=0)
    return Leap
end function

function month2Sdays(integer month)
    return (month*3057-3007)/100
end function

function years2Sdays(integer year)
    return year*365 + year/4 - year/100 + year/400
end function

function Date2sdn(atom year,atom month,atom day)
    -- calculate scalar date useful for calculating the number of days
    -- between two dates ** uses Jan. 1, 1 AD as te base date
    atom scalar
    scalar=day+month2Sdays(month)
    if month >2 then
        if isleap(year) then
            scalar=scalar-2
        else
            scalar=scalar-1
        end if
    end if
    year=year-1
    scalar=scalar+years2Sdays(year)
    return scalar
end function

function ParseMo(atom month)
    sequence MoName
    MoName={"Jan","Feb","Mar","Apr","May","Jun",
        "Jul","Aug","Sep","Oct","Nov","Dec"}
    return MoName[month]
end function

function ParseJul(atom Jul)
    sequence Caln
    Caln={"AutoMatic","Papal","Julian"}
    return Caln[2+Jul]
end function

constant LASTJD = 15821004

function ymd2jdn(atom y,atom m,atom d, atom LASTJD, atom julian)
    atom jdn
    if julian <0 then
        -- calculate if date is before or after conversion from Julian by
the
        -- pope on 4 Oct 1582 when the next day became 15 Oct 1582
        julian = (((y*100)+m)*100+d<=LASTJD)
    end if
    if y<0 then
        y=y+1
    end if
    if julian then
        jdn=367*y-7*(y+5001+(m-9)/7)/4+275*m/9+d+1729777

    else
        jdn=(d-32076)+1461*(y+4800+(m-14)/12)/4
        +367*(m-2-(m-14)/12*12)/12-3*((y+4900+(m-14)/12)/100)/4
    end if
    return {julian,jdn}
end function

procedure ScalarDate(atom yy, atom mm,atom dd)
    printf(1,"\n Scalar date at noon on %s/%d/%d is %d \n",
          {ParseMo(mm),dd,yy,Date2sdn(yy,mm,dd)})
end procedure

procedure JDNDate(atom yy, atom mm,atom dd, atom julian)
    sequence JDN
    JDN=ymd2jdn(yy,mm,dd,LASTJD,julian)
    printf(1," JDN(StarDate) by the %6s calander = %d\n",
          {ParseJul(JDN[1]),JDN[2]})
end procedure

-- main
atom yy,mm,dd,CalType

-- sub this with your own input routines
    yy=1582
    mm=10
    dd=4
    CalType=-1     -- <0=Automatic 0=Papal >0=Julian
-- then call this
ScalarDate(yy,mm,dd)
JDNDate(yy,mm,dd,CalType)

-- test data
CalType=1
JDNDate(yy,mm,dd,CalType)
CalType=0
JDNDate(yy,mm,dd,CalType)

yy=1582
mm=10
dd=5
CalType=-1
ScalarDate(yy,mm,dd)
JDNDate(yy,mm,dd,CalType)
CalType=1
JDNDate(yy,mm,dd,CalType)
CalType=0
JDNDate(yy,mm,dd,CalType)

yy=1582
mm=10
dd=15
CalType=-1
ScalarDate(yy,mm,dd)
JDNDate(yy,mm,dd,CalType)
CalType=1
JDNDate(yy,mm,dd,CalType)
CalType=0
JDNDate(yy,mm,dd,CalType)

yy=1997
mm=6
dd=13
CalType=-1
ScalarDate(yy,mm,dd)
JDNDate(yy,mm,dd,CalType)
CalType=1
JDNDate(yy,mm,dd,CalType)
CalType=0
JDNDate(yy,mm,dd,CalType)
-- end code

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu