Weather casting with Machine Learning (SVM and SRNN).
Dependencies: EthernetInterface GraphicHandler NTPClient SRNN SVM SensorModule mbed-rtos mbed
Diff: main_util.cpp
- Revision:
- 3:5add3759e08a
- Parent:
- 2:20ecfe6edd71
- Child:
- 5:b61f3f5b0fc8
--- a/main_util.cpp Wed Feb 18 15:02:16 2015 +0000 +++ b/main_util.cpp Thu Feb 19 08:20:46 2015 +0000 @@ -2,8 +2,10 @@ void check_file_open(FILE* file_p, const char* file_name) { + printf("[cnt:%d] %s : %p \r\n", open_count++, file_name, file_p); if ( file_p == NULL ) { fprintf( stderr, "Error : file %s open faild. \r\n", file_name ); + fflush( stderr ); exit(1); } } @@ -13,7 +15,7 @@ { FILE* dat_file_fp; const char tmp_file_name[] = "/local/TMP_DAT.CSV"; - int line; + int line, diff_line; char trunc_buf_str[BUF_SIZE]; // 最初に現在の行数を数える dat_file_fp = fopen( SEQUENCE_DATA_NAME, "r"); @@ -29,33 +31,32 @@ // 切り詰め開始 if ( line > LEN_DATA_SEQUENCE ) { FILE* tmp_fp; - int diff_line = line - LEN_DATA_SEQUENCE; + diff_line = (line - LEN_DATA_SEQUENCE); dat_file_fp = fopen(SEQUENCE_DATA_NAME, "r"); + // rewind( dat_file_fp ); check_file_open( dat_file_fp, SEQUENCE_DATA_NAME ); + tmp_fp = fopen( tmp_file_name, "w"); + check_file_open( tmp_fp, tmp_file_name ); line = 0; while(fgets(trunc_buf_str, BUF_SIZE, dat_file_fp) != NULL) { line++; - if (line == diff_line) break; + if (line >= diff_line) break; } // diff_line以降をテンポラリにコピー - tmp_fp = fopen( tmp_file_name, "w"); - check_file_open( tmp_fp, tmp_file_name ); - fflush( tmp_fp ); - fflush( dat_file_fp ); + while( fgets( trunc_buf_str, BUF_SIZE, dat_file_fp) != NULL) { - fputs( trunc_buf_str, tmp_fp); + fputs( trunc_buf_str, tmp_fp ); } - //fclose( tmp_fp ); - //fclose( dat_file_fp ); + + fclose( dat_file_fp ); + fclose( tmp_fp ); // 更新 - tmp_fp = freopen( tmp_file_name, "r", tmp_fp); + tmp_fp = fopen( tmp_file_name, "r"); check_file_open( tmp_fp, tmp_file_name ); - dat_file_fp = freopen(SEQUENCE_DATA_NAME, "w", dat_file_fp); + dat_file_fp = fopen(SEQUENCE_DATA_NAME, "w"); check_file_open( dat_file_fp, SEQUENCE_DATA_NAME ); // 一時ファイルからコピー - fflush( tmp_fp ); - fflush( dat_file_fp ); while( fgets( trunc_buf_str, BUF_SIZE, tmp_fp) != NULL) { fputs( trunc_buf_str, dat_file_fp); } @@ -65,5 +66,7 @@ // テンポラリの削除 remove( tmp_file_name ); + // free( tmp_fp ); } + // free( dat_file_fp ); } \ No newline at end of file