Date routines

If you are interested to convert a time column in a data file you should immediately read about cal2dy
Another possibility to convert time records, however more adequate for equal-spaced time-series is with  tslist

All  the commands below explain themselves if you call them by

    command -h


calrect    - regularize kalendar date, pick a parameter, reformat, etc.

 USAGE:
           calrect [options] year month day

 PURPOSE:
           Parse and reformat kalendar data.
           Month may be numeric or a three-character string.
           A date like 99 FEB 29 will be converted to 99 MAR 01,
           99 DEC 32 to 00 JAN 01 etc.

 OPTIONS:
 -[y][m][d]  or any permutation indicates the requested ordering of output
           Year Month Day. n and m are treated synonymously.
           M or C instead of m requests three-character month,
           C in capitals.           Specify -y to print only the year, etc.

 -s[d]     d signifies a delimiter for the output. Default is none.
           To enter a blank, use -s or -s" "

 -f[str]   Formatted input. Format code str. Outer parenthesis can be skipped.
           Default (i4,i3,i2), which is suitable also for
           3-character months. Needed if date is given without delimiters.

 -av       Numeric value v to be added to the date. Can be given with a blank
           inbetween.
 

 EXAMPLES:
             calrect -yCd 99 dec 32
             calrect -yCd 1999 dec 32
           Both produce 2000JAN01.

             calrect -s" " -a 1 -yCd 99 dec 31
             calrect -s" " -yCd 99 dec 32
             calrect -s -yCd 99,dec,32
             calrect -s -yCd -f 1999dec32
             calrect -s -yCd -f'(i2,i3,i2)' 99dec32
             calrect -s -yCd 99 0 366
             calrect -s -yCd 99 1 366
           All produce 2000 JAN 01.

             calrect -s -Md 1999 0 89
           produces mar 30
 



cal2yd   - calendar to year / day of year and vice versa

Usage:

  cal2yd  year doy     or    cal2yd year month day

alternates date form, "doy" is day-of-year number (1..366).

 cal2yd yeardoy
(no space) is possible. 1900 will be added to years less than 100.

Further options:
  -c delimiter       One character, to split off a heading string, example:
                     cal2dy -c: string:199810
                    will split off string until ':' and  return 1998 01 10

 -d delimiter       One character, to delimit between parts of the date
                                                 string. Examples:
                     cal2dy -d- year-month-day
                    will divide string at '-'
                     cal2dy -d. year.doy
                    will divide string at '.'
 

JD - Julian date conversion

Usage:   JD [-dr |-M|-R] y m d

Converts date to Julian days, assuming UT 00:00:00 that day
Year may by given in two digits in which case 1900 will be added

Options:
 -dr   - r defines a reference Julian Day.
 -M    - return MJD (remove 2,400,000.5 JD)
 -R    - return RJD (remove 2,400,000.0 JD)
         -d, -R, and -M are mutually exclusive.
         Consider e.g.
         set RD=`JD 1950,1,1`
                    JD -d$RD 1998,1,13

There is a much better routine: JDC
 

JDC - Julian date conversion

  USAGE:
           JDC  options date

 PURPOSE:  Convert Julian date to Kalendar or vice versa

 OPTIONS:                                                         [default]
  -j     - x is a Julian date, convert to kalendar form.
  -d yyyy mm dd [h [m [s [f]]]]
           - convert kalendar to Julian
  -n# -j x - output month in character form. #: Specify number,
             position in string                                         [6]
  -N       - like -n, upper case however
  -m  -r   - modified resp. reduced Julian
  -s       - kalendar form is  yyyy mm dd s (s=seconds, floating point)
  -h       - kalendar form is  yyyy mm dd h (h=hours, floating point)
  -k#      - a number 0 to 4 specifies h m s f part depth.              [0]
  -f fmt   - fmt is Fortran format code for kalendar output.
             Avoid the outer parentesis. Defaults exist
  -y2k     - Add 1900 to the year if greater than 50, else 2000.
  -y2k#    - Specify a year # 0..99 for the break.                     [50]

 NOTE:
           If the date part on the command line is empty,
           the program will try input from <stdin>
 
 

cal2dy  - calendar to decimal conversion, from STDIN  to STDOUT

Purpose: Reads a record with date in calendar form and outputs
         the same record but with date in decimal years in column 1.
         Reads from stdin, writes to stdout.

         Def.: Calender form is [YY]YY MM DD H M S m

         Months coded in character*3 form are always converted  to numeric
         form, 3 places, 2 digits, right-adjusted, i.e. in fortran speak  I3.2 .

         The input time record may be one of several kinds. The normal calendar
         form

 Options: (optional parameters within [ ])

  -db     Debug option.

 -Ty,m,d Input time record is hours from epoch. Use this option
         to specify the epoch date (year,month,day)

 -J[d]   Input time record is Reduced Julian Date. Add another d days.
 -Jh[d]  ... Modified Julian Date ...
 -c      Output date is calendar (meaningful only under -J)
 -j[d]   Output date is RJD; subtract d before output.
                    You may use program JD to find out a suitable d.
 -jh[d]  Output date is MJD...
 -Cj,k   Specifies date part to be contained between positions
         j and k of input record. Position j must contain a digit.
         Default = 2 11

 -I[str] Read date formatted, str is fortran format code except
         surrounding ( ). Default format = 1x,i4,2i2.
         Is needed if dates are coded without space.

 -S      Suppress records which fail processing of date.

 -Kk     Process k columns of the  H M S m  part (1 <= k <= 4),
         Default k=0

 -Dstr   Substitution string for a missing  H M S m  part.

 -Fstr   Output format code for decimal year; default = 'F12.6'.

 _date   (command line) convert this date to the other form. Stdin is not read.
         Observe nonblank first column; is required but ignored.

 Given a decimal _year, the procedure returns the calendar date in a fixed
 form. Option -M may be used to output month alphabetically.
 Option -K is significant.

 Example:
 echo " 1996nov01:00  xxxyyyzzz" | cal2dy -C2,13 -K1 -II4,I3,i2,1x,i2