int f_set_date(ARG1) { int year, month, day, hour, minute, second, i, j, units, n; int code_4_11,idx; unsigned int dtime; if (mode < 0) return 0; reftime(sec, &year, &month, &day, &hour, &minute, &second); i=strlen(arg1); if (i < 4 || i % 2 == 1) fatal_error("set_date: bad date code %s",arg1); i = sscanf(arg1,"%4d%2d%2d%2d%2d%2d" , &year, &month, &day, &hour, &minute, &second); if (i < 1) fatal_error("set_date: bad date code %s",arg1); if (check_datecode(year, month, day) != 0 || hour < 0 || hour >= 24 || minute < 0 || minute >= 60 || second < 0 || second >= 60) fatal_error("set_date: bad date code %s",arg1); // set reference time save_time(year,month,day,hour,minute,second, sec[1]+12); idx = stat_proc_n_time_ranges_index(sec); if (idx < 0) return 0; // not a stat processed template n = (int) sec[4][idx]; // number of stat proc elements j = idx + 35 - 42; // add forecast time to time units = code_table_4_4(sec); dtime = forecast_time_in_units(sec); add_time(&year, &month, &day, &hour, &minute, &second, dtime, units); for (i = 0; i < n; i++) { // add statistical processing time to time code_4_11 = (int) sec[4][47-34+j+i*12]; units = (int) sec[4][48-34+j+i*12]; dtime = uint4(sec[4]+49-34+j+i*12); if (code_4_11 == 3 || code_4_11 == 4) continue; if (code_4_11 == 1 || code_4_11 == 2) { add_time(&year, &month, &day, &hour, &minute, &second, dtime, units); } else { fatal_error_i("set_date: code 4.11=%d is not supported", code_4_11); } } save_time(year,month,day,hour,minute,second, sec[4]+j); return 0; }
/** * Called by the GUI when a key event is received, triggers an action in the * controller. * */ void Controller::receive_gui_event(const char *event,const char *value) { if(m_sleeping) return; //TODO: Fix this total mess, refactor into switch, break conditions out into methods. if(strcmp(event,"Sleep" ) == 0) event_sleep(event,value); else if(strcmp(event,"KEYPRESS" ) == 0) m_powerup=true; else if(strcmp(event,"TOTALTIMER" ) == 0) event_totaltimer(event,value); else if(strcmp(event,"Save:PulseWidth") == 0) event_save_pulsewidth(event,value); else if(strcmp(event,"Save:Calib" ) == 0) event_save_calibration(); else if(strcmp(event,"Save:Becq" ) == 0) event_save_becq(event,value); else if(strcmp(event,"Save:UTCOff" ) == 0) event_save_utcoff(event,value); else if(strcmp(event,"Save:Time" ) == 0) save_time(); else if(strcmp(event,"Save:Date" ) == 0) save_date(); else if(strcmp(event,"Save:WarnCPM" ) == 0) save_warncpm(); else if(strcmp(event,"Japanese" ) == 0) event_japanese(event,value); else if(strcmp(event,"Never Dim" ) == 0) event_neverdim(event,value); else if(strcmp(event,"English" ) == 0) event_english(event,value); else if(strcmp(event,"CPM/CPS Auto" ) == 0) event_cpm_cps_auto(event,value); else if(strcmp(event,"Geiger Beep" ) == 0) event_geiger_beep(event,value); else if(strcmp(event,"\x80Sv" ) == 0) event_usv(event,value); else if(strcmp(event,"\x80R" ) == 0) event_rem(event,value); else if(strcmp(event,"Clear Log" ) == 0) event_clear_log(event,value); else if(strcmp(event,"Save:Brightness") == 0) event_save_brightness(event,value); else if(strcmp(event,"Save:LogInter" ) == 0) save_loginterval(); else if(strcmp(event,"CALIBRATE" ) == 0) initialise_calibration(); else if(strcmp(event,"UTCSCREEN" ) == 0) event_utcscreen(event,value); else if(strcmp(event,"TIMESCREEN" ) == 0) event_timescreen(event,value); else if(strcmp(event,"BECQSCREEN" ) == 0) event_becqscreen(event,value); else if(strcmp(event,"LOGINTERVAL" ) == 0) event_loginterval(event,value); else if(strcmp(event,"WARNSCREEN" ) == 0) event_warnscreen(event,value); else if(strcmp(event,"DATESCREEN" ) == 0) event_datescreen(event,value); else if(strcmp(event,"BrightnessSCN" ) == 0) event_brightnessscn(event,value); else if(strcmp(event,"LeftBrightness" ) == 0) event_leftbrightness(event,value); else if(strcmp(event,"QR Transfer" ) == 0) qr_logxfer(); else if(strcmp(event,"Audio Xfer" ) == 0) event_audioxfer(event,value); else if(strcmp(event,"QR Tweet" ) == 0) event_qrtweet(event,value); else if(strcmp(event,"varnumchange" ) == 0) { if(strcmp ("BRIGHTNESS",value) == 0) event_varnum_brightness(event,value); else if(strcmpl("CAL" ,value,3) ) update_calibration(); else if(strcmpl("DATE" ,value,4) ) event_varnum_date(event,value); else if(strcmpl("TIME" ,value,4) ) event_varnum_time(event,value); } }
static void __jump_resetvec(void) { save_time(get_time()); ramdata_set_persistent(); emulator_reboot(); }
/* * HEADER:100:fix_CFSv2_fcst:misc:3:fixes CFSv2 monthly fcst X=daily or 00/06/12/18 Y=pert no. Z=number ens fcsts v1.0 */ int f_fix_CFSv2_fcst(ARG3) { int subcenter, n_time_ranges, fcst_time_0, fcst_time_1, i; int dtime, unit, id; int ref_year, ref_month, ref_day, ref_hour, ref_minute, ref_second; int fcst0_year, fcst0_month, fcst0_day, fcst0_hour, fcst0_minute, fcst0_second; int fcst1_year, fcst1_month, fcst1_day, fcst1_hour, fcst1_minute, fcst1_second; static unsigned char new_sec4[61]; struct local_struct { int fixed; // number of fields processed int dt; // dt either 6 or 24 int hour0; // initial hour int pert; // perturbation no, 0 = ctl int num_ensemble_members; }; struct local_struct *save; if (mode == -1) { *local = save = (struct local_struct *)malloc( sizeof(struct local_struct)); save->fixed = 0; save->dt = 24; if (strcmp(arg1,"daily") == 0) { save->dt = 6; save->hour0 = 0; } else if (strcmp(arg1,"00") == 0) { save->hour0 = 0; } else if (strcmp(arg1,"06") == 0) { save->hour0 = 6; } else if (strcmp(arg1,"12") == 0) { save->hour0 = 12; } else if (strcmp(arg1,"18") == 0) { save->hour0 = 1; } else fatal_error("fix_CFSv2_fcst: bad arg %s, wanted daily,00,06,12 or 18",arg1); save->pert = atoi(arg2); save->num_ensemble_members = atoi(arg2); } save = *local; if (mode == -2) sprintf(inv_out,"fix_CFSRv2_fcst %d fields fixed" , save->fixed); if (mode < 0) return 0; // only process NCEP CFSv2 monthly forecasts // must be NCEP generated if (GB2_Center(sec) != NCEP) return 0; // subcenter should be 0, 1 (reanalysis), 3 (EMC) or 4 (NCO) subcenter = GB2_Subcenter(sec); if (subcenter != 0 && subcenter != 1 && subcenter != 3 && subcenter != 4) return 0; // must have process id = 82 or 98 id = analysis_or_forecast_generating_process_identifier(sec); if (id != 82 && id != 98) return 0; // product defn table must be 8 (fcst average) if ( code_table_4_0(sec) != 8) return 0; // n_time_ranges should be 1 if ( (n_time_ranges = sec[4][41]) != 1) { fprintf(stderr,"unexected CFSv2 type forecast field .. pdt=8, n=%d\n", n_time_ranges); return 0; } // forecast time units should be months if (sec[4][17] != 3 || sec[4][48] != 3) return 0; fcst_time_0 = int4(sec[4]+18); fcst_time_1 = int4(sec[4]+49) + fcst_time_0; // get reference time reftime(sec, &ref_year, &ref_month, &ref_day, &ref_hour, &ref_minute, &ref_second); if (ref_minute != 0 || ref_second != 0) { fprintf(stderr,"unexected CFSv2 minute/second value != 0\n"); return 0; } if (fcst_time_0 != 0) { // start at day=1 hour=save->hour0 of proper month fcst0_year = ref_year; fcst0_month = ref_month + fcst_time_0; if (fcst0_month > 12) { i = (fcst0_month - 1) / 12; fcst0_year += i; fcst0_month -= (i*12); } fcst0_day = 1; fcst0_hour = save->hour0; fcst0_minute = 0; fcst0_second= 0; } else { // start at current month fcst0_year = ref_year; fcst0_month = ref_month; fcst0_day = ref_day; fcst0_hour = ref_hour; fcst0_minute = ref_minute; fcst0_second= ref_second; if (save->dt == 24) { i = save->hour0 - fcst0_hour; if (i < 0) i += 24; add_time(&fcst0_year, &fcst0_month, &fcst0_day, &fcst0_hour, &fcst0_minute, &fcst0_second, i, HOUR); } } sub_time(fcst0_year, fcst0_month, fcst0_day, fcst0_hour, fcst0_minute, fcst0_second, ref_year, ref_month, ref_day, ref_hour, ref_minute, ref_second, &dtime, &unit); // set forecast time. if (dtime == 0) unit = MONTH; sec[4][17] = unit; int_char(dtime, sec[4]+18); if (fcst_time_1 == 0) fatal_error("fix-CFSv2_fcst: unexpected end_ft",""); if (save->dt == 6) { // ends at 18Z of last day of month fcst1_year = ref_year; fcst1_month = ref_month + fcst_time_1-1; if (fcst1_month > 12) { i = (fcst1_month - 1) / 12; fcst1_year += i; fcst1_month -= (i*12); } fcst1_day = num_days_in_month(fcst1_year, fcst1_month); fcst1_hour = 18; fcst1_minute = 0; fcst1_second= 0; // time increment = 6 hours sec[4][53] = (unsigned char) HOUR; int_char(6, sec[4]+54); } else { fcst1_year = ref_year; fcst1_month = ref_month + fcst_time_1-1; if (fcst1_month > 12) { i = (fcst1_month - 1) / 12; fcst1_year += i; fcst1_month -= (i*12); } fcst1_day = num_days_in_month(fcst1_year, fcst1_month); fcst1_hour = save->hour0; fcst1_minute = 0; fcst1_second= 0; // time increment = 24 hours sec[4][53] = (unsigned char) HOUR; int_char(24, sec[4]+54); } // find stat processing time sub_time(fcst1_year, fcst1_month, fcst1_day, fcst1_hour, fcst1_minute, fcst1_second, fcst0_year, fcst0_month, fcst0_day, fcst0_hour, fcst0_minute, fcst0_second, &dtime, &unit); // change length of processing sec[4][48] = (unsigned char) unit; int_char(dtime, sec[4]+49); // fprintf(stderr,"length of processing %d unit (%d)\n", dtime, unit); // save end-of-processing time save_time(fcst1_year, fcst1_month, fcst1_day, fcst1_hour, fcst1_minute, fcst1_second, sec[4]+34); // make sure that some basic info is correct sec[4][47] = 2; // fcst_time++ // now to add ensemble information for (i = 0; i < 34; i++) new_sec4[i] = sec[4][i]; for (i = 34; i <= 57; i++) new_sec4[i+3] = sec[4][i]; uint_char(61, new_sec4); // length of new sec[4[ new_sec4[7] = 0; // pdt = 11 new_sec4[8] = 11; // add perturbation info if (save->pert == 0) { // pert == 0 means control forecast new_sec4[34] = 0; new_sec4[35] = 0; } else { new_sec4[34] = 3; new_sec4[35] = save->pert; } new_sec4[35] = save->num_ensemble_members; sec[4] = new_sec4; save->fixed = save->fixed + 1; return 0; }
/* ==================================== */ int32_t lsquel(struct xvimage *image, int32_t seuil, int32_t niseuil) /* ==================================== */ { int32_t x; /* index muet de pixel */ int32_t y; /* index muet (generalement un voisin de x) */ int32_t rs = rowsize(image); /* taille ligne */ int32_t cs = colsize(image); /* taille colonne */ int32_t N = rs * cs; /* taille image */ uint8_t *SOURCE = UCHARDATA(image); /* l'image de depart */ struct xvimage *lab; int32_t *M; /* l'image d'etiquettes de composantes connexes */ int32_t nminima; /* nombre de minima differents */ Fifo * FIFOn; Fifo * FIFOs; Fifo * FIFOe; Fifo * FIFOo; Fifo * FIFOna; Fifo * FIFOsa; Fifo * FIFOea; Fifo * FIFOoa; Fifo * FIFOtmp; Fifo * FIFO; int32_t niter; #ifdef PERF chrono chrono1; #endif if (depth(image) != 1) { fprintf(stderr, "lsquel: cette version ne traite pas les images volumiques\n"); exit(0); } #ifdef PERF start_chrono(&chrono1); /* pour l'analyse de performances */ #endif lab = allocimage(NULL, rs, cs, 1, VFF_TYP_4_BYTE); if (lab == NULL) { fprintf(stderr, "lhtkern: allocimage failed\n"); return 0; } M = SLONGDATA(lab); if (!llabelextrema(image, 4, LABMIN, lab, &nminima)) { fprintf(stderr, "lhtkern: llabelextrema failed\n"); return 0; } IndicsInit(N); FIFO = CreeFifoVide(N); FIFOn = CreeFifoVide(N/2); FIFOs = CreeFifoVide(N/2); FIFOe = CreeFifoVide(N/2); FIFOo = CreeFifoVide(N/2); if ((FIFO == NULL) && (FIFOn == NULL) && (FIFOs == NULL) && (FIFOe == NULL) && (FIFOo == NULL)) { fprintf(stderr, "lsquel() : CreeFifoVide failed\n"); return(0); } /* ================================================ */ /* DEBUT ALGO */ /* ================================================ */ /* ========================================================= */ /* INITIALISATION DES FIFOs: empile les voisins des minima */ /* ========================================================= */ for (x = 0; x < N; x++) { if (M[x] != 0) /* le pixel appartient a un minimum */ { Set(x, MINI); y = voisin(x, NORD, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOn, y); Set(y, EN_FIFO); } #ifdef DIAG y = voisin(x, NORD+1, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOn, y); Set(y, EN_FIFO); } #endif y = voisin(x, EST, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOe, y); Set(y, EN_FIFO); } #ifdef DIAG y = voisin(x, EST+1, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOe, y); Set(y, EN_FIFO); } #endif y = voisin(x, SUD, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOs, y); Set(y, EN_FIFO); } #ifdef DIAG y = voisin(x, SUD+1, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOs, y); Set(y, EN_FIFO); } #endif y = voisin(x, OUEST, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOo, y); Set(y, EN_FIFO); } #ifdef DIAG y = voisin(x, OUEST+1, rs, N); if ((y!=-1) && (M[y]==0) && !IsSet(y,EN_FIFO) && nonbord(y,rs,N)) { FifoPush(FIFOo, y); Set(y, EN_FIFO); } #endif } /* if (M[x] != 0) */ } /* for x */ freeimage(lab); FIFOna = CreeFifoVide(N/4); FIFOsa = CreeFifoVide(N/4); FIFOea = CreeFifoVide(N/4); FIFOoa = CreeFifoVide(N/4); if ((FIFOna == NULL) && (FIFOsa == NULL) && (FIFOea == NULL) && (FIFOoa == NULL)) { fprintf(stderr, "lsquel() : CreeFifoVide failed\n"); return(0); } /* ================================================ */ /* DEBUT SATURATION */ /* ================================================ */ niter = 0; while (! (FifoVide(FIFOn) && FifoVide(FIFOe) && FifoVide(FIFOs) && FifoVide(FIFOo))) { niter++; while (! FifoVide(FIFOn)) { x = FifoPop(FIFOn); UnSet(x, EN_FIFO); if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) { /* modifie l'image le cas echeant */ testmini(SOURCE, x, rs, N, FIFO); /* reactualise l'image MINI */ empilevoisins(x, rs, N, FIFOna, FIFOea, FIFOsa, FIFOoa); } /* if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) */ } /* while (! FifoVide(FIFOn)) */ while (! FifoVide(FIFOs)) { x = FifoPop(FIFOs); UnSet(x, EN_FIFO); if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) { /* modifie l'image le cas echeant */ testmini(SOURCE, x, rs, N, FIFO); /* reactualise l'image MINI */ empilevoisins(x, rs, N, FIFOna, FIFOea, FIFOsa, FIFOoa); } /* if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) */ } /* while (! FifoVide(FIFOs)) */ while (! FifoVide(FIFOe)) { x = FifoPop(FIFOe); UnSet(x, EN_FIFO); if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) { /* modifie l'image le cas echeant */ testmini(SOURCE, x, rs, N, FIFO); /* reactualise l'image MINI */ empilevoisins(x, rs, N, FIFOna, FIFOea, FIFOsa, FIFOoa); } /* if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) */ } /* while (! FifoVide(FIFOe)) */ while (! FifoVide(FIFOo)) { x = FifoPop(FIFOo); UnSet(x, EN_FIFO); if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) { /* modifie l'image le cas echeant */ testmini(SOURCE, x, rs, N, FIFO); /* reactualise l'image MINI */ empilevoisins(x, rs, N, FIFOna, FIFOea, FIFOsa, FIFOoa); } /* if (testabaisse(SOURCE, x, rs, N, seuil, niter, niseuil)) */ } /* while (! FifoVide(FIFOo)) */ FIFOtmp = FIFOn; FIFOn = FIFOna; FIFOna = FIFOtmp; FIFOtmp = FIFOe; FIFOe = FIFOea; FIFOea = FIFOtmp; FIFOtmp = FIFOs; FIFOs = FIFOsa; FIFOsa = FIFOtmp; FIFOtmp = FIFOo; FIFOo = FIFOoa; FIFOoa = FIFOtmp; } /* while (! (FifoVide(FIFOn) && FifoVide(FIFOe) && FifoVide(FIFOs) && FifoVide(FIFOo))) */ /* ================================================ */ /* UN PEU DE MENAGE */ /* ================================================ */ IndicsTermine(); FifoTermine(FIFO); FifoTermine(FIFOn); FifoTermine(FIFOe); FifoTermine(FIFOs); FifoTermine(FIFOo); FifoTermine(FIFOna); FifoTermine(FIFOea); FifoTermine(FIFOsa); FifoTermine(FIFOoa); #ifdef PERF save_time(N, read_chrono(&chrono1), "lsquel", image->name); #endif return(1); }
__interrupt void TIMER0_B0_ISR(void) { // Switch off button interrupts. P2IE &= ~BUTTON_BITS; // Reset leds. if (P1OUT & 0x01) { P1OUT ^= 0x01; } if (P1OUT & 0x02) { P1OUT ^= 0x02; } // Adjust time. if (time_adjustment & ADJUST_MINUTE_UP) { time_adjustment ^= ADJUST_MINUTE_UP; if (++time_data[1] >= 60) { time_data[1] = 0; } } if (time_adjustment & ADJUST_MINUTE_DOWN) { time_adjustment ^= ADJUST_MINUTE_DOWN; if (time_data[1] == 0) { time_data[1] = 59; } else { --time_data[1]; } } if (time_adjustment & ADJUST_HOUR_UP) { time_adjustment ^= ADJUST_HOUR_UP; if (++time_data[2] >= 24) { time_data[2] = 0; } } if (time_adjustment & ADJUST_HOUR_DOWN) { time_adjustment ^= ADJUST_HOUR_DOWN; if (time_data[2] == 0) { time_data[2] = 23; } else { --time_data[2]; } } if (time_adjustment & ADJUST_BRIGHTNESS_DOWN) { time_adjustment ^= ADJUST_BRIGHTNESS_DOWN; if (TA0CCR3 >= BRIGHTNESS_STEP) { TA0CCR3 -= BRIGHTNESS_STEP; } else { TA0CCR3 = 0; } } if (time_adjustment & ADJUST_BRIGHTNESS_UP) { time_adjustment ^= ADJUST_BRIGHTNESS_UP; TA0CCR3 += BRIGHTNESS_STEP; if (TA0CCR3 >= TA0CCR0) { TA0CCR3 = TA0CCR0; } } if (time_adjustment & ADJUST_SECONDS_RESET) { time_adjustment ^= ADJUST_SECONDS_RESET; time_data[0] = 0; } // Count time. if(++time_data[0] >= 60) { time_data[0] = 0; if (++time_data[1] >= 60) { time_data[1] = 0; if (++time_data[2] >= 24) { time_data[2] = 0; } } P1OUT ^= 0x02; } if (time_data[0] % 5 == 0) { P1OUT ^= 0x01; } render_time(time_data); save_time(time_data); // Reset status. time_adjustment = 0; status_str = ""; // Switch button interrupts on. P2IE |= BUTTON_BITS; }
static int do_ave(struct ave_struct *save) { int i, j, n, ndata, pdt; float *data; unsigned char *p, *sec4; double factor; sec4 = NULL; if (save->has_val == 0) return 0; #ifdef DEBUG printf(" ave nfields=%d missing=%d\n",save->n_fields,save->n_missing); #endif ndata = save->n_sum; if ((data = (float *) malloc(sizeof(float) * ndata)) == NULL) fatal_error("ave: memory allocation",""); factor = 1.0 / save->n_fields; for (i = 0; i < ndata; i++) { if (save->n[i] != save->n_fields) data[i] = UNDEFINED; else data[i] = factor * save->sum[i]; #ifdef DEBUG if (i < 10) printf("data[%d]=%lf n[%d]=%d, sum[%d]=%lf\n", i,data[i],i,save->n[i],i,save->sum[i]); #endif } pdt = GB2_ProdDefTemplateNo(save->first_sec); // average of a forecast if (pdt == 0) { sec4 = (unsigned char *) malloc(58 * sizeof(unsigned char)); if (sec4 == NULL) fatal_error("fcst_ave: memory allocation",""); for (i = 0; i < 34; i++) { sec4[i] = save->first_sec[4][i]; } uint_char((unsigned int) 58, sec4); // length sec4[8] = 8; // pdt // verification time save_time(save->year2,save->month2,save->day2,save->hour2,save->minute2,save->second2, sec4+34); sec4[41] = 1; // 1 time range uint_char(save->n_missing, sec4+42); sec4[46] = 0; // average sec4[47] = 2; // rt=constant, ft++ sec4[48] = save->dt_unit; // total length of stat processing uint_char(save->dt*(save->n_fields+save->n_missing-1), sec4+49); sec4[53] = save->dt_unit; // time step uint_char(save->dt, sec4+54); } // average of an ensemble forecast, use pdt 4.11 else if (pdt == 1) { sec4 = (unsigned char *) malloc(61 * sizeof(unsigned char)); if (sec4 == NULL) fatal_error("fcst_ave: memory allocation",""); for (i = 0; i < 37; i++) { sec4[i] = save->first_sec[4][i]; } uint_char((unsigned int) 61, sec4); // length sec4[8] = 11; // pdt // verification time save_time(save->year2,save->month2,save->day2,save->hour2,save->minute2,save->second2, sec4+37); sec4[44] = 1; // 1 time range uint_char(save->n_missing, sec4+45); sec4[49] = 0; // average sec4[50] = 2; // rt=constant, ft++ sec4[51] = save->dt_unit; // total length of stat processing uint_char(save->dt*(save->n_fields+save->n_missing-1), sec4+52); sec4[56] = save->dt_unit; // time step uint_char(save->dt, sec4+57); } // average of an average or accumulation else if (pdt == 8) { i = GB2_Sec4_size(save->first_sec); n = save->first_sec[4][41]; if (i != 46 + 12*n) fatal_error("ave: invalid sec4 size for pdt=8",""); // keep pdt == 8 but make it 12 bytes bigger sec4 = (unsigned char *) malloc( (i+12) * sizeof(unsigned char)); if (sec4 == NULL) fatal_error("fcst_ave: memory allocation",""); uint_char((unsigned int) i+12, sec4); // new length for (i = 4; i < 34; i++) { // keep base of pdt sec4[i] = save->first_sec[4][i]; } // new verification time save_time(save->year2,save->month2,save->day2,save->hour2,save->minute2,save->second2, sec4+34); // number of stat-proc loops is increased by 1 sec4[41] = n + 1; // copy old stat-proc loops // for (j = n*12-1; j >= 0; j--) sec4[58+j] = save->first_sec[4][46+j]; for (j = 0; j < n*12; j++) sec4[46+12+j] = save->first_sec[4][46+j]; #ifdef DEBUG printf("save->n_missing =%d save->n_fields=%d\n",save->n_missing,save->n_fields); #endif uint_char(save->n_missing, sec4+42); sec4[46] = 0; // average sec4[47] = 2; // fcst++ sec4[48] = save->dt_unit; // total length of stat processing uint_char(save->dt*(save->n_fields+save->n_missing-1), sec4+49); // missing sec4[53] = save->dt_unit; // time step uint_char(save->dt, sec4+54); } else { fatal_error_i("ave with pdt %d is not supported",pdt); } // write grib file p = save->first_sec[4]; save->first_sec[4] = sec4; grib_wrt(save->first_sec, data, ndata, save->nx, save->ny, save->use_scale, save->dec_scale, save->bin_scale, save->wanted_bits, save->max_bits, save->grib_type, save->output); if (flush_mode) fflush(save->output); save->first_sec[4] = p; free(data); free(sec4); return 0; }