void StarFile::parseStar() { countLine(); float x, y; starNum = 0; starList = (CMStar *) malloc(fileLine * sizeof (CMStar)); char line[MaxStringLength]; for (int j = 0; j < fileSize; j++) { int lineEnd = j; while (content[lineEnd++] != '\n'); memcpy(line, content + j, lineEnd - j); line[lineEnd - j] = '\0'; j = lineEnd - 1; //因为for循环中的j++ if (2 == sscanf(line, "%f%f", &x, &y)) { starList[starNum].id = starNum; starList[starNum].pixx = x; starList[starNum].pixy = y; starList[starNum].status = 0; starList[starNum].next = NULL; starList[starNum].line = (char*) malloc(strlen(line) + 1); strcpy(starList[starNum].line, line); starNum++; } else { printf("line illegal: %s\n", line); } } #ifdef PRINT_CM_DETAIL printf("%d %s lines, read %d stars\n", fileLine, fileName, starNum); #endif }
int loadData(PhoneBook **b, char *fileName) { FILE *f; int i; char buffer[500]; char tokens[2][200]; /* count the number of lines in the file */ int nline = countLine(fileName); /* allocate memory for the phonebook */ PhoneBook *book = (PhoneBook *) malloc(sizeof(PhoneBook)*nline); f = fopen(fileName, "r"); for(i = 0; i< nline; i++){ fgets(buffer, 500, f); getTokens(buffer, tokens, '-'); strcpy(book[i].name, tokens[0]); strcpy(book[i].phone, tokens[1]); } fclose(f); *b = book; return nline; }
int main() { ifstream fin; // ofstream fout; bool read_check = false; do { cout << "輸入指令:"; string command; cin >> command; Data *data; /*進入模式*/ if(command == "read"){ fin.open("source.txt",ios::in); checkFile(fin); read_check = true; int line = countLine(fin); fin.close(); // cout<<line<<endl; data = new Data(line); data->inputData(); data->printData(); } else if(command == "sort"){ /*TODO fix compare*/ if(!read_check){ cout << "還未讀取資料,請先讀取" <<endl; continue; } data->sortData(); data->printData(); } else if(command == "add"){ if(!read_check){ cout << "還未讀取資料,請先讀取" <<endl; continue; } string input_id, input_name; cout << "請輸入學號:"; cin >> input_id; cout << "請輸入姓名:"; cin >> input_name; } else if(command == "find"){ if(!read_check){ cout << "還未讀取資料,請先讀取" <<endl; continue; } } else if(command == "delete"){ delete data; read_check = false; } else if(command == "exit"){ break; } else{ cout << "沒有此指令" << endl; } } while(true);
main(){ double lineLength, textLength = 0; while((lineLength = countLine()) > 0){ textLength += lineLength; printf("%.0f\n", lineLength); } printf("Text length: %.0f\n", textLength); }
int countObjectsInLine(short K, short i, short j) { int totalCount = 0; int count; short x, y; for (int t = LINE_TB; t <= LINE_RTLB; ++t) { count = countLine((LineType)t, K, i, j); if (count > MAX_ALGORINUM) totalCount++; } return totalCount; }
int execPipe(char *dirname) { int fd[2]; int pid,stat; char line[MAXLINE]; int totline=0; int cline=0; pipe(fd); pid=fork(); if(pid==-1) { perror("Non e` possibile eseguire il comando."); exit(2); } if(pid==0) { close(1); dup(fd[1]); close(fd[0]); close(fd[1]); execlp("find","find",dirname,"-name","*.c",NULL); } else { close(0); dup(fd[0]); close(fd[0]); close(fd[1]); while(fgets(line,MAXLINE,stdin)!=NULL) { line[strlen(line)-1]='\0'; if((cline=countLine(line))==-1) return -1; else totline+=cline; } wait(&stat); return totline; } }
int main() { ifstream fin; // ofstream fout; do { cout << "輸入指令:"; string command; cin >> command; Data *data; /*進入模式*/ if(command == "read"){ fin.open("source.txt",ios::in); checkFile(fin); int line = countLine(fin); fin.close(); // cout<<line<<endl; data = new Data(line); data->inputData(); data->printData(); } else if(command == "sort"){ data->sortData(); data->printData(); } else if(command == "add"){ } else if(command == "find"){ } else if(command == "exit"){ break; } else{ cout << "沒有此指令" << endl; } } while(true); return 0; }
bool routing(const ap_int<8> trgt_line_id, const ap_uint<16> penalty_T, const ap_uint<16> penalty_C, const ap_uint<16> penalty_V, Board *board, ap_int<8> *output){ Line* trgt_line = board->line(trgt_line_id); trgt_line->track_index = 0; // ボードの初期化 IntraBox_4 my_board_1[MAX_BOXES][MAX_BOXES]; // ソース側のボード //#pragma HLS ARRAY_PARTITION variable=my_board_1 complete dim=1 IntraBox_4 my_board_2[MAX_BOXES][MAX_BOXES]; // シンク側のボード //#pragma HLS ARRAY_PARTITION variable=my_board_2 complete dim=2 IntraBox_4 init = { COST_MAX,COST_MAX,COST_MAX,COST_MAX, {false,false,false,false}, {false,false,false,false}, {false,false,false,false}, {false,false,false,false}}; for (ap_int<7> y = 0; y < board->getSizeY(); y++) { #pragma HLS LOOP_TRIPCOUNT min=10 max=40 avg=20 for (ap_int<7> x = 0; x < board->getSizeX(); x++) { #pragma HLS LOOP_TRIPCOUNT min=10 max=40 avg=20 ////#pragma HLS PIPELINE my_board_1[y][x] = init; my_board_2[y][x] = init; } } ap_int<7> start_x, start_y; IntraBox_4* start; Search qu[MAX_SEARCH]; //#pragma HLS ARRAY_PARTITION variable=qu cyclic factor=20 dim=0 ap_int<16> qu_head, qu_tail; ap_int<5> start_z = trgt_line->getSourceZ(); ap_int<5> end_z = trgt_line->getSinkZ(); /* ******************************** * Phase 1: ソース層の探索 ******************************** */ qu_head = 0; qu_tail = 0; // スタート地点の設定 start_x = trgt_line->getSourceX(); start_y = trgt_line->getSourceY(); start = &(my_board_1[start_y][start_x]); start->ne = 0; start->nw = 0; start->se = 0; start->sw = 0; // 北方向を探索 if(isInserted_1(start_x,start_y-1,start_z, board)){ Search trgt = {start_x,start_y-1,SOUTH}; qu[qu_tail] = trgt; qu_tail++; } // 東方向を探索 if(isInserted_1(start_x+1,start_y,start_z, board)){ Search trgt = {start_x+1,start_y,WEST}; qu[qu_tail] = trgt; qu_tail++; } // 南方向を探索 if(isInserted_1(start_x,start_y+1,start_z, board)){ Search trgt = {start_x,start_y+1,NORTH}; qu[qu_tail] = trgt; qu_tail++; } // 西方向を探索 if(isInserted_1(start_x-1,start_y,start_z, board)){ Search trgt = {start_x-1,start_y,EAST}; qu[qu_tail] = trgt; qu_tail++; } while (qu_head != qu_tail) { #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 //#pragma HLS PIPELINE // これONにするとメモリ使用率100%になる Search trgt = qu[qu_head]; qu_head++; Box* trgt_box = board->box(trgt.x,trgt.y,start_z); IntraBox_4* trgt_ibox = &(my_board_1[trgt.y][trgt.x]); bool update = false; // コストの更新があったか? // コスト計算 if(trgt.d == SOUTH){ // 南から来た IntraBox_4* find_ibox = &(my_board_1[trgt.y+1][trgt.x]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,start_z, board) - trgt_box->getSouthNum(); if(touch_count < 0){ *output = 10; return false; /*cout << "error! (error: 10)" << endl; exit(10);*/ } // コスト ap_int<16> cost_se = (find_ibox->ne) + ML + touch_count * penalty_T; ap_int<16> cost_ne = (find_ibox->ne) + ML + touch_count * penalty_T + trgt_box->getEastNum() * penalty_C; ap_int<16> cost_sw = (find_ibox->nw) + ML + touch_count * penalty_T; ap_int<16> cost_nw = (find_ibox->nw) + ML + touch_count * penalty_T + trgt_box->getWestNum() * penalty_C; // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = false; (trgt_ibox->d_se).e = false; (trgt_ibox->d_se).s = true; (trgt_ibox->d_se).w = false; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).s = true; } // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = false; (trgt_ibox->d_ne).e = false; (trgt_ibox->d_ne).s = true; (trgt_ibox->d_ne).w = false; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).s = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = false; (trgt_ibox->d_sw).e = false; (trgt_ibox->d_sw).s = true; (trgt_ibox->d_sw).w = false; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).s = true; } // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = false; (trgt_ibox->d_nw).e = false; (trgt_ibox->d_nw).s = true; (trgt_ibox->d_nw).w = false; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).s = true; } } if(trgt.d == WEST){ // 西から来た IntraBox_4* find_ibox = &(my_board_1[trgt.y][trgt.x-1]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,start_z, board) - trgt_box->getWestNum(); if(touch_count < 0){ *output = 11; return false; /*cout << "error! (error: 11)" << endl; exit(11);*/ } // コスト ap_int<16> cost_nw = (find_ibox->ne) + ML + touch_count * penalty_T; ap_int<16> cost_ne = (find_ibox->ne) + ML + touch_count * penalty_T + trgt_box->getNorthNum() * penalty_C; ap_int<16> cost_sw = (find_ibox->se) + ML + touch_count * penalty_T; ap_int<16> cost_se = (find_ibox->se) + ML + touch_count * penalty_T + trgt_box->getSouthNum() * penalty_C; // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = false; (trgt_ibox->d_nw).e = false; (trgt_ibox->d_nw).s = false; (trgt_ibox->d_nw).w = true; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).w = true; } // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = false; (trgt_ibox->d_ne).e = false; (trgt_ibox->d_ne).s = false; (trgt_ibox->d_ne).w = true; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).w = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = false; (trgt_ibox->d_sw).e = false; (trgt_ibox->d_sw).s = false; (trgt_ibox->d_sw).w = true; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).w = true; } // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = false; (trgt_ibox->d_se).e = false; (trgt_ibox->d_se).s = false; (trgt_ibox->d_se).w = true; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).w = true; } } if(trgt.d == NORTH){ // 北から来た IntraBox_4* find_ibox = &(my_board_1[trgt.y-1][trgt.x]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,start_z, board) - trgt_box->getNorthNum(); if(touch_count < 0){ *output = 12; return false; /*cout << "error! (error: 12)" << endl; exit(12);*/ } // コスト ap_int<16> cost_ne = (find_ibox->se) + ML + touch_count * penalty_T; ap_int<16> cost_se = (find_ibox->se) + ML + touch_count * penalty_T + trgt_box->getEastNum() * penalty_C; ap_int<16> cost_nw = (find_ibox->sw) + ML + touch_count * penalty_T; ap_int<16> cost_sw = (find_ibox->sw) + ML + touch_count * penalty_T + trgt_box->getWestNum() * penalty_C; // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = true; (trgt_ibox->d_ne).e = false; (trgt_ibox->d_ne).s = false; (trgt_ibox->d_ne).w = false; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).n = true; } // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = true; (trgt_ibox->d_se).e = false; (trgt_ibox->d_se).s = false; (trgt_ibox->d_se).w = false; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).n = true; } // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = true; (trgt_ibox->d_nw).e = false; (trgt_ibox->d_nw).s = false; (trgt_ibox->d_nw).w = false; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).n = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = true; (trgt_ibox->d_sw).e = false; (trgt_ibox->d_sw).s = false; (trgt_ibox->d_sw).w = false; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).n = true; } } if(trgt.d == EAST){ // 東から来た IntraBox_4* find_ibox = &(my_board_1[trgt.y][trgt.x+1]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,start_z, board) - trgt_box->getEastNum(); if(touch_count < 0){ *output = 13; return false; /*cout << "error! (error: 13)" << endl; exit(13);*/ } // コスト ap_int<16> cost_ne = (find_ibox->nw) + ML + touch_count * penalty_T; ap_int<16> cost_nw = (find_ibox->nw) + ML + touch_count * penalty_T + trgt_box->getNorthNum() * penalty_C; ap_int<16> cost_se = (find_ibox->sw) + ML + touch_count * penalty_T; ap_int<16> cost_sw = (find_ibox->sw) + ML + touch_count * penalty_T + trgt_box->getSouthNum() * penalty_C; // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = false; (trgt_ibox->d_ne).e = true; (trgt_ibox->d_ne).s = false; (trgt_ibox->d_ne).w = false; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).e = true; } // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = false; (trgt_ibox->d_nw).e = true; (trgt_ibox->d_nw).s = false; (trgt_ibox->d_nw).w = false; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).e = true; } // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = false; (trgt_ibox->d_se).e = true; (trgt_ibox->d_se).s = false; (trgt_ibox->d_se).w = false; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).e = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = false; (trgt_ibox->d_sw).e = true; (trgt_ibox->d_sw).s = false; (trgt_ibox->d_sw).w = false; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).e = true; } } if(!update) continue; if(trgt_box->isTypeNumber() || trgt_box->isTypeVia()) continue; // 北方向 if(trgt.d!=NORTH && isInserted_1(trgt.x,trgt.y-1,start_z, board)){ Search next = {trgt.x,trgt.y-1,SOUTH}; qu[qu_tail] = next; qu_tail++; } // 東方向 if(trgt.d!=EAST && isInserted_1(trgt.x+1,trgt.y,start_z, board)){ Search next = {trgt.x+1,trgt.y,WEST}; qu[qu_tail] = next; qu_tail++; } // 南方向 if(trgt.d!=SOUTH && isInserted_1(trgt.x,trgt.y+1,start_z, board)){ Search next = {trgt.x,trgt.y+1,NORTH}; qu[qu_tail] = next; qu_tail++; } // 西方向 if(trgt.d!=WEST && isInserted_1(trgt.x-1,trgt.y,start_z, board)){ Search next = {trgt.x-1,trgt.y,EAST}; qu[qu_tail] = next; qu_tail++; } } /* ******************************** * Phase 2-1: シンク層の判定 ******************************** */ if(start_z != end_z){ qu_head = 0; qu_tail = 0; ap_int<8> sp_via_id = trgt_line->getSpecifiedVia(); if(sp_via_id >= 1 && sp_via_id <= board->getViaNum()){ Via* sp_via = board->via(sp_via_id); if(sp_via->getSourceZ()!=start_z || sp_via->getSinkZ()!=end_z){ *output = 20; return false; /*cout << "error! (error: 20)" << endl; exit(20);*/ } ap_int<7> sp_x = sp_via->getSourceX(); ap_int<7> sp_y = sp_via->getSourceY(); if(my_board_1[sp_y][sp_x].ne == COST_MAX || my_board_1[sp_y][sp_x].nw == COST_MAX || my_board_1[sp_y][sp_x].se == COST_MAX || my_board_1[sp_y][sp_x].sw == COST_MAX){ *output = 21; return false; /*cout << "error! (error: 21)" << endl; exit(21);*/ } } for(ap_int<8> i=1;i<=board->getViaNum();i++){ #pragma HLS LOOP_TRIPCOUNT min=5 max=45 avg=25 ////#pragma HLS PIPELINE Via* trgt_via = board->via(i); if(trgt_via->getSourceZ()!=start_z || trgt_via->getSinkZ()!=end_z) continue; if(sp_via_id > 0 && sp_via_id != i) continue; start_x = trgt_via->getSourceX(); start_y = trgt_via->getSourceY(); start = &(my_board_2[start_y][start_x]); // ソース層に COST_MAX のコスト値が含まれている場合は引き継がない (issue #82) if(my_board_1[start_y][start_x].ne == COST_MAX || my_board_1[start_y][start_x].nw == COST_MAX || my_board_1[start_y][start_x].se == COST_MAX || my_board_1[start_y][start_x].sw == COST_MAX) continue; start->ne = my_board_1[start_y][start_x].ne + trgt_via->getUsedLineNum() * penalty_V; start->nw = my_board_1[start_y][start_x].nw + trgt_via->getUsedLineNum() * penalty_V; start->se = my_board_1[start_y][start_x].se + trgt_via->getUsedLineNum() * penalty_V; start->sw = my_board_1[start_y][start_x].sw + trgt_via->getUsedLineNum() * penalty_V; // 北方向を探索 if(isInserted_2(start_x,start_y-1,end_z, board)){ Search trgt = {start_x,start_y-1,SOUTH}; qu[qu_tail] = trgt; qu_tail++; } // 東方向を探索 if(isInserted_2(start_x+1,start_y,end_z, board)){ Search trgt = {start_x+1,start_y,WEST}; qu[qu_tail] = trgt; qu_tail++; } // 南方向を探索 if(isInserted_2(start_x,start_y+1,end_z, board)){ Search trgt = {start_x,start_y+1,NORTH}; qu[qu_tail] = trgt; qu_tail++; } // 西方向を探索 if(isInserted_2(start_x-1,start_y,end_z, board)){ Search trgt = {start_x-1,start_y,EAST}; qu[qu_tail] = trgt; qu_tail++; } } } /* ******************************** * Phase 2-2: シンク層の探索 ******************************** */ while (qu_head != qu_tail) { #pragma HLS LOOP_TRIPCOUNT min=100 max=100 avg=100 //#pragma HLS PIPELINE // これONにするとメモリ使用率100%になる Search trgt = qu[qu_head]; qu_head++; Box* trgt_box = board->box(trgt.x,trgt.y,end_z); IntraBox_4* trgt_ibox = &(my_board_2[trgt.y][trgt.x]); bool update = false; // コストの更新があったか? // コスト計算 if(trgt.d == SOUTH){ // 南から来た IntraBox_4* find_ibox = &(my_board_2[trgt.y+1][trgt.x]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,end_z, board) - trgt_box->getSouthNum(); if(touch_count < 0){ *output = 10; return false; /*cout << "error! (error: 10)" << endl; exit(10);*/ } // コスト ap_int<16> cost_se = (find_ibox->ne) + ML + touch_count * penalty_T; ap_int<16> cost_ne = (find_ibox->ne) + ML + touch_count * penalty_T + trgt_box->getEastNum() * penalty_C; ap_int<16> cost_sw = (find_ibox->nw) + ML + touch_count * penalty_T; ap_int<16> cost_nw = (find_ibox->nw) + ML + touch_count * penalty_T + trgt_box->getWestNum() * penalty_C; // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = false; (trgt_ibox->d_se).e = false; (trgt_ibox->d_se).s = true; (trgt_ibox->d_se).w = false; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).s = true; } // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = false; (trgt_ibox->d_ne).e = false; (trgt_ibox->d_ne).s = true; (trgt_ibox->d_ne).w = false; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).s = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = false; (trgt_ibox->d_sw).e = false; (trgt_ibox->d_sw).s = true; (trgt_ibox->d_sw).w = false; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).s = true; } // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = false; (trgt_ibox->d_nw).e = false; (trgt_ibox->d_nw).s = true; (trgt_ibox->d_nw).w = false; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).s = true; } } if(trgt.d == WEST){ // 西から来た IntraBox_4* find_ibox = &(my_board_2[trgt.y][trgt.x-1]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,end_z, board) - trgt_box->getWestNum(); if(touch_count < 0){ *output = 11; return false; /*cout << "error! (error: 11)" << endl; exit(11);*/ } // コスト ap_int<16> cost_nw = (find_ibox->ne) + ML + touch_count * penalty_T; ap_int<16> cost_ne = (find_ibox->ne) + ML + touch_count * penalty_T + trgt_box->getNorthNum() * penalty_C; ap_int<16> cost_sw = (find_ibox->se) + ML + touch_count * penalty_T; ap_int<16> cost_se = (find_ibox->se) + ML + touch_count * penalty_T + trgt_box->getSouthNum() * penalty_C; // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = false; (trgt_ibox->d_nw).e = false; (trgt_ibox->d_nw).s = false; (trgt_ibox->d_nw).w = true; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).w = true; } // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = false; (trgt_ibox->d_ne).e = false; (trgt_ibox->d_ne).s = false; (trgt_ibox->d_ne).w = true; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).w = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = false; (trgt_ibox->d_sw).e = false; (trgt_ibox->d_sw).s = false; (trgt_ibox->d_sw).w = true; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).w = true; } // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = false; (trgt_ibox->d_se).e = false; (trgt_ibox->d_se).s = false; (trgt_ibox->d_se).w = true; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).w = true; } } if(trgt.d == NORTH){ // 北から来た IntraBox_4* find_ibox = &(my_board_2[trgt.y-1][trgt.x]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,end_z, board) - trgt_box->getNorthNum(); if(touch_count < 0){ *output = 12; return false; /*cout << "error! (error: 12)" << endl; exit(12);*/ } // コスト ap_int<16> cost_ne = (find_ibox->se) + ML + touch_count * penalty_T; ap_int<16> cost_se = (find_ibox->se) + ML + touch_count * penalty_T + trgt_box->getEastNum() * penalty_C; ap_int<16> cost_nw = (find_ibox->sw) + ML + touch_count * penalty_T; ap_int<16> cost_sw = (find_ibox->sw) + ML + touch_count * penalty_T + trgt_box->getWestNum() * penalty_C; // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = true; (trgt_ibox->d_ne).e = false; (trgt_ibox->d_ne).s = false; (trgt_ibox->d_ne).w = false; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).n = true; } // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = true; (trgt_ibox->d_se).e = false; (trgt_ibox->d_se).s = false; (trgt_ibox->d_se).w = false; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).n = true; } // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = true; (trgt_ibox->d_nw).e = false; (trgt_ibox->d_nw).s = false; (trgt_ibox->d_nw).w = false; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).n = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = true; (trgt_ibox->d_sw).e = false; (trgt_ibox->d_sw).s = false; (trgt_ibox->d_sw).w = false; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).n = true; } } if(trgt.d == EAST){ // 東から来た IntraBox_4* find_ibox = &(my_board_2[trgt.y][trgt.x+1]); // タッチ数 ap_int<8> touch_count = countLine(trgt.x,trgt.y,end_z, board) - trgt_box->getEastNum(); if(touch_count < 0){ *output = 13; return false; /*cout << "error! (error: 13)" << endl; exit(13);*/ } // コスト ap_int<16> cost_ne = (find_ibox->nw) + ML + touch_count * penalty_T; ap_int<16> cost_nw = (find_ibox->nw) + ML + touch_count * penalty_T + trgt_box->getNorthNum() * penalty_C; ap_int<16> cost_se = (find_ibox->sw) + ML + touch_count * penalty_T; ap_int<16> cost_sw = (find_ibox->sw) + ML + touch_count * penalty_T + trgt_box->getSouthNum() * penalty_C; // 北東マス if(cost_ne < trgt_ibox->ne){ update = true; trgt_ibox->ne = cost_ne; (trgt_ibox->d_ne).n = false; (trgt_ibox->d_ne).e = true; (trgt_ibox->d_ne).s = false; (trgt_ibox->d_ne).w = false; } else if(cost_ne == trgt_ibox->ne){ (trgt_ibox->d_ne).e = true; } // 北西マス if(cost_nw < trgt_ibox->nw){ update = true; trgt_ibox->nw = cost_nw; (trgt_ibox->d_nw).n = false; (trgt_ibox->d_nw).e = true; (trgt_ibox->d_nw).s = false; (trgt_ibox->d_nw).w = false; } else if(cost_nw == trgt_ibox->nw){ (trgt_ibox->d_nw).e = true; } // 南東マス if(cost_se < trgt_ibox->se){ update = true; trgt_ibox->se = cost_se; (trgt_ibox->d_se).n = false; (trgt_ibox->d_se).e = true; (trgt_ibox->d_se).s = false; (trgt_ibox->d_se).w = false; } else if(cost_se == trgt_ibox->se){ (trgt_ibox->d_se).e = true; } // 南西マス if(cost_sw < trgt_ibox->sw){ update = true; trgt_ibox->sw = cost_sw; (trgt_ibox->d_sw).n = false; (trgt_ibox->d_sw).e = true; (trgt_ibox->d_sw).s = false; (trgt_ibox->d_sw).w = false; } else if(cost_sw == trgt_ibox->sw){ (trgt_ibox->d_sw).e = true; } } if(!update) continue; if(trgt_box->isTypeNumber()) continue; // 北方向 if(trgt.d!=NORTH && isInserted_2(trgt.x,trgt.y-1,end_z, board)){ Search next = {trgt.x,trgt.y-1,SOUTH}; qu[qu_tail] = next; qu_tail++; } // 東方向 if(trgt.d!=EAST && isInserted_2(trgt.x+1,trgt.y,end_z, board)){ Search next = {trgt.x+1,trgt.y,WEST}; qu[qu_tail] = next; qu_tail++; } // 南方向 if(trgt.d!=SOUTH && isInserted_2(trgt.x,trgt.y+1,end_z, board)){ Search next = {trgt.x,trgt.y+1,NORTH}; qu[qu_tail] = next; qu_tail++; } // 西方向 if(trgt.d!=WEST && isInserted_2(trgt.x-1,trgt.y,end_z, board)){ Search next = {trgt.x-1,trgt.y,EAST}; qu[qu_tail] = next; qu_tail++; } } #if 0 if (debug_option) { /*** デバッグ用*/ cout << endl; cout << "LAYER So (line_id: " << trgt_line_id << ") (z: " << (start_z + 1) << ")" << endl; cout << "========" << endl; for(int y=0;y<board->getSizeY();y++){ for(int x=0;x<board->getSizeX();x++){ IntraBox_4* trgt_box = &(my_board_1[y][x]); if(trgt_box->nw > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->nw; } if(trgt_box->ne > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->ne; } cout << " "; } cout << endl; for(int x=0;x<board->getSizeX();x++){ IntraBox_4* trgt_box = &(my_board_1[y][x]); if(trgt_box->sw > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->sw; } if(trgt_box->se > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->se; } cout << " "; } cout << endl; } cout << "LAYER Si (line_id: " << trgt_line_id << ") (z: " << (end_z + 1) << ")" << endl; cout << "========" << endl; for(int y=0;y<board->getSizeY();y++){ for(int x=0;x<board->getSizeX();x++){ IntraBox_4* trgt_box = &(my_board_2[y][x]); if(trgt_box->nw > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->nw; } if(trgt_box->ne > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->ne; } cout << " "; } cout << endl; for(int x=0;x<board->getSizeX();x++){ IntraBox_4* trgt_box = &(my_board_2[y][x]); if(trgt_box->sw > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->sw; } if(trgt_box->se > 10000){ cout << " +"; } else{ cout << setw(2) << trgt_box->se; } cout << " "; } cout << endl; } } #endif ap_int<7> now_x = trgt_line->getSinkX(); ap_int<7> now_y = trgt_line->getSinkY(); ap_uint<2> intra_box; ap_uint<2> next_direction_array[4]; #pragma HLS ARRAY_PARTITION variable=next_direction_array complete dim=0 ap_uint<3> next_direction_array_index = 0; ap_int<8> next_count; ap_uint<2> next_id; /* ******************************** * Phase 3-1: シンク層のバックトレース ******************************** */ if(start_z != end_z){ intra_box = NE; for (ap_uint<8> loop_count = 0; loop_count <= MAX_TRACKS; loop_count++) { //#pragma HLS PIPELINE // ONにするとLUTリソースオーバーする Point p = {now_x, now_y, end_z}; trgt_line->track[trgt_line->track_index] = p; (trgt_line->track_index)++; #if 0 if( debug_option ) { cout << "(" << now_x << "," << now_y << "," << end_z << ")"; } #endif if(board->box(now_x,now_y,end_z)->isTypeVia()) break; Direction trgt_d; switch(intra_box){ case NE: trgt_d = my_board_2[now_y][now_x].d_ne; break; case NW: trgt_d = my_board_2[now_y][now_x].d_nw; break; case SE: trgt_d = my_board_2[now_y][now_x].d_se; break; case SW: trgt_d = my_board_2[now_y][now_x].d_sw; break; default: ;//assert(!"Undefined Intra-Box"); break; } next_direction_array_index = 0; if(trgt_d.n) { next_direction_array[next_direction_array_index] = NORTH; next_direction_array_index++; } if(trgt_d.e) { next_direction_array[next_direction_array_index] = EAST; next_direction_array_index++; } if(trgt_d.s) { next_direction_array[next_direction_array_index] = SOUTH; next_direction_array_index++; } if(trgt_d.w) { next_direction_array[next_direction_array_index] = WEST; next_direction_array_index++; } next_count = /*(int)*/mt_genrand_int32(0, next_direction_array_index - 1); next_id = next_direction_array[next_count]; switch(next_id){ case NORTH: now_y = now_y - 1; // 北へ if(intra_box == NE || intra_box == SE) intra_box = SE; if(intra_box == NW || intra_box == SW) intra_box = SW; break; case EAST: now_x = now_x + 1; // 東へ if(intra_box == NE || intra_box == NW) intra_box = NW; if(intra_box == SE || intra_box == SW) intra_box = SW; break; case SOUTH: now_y = now_y + 1; // 南へ if(intra_box == NE || intra_box == SE) intra_box = NE; if(intra_box == NW || intra_box == SW) intra_box = NW; break; case WEST: now_x = now_x - 1; // 西へ if(intra_box == NE || intra_box == NW) intra_box = NE; if(intra_box == SE || intra_box == SW) intra_box = SE; break; } } } /* ******************************** * Phase 3-2: ソース層のバックトレース ******************************** */ intra_box = NE; for (ap_uint<8> loop_count = 0; loop_count <= MAX_TRACKS; loop_count++) { //#pragma HLS PIPELINE // ONにするとLUTリソースオーバーする Point p = {now_x, now_y, start_z}; trgt_line->track[trgt_line->track_index] = p; (trgt_line->track_index)++; #if 0 if( debug_option ){ cout << "(" << now_x << "," << now_y << "," << start_z << ")"; } #endif if(now_x==trgt_line->getSourceX() && now_y==trgt_line->getSourceY()) break; Direction trgt_d; switch(intra_box){ case NE: trgt_d = my_board_1[now_y][now_x].d_ne; break; case NW: trgt_d = my_board_1[now_y][now_x].d_nw; break; case SE: trgt_d = my_board_1[now_y][now_x].d_se; break; case SW: trgt_d = my_board_1[now_y][now_x].d_sw; break; default: ;//assert(!"Undefined Intra-Box"); break; } next_direction_array_index = 0; if(trgt_d.n) { next_direction_array[next_direction_array_index] = NORTH; next_direction_array_index++; } if(trgt_d.e) { next_direction_array[next_direction_array_index] = EAST; next_direction_array_index++; } if(trgt_d.s) { next_direction_array[next_direction_array_index] = SOUTH; next_direction_array_index++; } if(trgt_d.w) { next_direction_array[next_direction_array_index] = WEST; next_direction_array_index++; } next_count = /*(int)*/mt_genrand_int32(0, next_direction_array_index - 1); next_id = next_direction_array[next_count]; switch(next_id){ case NORTH: now_y = now_y - 1; // 北へ if(intra_box == NE || intra_box == SE) intra_box = SE; if(intra_box == NW || intra_box == SW) intra_box = SW; break; case EAST: now_x = now_x + 1; // 東へ if(intra_box == NE || intra_box == NW) intra_box = NW; if(intra_box == SE || intra_box == SW) intra_box = SW; break; case SOUTH: now_y = now_y + 1; // 南へ if(intra_box == NE || intra_box == SE) intra_box = NE; if(intra_box == NW || intra_box == SW) intra_box = NW; break; case WEST: now_x = now_x - 1; // 西へ if(intra_box == NE || intra_box == NW) intra_box = NE; if(intra_box == SE || intra_box == SW) intra_box = SE; break; } } #if 0 if( debug_option ) { cout << endl; } #endif /* ******************************** * Phase 4: ターゲットラインのトラックを整理 ******************************** */ routing_arrange(trgt_line); // delete は高位合成できないから放置。 /*for(int y=0;y<board->getSizeY();y++){ for(int x=0;x<board->getSizeX();x++){ delete my_board_1[y][x]; delete my_board_2[y][x]; } }*/ *output = 0; return true; }
//****************** //****************** uint8_t vobSubRead(char *filename,int index,VobSubInfo **info) { FILE *file=NULL; uint32_t nb_lines; VobSubInfo *sub=NULL; uint8_t success=0; uint32_t line=0,l; char str[1024]; char *dup; int language=0; if(!filename) { printf("Null file ?\n"); return 0; } *info=NULL; file=fopen(filename,"rt"); if(!file) { printf("Could not open %s file\n",filename); return 0; } nb_lines=countLine(file,index); if(!nb_lines) { printf("Empty file\n"); goto subAbort; } // Try to read the file sub=new VobSubInfo; memset(sub,0,sizeof(VobSubInfo)); // sub->nbLines=nb_lines; sub->lines=new vobSubLine[nb_lines]; memset(sub->lines,0,sizeof(vobSubLine)*nb_lines); printf("Rebuilding %d lines of subs\n",nb_lines); while(line<nb_lines && !feof(file)) { fgets(str,1023,file); if(!strncmp(str,"palette:",7)) { fillPalette(str,sub); sub->hasPalette=1; } else { if(!strncmp(str,"timestamp: ",10) && language) { fillLine(str,sub,line); line++; } else { if(!strncmp(str,"id:",3)) // Catch language/index { int l; char s[50]; s[0]=0; l=999; sscanf(str,"id: %s index: %d",s,&l); printf("Found lang : %s index %d while searching %d\n",s,l,index); if(l==index) { language=1; printf("Match\n"); } else language=0; } else { if(!strncmp(str,"size:",5)) // Catch original screen dimension { sscanf(str,"size:%"SCNu32"x%"SCNu32"",&(sub->width),&(sub->height)); } } } } } subSuccess: success=1; if(!sub->hasPalette) { for(int j=0;j<16;j++) sub->Palette[j]=j; } subAbort: if(success) { *info=sub; } else { destroySubInfo( sub); } fclose(file); return success; }