changing date to julian 
Author Message
 changing date to julian

Hello All,
How do I change the 4th and 6th field in a file to a juilian date?
Thanks

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sat, 17 Aug 2002 03:00:00 GMT  
 changing date to julian

Quote:

>Hello All,
>How do I change the 4th and 6th field in a file to a juilian date?

Set up conversion arrays in a BEGIN section, then reassign the fields
based upon the arrays, something like this:

$4=array1[$4]; $6=array2[$6]

If this isn't what you need, post an example of what you want.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sat, 17 Aug 2002 03:00:00 GMT  
 changing date to julian

..
Quote:
>How do I change the 4th and 6th field in a file to a
>juilian date?

..

Meaning that $4 and $6 are already dates in some format
that shows day, month and year and you want to change it to
either just julian day within year or year and julian day?

If so, functions for producing julian dates have been
posted before. If remarQ has a search feature, search for
the keywords 'julian date' in comp.lang.awk .

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful



Sat, 17 Aug 2002 03:00:00 GMT  
 changing date to julian

Quote:

> How do I change the 4th and 6th field in a file to a juilian date?

If you mean a Julian day number, try

  $4 = $6 = "351"

- this will set the 4th and 6th field to the Julian day number 351. You
can use any other number and will get any other Julian day number ;-)

But probably that's not what you want. I guess you want to parse $4 and
$6 and get the Julian day number for that day. But, alas, you didn't
provide any sample data that show how your $4 and $6 look, so I can't
tell more.

Regards...
                Michael



Sat, 17 Aug 2002 03:00:00 GMT  
 changing date to julian

   >Hello All,
   >How do I change the 4th and 6th field in a file to a juilian date?
   >Thanks
What are the 4th and 6th fields?  Month and day?  Is it the month name or
number?  You need to know the year to know if it is a leap year.  A true
Julian date is the number of days since Jan. 1, 50something B.C., but you
probably just want the day number within a given year.


Sat, 17 Aug 2002 03:00:00 GMT  
 changing date to julian
Try these routines:

#---------------------------------------------------------------------------
--
#
# Fileame:              CALENDAR.AWK
#
# Author:               Robert H. Morrison
# Date:                 Wed Apr 2, 1997
#
# Description:  Calendar routines
#
#---------------------------------------------------------------------------
--

BEGIN {

        #-----------------------
        #       Days of the Week
        #-----------------------

        Day_of_Week["0"] = "Monday"
        Day_of_Week["1"] = "Tuesday"
        Day_of_Week["2"] = "Wednesday"
        Day_of_Week["3"] = "Thursday"
        Day_of_Week["4"] = "Friday"
        Day_of_Week["5"] = "Saturday"
        Day_of_Week["6"] = "Sunday"

        List_of_Dates[ "12.10.97" ] = "Sunday"
        List_of_Dates[ "10.12.97" ] = "Wednesday"
        List_of_Dates[ "09.02.98" ] = "Monday"

        for ( MyDate in List_of_Dates )
        {
                jdate  = ToJul( MyDate )
                dow = DayOfWeek( jdate )

                if ( Day_of_Week[dow] == List_of_Dates[MyDate] )
                        result = "O.K."
                else
                        result = "ERROR"

                printf("%s (julian day %d) is a %s\t%s\n", MyDate, jdate,
Day_of_Week[dow], result )
        }

Quote:
}

# <f>
-----------------------------------------------------------------------
#
#       Name:           ToJul
#
#       Description:    Converts a Gregorian calendar date to its corresponding
#                               Julian Day number.
#
#                               The algorithm is an adaptation of the fortran code used
#                               to implement the algorithm presented by H. Fliegl and
#                               T. Van Flanders, Communications of the ACM, Vol. 11,
#                               No. 10, October, 1968, page 657.
#
#       Parameters:     in      date    "dd.mm.yy"
#                  
#       Return Value:   Number representing the Julian Day number.
#
#---------------------------------------------------------------------------
-

function ToJul( date, jul_day ) {

        split( date, datum, "." )

        lmonth = datum[2]
        lday   = datum[1]
        lyear  = datum[3]

        if ( lyear < 80 )
                lyear += 2000
        else if ( lyear < 100 )
                lyear += 1900

        jul_day = lday - 32075 + 1461 * (lyear + 4800 + int(int((lmonth - 14) /
12) / 4 ))      \
                          + 367 * int((lmonth - 2 - int((lmonth - 14) / 12) * 12) / 12 ) -              \
                          3 * int(int((lyear + 4900 + int((lmonth - 14) / 12)) / 100) / 4 )

        return jul_day

Quote:
}

# <f>
-----------------------------------------------------------------------
#      
#       Name:           FromJul      
#      
#       Description:    Converts a Julian Day number to its corresponding
#                               Gregorian calendar date components.
#      
#                               The algorithm is an adaptation of the FORTRAN code used
#                               to implement the algorithm presented by H. Fliegl and
#                               T. Van Flanders, Communications of the ACM, Vol. 11,
#                               No. 10, October, 1968, page 657.
#      
#       Parameters:     in      jul_date        julian day number to convert
#
#                       out     Month           Gregorian month for jul_date
#                       out     Day                     Gregorian day for jul_date
#                       out     Year            Gregorian year for jul_date
#                  
#       Return Value:   NONE (updates GLOBAL Month, Day, and Year variables)
#
#---------------------------------------------------------------------------
-

function FromJul( jul_date, t1, t2, yr, mo ) {

        t1 = jul_date + 68569
        t2 = 4 * t1 / 146097
        t1 = t1 - (146097 * t2 + 3) / 4
        yr = 4000 * (t1 + 1) / 1461001
        t1 = t1 - 1461 * yr / 4 + 31
        mo = 80 * t1 / 2447

        Day = int(t1 - 2447 * mo / 80)
        t1 = mo / 11

        Month = int(mo + 2 - 12 * t1)
        Year = int(100 * (t2 - 49) + yr + t1)

Quote:
}

# <f>
-----------------------------------------------------------------------
#      
#       Name:           IsLeapYear  
#      
#       Description:    Determines whether a given year is a leap year.
#      
#       Parameters:     in      year    Year to check for a leap year
#
#       Return Value:   TRUE if a leap year, FALSE otherwise.
#
#---------------------------------------------------------------------------
-

function IsLeapYear( year ){ return ( year % 4 == 0 && ( year % 100 != 0 ||
year % 400 == 0 )) }

# <f>
-----------------------------------------------------------------------
#
#       Name:           DayOfWeek
#
#       Description:    Determine the day of the week a given julian day number
#                               falls on.
#
#       Parameters:     in      jul_day         julian day number
#
#       Return Value:   0 ... 6, where 0 = Monday, 1 = Tuesday, ... 6 = Sunday.
#                  
#---------------------------------------------------------------------------
-

function DayOfWeek( jul_day ){ return (jul_day % 7) }

--
Best regards,
 _ __                      _    ,   _ _ _
' )  )     /         _/_  ' )  /   ' ) ) )
 /--' ____/___/> __  /     /--/     / / / __,_  __  o _   ______
/  \_(_) /_) (__/ (_<__   /  ( o   / ' (_(_) (_/ (_<_/_)_(_) / <_

Robert H. Morrison                      Tel:   +49 721 9628 167
Software Development, Basis Team        FAX:   +49 721 9628 149


Quote:

>    >Hello All,
>    >How do I change the 4th and 6th field in a file to a juilian date?
>    >Thanks
> What are the 4th and 6th fields?  Month and day?  Is it the month name or
> number?  You need to know the year to know if it is a leap year.  A true
> Julian date is the number of days since Jan. 1, 50something B.C., but you
> probably just want the day number within a given year.



Sun, 18 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Julian Date Converter Functions - julian.prg (1/1)

2. Date with Julian Date

3. Gregorian Dates to Julian dates, and back

4. CW2.003 File copy changes the date.....need a way to copy w/o date change

5. leap years, julian date, and stuff.

6. Converstion of dates to Julian

7. Julian Date implementation?

8. Julian Date Function

9. Julian Date???

10. Get Julian Date

11. Julian Date

12. Julian Date

 

 
Powered by phpBB® Forum Software