#include #include #include /* * Convert time in secs to Google earth readable representation format */ void convert_time(int TinS, char *outtime){ int days = TinS/86400; int year = 2006; int month; if(days <= 31){ month = 1; }else if(days <= 31+28){ month = 2; days = days - 31; }else if(days <= 31+28+31){ month = 3; days = days - 31 - 28; }else if(days <= 31+28+31+30){ month = 4; days = days - 31 - 28 - 31; }else if(days <= 31+28+31+30+31){ month = 5; days = days - 31 - 28 - 31 - 30; }else{ month = 6; days = days - 31 - 28 - 31 - 30 -31; } //get the remaining seconds TinS = TinS - (TinS/86400*86400); int hour = TinS / 3600; TinS = TinS - (TinS/3600*3600); int min = TinS/60; TinS = TinS - (TinS/60*60); sprintf(outtime,"%d-%02d-%02dT%02d:%02d:%02dZ", year, month, days, hour, min, TinS); } /* * Generate a kml file */ int main(int argc, char ** argv) { FILE *fout; char time_string[30]; double locRandX = 0, locRandY = 0; double loc_up=0,loc_down=0,loc_right=0,loc_left=0; double loc_x=0, loc_y=0; if(!(fout=fopen(argv[1],"w"))) { fprintf(stderr,"Cannot open file %s",argv[1]); exit(1); } /* Initial kml document and style definition part */ /* This part only needs to appear once in the beginning of a kml file */ fprintf(fout,"\n"); fprintf(fout,"\n"); fprintf(fout,""); fprintf(fout,"\n\n"); /* generate behaviors obtained from the database */ while ((row = mysql_fetch_row(res)) != NULL) { fprintf(fout,"\n"); fprintf(fout,"%s\n", row[0]); fprintf(fout,"\n"); convert_time(atoi(row[1]), time_string); // convert beginning time in secs to the year/month/days/hour/min/sec fprintf(fout,"\n%s\n",time_string); convert_time(atoi(row[2]), time_string); // convert ending time in secs to the year/month/days/hour/min/sec fprintf(fout,"%s\n", time_string); fprintf(fout,"#test\n"); fprintf(fout,"\n"); locRandX = (double) rand()/ (double) RAND_MAX; locRandY = (double) rand()/ (double) RAND_MAX; loc_up = atoi(row[3]); loc_down = atoi(row[5]); loc_left = atoi(row[4]); loc_right = atoi(row[6]); loc_x = loc_down + locRandY * (loc_up - loc_down); // to prevent duplication positioning of dots loc_y = loc_left + locRandX * (loc_right - loc_left); fprintf(fout,"%s,%s\n", loc_y, loc_x); fprintf(fout,"\n"); fprintf(fout,"\n"); } fprintf(fout,"\n"); fprintf(fout,"\n"); return 0; }