int cmp_action(void *e1, size_t s1, void *e2, size_t s2) { (void)s1; (void)s2; return (cmp_time(&((t_player_action)e1)->time, &((t_player_action)e2)->time)); }
int cmp_incant(void *e1, size_t s1, void *e2, size_t s2) { (void)s1; (void)s2; return (cmp_time(&(((t_incant)e1)->timeout), &(((t_incant)e2)->timeout))); }
file_list* get_filename(capture_time *time_cap,char *path) { int index; char command[150]; char filename[50],open_path[100]; int start_hr,end_hr,start_min,end_min; FILE *fp; file_list *file_start=0,*end=0,*tmp; sprintf(open_path,"%s%s",path,"BitMaps/"); sprintf(command,"%s%s%s%d_%d%s","ls -t ",open_path," | grep bit",time_cap->month,time_cap->day," | cut -d '_' -f 3,4,5,6,7 --output-delimiter ' ' > tempp.txt"); // printf("%s",command); system(command); fp=fopen("tempp.txt","r"); while(fscanf(fp,"%d%d%d%d%d",&start_hr,&start_min,&end_hr,&end_min,&index)==5) { if(!((cmp_time(start_hr,start_min,time_cap->start_hr,time_cap->start_min)==-1 && cmp_time(end_hr,end_min,time_cap->start_hr,time_cap->start_min)==-1) || (cmp_time(start_hr,start_min,time_cap->end_hr,time_cap->end_min)==1 && cmp_time(end_hr,end_min,time_cap->start_hr,time_cap->start_min)==1))) { sprintf(filename,"bit%d_%d_%d_%d_%d_%d_%d",time_cap->month,time_cap->day,start_hr,start_min,end_hr,end_min,index); printf("\nfilename::%s is here",filename); if(file_start==0) { file_start=end=get_file_node(filename); } else { end->next=get_file_node(filename); end=end->next; } } printf("\nIn function end %s",filename); } fclose(fp); //system("rm -f tempp.txt"); //printf("%s","Filenames Extracted"); printf("\n File name list %s",file_start->filename); return file_start; }
static int fts_cmp(const FTSENT **p, const FTSENT **q) { int ret; unsigned short info_p, info_q; info_p = (*p)->fts_info; info_q = (*q)->fts_info; /* error file comes first */ if (info_p == FTS_ERR) return -1; else if (info_q == FTS_ERR) return 1; else if (info_p == FTS_NS || info_q == FTS_NS) { if (info_q != FTS_NS) return -1; else if (info_p != FTS_NS) return 1; ret = cmp_lexico(*p, *q); /* reverse the order if -r specified */ if (!f_reverse) return ret; else return -ret; } /* sort by different options */ if (f_sortmtime) ret = cmp_time(*p, *q); else if (f_sortsize) ret = cmp_size(*p, *q); else ret = cmp_lexico(*p, *q); if (!f_reverse) return ret; else return -ret; }
int f_fcst_ave(ARG2) { struct ave_struct *save; int i, pdt, new_type; int year, month, day, hour, minute, second; int tyear, tmonth, tday, thour, tminute, tsecond; int missing; char string[10]; // initialization if (mode == -1) { save_translation = decode = 1; // allocate static structure *local = save = (struct ave_struct *) malloc( sizeof(struct ave_struct)); if (save == NULL) fatal_error("memory allocation fcst_ave",""); i = sscanf(arg1, "%d%2s", &save->dt,string); if (i != 2) fatal_error("fcst_ave: delta-time: (int)(2 characters) %s", arg1); save->dt_unit = -1; if (strcmp(string,"hr") == 0) save->dt_unit = 1; else if (strcmp(string,"dy") == 0) save->dt_unit = 2; else if (strcmp(string,"mo") == 0) save->dt_unit = 3; else if (strcmp(string,"yr") == 0) save->dt_unit = 4; if (save->dt_unit == -1) fatal_error("fcst_ave: unsupported time unit %s", string); if ((save->output = ffopen(arg2, file_append ? "ab" : "wb")) == NULL) { fatal_error("fcst_ave: could not open file %s", arg2); } save->has_val = 0; save->n = NULL; save->sum = NULL; init_sec(save->first_sec); init_sec(save->next_sec); return 0; } save = (struct ave_struct *) *local; if (mode == -2) { // cleanup if (save->has_val == 1) { do_ave(save); } ffclose(save->output); free_ave_struct(save); return 0; } // if data if (mode >= 0) { // 1/2015 use_scale = 0; pdt = GB2_ProdDefTemplateNo(sec); if (mode == 98) fprintf(stderr,"fcst_ave: pdt=%d\n",pdt); // only support pdt == 0, 1 and 8 if (pdt != 0 && pdt != 1 && pdt != 8) return 0; // first time through .. save data and return if (save->has_val == 0) { // new data: write and save init_ave_struct(save,ndata); add_to_ave_struct(save, sec, data, ndata, 0); // copy sec copy_sec(sec, save->first_sec); copy_sec(sec, save->next_sec); // get reference time and save it get_time(sec[1]+12,&save->ref_year, &save->ref_month, &save->ref_day, &save->ref_hour, &save->ref_minute, &save->ref_second); if (start_ft(sec, &save->fcst_year, &save->fcst_month, &save->fcst_day, &save->fcst_hour, &save->fcst_minute, &save->fcst_second) != 0) { fatal_error("fcst_ave: could not determine the start FT time",""); } // get verf time and save it if (verftime(sec, &save->year2, &save->month2, &save->day2, &save->hour2, &save->minute2, &save->second2) != 0) { fatal_error("fcst_ave: could not determine the verification time",""); } save->has_val = 1; return 0; } // check to see if new variable new_type = 0; // get the reference time of field get_time(sec[1]+12, &year, &month, &day, &hour, &minute, &second); // see if reference time has not changed if (year != save->ref_year) new_type = 1; else if (month != save->ref_month) new_type = 1; else if (day != save->ref_day) new_type = 1; else if (hour != save->ref_hour) new_type = 1; else if (minute != save->ref_minute) new_type = 1; else if (second != save->ref_second) new_type = 1; if (new_type == 0) { if (same_sec0(sec,save->first_sec) == 0 || same_sec1_not_time(sec,save->first_sec) == 0 || same_sec3(sec,save->first_sec) == 0 || same_sec4_not_time(sec,save->first_sec) == 0) new_type = 1; if (mode == 98) fprintf(stderr, "fcst_ave: testsec %d %d %d %d\n", same_sec0(sec,save->first_sec), same_sec1_not_time(sec,save->first_sec), same_sec3(sec,save->first_sec), same_sec4_not_time(sec,save->first_sec)); } if (mode == 98) fprintf(stderr, "fcst_ave: new_type %d\n", new_type); // unlike f_ave, assume no missing .. it is a fcst not observations // check to see if verification date is expected value if (new_type == 0) { tyear = save->fcst_year; tmonth = save->fcst_month; tday = save->fcst_day; thour = save->fcst_hour; tminute = save->fcst_minute; tsecond = save->fcst_second; add_time(&tyear, &tmonth, &tday, &thour, &tminute, &tsecond, save->dt, save->dt_unit); if (start_ft(sec, &year, &month, &day, &hour, &minute, &second) != 0) fatal_error("fcst_ave: could not determine the start_ft time",""); if (cmp_time(year,month,day,hour,minute,second,tyear,tmonth,tday,thour,tminute,tsecond)) { new_type = 1; if (mode == 98) fprintf(stderr, "fcst_ave: unexpected verf time, new_type=1\n"); } else { save->fcst_year = year; save->fcst_month = month; save->fcst_day = day; save->fcst_hour = hour; save->fcst_minute = minute; save->fcst_second = second; } } // check to see if verification date is expected value missing = 0; if (new_type == 0) { if (verftime(sec, &year, &month, &day, &hour, &minute, &second) != 0) fatal_error("fcst_ave: could not determine the verification time",""); tyear = save->year2; tmonth = save->month2; tday = save->day2; thour = save->hour2; tminute = save->minute2; tsecond = save->second2; add_time(&tyear, &tmonth, &tday, &thour, &tminute, &tsecond, save->dt, save->dt_unit); if (cmp_time(year,month,day,hour,minute,second,tyear,tmonth,tday,thour,tminute,tsecond) != 0) new_type = 1; else { save->year2 = year; save->month2 = month; save->day2 = day; save->hour2 = hour; save->minute2 = minute; save->second2 = second; } } // if data is the same as the previous, update the sum if (mode == 98) fprintf(stderr, "fcst_ave ave: before update_sum new_type %d\n", new_type); if (new_type == 0) { // update sum if (mode == 98) fprintf(stderr, "fcst_ave: update sum\n"); add_to_ave_struct(save, sec, data, ndata, missing); return 0; } // new field, do grib output and save current data do_ave(save); init_ave_struct(save, ndata); add_to_ave_struct(save, sec, data, ndata, 0); copy_sec(sec, save->first_sec); copy_sec(sec, save->next_sec); // get reference time and save it get_time(sec[1]+12,&save->ref_year, &save->ref_month, &save->ref_day, &save->ref_hour, &save->ref_minute, &save->ref_second); if (start_ft(sec, &save->fcst_year, &save->fcst_month, &save->fcst_day, &save->fcst_hour, &save->fcst_minute, &save->fcst_second) != 0) { fatal_error("fcst_ave: could not determine the start FT time",""); } // get verf time and save it if (verftime(sec, &save->year2, &save->month2, &save->day2, &save->hour2, &save->minute2, &save->second2) != 0) { fatal_error("fcst_ave: could not determine the verification time",""); } save->has_val = 1; return 0; } return 0; }