int startup(const char* _ip,int _port) //创建监听套接字 { assert(_ip); int sock=socket(AF_INET,SOCK_STREAM,0); if(sock<0) { printf_log("socket failed",FATAL); exit(2); } int opt=1; setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt)); struct sockaddr_in local; local.sin_family=AF_INET; local.sin_port=htons(_port); local.sin_addr.s_addr=inet_addr(_ip); if(bind(sock,(struct sockaddr*)&local,sizeof(local))<0) { printf_log("bind failed",FATAL); exit(3); } if(listen(sock,50)<0) { printf_log("listen failed",FATAL); exit(4); } return sock; }
double pulse_newton_sim_voc(struct device *in) { printf_log("Looking for Voc\n"); double C = in->C; double clamp = 0.1; double step = 0.01; double e0; double e1; double i0; double i1; double deriv; double Rdrain = pulse_config.pulse_Rload + in->Rcontact; solve_all(in); i0 = get_I(in); e0 = fabs(i0 + in->Vapplied * (1.0 / in->Rshunt - 1.0 / Rdrain)); in->Vapplied += step; solve_all(in); i1 = get_I(in); e1 = fabs(i1 + in->Vapplied * (1.0 / in->Rshunt - 1.0 / Rdrain)); deriv = (e1 - e0) / step; step = -e1 / deriv; step = step / (1.0 + fabs(step / clamp)); in->Vapplied += step; int count = 0; int max = 200; do { e0 = e1; solve_all(in); i1 = get_I(in); e1 = fabs(i1 + in->Vapplied * (1.0 / in->Rshunt - 1.0 / Rdrain)); deriv = (e1 - e0) / step; step = -e1 / deriv; step = step / (1.0 + fabs(step / clamp)); in->Vapplied += step; if (get_dump_status(dump_print_text) == TRUE) { printf_log ("%d pulse voc find Voc Vapplied=%lf step=%le error=%le\n", count, in->Vapplied, step, e1); } if (count > max) break; count++; } while (e1 > 1e-12); double ret = in->Vapplied - C * (i1 - in->Ilast) / in->dt; return ret; }
void newton_init(struct simulation *sim, char *solver_name) { printf_log(sim, _("Solver initialization\n")); char lib_name[100]; char lib_path[1000]; sprintf(lib_name, "%s.so", solver_name); join_path(2, lib_path, get_plugins_path(sim), lib_name); printf_log(sim, "I want to open %s %s %s\n", lib_path, get_plugins_path(sim), lib_name); char *error; dll_handle = dlopen(lib_path, RTLD_LAZY); if (!dll_handle) { fprintf(stderr, "%s\n", dlerror()); exit(0); } dll_solve_cur = dlsym(dll_handle, "dll_solve_cur"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_newton_set_min_ittr = dlsym(dll_handle, "dll_newton_set_min_ittr"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_set_interface = dlsym(dll_handle, "set_interface"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_solver_realloc = dlsym(dll_handle, "dll_solver_realloc"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } dll_solver_free_memory = dlsym(dll_handle, "dll_solver_free_memory"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(0); } (*dll_newton_set_min_ittr) (0); }
char *getCmdlinePath(char *cmdline, char *buffer) { while (*cmdline == ' ') cmdline++; if (!*cmdline) { printf_log("Too few arguments!\n"); return NULL; } if (*cmdline == '\"') //surrounding doublequotes { while (*cmdline && *cmdline != '\"' ) *buffer++ = *cmdline++; if (*cmdline == '\"') cmdline++; } else { while (*cmdline && *cmdline != ' ') *buffer++ = *cmdline++; } *buffer = '\0'; return cmdline; }
/* Parses config and populates ctx accordingly. Returns 0 on success, nonzero on failure. */ static int conf_parse(struct dechunkiser_ctx *ctx, const char *config) { int j; struct tag *cfg_tags; const char *error_str; // defaults ctx->verbosity = 1; sprintf(ctx->ip, "127.0.0.1"); ctx->ports_len = 0; for (j=0; j<RTP_UDP_PORTS_NUM_MAX; j++) { ctx->ports[j] = -1; } if (!config) { printf_log(ctx, 0, "No output ports specified"); return 1; } cfg_tags = grapes_config_parse(config); if (cfg_tags) { const char *addr; grapes_config_value_int(cfg_tags, "verbosity", &(ctx->verbosity)); printf_log(ctx, 2, "Verbosity set to %i", ctx->verbosity); addr = grapes_config_value_str(cfg_tags, "addr"); if (addr && strlen(addr) < IP_ADDR_LEN) { sprintf(ctx->ip, "%s", addr); } printf_log(ctx, 1, "Destination IP address: %s", ctx->ip); ctx->ports_len = rtp_ports_parse(cfg_tags, ctx->ports, NULL, &error_str); } free(cfg_tags); if (ctx->ports_len == 0) { printf_log(ctx, 0, error_str); return 2; } for (j=0; j<ctx->ports_len; j++) { printf_log(ctx, 1, " Configured output port: %i", ctx->ports[j]); } return 0; }
void client_shutdown(t_client *client) { printf_log("Client %s:%d disconnected", client->ip, client->port); close(client->socket); free(client->ip); if (client->receiver) client->receiver->destroy(client->receiver); list_clear(&client->inbound, true); list_clear(&client->outbound, true); list_remove(&g_server.network.pool.nodes, client, true); }
int cmdexcute(np_data *np) { int ret; if ((log_fp=fopen(NUM_FILENAME,"a+"))==NULL ) { printf("Can not open number file!\n"); return -1; } fscanf(log_fp,"%d",&chip_num); fclose(log_fp); chip_num++; if ((log_fp=fopen(NUM_FILENAME,"w"))==NULL ) { printf("Can not open number file!\n"); return -1; } printf_log(log_fp,"%d",chip_num); fclose(log_fp); if ((log_fp=fopen(LOG_FILENAME,"a+"))==NULL ) { printf("Can not open log file!\n"); return -1; } printf_log(log_fp,"\nNo.%d :\n",chip_num); if (np->ops == READ_FLASH) { printf_log(log_fp,"Read nand flash!\n"); printf_log(log_fp,"Args:index=%d spage=%d epage=%d file=%s cs=%d\n", idx,spage,epage,filename,cs_index); ret= do_read_flash(np); } else { printf_log(log_fp,"Write nand flash!\n"); printf_log(log_fp,"Args:index=%d spage=%d epage=%d file=%s cs=%d\n", idx,spage,epage,filename,cs_index); ret= do_write_flash(np); } if (!ret) printf_log(log_fp,"Operation success!\n"); else printf_log(log_fp,"Operation fail!\n"); fclose(log_fp); return 0; }
void Condition::compress() { size = MAXFIELDS; for (int i = size - 1; i >= 0; i--) { if (*(&amount + i) == defaultvals[i]) { size--; } else { if (setts.intense) printf_log("condition size %d.\n",size); break; } } }
int start(short port) { int listen_sock = socket(AF_INET,SOCK_STREAM,0); if(listen_sock == -1){ printf_log(__FUNCTION__,__LINE__,errno,strerror(errno)); exit(1); } struct sockaddr_in local; local.sin_family = AF_INET; local.sin_port = htons(port); local.sin_addr = INADDR_ANY; socklen_t len = sizeof(local); if(bind(listen_sock,(struct sockaddr*)local,len) == -1){ printf_log(__FUNCTION__,__LINE__,errno,strerror(errno)); exit(2); } if(listen(listen_sock,BACKLOG) == -1){ printf_log(__FUNCTION__,__LINE__,errno,strerror(errno)); exit(3); } return listen_sock; }
static void rtp_write(struct dechunkiser_ctx *ctx, int id, uint8_t *data, int size) { uint8_t* data_end = data + size; printf_log(ctx, 2, "Got chunk of size %i", size); while (data < data_end) { // NOTE: `stream` here is the index in the ports array. int stream, psize; rtp_payload_per_pkt_header_parse(data, &psize, &stream); data += RTP_PAYLOAD_PER_PKT_HEADER_SIZE; if (stream > ctx->ports_len) { printf_log(ctx, 1, "Received Chunk with bad stream %d > %d", stream, ctx->ports_len); return; } printf_log(ctx, 2, "sending packet of size %i from port id #%i to port %i", psize, stream, ctx->ports[stream]); packet_write(ctx->outfd, ctx->ip, ctx->ports[stream], data, psize); data += psize; } }
float T1_trans(int id) { int data; float ret; srand((unsigned)time(NULL)); sensor_get(ss,id,&data); data+=rand()%1; ret = (float)(data * 120/1000); printf_log(id,data,ret); return ret; }
int menu_event_handler(dialog_t * dialog, int *r1, gui_event_t event, int *r3, int r4, int r5, int r6, int code) { int ret; button_t button; // FW:FF915990 // this seems to be one of the addresses where the handler is called // standard menu 55-63 #ifdef ENABLE_DEBUG // print the dialog structure and diff the both cases of menu creation debug_log("_BTN_ [%s][guimode:%08X]", debug_btn_name(event), FLAG_GUI_MODE); //debug_log("_BTN_: 84=[%08X] 88=[%08X]", GET_FROM_MEM(menu_handler+0x84), GET_FROM_MEM(menu_handler+0x88) ); //debug_log("_BTN_: r1=[%08X], r3=[%08X], 90=[%08X]", *r1, *r3, /* *(int*) */(*(int*)((int)dialog+0x90)) ); //debug_log("_BTN_: r4=[%08X], r5=[%08X], r6=[%08X]", r4, r5, r6); #endif switch (event) { case GUI_BUTTON_MENU : button = BUTTON_MENU; break; // case GUI_BUTTON_DISP : button = BUTTON_DISP; break; case GUI_BUTTON_JUMP : button = BUTTON_JUMP; break; case GUI_BUTTON_PLAY : button = BUTTON_PLAY; break; case GUI_BUTTON_TRASH : button = BUTTON_TRASH; break; case GUI_BUTTON_UP : button = BUTTON_UP; break; case GUI_BUTTON_DOWN : button = BUTTON_DOWN; break; case GUI_BUTTON_ZOOM_OUT_PRESS : button = BUTTON_ZOOM_OUT; break; case GUI_BUTTON_ZOOM_IN_PRESS : button = BUTTON_ZOOM_IN; break; default: goto pass_event; } if (button_handler(button, true)) return false; pass_event: ret = InfoCreativeAppProc(dialog, r1, event, r3, r4, r5, r6, code); #ifdef ENABLE_DEBUG printf_log(1,6, "_BTN_ after: r1=[%08X], r3=[%08X]", *r1, *r3); #endif return ret; }
int light_load_laser(struct simulation *sim, struct light *in,char *name) { char pwd[1000]; char file_name[255]; struct inp_file inp; int ret=0; if (getcwd(pwd,1000)==NULL) { ewe(sim,"IO error\n"); } ret=search_for_token(sim,file_name,pwd,"#laser_name",name); if (ret==0) { inp_init(sim,&inp); inp_load_from_path(sim,&inp,get_input_path(sim),file_name); inp_check(sim,&inp,1.0); inp_search_gdouble(sim,&inp,&in->laser_wavelength,"#laserwavelength"); in->laser_pos=(int)((in->laser_wavelength-in->lstart)/in->dl); inp_search_gdouble(sim,&inp,&in->spotx,"#spotx"); inp_search_gdouble(sim,&inp,&in->spoty,"#spoty"); inp_search_gdouble(sim,&inp,&in->pulseJ,"#pulseJ"); inp_search_gdouble(sim,&inp,&in->pulse_width,"#laser_pulse_width"); inp_free(sim,&inp); printf_log(sim,"Loaded laser\n"); } else { ewe(sim,"laser name not found\n"); } return 0; }
static struct dechunkiser_ctx *rtp_open_out(const char *fname, const char *config) { struct dechunkiser_ctx *res; res = malloc(sizeof(struct dechunkiser_ctx)); if (res == NULL) { return NULL; } if (conf_parse(res, config) != 0) { free(res); return NULL; } res->outfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (res->outfd < 0) { printf_log(res, 0, "Could not open output socket"); free(res); return NULL; } return res; }
/* * Determines the teams based on the diplomacies. */ void LoadDiplomacy(HWND dialog) { ediplo diplo[8] = {NOT_DETERMINED}; // if still NOT_DETERMINED at the end, call it unclear int teams = 0; // check if p1 is in a team // ------------------------ // p1 must have no neutrals // see what players p1 is allied with // each of those players must only be allied with p1 and p1's allies excluding their selves. // // Then increment `int teams` and set team for each teammember in a main table (diplo) // ------------------------------------ int new_team = true; // until proven otherwise int already_in_a_team = false; bool allies[N_PLAYERS] = {false}; bool allied_anyone = false; bool neutral = false; // check each player for a team for (int i_subject = 0; i_subject < N_PLAYERS; i_subject++) { new_team = true; // until proven otherwise already_in_a_team = false; allied_anyone = false; neutral = true; switch (diplo[i_subject]) { case TEAM1: case TEAM2: case TEAM3: case TEAM4: already_in_a_team = true; goto determined; } for (int i = 0; i < N_PLAYERS; i++) { allies[i] = false; } // first make an inclusive list of that player's allies allies[i_subject] = true; for (int i = 0; i < N_PLAYERS; i++) { if (i == i_subject) continue; if (scen.players[i_subject].diplomacy[i] == DIP_neutral) { new_team = false; } else { neutral = false; } allies[i] = scen.players[i_subject].diplomacy[i] == DIP_ally && scen.players[i].diplomacy[i_subject] == DIP_ally; if (allies[i]) allied_anyone = true; } if (!allied_anyone) { new_team = false; } if (!new_team) { goto determined; } // but being a teammate is more than just being allies for (int i = 0; i < N_PLAYERS; i++) { if (i == i_subject) continue; if (allies[i]) { // for each ally, determine if they are faithful (fidelious) for (int j = 0; j < N_PLAYERS; j++) { if (j == i) continue; if (allies[j]) { if (scen.players[i].diplomacy[j] != DIP_ally) { new_team = false; goto determined; } } else { if (scen.players[i].diplomacy[j] != DIP_enemy) { new_team = false; goto determined; } } } } } determined: if (already_in_a_team) { continue; } else if (new_team) { printf_log("allies %d %d %d\n", allies[0], allies[1], allies[2]); for (int i = 0; i < N_PLAYERS; i++) { if (allies[i]) { diplo[i] = (ediplo)((int)TEAM1 + teams); } } teams++; } else if (neutral) { diplo[i_subject] = NEUTRAL; } else if (!allied_anyone) { diplo[i_subject] = ALONE; } } // Everything is worked out for (int i = 0; i < N_PLAYERS; i++) { SendDlgItemMessage(dialog, IDC_P_TEAM1 + i, CB_SETCURSEL, diplo[i], 0); } }
void device_free(struct simulation *sim,struct device *in) { //1d free(in->xmesh); free(in->ymesh); free(in->zmesh); //2d free_zx_gdouble(in,in->Vapplied); free_zx_gdouble(in,in->Jnleft); free_zx_gdouble(in,in->Jnright); free_zx_gdouble(in,in->Jpleft); free_zx_gdouble(in,in->Jpright); free_zx_int(in,in->n_contact); //3d free_3d_gdouble(in,in->phi); free_3d_gdouble(in,in->B); free_3d_gdouble(in,in->Nad); free_3d_gdouble(in,in->n); free_3d_gdouble(in,in->p); free_3d_gdouble(in,in->dn); free_3d_gdouble(in,in->dp); free_3d_gdouble(in,in->dndphi); free_3d_gdouble(in,in->dpdphi); free_3d_gdouble(in,in->Eg); free_3d_gdouble(in,in->Xi); free_3d_gdouble(in,in->Ev); free_3d_gdouble(in,in->Ec); free_3d_gdouble(in,in->mun); free_3d_gdouble(in,in->mup); free_3d_gdouble(in,in->Dn); free_3d_gdouble(in,in->Dp); free_3d_gdouble(in,in->Fn); free_3d_gdouble(in,in->Fp); free_3d_gdouble(in,in->Nc); free_3d_gdouble(in,in->Nv); free_3d_gdouble(in,in->G); free_3d_gdouble(in,in->Gn); free_3d_gdouble(in,in->Gp); free_3d_gdouble(in,in->Tl); free_3d_gdouble(in,in->Te); free_3d_gdouble(in,in->Th); free_3d_gdouble(in,in->R); free_3d_gdouble(in,in->Fi); free_3d_gdouble(in,in->Jn); free_3d_gdouble(in,in->Jp); free_3d_gdouble(in,in->Jn_drift); free_3d_gdouble(in,in->Jn_diffusion); free_3d_gdouble(in,in->Jp_drift); free_3d_gdouble(in,in->Jp_diffusion); free_3d_gdouble(in,in->x); free_3d_gdouble(in,in->t); free_3d_gdouble(in,in->xp); free_3d_gdouble(in,in->tp); free_3d_gdouble(in,in->ex); free_3d_gdouble(in,in->Dex); free_3d_gdouble(in,in->Hex); free_3d_gdouble(in,in->epsilonr); free_3d_gdouble(in,in->kf); free_3d_gdouble(in,in->kd); free_3d_gdouble(in,in->kr); free_3d_gdouble(in,in->Rfree); free_3d_gdouble(in,in->Rn); free_3d_gdouble(in,in->Rp); free_3d_gdouble(in,in->kl); free_3d_gdouble(in,in->ke); free_3d_gdouble(in,in->kh); free_3d_gdouble(in,in->Hl); free_3d_gdouble(in,in->He); free_3d_gdouble(in,in->Hh); free_3d_gdouble(in,in->Habs); free_3d_gdouble(in,in->nlast); free_3d_gdouble(in,in->plast); free_3d_gdouble(in,in->wn); free_3d_gdouble(in,in->wp); free_3d_gdouble(in,in->nt_all); free_3d_gdouble(in,in->tt); free_3d_gdouble(in,in->Rbi_k); free_3d_gdouble(in,in->pt_all); free_3d_gdouble(in,in->tpt); free_3d_gdouble(in,in->nf_save); free_3d_gdouble(in,in->pf_save); free_3d_gdouble(in,in->nt_save); free_3d_gdouble(in,in->pt_save); free_3d_gdouble(in,in->nfequlib); free_3d_gdouble(in,in->pfequlib); free_3d_gdouble(in,in->ntequlib); free_3d_gdouble(in,in->ptequlib); free_3d_gdouble(in,in->nrelax); free_3d_gdouble(in,in->ntrap_to_p); free_3d_gdouble(in,in->prelax); free_3d_gdouble(in,in->ptrap_to_n); free_3d_gdouble(in,in->n_orig); free_3d_gdouble(in,in->p_orig); free_3d_gdouble(in,in->n_orig_f); free_3d_gdouble(in,in->p_orig_f); free_3d_gdouble(in,in->n_orig_t); free_3d_gdouble(in,in->p_orig_t); free_3d_gdouble(in,in->phi_save); free_3d_int(in,in->imat); //Free solvers solver_free(sim); complex_solver_free(sim); printf_log(sim,"%s %i %s\n", _("Solved"), in->odes, _("Equations")); }
/* ProcessCmdline: processes the command-line and returns whether to exit */ bool ProcessCmdline(char *cmdline) { bool ret = true; char pathIn[_MAX_PATH], pathOut[_MAX_PATH]; FILE *fileIn, *fileOut; int size, code; unsigned char *buffer; int c; switch (c = tolower(cmdline[1])) { case 'c': case 'u': cmdline += 2; cmdline = getCmdlinePath(cmdline, pathIn); if (!cmdline) break; cmdline = getCmdlinePath(cmdline, pathOut); if (!cmdline) break; if (c == 'c') printf("Compressing %s to %s... ", pathIn, pathOut); else printf("Decompressing %s to %s... ", pathIn, pathOut); size = fsize(pathIn); buffer = new unsigned char[size]; if (!buffer) { printf_log("not enough memory.\n"); break; } fileIn = fopen(pathIn, "rb"); if (!fileIn) { printf_log("couldn\'t open input file\n"); delete [] buffer; break; } fread(buffer, sizeof(char), size, fileIn); fclose(fileIn); fileOut = fopen(pathOut, "wb"); if (!fileOut) { printf_log("couldn\'t open output file\n"); delete [] buffer; break; } if (c == 'c') code = deflate_file(buffer, size, fileOut); else code = inflate_file(buffer, size, fileOut); fclose(fileOut); if (code >= 0) printf_log("done!\n"); else printf_log("failed.\n"); break; default: ret = false; } return ret; }
static int excu_cgi(int sock,const char* method,\ const char* path,const char* query_string) //处理CGI模式的请求 { char line[SIZE]; int ret=0; int content_len=-1; if(strcasecmp(method,"GET")==0) //如果是GET方法的CGI { //清空消息报头 clear_header(sock); } else //POST方法的CGI { //获取post方法的参数大小 do { ret=get_line(sock,line); if(strncmp(line,"Content-Length: ",16)==0) //post的消息体记录正文长度的字段 { content_len=atoi(line+16); //求出正文的长度 } }while(ret!=1&&(strcmp(line,"\n")!=0)); } //将method、query_string、content_len导出为环境变量 char method_env[SIZE/8]; char query_string_env[SIZE/8]; char content_len_env[SIZE/8]; sprintf(method_env,"METHOD=%s",method); putenv(method_env); sprintf(query_string_env,"QUERY_STRING=%s",query_string); putenv(query_string_env); sprintf(content_len_env,"CONTENT_LEN=%d",content_len); putenv(content_len_env); int input[2]; //站在CGI程序的角度,创建两个管道 int output[2]; pipe(input); pipe(output); pid_t id=fork(); if(id<0) { printf_log("fork failed",FATAL); echo_error(sock,500); return 9; } else if(id==0) //子进程 { close(input[1]); //关闭input的写端 close(output[0]); //关闭output的读端 //将文件描述符重定向到标准输入标准输出 dup2(input[0],0); dup2(output[1],1); execl(path,path,NULL); //替换CGI程序 exit(1); } else //father { close(input[0]); //关闭input的读端 close(output[1]); //关闭output的写端 char ch='\0'; if(strcasecmp(method,"POST")==0) //如果是post方法,则父进程需要给子进程发送参数 { int i=0; for( i=0;i<content_len;i++) { recv(sock,&ch,1,0); //从sock里面一次读一个字符,总共读conten_len个字符 write(input[1],&ch,1); } } char* msg="HTTP/1.0 200 OK\r\n\r\n"; send(sock,msg,strlen(msg),0); //接收子进程的返回结果 while(read(output[0],&ch,1)) //如果CGI程序结束,写端关闭,则读端返回0 { send(sock,&ch,1,0); } waitpid(id,NULL,0); //回收子进程 } return 0; }
void get_initial(struct simulation *sim,struct device *in) { int i; int z; int x; int y; gdouble Ef=0.0; gdouble phi_ramp=0.0; gdouble Eg=0.0; gdouble Xi=0.0; gdouble charge_left=0.0; gdouble charge_right=0.0; gdouble top_l=0.0; gdouble top_r=0.0; Ef=0.0; phi_ramp=0.0; Eg=in->Eg[0][0][0]; Xi=in->Xi[0][0][0]; charge_left=in->lcharge; charge_right=in->rcharge; top_l=0.0; top_r=0.0; if (in->interfaceleft==TRUE) { top_l=in->phibleft-Eg; }else { if (in->lr_pcontact==LEFT) { top_l=get_top_from_p(in,charge_left,in->Te[0][0][0],in->imat[0][0][0]); }else { top_l= -(in->Eg[0][0][0]+get_top_from_n(in,charge_left,in->Te[0][0][0],in->imat[0][0][0])); } } if (in->interfaceright==TRUE) { top_r= -in->phibright; }else { if (in->lr_pcontact==LEFT) { top_r=get_top_from_n(in,charge_right,in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]); }else { top_r= -(Eg+get_top_from_p(in,charge_right,in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1])); } } if (get_dump_status(sim,dump_info_text)==TRUE) { printf_log(sim,"check1= %Le %Le\n",get_p_den(in,top_l,in->Te[0][0][0],in->imat[0][0][0]),charge_left); printf_log(sim,"check2= %Le %Le\n",get_n_den(in,top_r,in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]),charge_right); } gdouble delta_phi=top_l+top_r+in->Eg[0][0][0]+in->Xi[0][0][0]-in->Xi[0][0][in->ymeshpoints-1]; gdouble test_l= -in->Xi[0][0][0]+top_r; gdouble test_r= -in->Xi[0][0][0]-in->Eg[0][0][0]-top_l; in->vbi=delta_phi; if (get_dump_status(sim,dump_print_text)==TRUE) { printf_log(sim,"delta=%Le\n",delta_phi); printf_log(sim,">>>>top_l= %Le\n",top_l+Eg); printf_log(sim,">>>>top_r= %Le\n",-top_r); printf_log(sim,"left= %Le right = %Le %Le %Le\n",test_l,test_r,test_r-test_l,delta_phi); printf_log(sim,"%Le %Le %Le %Le %Le\n",top_l,top_r,Eg,delta_phi,in->phi[0][0][0]); } Ef= -(top_l+Xi+Eg); gdouble Lp=get_p_den(in,(-in->Xi[0][0][0]-in->phi[0][0][0]-Eg)-Ef,in->Th[0][0][0],in->imat[0][0][0]); gdouble Ln=get_n_den(in,Ef-(-in->Xi[0][0][0]-in->phi[0][0][0]),in->Te[0][0][0],in->imat[0][0][0]); gdouble Rp=get_p_den(in,(-in->Xi[0][0][in->ymeshpoints-1]-delta_phi-Eg)-Ef,in->Th[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]); gdouble Rn=get_n_den(in,Ef-(-in->Xi[0][0][in->ymeshpoints-1]-delta_phi),in->Te[0][0][in->ymeshpoints-1],in->imat[0][0][in->ymeshpoints-1]); in->l_electrons=Ln; in->l_holes=Lp; in->r_electrons=Rn; in->r_holes=Rp; if (get_dump_status(sim,dump_built_in_voltage)==TRUE) { printf_log(sim,"Ef=%Le\n",Ef); printf_log(sim,"Holes on left contact = %Le\n", Lp); printf_log(sim,"Electrons on left contact = %Le\n", Ln); printf_log(sim,"Holes on right contact = %Le\n", Rp); printf_log(sim,"Electrons on right contact = %Le\n", Rn); FILE *contacts=fopena(get_output_path(sim),"initial.dat","w"); fprintf (contacts,"#left_holes\n"); fprintf (contacts,"%Le\n", Lp); fprintf (contacts,"#left_electrons\n"); fprintf (contacts,"%Le\n", Ln); fprintf (contacts,"#right_holes\n"); fprintf (contacts,"%Le\n", Rp); fprintf (contacts,"#right_electrons\n"); fprintf (contacts,"%Le\n", Rn); fprintf (contacts,"#Vbi\n"); fprintf (contacts,"%Le\n", in->vbi); fprintf (contacts,"#end\n"); fclose(contacts); } int band; for (z=0;z<in->zmeshpoints;z++) { for (x=0;x<in->xmeshpoints;x++) { for (y=0;y<in->ymeshpoints;y++) { phi_ramp=delta_phi*(in->ymesh[y]/in->ymesh[in->ymeshpoints-1]); in->Fi[z][x][y]=Ef; in->Fn[z][x][y]=Ef; in->Fp[z][x][y]=Ef; in->phi[z][x][y]=phi_ramp; in->x[z][x][y]=in->phi[z][x][y]+in->Fn[z][x][y]; in->xp[z][x][y]= -(in->phi[z][x][y]+in->Fp[z][x][y]); in->Ec[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]; if (in->Ec[z][x][y]<in->Fi[z][x][y]) { in->phi[z][x][y]= -(in->Fi[z][x][y]+in->Xi[z][x][y]); in->Ec[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]; } in->Ev[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]-in->Eg[z][x][y]; if (in->Ev[z][x][y]>in->Fi[z][x][y]) { in->phi[z][x][y]= -(in->Fi[z][x][y]+in->Xi[z][x][y]+in->Eg[z][x][y]); in->Ev[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]-in->Eg[z][x][y]; in->Ec[z][x][y]= -in->phi[z][x][y]-in->Xi[z][x][y]; } gdouble t=in->Fi[z][x][y]-in->Ec[z][x][y]; gdouble tp=in->Ev[z][x][y]-in->Fi[z][x][y]; in->n[z][x][y]=in->Nc[z][x][y]*exp(((t)*Q)/(kb*in->Te[z][x][y])); in->p[z][x][y]=in->Nv[z][x][y]*exp(((tp)*Q)/(kb*in->Th[z][x][y])); //printf("%Le %Le\n",t,tp); //getchar(); in->mun[z][x][y]=get_n_mu(in,in->imat[z][x][y]); in->mup[z][x][y]=get_p_mu(in,in->imat[z][x][y]); for (band=0;band<in->srh_bands;band++) { in->Fnt[z][x][y][band]= -in->phi[z][x][y]-in->Xi[z][x][y]+dos_srh_get_fermi_n(in,in->n[z][x][y], in->p[z][x][y],band,in->imat[z][x][y],in->Te[z][x][y]); in->Fpt[z][x][y][band]= -in->phi[z][x][y]-in->Xi[z][x][y]-in->Eg[z][x][y]-dos_srh_get_fermi_p(in,in->n[z][x][y], in->p[z][x][y],band,in->imat[z][x][y],in->Th[z][x][y]); in->xt[z][x][y][band]=in->phi[z][x][y]+in->Fnt[z][x][y][band]; in->nt[z][x][y][band]=get_n_pop_srh(sim,in,in->xt[z][x][y][band]+in->tt[z][x][y],in->Te[z][x][y],band,in->imat[z][x][y]); in->dnt[z][x][y][band]=get_dn_pop_srh(sim,in,in->xt[z][x][y][band]+in->tt[z][x][y],in->Te[z][x][y],band,in->imat[z][x][y]); in->xpt[z][x][y][band]= -(in->phi[z][x][y]+in->Fpt[z][x][y][band]); in->pt[z][x][y][band]=get_p_pop_srh(sim,in,in->xpt[z][x][y][band]-in->tpt[z][x][y],in->Th[z][x][y],band,in->imat[z][x][y]); in->dpt[z][x][y][band]=get_dp_pop_srh(sim,in,in->xpt[z][x][y][band]-in->tpt[z][x][y],in->Th[z][x][y],band,in->imat[z][x][y]); } } } } in->Vl=0.0; in->Vr=delta_phi; in->Vbi=delta_phi; init_dump(sim,in); //getchar(); if (in->stoppoint==1) exit(0); return; }
static int examine_log(my_string file_name, char **table_names) { uint command,result,files_open; ulong access_time,length; my_off_t filepos; int lock_command,mi_result; char isam_file_name[FN_REFLEN],llbuff[21],llbuff2[21]; uchar head[20]; gptr buff; struct test_if_open_param open_param; IO_CACHE cache; File file; FILE *write_file; enum ha_extra_function extra_command; TREE tree; struct file_info file_info,*curr_file_info; DBUG_ENTER("examine_log"); if ((file=my_open(file_name,O_RDONLY,MYF(MY_WME))) < 0) DBUG_RETURN(1); write_file=0; if (write_filename) { if (!(write_file=my_fopen(write_filename,O_WRONLY,MYF(MY_WME)))) { my_close(file,MYF(0)); DBUG_RETURN(1); } } init_io_cache(&cache,file,0,READ_CACHE,start_offset,0,MYF(0)); bzero((gptr) com_count,sizeof(com_count)); init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1, (tree_element_free) file_info_free, NULL); VOID(init_key_cache(KEY_CACHE_SIZE)); files_open=0; access_time=0; while (access_time++ != number_of_commands && !my_b_read(&cache,(byte*) head,9)) { isamlog_filepos=my_b_tell(&cache)-9L; file_info.filenr= mi_uint2korr(head+1); isamlog_process=file_info.process=(long) mi_uint4korr(head+3); if (!opt_processes) file_info.process=0; result= mi_uint2korr(head+7); if ((curr_file_info=(struct file_info*) tree_search(&tree,&file_info))) { curr_file_info->accessed=access_time; if (update && curr_file_info->used && curr_file_info->closed) { if (reopen_closed_file(&tree,curr_file_info)) { command=sizeof(com_count)/sizeof(com_count[0][0])/3; result=0; goto com_err; } } } command=(uint) head[0]; if (command < sizeof(com_count)/sizeof(com_count[0][0])/3 && (!table_names[0] || (curr_file_info && curr_file_info->used))) { com_count[command][0]++; if (result) com_count[command][1]++; } switch ((enum myisam_log_commands) command) { case MI_LOG_OPEN: if (!table_names[0]) { com_count[command][0]--; /* Must be counted explicite */ if (result) com_count[command][1]--; } if (curr_file_info) printf("\nWarning: %s is opened with same process and filenumber\nMaybe you should use the -P option ?\n", curr_file_info->show_name); if (my_b_read(&cache,(byte*) head,2)) goto err; file_info.name=0; file_info.show_name=0; file_info.record=0; if (read_string(&cache,(gptr*) &file_info.name, (uint) mi_uint2korr(head))) goto err; { uint i; char *pos,*to; /* Fix if old DOS files to new format */ for (pos=file_info.name; (pos=strchr(pos,'\\')) ; pos++) *pos= '/'; pos=file_info.name; for (i=0 ; i < prefix_remove ; i++) { char *next; if (!(next=strchr(pos,'/'))) break; pos=next+1; } to=isam_file_name; if (filepath) to=convert_dirname(isam_file_name,filepath,NullS); strmov(to,pos); fn_ext(isam_file_name)[0]=0; /* Remove extension */ } open_param.name=file_info.name; open_param.max_id=0; VOID(tree_walk(&tree,(tree_walk_action) test_if_open,(void*) &open_param, left_root_right)); file_info.id=open_param.max_id+1; /* * In the line below +10 is added to accomodate '<' and '>' chars * plus '\0' at the end, so that there is place for 7 digits. * It is improbable that same table can have that many entries in * the table cache. * The additional space is needed for the sprintf commands two lines * below. */ file_info.show_name=my_memdup(isam_file_name, (uint) strlen(isam_file_name)+10, MYF(MY_WME)); if (file_info.id > 1) sprintf(strend(file_info.show_name),"<%d>",file_info.id); file_info.closed=1; file_info.accessed=access_time; file_info.used=1; if (table_names[0]) { char **name; file_info.used=0; for (name=table_names ; *name ; name++) { if (!strcmp(*name,isam_file_name)) file_info.used=1; /* Update/log only this */ } } if (update && file_info.used) { if (files_open >= max_files) { if (close_some_file(&tree)) goto com_err; files_open--; } if (!(file_info.isam= mi_open(isam_file_name,O_RDWR, HA_OPEN_WAIT_IF_LOCKED))) goto com_err; if (!(file_info.record=my_malloc(file_info.isam->s->base.reclength, MYF(MY_WME)))) goto end; files_open++; file_info.closed=0; if (opt_myisam_with_debug) file_info.isam->s->rnd= 0; else file_info.isam->s->rnd= isamlog_process; } VOID(tree_insert(&tree,(gptr) &file_info,0)); if (file_info.used) { if (verbose && !record_pos_file) printf_log("%s: open -> %d",file_info.show_name, file_info.filenr); com_count[command][0]++; if (result) com_count[command][1]++; } break; case MI_LOG_CLOSE: if (verbose && !record_pos_file && (!table_names[0] || (curr_file_info && curr_file_info->used))) printf_log("%s: %s -> %d",FILENAME(curr_file_info), command_name[command],result); if (curr_file_info) { if (!curr_file_info->closed) files_open--; VOID(tree_delete(&tree,(gptr) curr_file_info)); } break; case MI_LOG_EXTRA: if (my_b_read(&cache,(byte*) head,1)) goto err; extra_command=(enum ha_extra_function) head[0]; if (verbose && !record_pos_file && (!table_names[0] || (curr_file_info && curr_file_info->used))) printf_log("%s: %s(%d) -> %d",FILENAME(curr_file_info), command_name[command], (int) extra_command,result); if (update && curr_file_info && !curr_file_info->closed) { if (mi_extra(curr_file_info->isam, extra_command, 0) != (int) result) { fflush(stdout); VOID(fprintf(stderr, "Warning: error %d, expected %d on command %s at %s\n", my_errno,result,command_name[command], llstr(isamlog_filepos,llbuff))); fflush(stderr); } } break; case MI_LOG_DELETE: if (my_b_read(&cache,(byte*) head,8)) goto err; filepos=mi_sizekorr(head); if (verbose && (!record_pos_file || ((record_pos == filepos || record_pos == NO_FILEPOS) && !cmp_filename(curr_file_info,record_pos_file))) && (!table_names[0] || (curr_file_info && curr_file_info->used))) printf_log("%s: %s at %ld -> %d",FILENAME(curr_file_info), command_name[command],(long) filepos,result); if (update && curr_file_info && !curr_file_info->closed) { if (mi_rrnd(curr_file_info->isam,curr_file_info->record,filepos)) { if (!recover) goto com_err; if (verbose) printf_log("error: Didn't find row to delete with mi_rrnd"); com_count[command][2]++; /* Mark error */ } mi_result=mi_delete(curr_file_info->isam,curr_file_info->record); if ((mi_result == 0 && result) || (mi_result && (uint) my_errno != result)) { if (!recover) goto com_err; if (mi_result) com_count[command][2]++; /* Mark error */ if (verbose) printf_log("error: Got result %d from mi_delete instead of %d", mi_result, result); } } break; case MI_LOG_WRITE: case MI_LOG_UPDATE: if (my_b_read(&cache,(byte*) head,12)) goto err; filepos=mi_sizekorr(head); length=mi_uint4korr(head+8); buff=0; if (read_string(&cache,&buff,(uint) length)) goto err; if ((!record_pos_file || ((record_pos == filepos || record_pos == NO_FILEPOS) && !cmp_filename(curr_file_info,record_pos_file))) && (!table_names[0] || (curr_file_info && curr_file_info->used))) { if (write_file && (my_fwrite(write_file,buff,length,MYF(MY_WAIT_IF_FULL | MY_NABP)))) goto end; if (verbose) printf_log("%s: %s at %ld, length=%ld -> %d", FILENAME(curr_file_info), command_name[command], filepos,length,result); } if (update && curr_file_info && !curr_file_info->closed) { if (curr_file_info->isam->s->base.blobs) fix_blob_pointers(curr_file_info->isam,buff); if ((enum myisam_log_commands) command == MI_LOG_UPDATE) { if (mi_rrnd(curr_file_info->isam,curr_file_info->record,filepos)) { if (!recover) { result=0; goto com_err; } if (verbose) printf_log("error: Didn't find row to update with mi_rrnd"); if (recover == 1 || result || find_record_with_key(curr_file_info,buff)) { com_count[command][2]++; /* Mark error */ break; } } mi_result=mi_update(curr_file_info->isam,curr_file_info->record, buff); if ((mi_result == 0 && result) || (mi_result && (uint) my_errno != result)) { if (!recover) goto com_err; if (verbose) printf_log("error: Got result %d from mi_update instead of %d", mi_result, result); if (mi_result) com_count[command][2]++; /* Mark error */ } } else { mi_result=mi_write(curr_file_info->isam,buff); if ((mi_result == 0 && result) || (mi_result && (uint) my_errno != result)) { if (!recover) goto com_err; if (verbose) printf_log("error: Got result %d from mi_write instead of %d", mi_result, result); if (mi_result) com_count[command][2]++; /* Mark error */ } if (!recover && filepos != curr_file_info->isam->lastpos) { printf("error: Wrote at position: %s, should have been %s", llstr(curr_file_info->isam->lastpos,llbuff), llstr(filepos,llbuff2)); goto end; } } } my_free(buff,MYF(0)); break; case MI_LOG_LOCK: if (my_b_read(&cache,(byte*) head,sizeof(lock_command))) goto err; memcpy_fixed(&lock_command,head,sizeof(lock_command)); if (verbose && !record_pos_file && (!table_names[0] || (curr_file_info && curr_file_info->used))) printf_log("%s: %s(%d) -> %d\n",FILENAME(curr_file_info), command_name[command],lock_command,result); if (update && curr_file_info && !curr_file_info->closed) { if (mi_lock_database(curr_file_info->isam,lock_command) != (int) result) goto com_err; } break; case MI_LOG_DELETE_ALL: if (verbose && !record_pos_file && (!table_names[0] || (curr_file_info && curr_file_info->used))) printf_log("%s: %s -> %d\n",FILENAME(curr_file_info), command_name[command],result); break; default: fflush(stdout); VOID(fprintf(stderr, "Error: found unknown command %d in logfile, aborted\n", command)); fflush(stderr); goto end; } } end_key_cache(); delete_tree(&tree); VOID(end_io_cache(&cache)); VOID(my_close(file,MYF(0))); if (write_file && my_fclose(write_file,MYF(MY_WME))) DBUG_RETURN(1); DBUG_RETURN(0); err: fflush(stdout); VOID(fprintf(stderr,"Got error %d when reading from logfile\n",my_errno)); fflush(stderr); goto end; com_err: fflush(stdout); VOID(fprintf(stderr,"Got error %d, expected %d on command %s at %s\n", my_errno,result,command_name[command], llstr(isamlog_filepos,llbuff))); fflush(stderr); end: end_key_cache(); delete_tree(&tree); VOID(end_io_cache(&cache)); VOID(my_close(file,MYF(0))); if (write_file) VOID(my_fclose(write_file,MYF(MY_WME))); DBUG_RETURN(1); }
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPTSTR cmdline, int cmdshow) { MSG msg; BOOL ret; HWND sheet, active; HACCEL accelerators; #ifdef MSVC_MEMLEAK_CHECK _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); //check for memory leaks #endif // These two methods are not the same GetModuleFileName(NULL, global::exedir, MAX_PATH); // works PathRemoveFileSpec(global::exedir); //GetCurrentDirectory(_MAX_PATH, global::exedir); // doesn't work //basic initializations aokts = inst; propdata.p = scen.players; //start pointing to first member ret = setts.load(); if (*setts.logname) { char logpath[_MAX_PATH]; //GetCurrentDirectory(_MAX_PATH, logpath); strcpy(logpath, global::exedir); strcat(logpath, "\\"); strcat(logpath, setts.logname); freopen(logpath, "w", stdout); printf_log("Opened log file %s.\n", logpath); } printf_log("TS Path: %s\n", global::exedir); // Hint about whether to open as AOC or SGWB if (setts.recent_first) { scen.game = (Game)setts.recent_first->game; printf_log("Last game was %s.\n", gameName(scen.game)); } //process any compress/decompress requests if ((*cmdline == '/' || *cmdline == '-') && ProcessCmdline(cmdline)) return 0; //read genie data try { switch (scen.game) { case AOK: case AOC: case AOHD: case AOF: esdata.load(datapath_aok); break; case SWGB: case SWGBCC: esdata.load(datapath_swgb); break; default: esdata.load(datapath_aok); } } catch (std::exception& ex) { printf_log("Could not load data: %s\n", ex.what()); MessageBox(NULL, "Could not read Genie Data from data.xml. Terminating...", "Error", MB_ICONERROR); return 0; } //create the property sheet & init misc data InitCommonControls(); sheet = MakeSheet(inst); propdata.tformat = RegisterClipboardFormat("AOKTS Trigger"); propdata.ecformat = RegisterClipboardFormat("AOKTS EC"); propdata.mcformat = RegisterClipboardFormat("AOKTS Mapcopy"); accelerators = LoadAccelerators(inst, (LPCTSTR)IDA_MAIN); //checked for err later //give the sheet its own DialogProc pproc = (DLGPROC)SetWindowLong(sheet, DWL_DLGPROC, (LONG)&MainDlgProc); //check for errors down here, after we create the sheet if (!accelerators) { MessageBox(sheet, "Keyboard Accelerators failed to load. Keyboard shortcuts will not be available.", "Warning", MB_ICONWARNING); } if (!propdata.tformat | !propdata.ecformat) { MessageBox(sheet, "Could not register clipboard format. Clipboard operations will not function.", "Warning", MB_ICONWARNING); } //if (!ret) // MessageBox(sheet, warnNoAOEII, "Warning", MB_ICONWARNING); //open mapview window propdata.mapview = MakeMapView(sheet, cmdshow || SW_MAXIMIZE); //check for, then open the scenario specified in command string if (*cmdline != '\0') { if (*cmdline == '"') { cmdline++; //increment past first doublequote *strrchr(cmdline, '"') = '\0'; //find last " and replace it } strcpy(setts.ScenPath, cmdline); printf_log("cmdline scenpath: %s\n", setts.ScenPath); FileOpen(sheet, false, -1); } //the message loop while (ret = GetMessage(&msg, NULL, 0, 0)) { if (ret < 0) //did GetMessage() fail? { MessageBox(sheet, "Unable to retrieve messages from queue. Click OK to terminate.", "AOKTS Fatal Error", MB_ICONERROR); break; } // Give first dibs to keyboard accelerators and the propsheet. if (TranslateAccelerator(sheet, accelerators, &msg) || PropSheet_IsDialogMessage(sheet, &msg)) continue; // Usually active is the sheet. If it's not, it's a modeless dialog and // it should get a crack, too. if ((active = GetActiveWindow()) != sheet && IsDialogMessage(active, &msg)) continue; // If we get here, it's just a normal message, so Translate and // Dispatch. TranslateMessage(&msg); DispatchMessage(&msg); } //cleanup if (setts.DelTempOnExit) DeleteFile(setts.TempPath); fclose(stdout); return msg.wParam; }
int do_write_flash(np_data *np) { FILE *fp; u32 sp,flen,offset; int i,j,k,r,error_flag=0; if ((fp = fopen((const char *)np->fname,"r")) == NULL ) { printf("Can not open source or object file!\n"); return -1; } fseek(fp,0,SEEK_END); flen = ftell(fp); i = flen / OOBPAGE_SIZE; if (flen % OOBPAGE_SIZE !=0) { printf("Source file length is not fit!\n"); return -1; } sp = np->spage; if (sp % np->ppb !=0) { printf("Start page number not blockaligned!\n"); return -1; } //Erase object block first j = sp / np->ppb; k = flen/OOBPAGE_SIZE; if (k % np->ppb == 0) k = k / np->ppb; else k = k / np->ppb +1; np->nand_erase(k,j,0); j = i / MAX_BUF_PAGE; k = i % MAX_BUF_PAGE; offset = 0; // printf("j k %d %d %d %d\n",j,k,i,flen); for (i=0;i<j;i++) { fseek(fp,offset,SEEK_SET); fread(nand_buf,1,MAX_BUF_SIZE,fp); BLOCK_BROKEN: for (r=0;r<MAX_RETRY;r++) { for (;sp <=np->epage - np->ppb;sp += np->ppb) { //old bad block if (!np->nand_check_block(sp/np->ppb)) break; printf("Skip a old bad blocks!\n"); printf_log(log_fp,"Skip a old block at %x!\n",sp/np->ppb); } if (sp/np->ppb > np->epage /np->ppb) { printf("Program end but not finish,due to bad block!\n"); printf_log(log_fp,"Program end but not finish,due to bad block!\n"); return -1; } if (np->nand_program(nand_buf,sp,np->ppb)) { error_flag = 1; printf("Program error!\n"); printf_log(log_fp,"Program error! %x\n",sp/np->ppb); break; } memset(check_buf,0,MAX_BUF_SIZE); np->nand_read(check_buf,sp,np->ppb); if (np->nand_check(nand_buf,check_buf, MAX_BUF_SIZE) ) { //check error! error_flag = 1; printf("Error retry!\n"); printf_log(log_fp,"Error retry!\n"); continue; } else { error_flag = 0; break; } } if (error_flag) { //block has broken! printf("Found a new bad block: %x!\n",sp/np->ppb); printf_log(log_fp,"Found a new bad block at %x!\n",sp/np->ppb); np->nand_erase(1,sp/np->ppb,0); //erase before mark bad block! np->nand_block_markbad(sp /np->ppb); sp += np->ppb; goto BLOCK_BROKEN; } else { printf("Write block %d finish\n",sp/np->ppb); sp += np->ppb; offset += MAX_BUF_SIZE; } } if (k) { fseek(fp,offset,SEEK_SET); fread(nand_buf,1,k * OOBPAGE_SIZE ,fp); BLOCK_BROKEN1: for (r=0;r<MAX_RETRY;r++) { for (;sp <=np->epage - np->ppb;sp += np->ppb) { //old bad block if (!np->nand_check_block(sp/np->ppb)) break; printf("Skip a old bad blocks!\n"); printf_log(log_fp,"Skip a old block at %x!\n",sp/np->ppb); } if (sp/np->ppb > np->epage/np->ppb) { printf("Program end but not finish,due to bad block!\n"); printf_log(log_fp,"Program end but not finish,due to bad block!\n"); return 0; } if (np->nand_program(nand_buf,sp,k)) { error_flag = 1; printf("Program error!\n"); printf_log(log_fp,"Program error! %x\n",sp/np->ppb); break; } memset(check_buf,0,MAX_BUF_SIZE); np->nand_read(check_buf,sp,k); if (np->nand_check(nand_buf,check_buf, k * OOBPAGE_SIZE) ) { //check error! error_flag = 1; printf("Error retry!\n"); printf_log(log_fp,"Error retry!\n"); continue; } else { error_flag = 0; break; } } if (error_flag) { //block has broken! printf("Found a new bad block : %x!\n",sp/np->ppb); printf_log(log_fp,"Found a new bad block at %x!\n",sp/np->ppb); np->nand_erase(1,sp/np->ppb,0); //erase before mark bad block! np->nand_block_markbad(sp /np->ppb); sp += np->ppb; goto BLOCK_BROKEN1; } } printf("Nand flash write finish!\n"); return 0; }
int run_simulation(struct simulation *sim) { struct device cell; log_clear(sim); printf_log(sim,_("Run_simulation\n")); device_init(&cell); cell.onlypos=FALSE; dump_init(sim,&cell); set_dump_status(sim,dump_stop_plot, FALSE); set_dump_status(sim,dump_print_text, TRUE); char temp[1000]; cell.kl_in_newton=FALSE; //if (strcmp(outputpath,"")!=0) strcpy(get_output_path(sim),outputpath); //if (strcmp(inputpath,"")!=0) strcpy(get_input_path(sim),inputpath); dump_load_config(sim,&cell); int i; int z; int x; int y; join_path(2,temp,get_output_path(sim),"error.dat"); remove(temp); join_path(2,temp,get_output_path(sim),"equilibrium"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"snapshots"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"light_dump"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"dynamic"); remove_dir(sim,temp); join_path(2,temp,get_output_path(sim),"frequency"); remove_dir(sim,temp); load_config(sim,&cell); if (strcmp(sim->force_sim_mode,"")!=0) { strcpy(cell.simmode,sim->force_sim_mode); } if (strcmp(cell.simmode,"opticalmodel@optics")!=0) { solver_init(sim,cell.solver_name); newton_init(sim,cell.newton_name); printf_log(sim,_("Loading DoS for %d layers\n"),cell.my_epitaxy.electrical_layers); char tempn[100]; char tempp[100]; i=0; for (i=0;i<cell.my_epitaxy.electrical_layers;i++) { dos_init(&cell,i); printf_log(sim,"Load DoS %d/%d\n",i,cell.my_epitaxy.electrical_layers); sprintf(tempn,"%s_dosn.dat",cell.my_epitaxy.dos_file[i]); sprintf(tempp,"%s_dosp.dat",cell.my_epitaxy.dos_file[i]); load_dos(sim,&cell,tempn,tempp,i); } device_alloc_traps(&cell); if (get_dump_status(sim,dump_write_converge)==TRUE) { sim->converge = fopena(get_output_path(sim),"converge.dat","w"); fclose(sim->converge); sim->tconverge=fopena(get_output_path(sim),"tconverge.dat","w"); fclose(sim->tconverge); } mesh_cal_layer_widths(&cell); long double depth=0.0; long double percent=0.0; long double value=0.0; for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { for (y=0;y<cell.ymeshpoints;y++) { depth=cell.ymesh[y]-cell.layer_start[cell.imat[z][x][y]]; percent=depth/cell.layer_width[cell.imat[z][x][y]]; cell.Nad[z][x][y]=get_dos_doping_start(&cell,cell.imat[z][x][y])+(get_dos_doping_stop(&cell,cell.imat[z][x][y])-get_dos_doping_start(&cell,cell.imat[z][x][y]))*percent; } } } init_mat_arrays(&cell); for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { for (y=0;y<cell.ymeshpoints;y++) { cell.phi[z][x][y]=0.0; cell.R[z][x][y]=0.0; cell.n[z][x][y]=0.0; } } } contacts_load(sim,&cell); cell.C=cell.xlen*cell.zlen*epsilon0*cell.epsilonr[0][0][0]/(cell.ylen+cell.other_layers); if (get_dump_status(sim,dump_print_text)==TRUE) printf_log(sim,"C=%Le\n",cell.C); cell.A=cell.xlen*cell.zlen; cell.Vol=cell.xlen*cell.zlen*cell.ylen; ///////////////////////light model char old_model[100]; gdouble old_Psun=0.0; old_Psun=light_get_sun(&cell.mylight); light_init(&cell.mylight); light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]); light_load_config(sim,&cell.mylight); if (cell.led_on==TRUE) { strcpy(old_model,cell.mylight.mode); strcpy(cell.mylight.mode,"ray"); } light_load_dlls(sim,&cell.mylight); light_setup_ray(sim,&cell,&cell.mylight); if (cell.led_on==TRUE) { cell.mylight.force_update=TRUE; light_set_sun(&(cell.mylight),1.0); light_set_sun_delta_at_wavelength(&(cell.mylight),cell.led_wavelength); light_solve_all(sim,&(cell.mylight)); cell.mylight.force_update=FALSE; strcpy(cell.mylight.mode,old_model); light_set_sun(&(cell.mylight),old_Psun); light_free_dlls(sim,&cell.mylight); light_load_dlls(sim,&cell.mylight); } /////////////////////// //update_arrays(&cell); contact_set_all_voltages(sim,&cell,0.0); get_initial(sim,&cell); remesh_shrink(&cell); if (cell.math_enable_pos_solver==TRUE) { for (z=0;z<cell.zmeshpoints;z++) { for (x=0;x<cell.xmeshpoints;x++) { solve_pos(sim,&cell,z,x); } } } time_init(sim,&cell); cell.N=0; cell.M=0; solver_realloc(sim,&cell); plot_open(sim); cell.go_time=FALSE; plot_now(sim,"plot"); //set_solver_dump_every_matrix(1); find_n0(sim,&cell); //set_solver_dump_every_matrix(0); draw_gaus(&cell); if (cell.onlypos==TRUE) { join_path(2,temp,get_output_path(sim),"equilibrium"); dump_1d_slice(sim,&cell,temp); device_free(sim,&cell); device_free_traps(&cell); mesh_free(sim,&cell); return 0; } } //Load the dll if (is_domain(cell.simmode)!=0) { char gussed_full_mode[200]; if (guess_whole_sim_name(sim,gussed_full_mode,get_input_path(sim),cell.simmode)==0) { printf_log(sim,"I guess we are using running %s\n",gussed_full_mode); strcpy(cell.simmode,gussed_full_mode); }else { ewe(sim,"I could not guess which simulation to run from the mode %s\n",cell.simmode); } } run_electrical_dll(sim,&cell,strextract_domain(cell.simmode)); if (strcmp(cell.simmode,"opticalmodel@optics")!=0) { device_free(sim,&cell); device_free_traps(&cell); mesh_free(sim,&cell); plot_close(sim); for (i=0;i<cell.my_epitaxy.electrical_layers;i++) { dos_free(&cell,i); } solver_free_memory(sim,&cell); newton_interface_free(sim); light_free(sim,&cell.mylight); } return cell.odes; }
int handler_msg(int sock) //浏览器请求处理函数 { char buf[SIZE]; int count=get_line(sock,buf); int ret=0; char method[32]; char url[SIZE]; char *query_string=NULL; int i=0; int j=0; int cgi=0; //获取请求方法和请求路径 while(j<count) { if(isspace(buf[j])) { break; } method[i]=buf[j]; i++; j++; } method[i]='\0'; while(isspace(buf[j])&&j<SIZE) //过滤空格 { j++; } if(strcasecmp(method,"POST")&&strcasecmp(method,"GET")) { printf_log("method failed",FATAL); echo_error(sock,405); ret=5; goto end; } if(strcasecmp(method,"POST")==0) { cgi=1; } i=0; while(j<count) { if(isspace(buf[j])) { break; } if(buf[j]=='?') { query_string=&url[i]; query_string++; url[i]='\0'; } else url[i]=buf[j]; j++; i++; } url[i]='\0'; if(strcasecmp(method,"GET")==0&&query_string!=NULL) { cgi=1; } //找到请求的资源路径 char path[SIZE]; sprintf(path,"wwwroot%s",url); if(path[strlen(path)-1]=='/') //判断浏览器请求的是不是目录 { strcat(path,"index.html"); //如果请求的是目录,则就把该目录下的首页返回回去 } struct stat st; if(stat(path,&st)<0) //获取客户端请求的资源的相关属性 { printf_log("stat path faile\n",FATAL); echo_error(sock,404); ret=6; goto end; } else { if(S_ISDIR(st.st_mode)) { strcat(path,"/index.html"); } if(st.st_mode & (S_IXUSR | S_IXOTH | S_IXGRP)) { cgi=1; } } if(cgi) //请求的是可执行程序或者带参数用cgi程序处理 { ret=excu_cgi(sock,method,path,query_string); //处理CGI模式的请求 } else { clear_header(sock); ret=echo_www(sock,path,st.st_size); //如果是GET方法,而且没有参数,请求的也不是可执行程序,则直接返回资源 } end: close(sock); return ret; }
int hack_GUI_IDLEHandler(int unk0, int event, int unused, int unk1) { printf_log(8, 8, "[400Plus-IDLE] 0x%08X, %s, 0x%08X, 0x%08X", unk0, debug_gui_name(event), unused, unk1); return GUI_IDLEHandler(unk0, event, unused, unk1); }
EXPORT void light_dll_ver(struct simulation *sim) { printf_log(sim,"Flat light model\n"); }
void load_dos_file(struct dos *mydos, char *file) { #ifndef dos_bin double srh_r1 = 0.0; double srh_r2 = 0.0; double srh_r3 = 0.0; double srh_r4 = 0.0; double srh_c = 0.0; double w0; double n; #endif mydos->used = TRUE; mydos->used = TRUE; if (get_dump_status(dump_print_text) == TRUE) printf_log("%s %s\n", _("Loading file"), file); #ifdef dos_bin gzFile in; #else FILE *in; #endif /*FILE *rt; #ifdef dos_bin if (strcmp(file,"dosn.dat")==0) { rt = fopen("rtbinn.inp", "w"); }else { rt = fopen("rtbinp.inp", "w"); } #else if (strcmp(file,"dosn.dat")==0) { rt = fopen("rtnormn.inp", "w"); }else { rt = fopen("rtnormp.inp", "w"); } #endif */ #ifdef dos_bin int len; //in = fopen(file, "rb"); FILE *tl = fopen(file, "rb"); fseek(tl, -4, SEEK_END); if (fread((char *)&len, 4, 1, tl) == 0) { ewe("Error in reading file\n"); } //fscanf(tl,"%x",&a);//=ftell(in); fclose(tl); //printf("here '%ld'\n",len); //getchar(); in = gzopen(file, "rb"); if (in == Z_NULL) { ewe(_("DOS file not found\n")); } //fseek(in, 0, SEEK_END); //len=ftell(in); //fseek(in, 0, SEEK_SET); //long moved=gzseek(in, 0, SEEK_END); //len = (long)gztell(in); //z_off_t fileSize //printf("here %ld %s %ld %ld\n",len,file,moved,in); //getchar(); //gzseek(in, 0, SEEK_SET); int buf_len = len / sizeof(double); double *buf = (double *)malloc(sizeof(double) * buf_len); int buf_pos = 0; gzread(in, (char *)buf, len); gzclose(in); #else in = fopen(file, "r"); if (in == NULL) { ewe(_("DoS n file not found\n")); } #endif int t = 0; int x = 0; int srh_band = 0; #ifdef dos_bin mydos->xlen = (int)buf[buf_pos++]; mydos->tlen = (int)buf[buf_pos++]; mydos->srh_bands = (int)buf[buf_pos++]; mydos->config.epsilonr = buf[buf_pos++]; mydos->config.doping = buf[buf_pos++]; mydos->config.mu = buf[buf_pos++]; mydos->config.srh_vth = buf[buf_pos++]; mydos->config.srh_sigman = buf[buf_pos++]; mydos->config.srh_sigmap = buf[buf_pos++]; mydos->config.Nc = buf[buf_pos++]; mydos->config.Nv = buf[buf_pos++]; mydos->config.Eg = buf[buf_pos++]; mydos->config.Xi = buf[buf_pos++]; mydos->config.pl_fe_fh = buf[buf_pos++]; mydos->config.pl_trap = buf[buf_pos++]; mydos->config.pl_recom = buf[buf_pos++]; mydos->config.pl_enabled = (int)buf[buf_pos++]; mydos->config.B = buf[buf_pos++]; #else fscanf(in, "%d %d %d %le %le %le %le %le %le %le %le %le %le %le %le %le %d %le\n", &(mydos->xlen), &(mydos->tlen), &(mydos->srh_bands), &(mydos->config.epsilonr), &(mydos->config.doping), &(mydos->config.mu), &(mydos->config.srh_vth), &(mydos->config.srh_sigman), &(mydos->config.srh_sigmap), &(mydos->config.Nc), &(mydos->config.Nv), &(mydos->config.Eg), &(mydos->config.Xi), &(mydos->config.pl_fe_fh), &(mydos->config.pl_trap), &(mydos->config.pl_recom), &(mydos->config.pl_enabled), &(mydos->config.B)); #endif //fprintf(rt,"%d %d %d %lf %le %le %le %le %le %le\n",(mydos->xlen),(mydos->tlen),(mydos->srh_bands),(mydos->config.sigma),(mydos->config.mu),(mydos->config.srh_vth),(mydos->config.srh_sigman),(mydos->config.srh_sigmap),(mydos->config.Nc),(mydos->config.Nv)); double xsteps = mydos->xlen; double tsteps = mydos->tlen; mydos->x = (double *)malloc(sizeof(double) * (int)xsteps); mydos->t = (double *)malloc(sizeof(double) * (int)tsteps); mydos->srh_E = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_den = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r1 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_r2 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_r3 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_r4 = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->srh_c = (double ***)malloc(sizeof(double **) * (int)mydos->tlen); mydos->w = (double **)malloc(sizeof(double **) * (int)mydos->tlen); mydos->c = (double **)malloc(sizeof(double *) * (int)mydos->tlen); for (t = 0; t < tsteps; t++) { mydos->c[t] = (double *)malloc(sizeof(double) * (int)xsteps); mydos->w[t] = (double *)malloc(sizeof(double) * (int)xsteps); mydos->srh_r1[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_r2[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_r3[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_r4[t] = (double **)malloc(sizeof(double *) * (int)xsteps); mydos->srh_c[t] = (double **)malloc(sizeof(double *) * (int)xsteps); for (x = 0; x < xsteps; x++) { mydos->srh_r1[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r2[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r3[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_r4[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); mydos->srh_c[t][x] = (double *)malloc(sizeof(double) * (int)(mydos->srh_bands)); } } for (x = 0; x < xsteps; x++) { #ifdef dos_bin mydos->x[x] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->x[x])); #endif //fprintf(rt,"%le\n",(mydos->x[x])); } for (t = 0; t < tsteps; t++) { #ifdef dos_bin mydos->t[t] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->t[t])); #endif //fprintf(rt,"%le\n",(mydos->t[t])); } for (srh_band = 0; srh_band < (mydos->srh_bands); srh_band++) { #ifdef dos_bin mydos->srh_E[srh_band] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->srh_E[srh_band])); #endif //fprintf(rt,"%le\n",(mydos->srh_E[srh_band])); } for (srh_band = 0; srh_band < (mydos->srh_bands); srh_band++) { #ifdef dos_bin mydos->srh_den[srh_band] = buf[buf_pos++]; #else fscanf(in, "%le", &(mydos->srh_den[srh_band])); #endif //fprintf(rt,"%le\n",(mydos->srh_den[srh_band])); } for (t = 0; t < tsteps; t++) { for (x = 0; x < xsteps; x++) { #ifdef dos_bin mydos->c[t][x] = buf[buf_pos++]; mydos->w[t][x] = buf[buf_pos++]; #else fscanf(in, "%le %le ", &n, &w0); mydos->c[t][x] = n; mydos->w[t][x] = w0; #endif //fprintf(rt,"%.20le %.20le ",mydos->c[t][x],mydos->w[t][x]); for (srh_band = 0; srh_band < mydos->srh_bands; srh_band++) { #ifdef dos_bin mydos->srh_r1[t][x][srh_band] = buf[buf_pos++]; mydos->srh_r2[t][x][srh_band] = buf[buf_pos++]; mydos->srh_r3[t][x][srh_band] = buf[buf_pos++]; mydos->srh_r4[t][x][srh_band] = buf[buf_pos++]; mydos->srh_c[t][x][srh_band] = buf[buf_pos++]; //printf("%le\n",mydos->srh_c[t][x][srh_band]); #else fscanf(in, "%le %le %le %le %le ", &srh_r1, &srh_r2, &srh_r3, &srh_r4, &srh_c); mydos->srh_r1[t][x][srh_band] = srh_r1; mydos->srh_r2[t][x][srh_band] = srh_r2; mydos->srh_r3[t][x][srh_band] = srh_r3; mydos->srh_r4[t][x][srh_band] = srh_r4; mydos->srh_c[t][x][srh_band] = srh_c; #endif //fprintf(rt,"%.20le %.20le %.20le %.20le %.20le",mydos->srh_r1[t][x][srh_band],mydos->srh_r2[t][x][srh_band],mydos->srh_r3[t][x][srh_band],mydos->srh_r4[t][x][srh_band],mydos->srh_c[t][x][srh_band]); } //fprintf(rt,"\n"); } } #ifdef dos_bin free(buf); #else fclose(in); #endif //fclose(rt); }
/* FileOpen: Handles a request to open a file. (Either by menu or generated by the app.) Parameters: HWND sheet: Handle to the property sheet. bool ask: Should AOKTS ask the user which file? int recent: Optionally open from one of the recent file entries. (-1 to disable.) */ void FileOpen(HWND sheet, bool ask, int recent) { OPENFILENAME ofn; struct RecentFile *file = NULL; //the file info will be stored here one way or another char titleBuffer[100]; const char *filename; Game version = scen.game; HWND page = PropSheet_GetCurrentPageHwnd(sheet); //save the scenario if changes have been made (NOT FUNCTIONAL) if (scen.needsave()) { int sel = MessageBox(sheet, askSaveChanges, "Save", MB_YESNOCANCEL); if (sel == IDYES) FileSave(sheet, false, true); else if (sel == IDCANCEL) return; //stop closing } // Hint about whether to open as AOC or SGWB if (setts.recent_first) { scen.game = (Game)setts.recent_first->game; } /* Using a recent file... */ if (recent >= 0) { ofn.Flags = 0; //make sure no random flags set file = setts.recent_first; /* Parse the linked list to find the one we want */ while (recent--) { if (file) file = file->next; else { MessageBox(sheet, "Warning: Recent File open failed.", "Open Warning", MB_ICONWARNING); } } strcpy(setts.ScenPath, file->path); version = (Game)file->game; } /* Prompt the user for a filename. */ else if (ask) { struct RecentFile *r_parse; char dir[_MAX_PATH]; strcpy(dir, setts.BasePath); strcat(dir, "Scenario"); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = sheet; //ofn.hInstance unused ofn.lpstrFilter = extOpen; ofn.lpstrCustomFilter = NULL; //user should not set custom filters ofn.lpstrFile = setts.ScenPath; ofn.nMaxFile = _MAX_PATH; ofn.lpstrFileTitle = NULL; ofn.lpstrInitialDir = dir; ofn.lpstrTitle = NULL; ofn.Flags = OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_NOCHANGEDIR; if (scen.header.header_type == HT_AOE2SCENARIO) { ofn.nFilterIndex = 1; ofn.lpstrDefExt = "aoe2scenario"; } else { switch (scen.game) { case AOK: case AOC: case AOHD: case AOF: case AOHD4: case AOF4: case AOHD6: case AOF6: ofn.nFilterIndex = 1; ofn.lpstrDefExt = "scx"; break; case SWGB: case SWGBCC: ofn.nFilterIndex = 2; ofn.lpstrDefExt = "scx"; break; } } if (!GetOpenFileName(&ofn)) return; switch (ofn.nFilterIndex) { case 1: version = AOC; printf_log("Selected %d, AOE 2.\n", ofn.nFilterIndex); break; case 2: version = SWGB; printf_log("Selected %d, Star Wars.\n", ofn.nFilterIndex); break; } /* Now check if selected file is already on recent list. */ r_parse = setts.recent_first; while (r_parse) { if (!strcmp(r_parse->path, setts.ScenPath)) { file = r_parse; break; } r_parse = r_parse->next; } } /* Open it! */ SendMessage(page, AOKTS_Closing, 0, 0); // set hourglass, might take more than 1ms HCURSOR previous = SetCursor(LoadCursor(NULL, IDC_WAIT)); scen.reset(); try { version = scen.open(setts.ScenPath, setts.TempPath, version); /* Handle recent file stuff */ if (!file) { file = setts.recent_getnext(); strcpy(file->path, setts.ScenPath); strcpy(file->display, PathFindFileName(setts.ScenPath)); file->game = (int)version; } setts.recent_push(file); UpdateRecentMenu(propdata.menu); SetCursor(previous); // for some reason this is always read only. on Wine at least //SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_GRAYED : MF_ENABLED); SetSaveState(sheet, ofn.Flags & OFN_READONLY ? MF_ENABLED : MF_ENABLED); // set status bar text SetWindowTextW(propdata.statusbar, L"Scenario loaded successfully."); SendMessage(page, AOKTS_Loading, 0, 0); SendMessageW(propdata.mapview, MAP_Recreate, 0, 0); MapView_Reset(propdata.mapview, true); filename = getFilenameFromPath(setts.ScenPath); _snprintf(titleBuffer, sizeof(titleBuffer), "%s - %s", szTitle, filename); SetWindowText(sheet, titleBuffer); } catch (std::exception &ex) { // TODO: better atomic cursor handling? SetCursor(previous); // set status bar text SetWindowText(propdata.statusbar, ex.what()); // report error to user std::string desc = "Failed to open as "; desc.append(gameName(scen.game)); desc.append(" scenario file.\n"); switch (scen.game) { case AOC: desc.append("Try opening as a SWGB scx file instead\nusing File->Open\n"); break; case SWGB: desc.append("Try opening as a Conquerors scx file instead\nusing File->Open\n"); break; } desc.append("\nThe problem: "); desc.append(ex.what()); desc.append("\n\nIf the game is able to open the scenario,\nplease report this error. Thanks."); printf_log("User message: %s\n", desc.c_str()); MessageBox(sheet, desc.c_str(), "Scenario Load Error", MB_ICONWARNING); // unless it's a debug build, clear the bad data #ifndef _DEBUG scen.reset(); SendMessage(page, AOKTS_Closing, 0, 0); #endif /* Updates*/ SendMessage(page, AOKTS_Loading, 0, 0); _snprintf(titleBuffer, sizeof(titleBuffer), "%s", szTitle); SetWindowText(sheet, titleBuffer); } //report errors to logfile fflush(stdout); }
int solve_pos(struct device *in) { if (get_dump_status(dump_iodump) == TRUE) printf_log("Solve pos\n"); int i; int N = in->ymeshpoints * 3 - 2; int M = in->ymeshpoints; int *Ti = malloc(N * sizeof(int)); int *Tj = malloc(N * sizeof(int)); double *Tx = malloc(N * sizeof(double)); double *b = malloc(M * sizeof(double)); double phil; double phic; double phir; double yl; double yc; double yr; double dyl; double dyr; double dyc = 0.0; int ittr = 0; int pos = 0; double error = 1000; double el = 0.0; double ec = 0.0; double er = 0.0; double e0 = 0.0; double e1 = 0.0; int pos_max_ittr = 250; int quit = FALSE; int adv_step = 0; int adv = FALSE; int band; double kTq = (in->Te[0] * kb / Q); do { if (in->interfaceleft == TRUE) { in->phi[0] = in->Vl; } if (in->interfaceright == TRUE) { in->phi[in->ymeshpoints - 1] = in->Vr; } pos = 0; for (i = 0; i < in->ymeshpoints; i++) { if (i == 0) { phil = in->Vl; el = in->epsilonr[0] * epsilon0; yl = in->ymesh[0] - (in->ymesh[1] - in->ymesh[0]); } else { el = in->epsilonr[i - 1] * epsilon0; phil = in->phi[i - 1]; yl = in->ymesh[i - 1]; } if (i == (in->ymeshpoints - 1)) { phir = in->Vr; er = in->epsilonr[i] * epsilon0; yr = in->ymesh[i] + (in->ymesh[i] - in->ymesh[i - 1]); } else { er = in->epsilonr[i + 1] * epsilon0; phir = in->phi[i + 1]; yr = in->ymesh[i + 1]; } yc = in->ymesh[i]; dyl = yc - yl; dyr = yr - yc; dyc = (dyl + dyr) / 2.0; ec = in->epsilonr[i] * epsilon0; e0 = (el + ec) / 2.0; e1 = (ec + er) / 2.0; phic = in->phi[i]; double dphidn = 0.0; if (adv == FALSE) { dphidn = (Q / (kb * in->Tl[i])) * in->Nc[i] * exp(((in->Fi[i] - (-in->phi[i] - in->Xi[i]))) / (kTq)); } else { dphidn = get_dn_den(in->Fi[i] - in->Ec[i], in->Tl[i], in->imat[i]); } double dphidp = 0.0; if (adv == FALSE) { dphidp = -(Q / (kb * in->Tl[i])) * in->Nv[i] * exp((((-in->phi[i] - in->Xi[i] - in->Eg[i]) - in->Fi[i])) / (kTq)); } else { dphidp = -get_dp_den(in->xp[i] - in->tp[i], in->Tl[i], in->imat[i]); } double dphil = e0 / dyl / dyc; double dphic = -(e0 / dyl / dyc + e1 / dyr / dyc); double dphir = e1 / dyr / dyc; double dphil_d = dphil; double dphic_d = dphic; double dphir_d = dphir; if (in->interfaceleft == TRUE) { if (i == 1) { dphil_d = 0.0; phil = in->Vl; } if (i == 0) { dphil_d = 0.0; dphic_d = 1e-6; dphir_d = 0.0; } } if (in->interfaceright == TRUE) { if (i == in->ymeshpoints - 2) { dphir_d = 0.0; phir = in->Vr; } if (i == in->ymeshpoints - 1) { dphil_d = 0.0; dphic_d = 1e-6; dphir_d = 0.0; } } double dphi = dphil * phil + dphic * phic + dphir * phir; dphic_d += -Q * (dphidn - dphidp); // just put in the _d to get it working again. //if (adv==TRUE) //{ // for (band=0;band<in->srh_bands;band++) // { // dphic_d+=(-q*(in->dnt[i][band]-in->dpt[i][band])); // } //} if (i != 0) { Ti[pos] = i; Tj[pos] = i - 1; Tx[pos] = dphil_d; pos++; } Ti[pos] = i; Tj[pos] = i; Tx[pos] = dphic_d; pos++; if (i != (in->ymeshpoints - 1)) { Ti[pos] = i; Tj[pos] = i + 1; Tx[pos] = dphir_d; pos++; } if ((in->interfaceleft == TRUE) && (i == 0)) { b[i] = -0.0; } else if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) { b[i] = -0.0; } else { b[i] = -(dphi - Q * (in->n[i] - in->p[i] - in->Nad[i])); // if (adv == TRUE) { for (band = 0; band < in->srh_bands; band++) { b[i] += -(-Q * (in->nt[i][band] - in->pt[i][band])); } } } //in->n[i]=in->Nc[i]*exp(((in->Fi[i]-in->Ec[i])*q)/(kb*in->Tl[i])); } error = get_p_error(in, b); solver(M, N, Ti, Tj, Tx, b); for (i = 0; i < in->ymeshpoints; i++) { if ((in->interfaceleft == TRUE) && (i == 0)) { } else if ((in->interfaceright == TRUE) && (i == in->ymeshpoints - 1)) { } else { double update; //printf("%d\n",get_clamp_state()); double clamp_temp = 300.0; update = b[i] / (1.0 + fabs(b[i] / in->posclamp / (clamp_temp * kb / Q))); in->phi[i] += update; //printf("%le %le\n",i,b[i]); } } //getchar(); for (i = 0; i < in->ymeshpoints; i++) { in->Ec[i] = -in->phi[i] - in->Xi[i]; in->Ev[i] = -in->phi[i] - in->Xi[i] - in->Eg[i]; if (adv == FALSE) { in->n[i] = in->Nc[i] * exp(((in->Fi[i] - in->Ec[i]) * Q) / (kb * in->Tl[i])); in->dn[i] = (Q / (kb * in->Tl[i])) * in->Nc[i] * exp((Q * (in->Fi[i] - in->Ec[i])) / (kb * in->Tl[i])); } else { in->n[i] = get_n_den(in->Fi[i] - in->Ec[i], in->Tl[i], in->imat[i]); in->dn[i] = get_dn_den(in->Fi[i] - in->Ec[i], in->Tl[i], in->imat[i]); } in->Fn[i] = in->Fi[i]; in->Fp[i] = in->Fi[i]; in->x[i] = in->phi[i] + in->Fn[i]; in->xp[i] = -(in->phi[i] + in->Fp[i]); if (adv == FALSE) { in->p[i] = in->Nv[i] * exp(((in->xp[i] - in->tp[i]) * Q) / (kb * in->Tl[i])); in->dp[i] = (Q / (kb * in->Tl[i])) * in->Nv[i] * exp(((in->xp[i] - in->tp[i]) * Q) / (kb * in->Tl[i])); } else { in->p[i] = get_p_den(in->xp[i] - in->tp[i], in->Tl[i], in->imat[i]); in->dp[i] = get_dp_den(in->xp[i] - in->tp[i], in->Tl[i], in->imat[i]); } for (band = 0; band < in->srh_bands; band++) { //printf("%lf %lf\n",in->xpt[i][band],in->Fpt[i][band]); //getchar(); in->Fnt[i][band] = -in->phi[i] - in->Xi[i] + dos_srh_get_fermi_n(in->n[i], in->p[i], band, in->imat[i], in->Te[i]); in->Fpt[i][band] = -in->phi[i] - in->Xi[i] - in->Eg[i] - dos_srh_get_fermi_p(in->n[i], in->p[i], band, in->imat[i], in->Th[i]); in->xt[i][band] = in->phi[i] + in->Fnt[i][band]; in->nt[i][band] = get_n_pop_srh(in->xt[i][band] + in->tt[i], in->Te[i], band, in->imat[i]); in->dnt[i][band] = get_dn_pop_srh(in->xt[i][band] + in->tt[i], in->Te[i], band, in->imat[i]); in->xpt[i][band] = -(in->phi[i] + in->Fpt[i][band]); in->pt[i][band] = get_p_pop_srh(in->xpt[i][band] - in->tpt[i], in->Th[i], band, in->imat[i]); in->dpt[i][band] = get_dp_pop_srh(in->xpt[i][band] - in->tpt[i], in->Th[i], band, in->imat[i]); } } update_arrays(in); in->xnl_left = in->x[0]; in->xpl_left = in->xp[0]; if (error < 1) { adv = TRUE; } //#ifdef print_newtonerror if (get_dump_status(dump_print_pos_error) == TRUE) printf_log("%d Pos error = %e %d\n", ittr, error, adv); //#endif #ifdef dump_converge /*in->converge=fopena(in->outputpath,"converge.dat","a"); fprintf(in->converge,"%e\n",error); fclose(in->converge); */ #endif //double N=2.0*pow(((2.0*pi*kb*in->Tl[0]*in->me[0]*m0)/(hp*hp)),1.5); //double test=N*exp((-3.000000e-03*Q)/(kb*in->Tl[0])); //printf("Check now %e %e\n",get_n_den(-3.000000e-03,in->Tl[0],in->me[0],in->dostype[0],dos_all),test); //getchar(); //getchar(); ittr++; if (adv == TRUE) { adv_step++; } if (ittr > pos_max_ittr) { quit = TRUE; } if ((error < min_pos_error) && (adv_step > 3)) { quit = TRUE; } } while (quit == FALSE); //getchar(); pos_dump(in); update_arrays(in); if (in->srh_sim == TRUE) { time_init(in); } in->odes += in->ymeshpoints; for (i = 0; i < in->ymeshpoints; i++) { in->nf_save[i] = in->n[i]; in->pf_save[i] = in->p[i]; in->nt_save[i] = 0.0; //in->nt[i]; in->pt_save[i] = 0.0; //in->pt[i]; } free(Ti); free(Tj); free(Tx); free(b); printf_log("Solved pos\n"); printf_log("Vl=%le Vr=%le phi_mid=%le\n", in->Vl, in->Vr, in->phi[in->ymeshpoints / 2]); return 0; }
int do_read_flash(np_data *np) { FILE *fp; u32 sp; int i,j,k; if ((fp = fopen((const char *)np->fname, "w+")) == NULL ) { printf("Can not open source or object file!\n"); return -1; } i = np->epage - np->spage; j = i / MAX_BUF_PAGE; k = i % MAX_BUF_PAGE; sp = np->spage; for (i=0;i<j;i++) { if (np->nand_check_block(sp/np->ppb)) { printf_log(log_fp,"Skip a old block at %x!\n",sp/np->ppb); sp += MAX_BUF_PAGE; printf("Skip a old block!\n"); continue; } np->nand_read(nand_buf, sp, MAX_BUF_PAGE); #ifdef USE_VALID_CHECK if ( check_invalid_block(nand_buf,np) ) { #endif fwrite(nand_buf,1,MAX_BUF_SIZE,fp); printf("Read block %d finish\n",sp/np->ppb); #ifdef USE_VALID_CHECK } else printf("Skip a invalid block! %d \n",sp/np->ppb); #endif sp += MAX_BUF_PAGE; } if (k) { if (np->nand_check_block(sp/np->ppb)) { printf_log(log_fp,"Skip a old block at %x!\n",sp/np->ppb); printf("Skip a old block!\n"); } else { np->nand_read(nand_buf, sp, k); #ifdef USE_VALID_CHECK if ( check_invalid_block(nand_buf,np) ) { #endif fwrite(nand_buf, 1, k*OOBPAGE_SIZE, fp); #ifdef USE_VALID_CHECK } else printf("Skip a invalid block! %d \n",sp/np->ppb); #endif } } printf("Read nand flash finish!\n"); fclose(fp); return 0; }