Changeset 873 for applications/doprava

Show
Ignore:
Timestamp:
03/22/10 17:00:06 (14 years ago)
Author:
prikryl
Message:

New function replace_stoptime() that allows user-specified stop time of simulation instead of the default 24:00:00.

Location:
applications/doprava/aimsun_bdm
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/aimsun_bdm/tools.cpp

    r859 r873  
    139139                { 
    140140                        /* We are inside the section, try to replace the text 
    141                            that shoudl be replaced. */ 
     141                           that should be replaced. */ 
    142142                        bool is_pat = false; 
    143143                        for (int i=0;i<num_patterns;i++) 
     
    184184} 
    185185 
     186errno_t replace_stoptime ( 
     187        const TCHAR * net_path, 
     188        const TCHAR * stoptime 
     189        ) 
     190{ 
     191        TCHAR   tline[MAX_LINE]; 
     192    TCHAR   tmp_name[MAX_PATH]; 
     193    TCHAR   run_name[MAX_EXE_PATH]; 
     194        FILE *  tmp_stream; 
     195        FILE *  run_stream; 
     196        errno_t res; 
     197        int     line_no; 
     198 
     199        /* Create filename of the temporary file with replaced stoptime. */ 
     200        _ttmpnam_s ( tmp_name ); 
     201 
     202    /* Open the temporary file for writting. */ 
     203    res = _tfopen_s ( &tmp_stream, tmp_name, TEXT("w") ); 
     204        if ( res != 0 ) 
     205        { 
     206                perror ( "Cannot create temporary file" ); 
     207                return res; 
     208        } 
     209 
     210        /* Create the name of the time file. */ 
     211        StringCbCopy ( run_name, MAX_EXE_PATH, net_path ); 
     212        StringCbCat  ( run_name, MAX_EXE_PATH, TEXT("\\AIMSUN\\RunTime") ); 
     213 
     214        /* Open the time file for reading */ 
     215    res = _tfopen_s ( &run_stream, run_name, TEXT("r") ); 
     216    if ( res != 0 ) 
     217        { 
     218                perror ( "Cannot open scenario for reading" ); 
     219                return res; 
     220        } 
     221 
     222    /* Copy the time file to the temporary location line by line, 
     223       changing the third line containing stop time. */ 
     224        line_no = 0; 
     225        while ( !feof ( run_stream )) 
     226        { 
     227        /* Read a single line from the scenario file. */ 
     228        if ( _fgetts ( tline, MAX_LINE, run_stream ) == NULL ) 
     229                { 
     230                        /* Error reading from source file. */ 
     231                        if ( !feof ( run_stream )) perror ( "Error reading scenario" ); 
     232                        break; 
     233                } 
     234 
     235                /* Increase the line counter. */ 
     236                line_no++; 
     237 
     238                /* Replace the third line. */ 
     239                if ( line_no == 3 ) 
     240                { 
     241                        _sntprintf_s ( tline, MAX_LINE, MAX_LINE-2, TEXT("%s\n"), stoptime ); 
     242                } 
     243 
     244        _fputts ( tline, tmp_stream ); 
     245        } 
     246 
     247    fclose ( tmp_stream ); 
     248    fclose ( run_stream ); 
     249 
     250    /* Rewrite the original RunTime file. */ 
     251    if ( ! _taccess ( run_name, 00 )) 
     252        { 
     253                /* File exists, delete it. */ 
     254        DeleteFile ( run_name ); 
     255        } 
     256    MoveFile ( tmp_name, run_name ); 
     257 
     258        return 0; 
     259 
     260} 
     261 
    186262int _search_index ( const int *list, int numElements, int value ) 
    187263{ 
  • applications/doprava/aimsun_bdm/tools.h

    r859 r873  
    44 
    55#define MAX_LINE                1024 
     6#define MAX_EXE_PATH    (2*MAX_PATH) 
    67 
    78void    _addpath ( TCHAR * path ); 
     
    1617        const TCHAR * replacement 
    1718        ); 
    18          
     19 
     20errno_t replace_stoptime ( 
     21        const TCHAR * net_path, 
     22        const TCHAR * stoptime 
     23        ); 
     24 
    1925int _search_index ( const int *list, int numElements, int value ); 
    2026