unsigned char *sec3_polar_stereo(double lov, double lad, int proj, int nx, double x0, double dx, int ny, double y0, double dy, unsigned char **old_sec) { static unsigned char gds[65]; int i; unsigned char *p; if (x0 < 0) x0 += 360.0; uint_char(65, gds); /* 1-4 length of section */ gds[4] = 3; /* section 3 */ gds[5] = 0; /* source of grid */ uint_char(nx*ny, gds+6); /* number of data points */ gds[10] = 0; /* number of octets for optional list of number */ gds[11] = 0; /* list */ gds[12] = 0; /* gdt=20 polar stereographic */ gds[13]= 20; /* shape of the earth */ if (old_sec == NULL) { /* use NCEP default */ gds[14] = 6; /* shape of earth */ gds[15] = 0; /* scale factor of radius of spherical earth */ uint_char(0, gds+16); /* scaled value of radius of spherical earth */ gds[20] = 0; /* scale factor of major radious of oblate earth */ uint_char(0, gds+21); /* scaled value of major axis */ gds[25] = 0; /* scale factor of minor axis */ uint_char(0, gds+26); /* scaled value of minor axis */ } else { p = code_table_3_2_location(old_sec); for (i = 0; i < 16; i++) gds[14+i] = p[i]; } uint_char(nx, gds+30); uint_char(ny, gds+34); int_char((int) floor(y0*ANGLE_FACTOR+0.5), gds+38); /* lat1 */ uint_char((int) floor(x0*ANGLE_FACTOR+0.5), gds+42); /* lon1 */ gds[46] = 32+16; /* flag table 3.3 */ int_char((int) floor(lad*ANGLE_FACTOR+0.5), gds+47); uint_char((int) floor(lov*ANGLE_FACTOR+0.5), gds+51); int_char((int) floor(fabs(dx)*1000+0.5), gds+55); /* Di 1/1000 of a meter */ int_char((int) floor(fabs(dy)*1000+0.5), gds+59); /* Dj 1/1000 of a meter */ gds[63] = proj; gds[64] = 0; /* scanning mode */ if (dx < 0.0) gds[64] |= 128; if (dy > 0.0) gds[64] |= 64; return gds; }
unsigned char *gds_lola(int nx, float x0, float dx, int ny, float y0, float dy) { static unsigned char gds[100]; double r; uint_char(72, gds); /* 1-4 length of section */ gds[4] = 3; /* number of section */ gds[5] = 0; uint_char(nx*ny, gds+6); /* number of data points */ gds[10] = 0; /* number of octtets for optional list of number */ gds[11] = 0; /* code 3.11 */ gds[12] = gds[13] = 0; /* template 3.0 */ /* template 3.0 values */ gds[14] = 0; /* shape of earth */ gds[15] = 0; /* scale factor of radius of spherical earth */ uint_char(0, gds+16); /* scaled value of radius of spherical earth */ gds[20] = 0; /* scale factor of major radious of oblate earth */ uint_char(0, gds+21); /* scaled value of major axis */ gds[25] = 0; /* scale factor of minor axis */ uint_char(0, gds+26); /* scaled value of minor axis */ uint_char(nx, gds+30); uint_char(ny, gds+34); uint_char(0, gds+38); uint_char(0, gds+42); uint_char((int) (y0*1000000.0), gds+46); /* lat1 */ uint_char((int) (x0*1000000.0), gds+50); /* lon1 */ gds[54] = 0; /* flag table 3.3 */ r = y0 + (ny-1)*dy; uint_char((int) (r*1000000.0), gds+55); /* lat1 */ r = x0 + (nx-1)*dx; if (r >= 360.0) r -= 360.0; uint_char((int) (r*1000000.0), gds+59); /* lat1 */ int_char((int) (dx*1000000.0), gds+63); /* Di i direction increment */ int_char((int) (dy*1000000.0), gds+67); /* Dj i direction increment */ gds[71] = 0x40; /* scanning mode */ return gds; }
int main(int argc, const char *argv[]) { char str[100]; // int i = 0; int number = 0; char *p; // printf("please input the digit_character:"); // scanf("%s", str); printf("please input the number:"); scanf("%d", &number); #if 0 for(i = 0; i < strlen(str); i++) { if(!isdigit(str[i])) { printf("input error\n"); exit(1); } } number = char_int(str); printf("the number is %d\n", number); #endif p = int_char(str, number); printf("%s\n", p); return 0; }
int main() { int i; sfmt_t sfmt; unsigned long long int tmp; sfmt_init_gen_rand(&sfmt, (unsigned)time(NULL)); // sfmtを用いた乱数の初期化 for (i = 0; i < 100; i++) { printf("%02llx\n", sfmt_genrand_uint64(&sfmt)); } tmp = sfmt_genrand_uint64(&sfmt); printf("%llu\n", tmp); int select[ITEM] = {0}; sfmt_t stmf; for (i = 0; i < 30; i++) { get_rand(select, &sfmt); printf("c : %s\n", int_char(select)); } return 0; }
void call3() { renderBitmapString(1600,3500,(void *)font1,"YOUR TOTAL SCORE IS : "); array=int_char(); renderBitmapString(2400,3500,(void *)font1,array); renderBitmapString(1600,3000,(void *)font1,"THANK YOU :)"); }
void s_printf(char *format,...) { va_list opt; char out[2]=" "; int val; char *s; va_start(opt, format); while(format[0]) { if(format[0]!='%') {out[0]=*format++;os_puts(out);} else { format++; switch(format[0]) { case 'd': case 'i': val=va_arg(opt,int); int_char(val); os_puts(mem_cad); break; case 'u': val=va_arg(opt, unsigned); uint_char(val); os_puts(mem_cad); break; case 'x': val=va_arg(opt,int); hex_char((u32) val); os_puts(mem_cad); break; case 's': s=va_arg(opt,char *); os_puts(s); break; } format++; } } va_end(opt); }
int fix_ncep_2(unsigned char **sec) { unsigned char *p; int i; p = code_table_4_9_location(sec); if (p == NULL) return 0; if ((p[2] & 0x0c) == 0x0c) { // fix bug i = int4_comp(p+2); int_char(i, p+2); } if ((p[7] & 0x0c) == 0x0c) { // fix bug i = int4_comp(p+7); int_char(i, p+7); } return 0; }
int main(void) { int i; int point; int selection[ITEM]; int rand_num; srand((unsigned)time(NULL)); dragonpoleMain(); for (i=0; i<ITEM; i++) { selection[i] = 0; } int all_max_num = 0; int all_max_index[ITEM] = {0}; #pragma omp parallel num_threads(1) // #pragma omp parallel { int max_index[ITEM] = {0}; int max_num = 0; for (i=0; i<LOOPMAX; i++){ get_rand(selection); point = calcBattlePoint(selection); if (max_num < point){ max_num = point; memcpy( max_index, selection, sizeof(int) * ITEM); if (all_max_num < point){ all_max_num = point; memcpy( all_max_index, selection, sizeof(int) * ITEM); } } } printf("thread : %3d | comb : %s | point : %d\n", omp_get_thread_num(), int_char(max_index), max_num); } // Bad coding? // all_max_index & all_max_num printf("all_max_comb: %s | point : %d\n", int_char(all_max_index), all_max_num); return 0; }
unsigned char *sec3_mercator(double lad, int nx, double x0, double dx, double xn, int ny, double y0, double dy, double yn, unsigned char **old_sec) { static unsigned char gds[100]; unsigned char *p; int i; if (x0 < 0) x0 += 360.0; uint_char(72, gds); /* 1-4 length of section */ gds[4] = 3; /* section 3 */ gds[5] = 0; /* source of grid */ uint_char(nx*ny, gds+6); /* number of data points */ gds[10] = 0; /* number of octets for optional list of number */ gds[11] = 0; /* list */ gds[12] = 0; gds[13] = 10; /* template 3.0 mercator grid */ /* shape of the earth */ if (old_sec == NULL) { /* use NCEP default */ gds[14] = 6; /* shape of earth */ gds[15] = 0; /* scale factor of radius of spherical earth */ uint_char(0, gds+16); /* scaled value of radius of spherical earth */ gds[20] = 0; /* scale factor of major radious of oblate earth */ uint_char(0, gds+21); /* scaled value of major axis */ gds[25] = 0; /* scale factor of minor axis */ uint_char(0, gds+26); /* scaled value of minor axis */ } else { p = code_table_3_2_location(old_sec); for (i = 0; i < 16; i++) gds[14+i] = p[i]; } uint_char(nx, gds+30); uint_char(ny, gds+34); int_char((int) floor(y0*ANGLE_FACTOR+0.5), gds+38); /* lat1 */ uint_char((int) floor(x0*ANGLE_FACTOR+0.5), gds+42); /* lon1 */ int_char((int) floor(lad*ANGLE_FACTOR+0.5), gds+47); int_char((int) floor(yn*ANGLE_FACTOR+0.5), gds+51); /* lat2 */ if (xn > 360.0) xn -= 360.0; if (xn < 0.0) xn += 360.0; uint_char( (int) floor(xn*ANGLE_FACTOR+0.5), gds+55); /* lon2 */ int_char(0, gds+60); /* only handle 0 orient */ int_char((int) floor(fabs(dx) * 1000.0 + 0.5), gds+64); /* Di i direction increment */ int_char((int) floor(fabs(dy) * 1000.0 + 0.5), gds+68); /* Dj i direction increment */ gds[46] = 32+16; /* flag table 3.3 */ gds[59] = 0; /* scanning mode */ if (dx < 0.0) gds[59] |= 128; if (dy > 0.0) gds[59] |= 64; return gds; }
void UncompressFile::buildNodeList(HuffmanTree& ht) { if ( !isPtr.is_open()) { isPtr.open(inFile.c_str()); if (!isPtr) { cerr << "Error: Could not open: '" << inFile << "' for reading" << endl; return; } } // char readBuf[readBufSize]; isPtr.getline((char*)readBuf,readBufSize); string buf; // Have a buffer string vector<string> token; stringstream ss((char*)readBuf); unsigned int count; // Tokenize the string into a vector while (ss >> buf) { token.push_back(buf); count++; } // Validate that we have a even number if (count % 2 != 0) { cerr << "CountTable::extractCharMap() : Internal Error\n"; return; } unsigned int c; // Convert the first token to 'hex' and the second to 'unsigned' for (unsigned i=0; i<token.size(); i+=2) { istringstream hex_char(token[i]); hex_char >> hex >> c; istringstream int_char(token[i+1]); int_char >> count; ht.buildNodeList(c, count); } if (isPtr.is_open()) isPtr.close(); } // End buildNodeList()
MINDY_NORETURN static void getc_or_wait(struct thread *thread) { // if (FBUFEMPTYP(stdin) && !feof(stdin)) { if (!feof(stdin)) { int fd = fileno(stdin); int nfound = input_available(fd); if (nfound < 0) { switch (errno) { case EBADF: error("Tried to getc with stdin broken."); case EINTR: wait_for_input(thread, fd, getc_or_wait); case EINVAL: lose("select failed with EINVAL?"); } } else if (nfound == 0) wait_for_input(thread, fd, getc_or_wait); } { obj_t *old_sp; int c = mindy_getchar(); old_sp = pop_linkage(thread); if (c != EOF) *old_sp = int_char(c); else *old_sp = obj_False; thread->sp = old_sp + 1; do_return(thread, old_sp, old_sp); } }
void clispPutc(char c) { pushSTACK(int_char(c)); pushSTACK(Symbol_value(S(standard_output))); funcall(L(write_char),2); }
int small_grib(unsigned char **sec, int mode, float *data, double *lon, double *lat, unsigned int ndata, int ix0, int ix1, int iy0, int iy1, FILE *out) { int can_subset, grid_template; int nx, ny, res, scan, new_nx, new_ny, i, j; unsigned int sec3_len, new_ndata, k, npnts; unsigned char *sec3, *new_sec[9]; double units; int basic_ang, sub_ang, cyclic_grid; float *new_data; get_nxny(sec, &nx, &ny, &npnts, &res, &scan); /* get nx, ny, and scan mode of grid */ grid_template = code_table_3_1(sec); // make a copy of the gds (sec3) sec3_len = GB2_Sec3_size(sec); sec3 = (unsigned char *) malloc(sec3_len); for (k = 0; k < sec3_len; k++) sec3[k] = sec[3][k]; // make a copy of the sec[] with new sec3 new_sec[0] = sec[0]; new_sec[1] = sec[1]; new_sec[2] = sec[2]; new_sec[3] = sec3; new_sec[4] = sec[4]; new_sec[5] = sec[5]; new_sec[6] = sec[6]; new_sec[7] = sec[7]; // new_sec[8] = sec[8]; not needed by writing routines can_subset = 1; if (lat == NULL || lon == NULL) can_subset = 0; new_nx = ix1-ix0+1; new_ny = iy1-iy0+1; if (new_nx <= 0) fatal_error("small_grib, new_nx is <= 0",""); if (new_ny <= 0) fatal_error("small_grib, new_ny is <= 0",""); new_ndata = new_nx * new_ny; cyclic_grid = 0; if (can_subset) { cyclic_grid = cyclic(sec); // lat-lon grid - no thinning if ((grid_template == 0 && sec3_len == 72) || (grid_template == 1 && sec3_len == 04)) { uint_char(new_nx,sec3+30); // nx uint_char(new_ny,sec3+34); // ny basic_ang = GDS_LatLon_basic_ang(sec3); sub_ang = GDS_LatLon_sub_ang(sec3); if (basic_ang != 0) { units = (double) basic_ang / (double) sub_ang; } else { units = 0.000001; } i = lat[ idx(ix0,iy0,nx,ny,cyclic_grid) ] / units; // lat1 int_char(i,sec3+46); i = lon[ idx(ix0,iy0,nx,ny,cyclic_grid) ] / units; // lon1 int_char(i,sec3+50); i = lat[ idx(ix1,iy1,nx,ny,cyclic_grid) ] / units; // lat2 int_char(i,sec3+55); i = lon[ idx(ix1,iy1,nx,ny,cyclic_grid) ] / units; // lon2 int_char(i,sec3+59); } else if ((grid_template == 40 && sec3_len == 72)) { // full Gaussian grid uint_char(new_nx,sec3+30); // nx uint_char(new_ny,sec3+34); // ny basic_ang = GDS_Gaussian_basic_ang(sec3); sub_ang = GDS_Gaussian_sub_ang(sec3); if (basic_ang != 0) { units = (double) basic_ang / (double) sub_ang; } else { units = 0.000001; } i = lat[ idx(ix0,iy0,nx,ny,cyclic_grid) ] / units; // lat1 int_char(i,sec3+46); i = lon[ idx(ix0,iy0,nx,ny,cyclic_grid) ] / units; // lon1 int_char(i,sec3+50); i = lat[ idx(ix1,iy1,nx,ny,cyclic_grid) ] / units; // lat2 int_char(i,sec3+55); i = lon[ idx(ix1,iy1,nx,ny,cyclic_grid) ] / units; // lon2 int_char(i,sec3+59); } // polar-stereo graphic, lambert conformal , no thinning else if ((grid_template == 20 && sec3_len == 65) || // polar stereographic (grid_template == 30 && sec3_len == 81)) { // lambert conformal uint_char(new_nx,sec3+30); // nx uint_char(new_ny,sec3+34); // ny i = (int) (lat[ idx(ix0,iy0,nx,ny,cyclic_grid) ] * 1000000.0); // lat1 int_char(i,sec3+38); i = (int) (lon[ idx(ix0,iy0,nx,ny,cyclic_grid) ] * 1000000.0); // lon1 int_char(i,sec3+42); } // mercator, no thinning else if (grid_template == 10 && sec3_len == 72) { // mercator uint_char(new_nx,sec3+30); // nx uint_char(new_ny,sec3+34); // ny units = 0.000001; i = lat[ idx(ix0,iy0,nx,ny,cyclic_grid) ] / units; // lat1 int_char(i,sec3+38); i = lon[ idx(ix0,iy0,nx,ny,cyclic_grid) ] / units; // lon1 int_char(i,sec3+42); i = lat[ idx(ix1,iy1,nx,ny,cyclic_grid) ] / units; // lat2 int_char(i,sec3+51); i = lon[ idx(ix1,iy1,nx,ny,cyclic_grid) ] / units; // lon2 int_char(i,sec3+55); } else { can_subset = 0; } } // copy data to a new array if (can_subset) { uint_char(new_ndata, sec3+6); new_data = (float *) malloc(new_ndata * sizeof(float)); #pragma omp parallel for private(i,j,k) for(j = iy0; j <= iy1; j++) { k = (j-iy0)*(ix1-ix0+1); for(i = ix0; i <= ix1; i++) { new_data[(i-ix0) + k ] = data[ idx(i,j,nx,ny,cyclic_grid) ]; } } } else { new_ndata = ndata; new_data = (float *) malloc(new_ndata * sizeof(float)); for (k = 0; k < ndata; k++) new_data[k] = data[k]; new_nx = nx; new_ny = ny; } set_order(new_sec, output_order); grib_wrt(new_sec, new_data, new_ndata, new_nx, new_ny, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, out); if (flush_mode) fflush(out); free(new_data); free(sec3); return 0; }
int f_ncep_norm(ARG1) { struct local_struct { float *val; int has_val; unsigned char *clone_sec[9]; FILE *output; }; struct local_struct *save; int j, pdt, fhr_1, fhr_2, dt1, dt2, new_type, is_ave; unsigned int i; float *d1, *data_tmp; if (mode == -1) { // initialization save_translation = decode = 1; // allocate static variables *local = save = (struct local_struct *) malloc( sizeof(struct local_struct)); if (save == NULL) fatal_error("memory allocation f_normalize",""); if ((save->output = (void *) ffopen(arg1, file_append ? "ab" : "wb")) == NULL) { fatal_error("f_ncep_norm: could not open file %s", arg1); } save->has_val = 0; init_sec(save->clone_sec); return 0; } save = *local; if (mode == -2) { // cleanup if (save->has_val == 1) { free(save->val); free_sec(save->clone_sec); free(save); } return 0; } if (mode >= 0) { // processing // only hande PDT = 8 pdt = GB2_ProdDefTemplateNo(sec); if (pdt != 8) return 0; // only process averages or accumulations // check for code table 4.8 j = code_table_4_10(sec); if (mode == 99) fprintf(stderr,"\nncep_norm: code table 4.10 (ave/acc/etc)=%d\n",j); if (j == 0) is_ave = 1; // average else if (j == 1) is_ave = 0; // accumulation else return 0; // only process average or accumulations // only process when fcst time units == ave/acc time units if (sec[4][17] != sec[4][48]) { if (int4(sec[4]+18) != 0) { return 0; } } fhr_2 = int4(sec[4]+18); // start time dt2 = int4(sec[4]+49); // delta-time if (dt2 == 0) return 0; // dt == 0 if (save->has_val == 0) { // new data: write and save if ((data_tmp = (float *) malloc(ndata * sizeof(float))) == NULL) fatal_error("memory allocation - data_tmp",""); undo_output_order(data, data_tmp, ndata); grib_wrt(sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, save->output); /* if (grib_type == simple) grib_out(sec, data_tmp, ndata, save->output); else if (grib_type == jpeg) jpeg_grib_out(sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, save->output); else if (grib_type == ieee) ieee_grib_out(sec, data_tmp, ndata, save->output); else fatal_error("NCEP_norm: unsupported grib type output",""); */ if (flush_mode) fflush(save->output); free(data_tmp); if (save->has_val == 1) { // copy data to save free(save->val); // save = new field free_sec(save->clone_sec); } copy_sec(sec, save->clone_sec); copy_data(data,ndata,&(save->val)); save->has_val = 1; if (mode == 99) fprintf(stderr," ncep_norm: saved as new field\n"); return 0; } new_type = 0; fhr_1 = int4(save->clone_sec[4]+18); // start time of save message dt1 = int4(save->clone_sec[4]+49); // delta time if (mode == 99) fprintf(stderr,"ncep_norm: is_ave = %d\n fhr_1 %d dt1 %d fhr_2 %d dt2 %d\n",is_ave, fhr_1, dt1, fhr_2, dt2); if (fhr_1 != fhr_2) new_type = 1; if (new_type == 0) { if (same_sec0(sec,save->clone_sec) == 0 || same_sec1(sec,save->clone_sec) == 0 || same_sec3(sec,save->clone_sec) == 0 || same_sec4_diff_ave_period(sec,save->clone_sec) == 0) { new_type = 1; } } if (new_type == 1) { // fields dont match: write and save if ((data_tmp = (float *) malloc(ndata * sizeof(float))) == NULL) fatal_error("memory allocation - data_tmp",""); undo_output_order(data, data_tmp, ndata); grib_wrt(sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, save->output); /* if (grib_type == simple) grib_out(sec, data_tmp, ndata, save->output); else if (grib_type == jpeg) jpeg_grib_out(sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, save->output); else if (grib_type == ieee) ieee_grib_out(sec, data_tmp, ndata, save->output); */ if (flush_mode) fflush(save->output); free(data_tmp); if (save->has_val == 1) { // copy data to save free(save->val); // save = new field free_sec(save->clone_sec); } copy_sec(sec, save->clone_sec); copy_data(data,ndata,&(save->val)); save->has_val = 1; if (mode == 99) fprintf(stderr," ncep_norm: saved as new type/sequence\n"); return 0; } /* now do stuff */ if (dt1 == dt2) return 0; // same ending time // change metadata int_char(dt2-dt1, save->clone_sec[4]+49); // dt = dt2 - dt1 save->clone_sec[4][17] = sec[4][48]; // new forecast time unit int_char(dt1+fhr_1, save->clone_sec[4]+18); // fhr = fhr + dt1 for (i = 34; i < 41; i++) { // ending time from pds2 save->clone_sec[4][i] = sec[4][i]; } if (mode == 99) { if (is_ave) fprintf(stderr," process: factor: NEW*%g - OLD*%g\n", dt2/ (double) (dt2 - dt1), dt1/ (double) (dt2-dt1)); else fprintf(stderr," process: current-last\n"); } // change floating point data d1= save->val; for (i = 0; i < ndata; i++) { if (!UNDEFINED_VAL(data[i]) && !UNDEFINED_VAL(*d1) ) { if (is_ave) { *d1 = (data[i]*dt2 - *d1*dt1) / (double) (dt2 - dt1); } else { // accumulation *d1 = data[i] - *d1; } } else *d1 = UNDEFINED; d1++; } // write grib output if ((data_tmp = (float *) malloc(ndata * sizeof(float))) == NULL) fatal_error("memory allocation - data_tmp",""); undo_output_order(save->val, data_tmp, ndata); grib_wrt(save->clone_sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, save->output); /* if (grib_type == simple) grib_out(save->clone_sec, data_tmp, ndata, save->output); else if (grib_type == jpeg) jpeg_grib_out(save->clone_sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, save->output); else if (grib_type == ieee) ieee_grib_out(save->clone_sec, data_tmp, ndata, save->output); else if (grib_type == complex1) complex_grib_out(save->clone_sec, data_tmp, ndata, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, 1, save->output); else if (grib_type == complex2) complex_grib_out(save->clone_sec, data_tmp, ndata, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, 2, save->output); else if (grib_type == complex3) complex_grib_out(save->clone_sec, data_tmp, ndata, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, 3, save->output); else fatal_error("NCEP_norm: unsupported grib output type",""); */ if (flush_mode) fflush(save->output); free(data_tmp); // save data free(save->val); // save = new field free_sec(save->clone_sec); copy_sec(sec, save->clone_sec); copy_data(data,ndata,&(save->val)); return 0; } return 0; }
void clispErrPutc(char c) { pushSTACK(int_char(c)); pushSTACK(Symbol_value(S(error_output))); funcall(L(write_char),2); }
int f_ncep_norm(ARG1) { struct local_struct { float *val; int has_val; unsigned char *clone_sec[9]; FILE *output; }; struct local_struct *save; int idx, j, fhr_1, fhr_2, dt1, dt2, new_type, is_ave; unsigned int i; float *d1, *data_tmp; if (mode == -1) { // initialization save_translation = decode = 1; // 1/2015 use_scale = 0; // allocate static variables *local = save = (struct local_struct *) malloc( sizeof(struct local_struct)); if (save == NULL) fatal_error("memory allocation f_ncep_norm",""); if ((save->output = ffopen(arg1, file_append ? "ab" : "wb")) == NULL) { fatal_error("f_ncep_norm: could not open file %s", arg1); } save->has_val = 0; init_sec(save->clone_sec); return 0; } save = (struct local_struct *) *local; if (mode == -2) { // cleanup ffclose(save->output); if (save->has_val == 1) { free(save->val); free_sec(save->clone_sec); } free(save); return 0; } if (mode >= 0) { // processing idx = stat_proc_n_time_ranges_index(sec); // only process stat processed fields if (idx < 0) return 0; // n_time_ranges has to be one if (sec[4][idx] != 1) return 0; // only process averages or accumulations j = code_table_4_10(sec); if (mode == 99) fprintf(stderr,"\nncep_norm: code table 4.10 (ave/acc/etc)=%d\n",j); if (j == 0) is_ave = 1; // average else if (j == 1) is_ave = 0; // accumulation else return 0; // only process average or accumulations fhr_2 = forecast_time_in_units(sec); // start time dt2 = int4(sec[4]+idx+50-42); // delta-time if (mode == 99) fprintf(stderr,"\nncep_norm: fhr_2=%d dt2=%d index of dt2=%d\n",fhr_2, dt2, idx+50-42); if (dt2 == 0) return 0; // dt == 0 // units of fcst and stat proc should be the same if fcst time != 0 if (fhr_2 != 0 && code_table_4_4(sec) != sec[4][49-42+idx]) return 0; if (save->has_val == 0) { // new data: write and save if ((data_tmp = (float *) malloc(ndata * sizeof(float))) == NULL) fatal_error("memory allocation - data_tmp",""); undo_output_order(data, data_tmp, ndata); grib_wrt(sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, save->output); if (flush_mode) fflush(save->output); free(data_tmp); if (save->has_val == 1) { // copy data to save free(save->val); // save = new field free_sec(save->clone_sec); } copy_sec(sec, save->clone_sec); copy_data(data,ndata,&(save->val)); save->has_val = 1; if (mode == 99) fprintf(stderr," ncep_norm: saved as new field\n"); return 0; } new_type = 0; fhr_1 = forecast_time_in_units(save->clone_sec); // start_time of save message dt1 = int4(save->clone_sec[4]+idx+50-42); // delta-time if (mode == 99) fprintf(stderr,"ncep_norm: is_ave = %d\n fhr_1 %d dt1 %d fhr_2 %d dt2 %d\n",is_ave, fhr_1, dt1, fhr_2, dt2); if (fhr_1 != fhr_2) new_type = 1; if (new_type == 0) { if (same_sec0(sec,save->clone_sec) == 0 || same_sec1(sec,save->clone_sec) == 0 || same_sec3(sec,save->clone_sec) == 0 || same_sec4_diff_ave_period(sec,save->clone_sec) == 0) { if (mode == 99) fprintf(stderr,"ncep_norm: new_type sec test %d %d %d %d\n", same_sec0(sec,save->clone_sec), same_sec1(sec,save->clone_sec), same_sec3(sec,save->clone_sec), same_sec4_diff_ave_period(sec,save->clone_sec)); new_type = 1; } } if (mode == 99) fprintf(stderr,"ncep_norm: new_type=%d write and save\n",new_type); if (new_type == 1) { // fields dont match: write and save if ((data_tmp = (float *) malloc(ndata * sizeof(float))) == NULL) fatal_error("memory allocation - data_tmp",""); undo_output_order(data, data_tmp, ndata); grib_wrt(sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, save->output); if (flush_mode) fflush(save->output); free(data_tmp); if (save->has_val == 1) { // copy data to save free(save->val); // save = new field free_sec(save->clone_sec); } copy_sec(sec, save->clone_sec); copy_data(data,ndata,&(save->val)); save->has_val = 1; if (mode == 99) fprintf(stderr," ncep_norm: saved as new type/sequence\n"); return 0; } /* now do stuff */ if (dt1 == dt2) return 0; // same ending time // change metadata int_char(dt2-dt1, save->clone_sec[4]+50-42+idx); // dt = dt2 - dt1 save->clone_sec[4][17] = sec[4][49-42+idx]; // new forecast time unit int_char(dt1+fhr_1, save->clone_sec[4]+18); // fhr = fhr + dt1 if (mode == 99) fprintf(stderr,"ncep_norm new fcst time %d + %d\n", dt1,fhr_1); for (i = idx-7; i < idx; i++) { // ending time from pds2 save->clone_sec[4][i] = sec[4][i]; } if (mode == 99) { if (is_ave) fprintf(stderr," process: factor: NEW*%g - OLD*%g\n", dt2/ (double) (dt2 - dt1), dt1/ (double) (dt2-dt1)); else fprintf(stderr," process: current-last\n"); } // change floating point data d1= save->val; for (i = 0; i < ndata; i++) { if (!UNDEFINED_VAL(data[i]) && !UNDEFINED_VAL(*d1) ) { if (is_ave) { *d1 = (data[i]*dt2 - *d1*dt1) / (double) (dt2 - dt1); } else { // accumulation *d1 = data[i] - *d1; } } else *d1 = UNDEFINED; d1++; } // write grib output if ((data_tmp = (float *) malloc(ndata * sizeof(float))) == NULL) fatal_error("memory allocation - data_tmp",""); undo_output_order(save->val, data_tmp, ndata); grib_wrt(save->clone_sec, data_tmp, ndata, nx, ny, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, save->output); if (flush_mode) fflush(save->output); free(data_tmp); // save data free(save->val); // save = new field free_sec(save->clone_sec); copy_sec(sec, save->clone_sec); copy_data(data,ndata,&(save->val)); return 0; } return 0; }
/* * 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; }
void last_ten_callers(char *string, char *name, int portnum) { FILE *fileptr; char s[80]; int num; int not_abort = 1; int key; char *data; int num_last = str_to_num(string,&data); if (num_last == -1) num_last = 10; if (num_last>99) num_last = 99; while( (*data==' ' || *data=='-' )&& *data!=0) data++; if (*data=='K' || *data=='k') { last_ten_kills(num_last,portnum); return; } print_cr(); sprintf(s,"Last %d callers",num_last); print_str_cr(s); num_last++; print_cr(); lock_dos(276); if (!(fileptr=g_fopen(USER_LOG_FILE,"rb","FILES#4"))) /* open the user log */ { log_error(USER_LOG_FILE); unlock_dos(); return; }; call_on_logoff(close_last_ten_callers,(void *)fileptr); num = 1; while (not_abort && (num<num_last)) { fseek(fileptr,-80*(long int)(num),SEEK_END); not_abort = (ftell(fileptr) != 0); if (not_abort) { sprintf(s,"%2d: ",num); unlock_dos(); print_string(s); lock_dos(276); fread(s,1,80,fileptr); unlock_dos(); print_str_cr(s); key = get_first_char(portnum); if ((key == 3) || (key == 27)) { int_char(portnum); not_abort = 0; }; lock_dos(277); }; num++; }; g_fclose(fileptr); clear_call_on_logoff(); unlock_dos(); print_cr(); };
/* * HEADER:100:irr_grid:output:3:make irregular grid, nearest neighbor, X=lon-lat list Y=radius (km) Z=output grib file */ int f_irr_grid(ARG3) { int i, k, m; struct local_struct { int ngrid; double *lon_lat_list, radius; FILE *out; int *iptr; int last_GDS_change_no; }; struct local_struct *save; const char *t; unsigned char *p; double tmp; float *array; unsigned char *new_sec[8], *new_sec3; /* initialization phase */ if (mode == -1) { decode = latlon = 1; *local = save = (struct local_struct *)malloc( sizeof(struct local_struct)); if (save == NULL) fatal_error("irr_grid: memory allocation",""); /* count number of colons */ t = arg1; i = 0; while (*t) { if (*t++ == ':') i++; } if (i % 2 != 1) fatal_error("irr_grid: need lon0:lat0:lon1:lat1:..:lonN:latN",""); save->ngrid = (i + 1)/2; save->lon_lat_list = (double *) malloc(save->ngrid * 2 * sizeof(double)); save->iptr = (int *) malloc(save->ngrid * sizeof(int)); if (save->lon_lat_list == NULL || save->iptr == NULL ) fatal_error("irr_grid: memory allocation",""); t = arg1; k = sscanf(t, "%lf%n", &tmp, &m); if (k != 1) fatal_error("irr_grid: lat-lon list, %s",t); save->lon_lat_list[0] = tmp; t += m; for (i = 1; i < 2*save->ngrid; i++) { k = sscanf(t, ":%lf%n", &tmp, &m); if (k != 1) fatal_error("irr_grid: lat-lon list, %s",t); save->lon_lat_list[i] = tmp; t += m; } for (i = 0 ; i < save->ngrid; i++) { tmp = save->lon_lat_list[i*2]; if (tmp < 0.0) save->lon_lat_list[i*2] = tmp + 360.0; if (tmp > 360.0) save->lon_lat_list[i*2] = tmp - 360.0; if (fabs(save->lon_lat_list[i*2+1]) > 90.0) fatal_error("irr_grid: bad latitude",""); } if (sscanf(arg2,"%lf",&(save->radius)) != 1) fatal_error("irr_grid: radius %s", arg2); if ((save->out = ffopen(arg3, file_append ? "ab" : "wb" )) == NULL) fatal_error("irr_grid could not open file %s", arg3); } if (mode < 0) return 0; save = (struct local_struct *) *local; if (save->last_GDS_change_no != GDS_change_no) { save->last_GDS_change_no = GDS_change_no; if (lat == NULL || lon == NULL || data == NULL) fatal_error("irr_grid: no val",""); /* find the nearest points for the grid */ closest_init(sec); for (i = 0; i < save->ngrid; i++) { save->iptr[i] = closest(sec, save->lon_lat_list[i*2+1], save->lon_lat_list[i*2]); } } array = (float *) malloc(save->ngrid * sizeof(float)); new_sec3 = (unsigned char *) malloc((30+8*save->ngrid) * sizeof(unsigned char)); if (array == NULL || new_sec3 == NULL) fatal_error("irr_grid: memory allocation",""); /* sec3 = grid defintion */ uint_char(30+save->ngrid*8, new_sec3); new_sec3[4] = 3; // sec3 new_sec3[5] = 0; // use table 3.1 uint_char(save->ngrid, new_sec3+6); new_sec3[10] = 0; // no optional list octets new_sec3[11] = 0; uint2_char(130, new_sec3+12); p = code_table_3_2_location(sec); if (p == NULL) { // no earth descripition for (i = 14; i < 30; i++) { new_sec3[i] = 255; } } else { for (i = 14; i < 30; i++) { new_sec3[i] = p[i-14]; } } /* make new_sec[] with new grid definition */ for (i = 0; i < 8; i++) new_sec[i] = sec[i]; new_sec[3] = new_sec3; for (i = 0; i < save->ngrid; i++) { array[i] = save->iptr[i] >= 0 ? data[save->iptr[i]] : UNDEFINED; int_char( (int) (save->lon_lat_list[i*2+1] * 1000000.0), new_sec3 + 30 + i*8); uint_char( (int) (save->lon_lat_list[i*2] * 1000000.0), new_sec3 + 34 + i*8); } grib_wrt(new_sec, array, save->ngrid, save->ngrid, 1, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, save->out); free(array); free(new_sec3); return 0; }
void list_bbs(char *directory, struct bbs_board_info *bbs_info, int num_files,struct bbs_user_account *bbs_user) { int file; int anyfile = 1; int key; int abort=0; char user_l[80]; char date_l[80]; char subject_l[120]; char num_l[120]; int count=0; FILE *fileptr; print_cr(); file=num_files; while ((file>0) && (!abort)) { file--; lock_dos(); if (open_bbs_file(directory,bbs_info,file,&fileptr)) { mail_line(user_l,20,40,fileptr); mail_line(subject_l,32,70,fileptr); mail_line(date_l,16,40,fileptr); g_fclose(fileptr); unlock_dos(); anyfile = 0; if (bbs_info[file].filedate > (bbs_user->last_entered_bbs)) sprintf(num_l,"*%02d: ",file+1); else sprintf(num_l," %02d: ",file+1); special_code(1,tswitch); print_string(num_l); print_string(user_l); print_chr(' '); print_string(date_l); print_chr(' '); print_string(subject_l); print_cr(); count++; special_code(0,tswitch); key = get_first_char(tswitch); if ((key == 27) || (key == 3)) { int_char(tswitch); file = -1; }; if (key == 19) { wait_ch(); wait_ch(); }; if (count>=24) { abort= do_page_break(); count=0; } lock_dos(); }; unlock_dos(); }; if (anyfile) print_str_cr("No BBS messages."); };
unsigned char *sec3_gaussian(int nx, double x0, double dx, int ny, double y0, unsigned char **old_sec) { static unsigned char gds[72]; unsigned char *p; double r; int i; if (x0 < 0) x0 += 360.0; uint_char(72, gds); /* 1-4 length of section */ gds[4] = 3; /* section 3 */ gds[5] = 0; /* source of grid */ uint_char(nx*ny, gds+6); /* number of data points */ gds[10] = 0; /* number of octets for optional list of number */ gds[11] = 0; /* list */ gds[12] = 0; gds[13] = 40; /* template 3.0 gaussian grid*/ /* shape of the earth */ if (old_sec == NULL) { /* use NCEP default */ gds[14] = 6; /* shape of earth */ gds[15] = 0; /* scale factor of radius of spherical earth */ uint_char(0, gds+16); /* scaled value of radius of spherical earth */ gds[20] = 0; /* scale factor of major radious of oblate earth */ uint_char(0, gds+21); /* scaled value of major axis */ gds[25] = 0; /* scale factor of minor axis */ uint_char(0, gds+26); /* scaled value of minor axis */ } else { p = code_table_3_2_location(old_sec); for (i = 0; i < 16; i++) gds[14+i] = p[i]; } uint_char(nx, gds+30); uint_char(ny, gds+34); uint_char(0, gds+38); /* 0 */ uint_char(0xffffffff, gds+42); /* undefined */ int_char((int) floor(y0*ANGLE_FACTOR+0.5), gds+46); /* lat1 */ uint_char((int) floor(x0*ANGLE_FACTOR+0.5), gds+50); /* lon1 */ gds[54] = 32+16; /* flag table 3.3 */ r = -y0; int_char((int) floor(r*ANGLE_FACTOR+0.5), gds+55); /* lat2 */ r = x0 + (nx-1)*dx; if (r >= 360.0) r -= 360.0; if (r < 0.0) r += 360.0; uint_char((int) floor(r*ANGLE_FACTOR+0.5), gds+59); /* lon2 */ int_char((int) floor(fabs(dx) * ANGLE_FACTOR + 0.5), gds+63); /* Di i direction increment */ uint_char(ny/2, gds+67); gds[71] = 0; /* scanning mode */ if (dx < 0.0) gds[71] |= 128; if (y0 < 0.0) gds[71] |= 64; return gds; }
int f_grib_out_irr(ARG2) { float *data_tmp; int all, i, j; unsigned int n; unsigned char *gds, *old_gds, *p; if (mode == -1) { latlon = decode = 1; if (strcmp(arg1,"defined") && strcmp(arg1,"all")) fatal_error("grib_out_irr: %s should be all or defined", arg1); *local = (void *) ffopen(arg2, file_append? "ab" : "wb" ); if (*local == NULL) fatal_error("Could not open %s", arg2); return 0; } if (mode == -2) { ffclose((FILE *) *local); return 0; } if (lat == NULL || lon == NULL) fatal_error("grid_out_irr: failed, no lat-lon information",""); all = strcmp(arg1,"all") == 0; if (all) { n = ndata; } else { for (i = n = 0; i < ndata; i++) { if (DEFINED_VAL(data[i])) n++; } } if (n == 0) { fprintf(stderr,"grib_out_irr: no grid points to write out, no write\n"); return 0; } if ((gds = (unsigned char *) malloc(n * 8 + 30)) == NULL) fatal_error("grib_out_irr: memory allocation",""); if ((data_tmp = (float *) malloc(n* sizeof(float))) == NULL) fatal_error("grib_out_irr: memory allocation",""); /* sec3 = grid defintion */ uint_char(30+n*8, gds); gds[4] = 3; // sec3 gds[5] = 0; // use table 3.1 uint_char(n, gds+6); gds[10] = 0; // no optional list octets gds[11] = 0; uint2_char(130, gds+12); p = code_table_3_2_location(sec); if (p == NULL) { // no earth descripition for (i = 14; i < 30; i++) { gds[i] = 255; } } else { for (i = 14; i < 30; i++) { gds[i] = p[i-14]; } } if (all) { for (i = 0; i < ndata; i++) { int_char( (int) (lat[i] * 1000000.0), gds + 30 + i*8); int_char( (int) (lon[i] * 1000000.0), gds + 34 + i*8); data_tmp[i] = data[i]; } } else { for (j = i = 0; i < ndata; i++) { if (DEFINED_VAL(data[i])) { int_char( (int) (lat[i] * 1000000.0), gds + 30 + j*8); int_char( (int) (lon[i] * 1000000.0), gds + 34 + j*8); data_tmp[j++] = data[i]; } } } old_gds = sec[3]; sec[3] = gds; grib_wrt(sec, data_tmp, n, n, 1, use_scale, dec_scale, bin_scale, wanted_bits, max_bits, grib_type, (FILE *) *local); sec[3] = old_gds; if (flush_mode) fflush((FILE *) *local); free(data_tmp); free(gds); return 0; }
void debug_printf(char *format,...) { #if 1 va_list opt; static char out[32] ATTRIBUTE_ALIGN(32)=" "; int val; char *s; va_start(opt, format); int fd; int message; static int one=1; static u32 buffer[8]; static u32 queuehandle2=-1; if(one) { queuehandle2 = os_message_queue_create(buffer, 8); one=0; } else os_message_queue_receive(queuehandle2, (void *)&message, 0); internal=internal_debug_printf; if(internal & 2) goto salir; if(index_dev & 1) { if(internal) fd = FAT_Open("usb:/ffs_log.txt" ,O_WRONLY | O_APPEND); else fd=os_open("usb:/ffs_log.txt" ,O_WRONLY | O_APPEND); } else { if(internal) fd = FAT_Open("sd:/ffs_log.txt" ,O_WRONLY | O_APPEND); else fd=os_open("sd:/ffs_log.txt" ,O_WRONLY | O_APPEND); } if(fd<0) goto salir; while(format[0]) { if(format[0]!='%') {out[0]=*format++; printf_write(fd, out, strlen(out));} else { format++; switch(format[0]) { case 'd': case 'i': val=va_arg(opt,int); int_char(val); printf_write(fd, mem_cad, strlen(mem_cad)); break; case 'u': val=va_arg(opt, unsigned); uint_char(val); //printf_write(fd, mem_cad, strlen(mem_cad)); printf_write(fd, mem_cad, strlen(mem_cad)); break; case 'x': val=va_arg(opt,int); hex_char((u32) val); printf_write(fd, mem_cad, strlen(mem_cad)); break; case 's': s=va_arg(opt,char *); printf_write(fd, s, strlen(s)); break; } format++; } } va_end(opt); if(internal) FAT_Close(fd); else os_close(fd); salir: os_message_queue_send(queuehandle2, 0, 0); #endif }