Thursday, December 2, 2010

Calculation Of Melting Temperature In Pcr

date in C even tinkered

date calculations are always a source of great tedious, error-prone parts of the program. Especially in languages that do not support such date operations. They are also always suitable to practice programming. Here the model solution to a simple calendar program in C, where much of the date functions are self-knitted. Have fun!
use:
are no parameters are simply the current month Marking \u0026lt;2> for today and : 8: as a marker for Austrian holidays. Then the list of holidays will be issued.
 $ / cal 
December 2010

Monday 6 Tuesday 7 13 20 27 14 21 28

Wednesday 1. 8: 15 22 29
Thursday < 2> 9 16 23 30 10 17
Friday 3: 24:: 31:
Saturday 4 11 18: 25:
Sunday: 5:: 12:: 19:: 26:

5.12. 2. Advent
8.12. Immaculate Conception
12.12. 3. Advent
19.12. 4. Advent
24.12. Christmas Eve
25.12. Christmas Day
26.12. Boxing
31.12. New Year :-)

Here comes the Source ...

 / 
* * File: cal.c

* * Purpose: * ...
calendar program for a given month.
* with / without argc / argv

* * Author: Harald Haberstroh

* * Algorithm:

* * History: * 2003-10-15 2002-09-29
, Holidays + arguments from main () *
2004-11-05, List of holidays
* /

/*--------------------------- includes ------ ------------------------*/
# include # include \u0026lt;stdio.h>
\u0026lt;string.h>
# include # include \u0026lt;stdlib.h>
\u0026lt;assert.h>
# include \u0026lt;time.h>

/*------------------- -------- defines -------------------------------*/
# define DAY 3 / week * of 01/01/1582 * / # define
Monday 0 Tuesday 1

# define # define # define
Wednesday 2 Thursday 3 Friday 4

# define # define # define
Saturday 5 Sunday 6

/*----- --------------------------- ---------------------- typedefs ---*/

/*--------------------------- globals ------------- ------------------*/

enum {NO = 0,
NEW YEAR,
HL3KOENIGE,
ASH WEDNESDAY
PALM SUNDAY,
GOOD FRIDAY,
EASTER SUNDAY,
EASTER MONDAY
STATE HOLIDAY,
MOTHER,
WHIT SUNDAY,
WHIT MONDAY
TRINITY SUNDAY,
CORPUS CHRISTI,
Assumption,
NATIONAL,
Reformation,
ALL SAINTS,
ALLERSEELEN,
MARIAEMPFAENGNIS,
ADVENT1,
ADVENT2,
ADVENT3,
ADVENT4,
CHRISTMAS EVE,
Christiani
STEFANI,
NEW
};

/*----------------- --------- prototypes -----------------------------*/
void print holidays (int year, int month);
int day month (int year, int month);
int sunday (int year, month int, int tag);
void tag2datum (int tagzahl, int * year, int * month, int * tag); Easter
void (int year, int * month, int * tag);
holiday int (int year, int month, int day);
anzProMonat int (int year, int month);
void PrintCal ( int start, int num, int day, int month, int year);
int leap year (int year);
Anzahl_Tage int (int year, int month, int day);

/*-------- --------------------- ---------------------------- main ----*/
int main (int argc, char * argv [])
{Int
day, day, month, year, start;
struct tm * time;
time_t sec;

if (argc == 2 & & strcmp (argv [1], "-i") == 0) {
/ * interactive * / printf
("Year"); scanf ("% d", & year);
printf ("month"); scanf ("% d", & month);
printf ("day (0 for no particular)> "); scanf ("% d ", & tag);
if (tag == 0) {

tag = 1;
if (1 <= monat && monat <= 12 &&
1582 < jahr && jahr < 3000)
{
Anzahl_Tage days = ( Year Month, 1);
start = (day + week)% 7;
PrintCal (start, anzProMonat (year, month), 0, month, year);
return 0;}


else {fprintf
( stderr, "month between 1 and 12 years between"
's 1583 and 2999 ");
return 2;}


} if (1 <= monat && monat <= 12 &&
1582 < jahr && jahr < 3000 &&
a <= tag && tag <= anzProMonat(jahr,monat))
{
Anzahl_Tage days = (year month, 1 );
start = (day + week)% 7;
PrintCal (start, anzProMonat (year, month), day, month, year);
return 0;}

else {

fprintf (stderr, "month between 1 and 12 years between"
"in 1583 and 2999 \\ n"
[day between 1 and Number for this month] \\ n ");
return 2;}


} else if (argc == 3) / * Month and year * / {

month = atoi (argv [1]);
year = atoi (argv [2 ]);
tag = 1;
if (1 <= monat && monat <= 12 &&
1582 < jahr && jahr < 3000)
{
Anzahl_Tage days = (year, month, 1);
start = (days WEEKDAY +)% 7;
PrintCal (start, anzProMonat (year, month), 0 month, year);
return 0;}

else {

fprintf (stderr, "month between 1 and 12 years between"
"in 1583 and 2999 \\ n");
return 2;}


} else if (argc == 4) / * all day * / {

month = atoi (argv [2]);
year = atoi (argv [3]);
tag = atoi (argv [1]);
if (1 <= monat && monat <= 12 &&
1582 < jahr && jahr < 3000 &&
a <= tag && tag <= anzProMonat(jahr,monat))
{
Anzahl_Tage days = (year, month, 1); start
= (DAY + days)% 7;
PrintCal (start, anzProMonat (year, month), day, month, year);
return 0;}

else

{fprintf (stderr, "Monthly 1-12 per year between "
" in 1583 and 2999 \\ n "
[day between 1 and Number for this month] \\ n");
return 2;}


} else if (argc == 1) / * current month * / {

time (& sec);
time = localtime (& sec);
tag = time-> tm_mday;
month = time-> tm_mon + 1;
year = time-> tm_year + 1900;
Anzahl_Tage days = (year month, 1);
start = (DAY + days)% 7;
PrintCal (start, anzProMonat (year , month), day, month, year);
return 0;}

else

{fprintf (stderr, "Usage: \\ n% s [[day] month year] \\ n", argv [0]);
return 1;}

}

/*-------------------------- functions ----------- -------------------*/
/ ** * Calendar spend
start ... Week of the 1st This month
* vol ... Number of days this month
* Today ... Day's date, 0 if in a month other month
* ... Month (1 .12)

* year * / void
PrintCal (int start, int num, int day, int month, int year) {

char * days [] = {"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday, Sunday};
char * months [] = {" January "," February "" March "," April ",
" May " , "June" "July", "August",
"September", "October", "November" "December"};
int i;
int tag;

printf ("% s% d \\ n \\", [month-1] for months, year);
for (i = 0; < 7; i++)

{printf ("% 10s", days [i]);
for (tag = i + 1 - start; tag < anz + 7 + start; tag += 7)
if (tag == today & & holidays (year month, day)
& & day> = 1 & & tag <= anz)
printf ("[% 2d]", tag);
else if (day == today & & day> = 1 & & tag <= anz)
printf ("<%2d>, day);
else if (holiday (year, month, day) & & day> = 1 & & tag <= anz)
printf ("% 2d " , tag);
else if (tag> = 1 & & tag <= anz)
printf ("% 3d", tag);
else
printf ("");
printf ("\\ n");
}
printf ("\\ n ");
print holidays (year, month);
}

/ *
* Function leap year
*
* Purpose: Returns 1 if specified year is a leap year
*
* Algorithm:
* from 1582 the following rule applies to Leap years:
* If the year is divisible by 400 or
* is the year number is divisible by 4 but not by 100 then
* is the year a leap year

* * Parameters: * IN
: Year
* OUT:

* * Return value: 1 ... Leap year
* 0 ...
otherwise * / int
leap year (int year) {

if (year% 400 == 0) return 1
;
else if (year% 100 == 0) return 0
;
else if (year% 4 = = 0)
return 1;
else
return 0;
}

int anzProMonat (int year, int month)
{
switch (month)
{
case 2:
return 28 + leap year (year);
break ;
case 4:
case 6: case 9
:
case 11: return
30;
break;
default:
return 31;}



} / * * Function
Anzahl_Tage

* * Purpose: Determines the number of days from 1.1 .1582

* * Algorithm: *
day + number of days for months + Number of days for years

* * Parameters: * IN
: year, month, day
* OUT:

* * Return value: number of days from 01/01/1582
* / int
Anzahl_Tage (int year, int month, int day) {

int j;
int m, int
day = day / * day of month * /

/ *
* days for years to calculate
* /
for (j = 1582; j < Jahr; j++ )
days + = 365 + leap year (j);

/ *
* days for months Calculate
* /
for (m = 1, m < Monat; m++ )
switch (m)
{
case 2:
case 6::
case 9:

days + = 28 + leap year (year);
case 4;
break case 11:
days + = 30;
break;
default:
days + = 31;}

return ( days);}


/ ** Determines holiday.
* @ param year * @ param month

* @ param tag * @ return number
of the holiday, 0 otherwise
* / int
holiday (int year, int month, int day) {tagzahl

int, j, m , t;
Easter (year, & m, & t);
tagzahl = Anzahl_Tage (year, m, t);

if (& & month == m tag == t) / * Easter * /
return EASTER SUNDAY;
tag2datum (tagzahl + 1, & j, & m, & t);
if (month == m & & tag == t) / * Easter * / return
Easter Monday;
tag2datum (tagzahl - 46, & j, & m, & t);
if (& month == m & tag == t) / * Ash Wednesday * /
return ASH WEDNESDAY;
tag2datum (tagzahl - 7, & j, & m, & t );
if (month == m & & tag == t) / * Palm Sunday * /
return PALM SUNDAY;
tag2datum (tagzahl - 2, & j, & m, & t);
if (month == & m & tag == t ) / * Good Friday * / return
GOOD FRIDAY;
tag2datum (tagzahl + 49, & j, & m, & t);
if (month == m & & tag == t) / * Whitsunday * /
return Whitsunday;
tag2datum (tagzahl + 50, & j, & m, & t);
if (month == & & m tag == t) / * Whit Monday * /
return Whit Monday;
tag2datum (tagzahl + 56, & j, & m, & t);
if (month == & & m tag == t) / * Trinity Sunday * /
return Trinity Sunday;
tag2datum (tagzahl + 60, & j, & m, & t);
if (month == m & & tag == t) / * Corpus Christi * / return
CORPUS CHRISTI,

if (month == 1 & & tag == 1) / * Year * /
return YEAR;
if (month == 1 & & day == 6) / * Holy 3 Kings * / return
HL3KOENIGE;
if (month = returnType = 5 & & tag == 1) / * National Day * /
STATE HOLIDAY;
tag2datum (Sunday (year, 5, 13), & j, & m, & t);
if (month == 5 & & tag == t) / Mother * FIXME * / return
MOTHER;
if (month == 8 & & tag == 15) / * Assumption * / return
MARIA ASCENSION;
if (month == 10 & & tag == 26) / * National * / return
NATIONAL;
if (month == 10 & & tag == 31) / * * Reformation /
return Reformation;
if (month == 11 & & tag == 1) / * All Saints * /
return ALL SAINTS;
if (month == 11 & & tag == 2) / * All Selenium * /
return ALLERSEELEN;
if (month == 11)
{
if ( Sunday (year, 12, 24) == Anzahl_Tage (year, 12, 24)) =
tagzahl Sunday (year, 12, 24) - 21;
else
tagzahl = Sunday (year, 12, 24) - 28;
tag2datum (tagzahl, & j, & m, & t);
if (tag == t & & m == 11) / * 1 Advent * / return
ADVENT1;

} if (month == 12) {

if (tag == 8) / * return * Maria Emfängnis /
MARIAEMPFAENGNIS;

if (Sunday (year, 12, 24) = = Anzahl_Tage (year, 12, 24))
tagzahl = Sunday (year, 12, 24) - 21;
else
tagzahl = Sunday (year, 12, 24) - 28;
tag2datum (tagzahl, & j, & m, & t );
if (tag == t && m == 12) /* 1. Advent */
return ADVENT1;
tag2datum(tagzahl+7, &j, &m, &t);
if (tag == t) /* 2. Advent */
return ADVENT2;
tag2datum(tagzahl+14, &j, &m, &t);
if (tag == t) /* 3. Advent */
return ADVENT3;
tag2datum(tagzahl+21, &j, &m, &t);
if (tag == t) /* 4. Advent */
return ADVENT4;
if (tag == 24) /* Hl. Evening * / return
CHRISTMAS EVE;
if (tag == 25) / * Christiani * / return
Christiani;
if (tag == 26) / * Boxing * / return
STEFANI;
if (tag == 31) / * New Year :-) * / return
NEW YEAR'S EVE;}


return NO / * No holiday * /}


void easter (int year, int * month, int * tag) {

int a = year% 19;
int b = year / 100;
int c = year% 100;
int d = b / 4;
int e = b% 4;
int f = (B + 8) / 25;
int g = (b - f + 1) / 3;
int h = (19 * a + b - d - g + 15)% 30;
int i = c / 4 ;
int k = c% 4;
int l = (32 + 2 * e + 2 * i-h-k)% 7;
int m = (a + 11 + 22 * h * l) / 451;
int p = (h + l - 7 * m + 114)% 31;

* month = (h + l - 7 * m + 114) / 31;
tag = * p + 1;}

void tag2datum ( tagzahl int, int * year, int * month, int * tag) {

/ *

* year * / * year =
calculate 1582;
while (tagzahl> 365 + leap year (* year ))
{
tagzahl -= 365 + leap year (* year);
(* year) + +;
}
/ *
* Monthly
* /
for (* month = 1; tagzahl> day month (* year, * month) (month *) + +) -=
tagzahl days month (* year, * month);
/ *

* day * / * tag =
tagzahl;}


int sunday (int year, int month, int day) {

int tagzahl Anzahl_Tage = (year, month, day);
int wt = (THURSDAY tagzahl +)% 7;
if (wt == Sunday) / * already Sunday * / return tagzahl
; return else

tagzahl + (SUNDAY - wt);
}
int day month (int year, int month)
{
switch (month)
{
case 2:
return 28 + leap year (year);
break;
case 4:
case 6: case 9
:
case 11: return
30;
break;
default:
return 31;}



} / ** Give a list of public holidays off.
* @ param year * @ param month
IN OUT
* / void print
holidays (int year, int month) {

int i;
char * ref = "";
for (i = 1; i <= tagemonat(jahr, monat); i++)

{bez = "";
switch (holiday (year, month, i)) {

case YEAR:
bez = "New Year"; break
;
case HL3KOENIGE:
bez break
;; = "Three Kings"
case ASH WEDNESDAY:
bez = "Ash Wednesday";
break;
case PALM SUNDAY:
bez = "Palm Sunday";
break;
case GOOD FRIDAY:
bez = "Good Friday";
break ;
case EASTER SUNDAY:
bez = "Ostersonntag"
break;
case Ostermontag:
without = "Ostermontag"
break;
case STAATSFEIERTAG:
without = "Staatsfeiertag"
break;
case Muttertag:
without = "Muttertag"
break;
case PFINGSTSONNTAG:
without = "Pfingstsonntag"
break;
case PFINGSTMONTAG:
without = "Pfingstmontag"
break;
case DREIFALTIGKEITSSONNTAG:
without = "Dreifaltigkeitssonntag"
break;
case FRONLEICHNAM:
without = "Fronleichnam"
break;
case MARIAHIMMELFAHRT:
without = "Maria Himmelfahrt"
break;
case NATIONALFEIERTAG:
without = "Nationalfeiertag"
break;
case REFORMATIONSTAG:
without = "Reformationstag "
break;
case Allerheiligen:
without =" Allerheiligen "
break;
case Allerseelen:
without =" Allerseelen "
break;
case MARIAEMPFAENGNIS:
without =" Maria Empfängnis "
break;
case ADVENT1:
without = "1 Advent"
break;
case ADVENT2:
without = "2 Advent"
break;
case ADVENT3:
without = "3 Advent"
break ;
case ADVENT4:
without = "4 Advent"
break;
case HEILIGABEND:
without = "Heiligabend"
break;
case Christie
without = "Christtag"
break;
case STEFANI:
no = "Stefanitag"
break;
case NEW:
bez = "New Year :-)";
break;}

if (strlen (bez)> 0)
printf ("% 2d% d.% s \\ n ", i, month, mar. );}

}

0 comments:

Post a Comment