Permalink
Browse files

Conbine into one program.

  • Loading branch information...
1 parent 0cee1fc commit dd4926373f3a7bab69c40869e92535bc297f4278 Leon.L committed Aug 17, 2010
Showing with 206 additions and 126 deletions.
  1. +10 −0 SolarAndLunar.h
  2. +6 −1 db.h
  3. +49 −0 main.cpp
  4. +35 −51 make24db.c
  5. +10 −7 makedb.c
  6. +27 −0 makedb.h
  7. +69 −67 transfer.c
View
@@ -0,0 +1,10 @@
+
+
+#ifndef SOLARANDLUNAR
+#define SOLARANDLUNAR
+
+void ToSolar( int*, int*, int*, int );
+void ToLunar( int*, int*, int*, int*);
+void readDB ( void );
+
+#endif // SOLARANDLUNAR //
View
7 db.h 100644 → 100755
@@ -1,3 +1,6 @@
+
+#ifndef SOLARANDLUNAR_DB
+#define SOLARANDLUNAR_DB
struct Sday {
int month;
int day;
@@ -16,4 +19,6 @@ struct MappingOfLunarToSolar {
int leap;
};
-struct MappingOfLunarToSolar stMOLTS[200];
+
+
+#endif // SOLARANDLUNAR_DB //
View
@@ -0,0 +1,49 @@
+#include <cstdlib>
+#include <iostream>
+#include "SolarAndLunar.h"
+#include "makedb.h"
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+
+ int y, m, d, l;
+ if ( argc >= 5 )
+ {
+ readDB();
+ y = atoi(argv[1]);
+ m = atoi(argv[2]);
+ d = atoi(argv[3]);
+ l = atoi(argv[4]);
+ ToSolar(&y, &m, &d, l);
+
+ printf("%d %d %d \n", y, m, d);
+ return 0;
+ }
+ else if ( argc == 4 )
+ {
+ readDB();
+ y = atoi(argv[1]);
+ m = atoi(argv[2]);
+ d = atoi(argv[3]);
+ ToLunar(&y, &m, &d, &l);
+ printf("%d %d %d %s\n", y, m, d, (l != 0)?"leap":"");
+
+
+ }
+ else if ( argc == 1 )
+ {
+ make24SolarTermsDB();
+ save2file24();
+ }
+ else
+ {
+ makeLunarDB();
+ makeSolarDB();
+ save2file();
+ }
+
+ system("PAUSE");
+ return EXIT_SUCCESS;
+}
View
86 make24db.c 100644 → 100755
@@ -1,19 +1,14 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include "makedb.h"
+#include "SolarAndLunar.h"
+
//#define DEBUG
-struct SOLARTERMS{
- int month ;
- int day ;
- int hour ;
- int minute ;
- int second ;
-};
-
-struct SOLARTERM24 {
- int year;
- struct SOLARTERMS sts[24];
-}ST[200];
+
+struct SOLARTERM24 ST[200];
+
+int SMONTHDAY[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void make24SolarTermsDB()
{
@@ -70,7 +65,7 @@ void make24SolarTermsDB()
}
-void save2file()
+void save2file24()
{
FILE *f2;
f2 = fopen("db24","wb");
@@ -85,17 +80,20 @@ void save2file()
}
+// input is Gregorian.
void search(int y, int m, int d, int h)
{
if ( y < 1900 || y > 2100 )
return;
if ( m < 1 || m > 12 )
return;
- if ( d < 1 || d > 31 )
+ if ( d < 1 || d > SMONTHDAY[m] )
return;
if ( h < 0 || h > 23 )
return;
+
+
int i, j;
int after, before;
int afterY = y;
@@ -115,23 +113,23 @@ void search(int y, int m, int d, int h)
if ( ST[y-1900].sts[i*2].month == m )
{
solarTerm = i;
- if ( d < ST[y-1900].sts[i*2].day )
+ if ( ST[y-1900].sts[i*2].day < d )
c = 1;
- else if ( ST[y-1900].sts[ i * 2 + 1].day < d )
+ else if ( ST[y-1900].sts[ i * 2 + 1].day > d )
c = 2;
else if ( ST[y-1900].sts[i * 2].day <= d && d <= ST[y-1900].sts[i * 2 + 1].day )
{
- if ( h < ST[y-1900].sts[i*2].hour && ST[y-1900].sts[i * 2].day == d )
+ if ( h < ST[y-1900].sts[i*2].hour )
{
c = 1;
}
- else if ( ST[y-1900].sts[i*2 + 1].hour <= h && d == ST[y-1900].sts[i * 2 + 1].day)
+ else if ( ST[y-1900].sts[i*2].hour <= h )
c = 2;
// if ( ST[y-1900].sts[i * 2].hour <= h && h <= ST[y-1900 ].sts[i * 2 + 1].minute )
// {
-// if ( mi < ST[y-1900].sts[i*2].minute && ST[y-1900].sts[i*2].hour == h )
+// if ( mi < ST[y-1900].sts[i*2].minute )
// c = 1;
-// if ( ST[y-1900].sts[i*2+1].minute <= mi && h == ST[y-1900].sts[i*2+1].minute)
+// if ( ST[y-1900].sts[i*2].minute <= mi )
// c = 2;
// }
@@ -179,34 +177,20 @@ void search(int y, int m, int d, int h)
}
-void debug(void)
-{
- int i, j;
- for ( i = 1 ; i <= 23 ; i++)
- {
- printf("The date is 1978/7/7 %dh\n",i);
- search(1978, 7, 7, i);
- }
-
-};
-
-
-int main ( int argc, char *argv[] )
-{
- make24SolarTermsDB();
- save2file();
-
- int y, m, d, h;
- if ( argc == 5 )
- {
- y = atoi(argv[1]);
- m = atoi(argv[2]);
- d = atoi(argv[3]);
- h = atoi(argv[4]);
- search(y, m, d, h);
- }
- else
- debug();
-
- return 0;
-}
+//int main ( int argc, char *argv[] )
+//{
+// make24SolarTermsDB();
+// save2file24();
+//
+// int y, m, d, h;
+// if ( argc == 5 )
+// {
+// y = atoi(argv[1]);
+// m = atoi(argv[2]);
+// d = atoi(argv[3]);
+// h = atoi(argv[4]);
+// search(y, m, d, h);
+// }
+//
+// return 0;
+//}
View
17 makedb.c 100644 → 100755
@@ -1,7 +1,10 @@
#include <stdio.h>
#include <string.h>
+#include "makedb.h"
#include "db.h"
+static struct MappingOfLunarToSolar stMOLTS[200];
+
int makeLunarDB()
{
int Y, M, D, LM;
@@ -108,10 +111,10 @@ void save2file()
}
-int main ( void )
-{
- makeLunarDB();
- makeSolarDB();
- save2file();
- return 0;
-}
+//int main ( void )
+//{
+// makeLunarDB();
+// makeSolarDB();
+// save2file();
+// return 0;
+//}
View
@@ -0,0 +1,27 @@
+#ifndef SOLARANDLUNAR_MAKEDB
+#define SOLARANDLUNAR_MAKEDB
+
+struct SOLARTERMS{
+ int month ;
+ int day ;
+ int hour ;
+ int minute ;
+ int second ;
+};
+
+struct SOLARTERM24 {
+ int year;
+ struct SOLARTERMS sts[24];
+};
+
+// makedb
+int makeLunarDB();
+int makeSolarDB();
+void save2file();
+
+// makedb24
+void make24SolarTermsDB();
+void save2file24();
+void search(int, int, int, int);
+
+#endif // SOLARANDLUNAR_MAKEDB //
Oops, something went wrong.

0 comments on commit dd49263

Please sign in to comment.