/*************************************************************** TIMELGRID.C This program produces a list of subset of time range based on the time_range and time_interval specified by the user. Willa Zhu 91/05/28 ---------------------------------------------------------------- control file structure: output: (file name) time_interval: (in minutes) time_range: (yy/mm/dd hh:mm:ss) to (yy/mm/dd hh:mm:ss) ****************************************************************/ #include #include "geninc.h" #include "ioserv.h" /* PARAMETER_LIST_ENTRY_TYPE, get_parameters(), check_error() */ #include "use_db.h" /* check_db*() get_time_range */ int main(int argc, char *argv[]) { FILE *fp_out; FILE *fp_cnt; YMDHMS_TIME_TYPE start, end, current_date; double start_day, end_day, current_day; static int year_base; static FILE_NAME_TYPE out_filename; static double interval; static PARAMETER_LIST_ENTRY_TYPE parameters[] = { { " output:", PATH_FMT, out_filename, TYPE_STRING }, { " time_interval:", " %lf", &interval, TYPE_DOUBLE }, { " time_range:", NULL, NULL, 0 }, { NULL, NULL, NULL, 0 } }; /* parameters[] */ fp_cnt = get_fpcnt(argc, argv); if (get_parameters(fp_cnt, parameters, NULL)) exit(-1); if ((fp_out = fopen(out_filename, "w")) == NULL) { printf("\n ERROR: Cannot open file %s.\n",out_filename); exit(-1); } fprintf(fp_out, "/* TimeGrid:\n"); print_parameters(fp_out, parameters, NULL, " "); fprintf(fp_out, " */\n"); while (get_time_range(fp_cnt, &start, &end) == 1) { start.year = yr4digit(start.year); end.year = yr4digit(end.year); year_base = start.year; fprintf(fp_out, "/* time_range: "); write_ymdhms_time(fp_out, &start); fprintf(fp_out, " to "); write_ymdhms_time(fp_out, &end); fprintf(fp_out, " */"); start_day = year_day(&start, year_base); end_day = year_day(&end, year_base); current_day = start_day; fprintf(fp_out, "\n"); while((end_day - current_day) > (1./(24.*60.))) { fprintf(fp_out, " "); yd_to_ymdhms_time(current_day, year_base, ¤t_date); write_ymdhms_time(fp_out, ¤t_date); fprintf(fp_out, " to "); current_day += interval/(24.*60.); yd_to_ymdhms_time(current_day, year_base, ¤t_date); if(current_day > end_day) write_ymdhms_time(fp_out, &end); else write_ymdhms_time(fp_out, ¤t_date); fprintf(fp_out, "\n"); } } fclose(fp_out); return 0; }