📄 routelink_analyse.c
字号:
/****************************************************************************
FileName : routelink_analyse.c
Date : 2006.07.22
Author :
Copyright :
-----------------------------------------------------------------------------
Modify History
NO Date Modifier Modified Contet
****************************************************************************/
/*-------------------------------------------------------------------------*/
/* */
/* Include File Section */
/* */
/*-------------------------------------------------------------------------*/
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
#include "routelink_c.h"
#include "routelink_in_c.h"
#include "routelink_in_s.h"
#include "routelink_in_p.h"
/*-------------------------------------------------------------------------*/
/* */
/* Function Definition Section */
/* */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
/* routelink_analyse_slinkcre */
/* -----------------------------------------------------------------------*/
/* Input: */
/* FILE* : Data file handle[IN] */
/* BYTE* : Buffer for read from file[IN] */
/* int : Size of file read buffer[IN] */
/* S_LNKTBL** : Header node pointer[OUT] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯Link node number */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Create single link table for data analysing using. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_slinkcre(
FILE* pOrgFile, /* I/ Route link data file */
BYTE* pbFileBuf, /* I/ Buffer for read from file */
int iReadBlockSize, /* I/ Size of file read buffer */
S_LNKTBL** pstHeader /* O/ Header node pointer */
)
{
UWORD uwRecSize = 0; /* Current Record size */
UDWORD udwLinkID = 0; /* Link ID */
int iRetReadFile= 0; /* Return value for read file */
int iRoadLnkNum = 0; /* Number of Road Link Node */
BYTE* pbCurBuf = NULL; /* Current record buffer pointer */
S_LNKTBL* pstHeaderLnk= NULL; /* Header node pointer */
S_LNKTBL* pstCurLnk = NULL; /* Current node pointer */
S_LNKTBL* pstNxtLnk = NULL; /* Next node pointer */
/* Exception prevention */
if( NULL == pOrgFile )
{
return RET_FAILED;
}
/* Header Link node allocation */
pstHeaderLnk = malloc( sizeof(S_LNKTBL) );
if( NULL == pstHeaderLnk )
{
printf( "\nData area allocation failed!\n" );
return RET_FAILED;
}
memset( pstHeaderLnk, 0, sizeof(S_LNKTBL) );
pstCurLnk = pstHeaderLnk;
/* File read buffer initialization */
memset( pbFileBuf, 0, iReadBlockSize );
/* Read from file */
iRetReadFile = fread( pbFileBuf, iReadBlockSize, 1, pOrgFile );
if( iRetReadFile <= 0 )
{
free( pstHeaderLnk );
pstHeaderLnk = NULL;
return iRoadLnkNum;
}
/* Current pointer get */
pbCurBuf = pbFileBuf;
while( pbCurBuf < ( pbFileBuf + iReadBlockSize ) )
{
/* Get Record size and Link ID */
uwRecSize = MC_GET_SHORT( pbCurBuf );
udwLinkID = MC_GET_LONG( (pbCurBuf + RL_OFFSET_LNKID) );
/* Next link node area allocation */
pstNxtLnk = malloc( sizeof(S_LNKTBL) );
if( NULL == pstNxtLnk )
{
routelink_analyse_slinkfree( &pstHeaderLnk, iRoadLnkNum );
printf( "\n Create Link Table failed.\n" );
}
memset( pstNxtLnk, 0, sizeof(S_LNKTBL) );
/* Next Link Info set */
pstNxtLnk->stLnkTblRec.uwRecSize = uwRecSize;
pstNxtLnk->stLnkTblRec.udwLinkID = udwLinkID;
pstNxtLnk->stLnkTblRec.pvRtLnk = (void*)pbCurBuf;
pstNxtLnk->pNxtNode = NULL;
/* Link next node into current node */
pstCurLnk->pNxtNode = pstNxtLnk;
/* Current node pointer move */
pstCurLnk = pstNxtLnk;
/* Current buffer pointer move(to next buffer) */
pbCurBuf += uwRecSize;
/* Road link node counter */
iRoadLnkNum ++;
}
/* Header node pointer save */
*pstHeader = pstHeaderLnk;
return iRoadLnkNum;
}
/***************************************************************************/
/* routelink_analyse_slinkanalyse */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL_REC* : Link data info record area[IN] */
/* int : Number of Road Link Node[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* analyse the link data by different analyse method. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_slinkanalyse(
S_LNKTBL_REC* pstLnkRecArray, /* I/ Link data info record area */
int iRoadLnkNum /* I/ Number of Road Link Node */
)
{
int iAnalyseMethod = 0; /* analyse method selection */
int iResult = 0;
/* Exception prevention */
if( NULL == pstLnkRecArray )
{
printf( "\nRoute link Data NULL. Please check it!\n" );
return RET_FAILED;
}
/* Prompt the user to select the analyse proc method */
printf( "\nPlease select the analyse proc method>>>>>>>>\n" );
printf( "1 : Kiwi analyse.\n" );
printf( "2 : Double direction Kiwi analyse.\n" );
printf( "3 : Selected Kiwi analyse.\n" );
printf( "Other : Default analyse method will be Selected Kiwi analyse!\n" );
/* Read the user's selection from key buffer */
iResult = scanf( "%d", &iAnalyseMethod );
while( iResult <= 0 )
{
printf( "Invalid input! Please input again:\n");
fflush( stdin );
iResult = scanf( "%d", &iAnalyseMethod);
}
/* analyse by the different analyseint proc method */
switch( iAnalyseMethod )
{
case 1:
routelink_analyse_in_bubbleanalyse( pstLnkRecArray, iRoadLnkNum );
break;
case 2:
routelink_analyse_in_2dirbubbleanalyse( pstLnkRecArray, iRoadLnkNum );
break;
case 3:
routelink_analyse_in_selectanalyse( pstLnkRecArray, iRoadLnkNum );
break;
default:
routelink_analyse_in_selectanalyse( pstLnkRecArray, iRoadLnkNum );
break;
}
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_analyse_resultoutput */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL_REC* : Link data info record area[IN] */
/* int : Number of Road Link Node[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : 乮Normal乯RET_SUCCESS */
/* 乮Error乯 RET_FAILED */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Output the result data after analysing into file(analyseresult.dat). */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_resultoutput(
S_LNKTBL_REC* pstLnkRecArray, /* I/ Link data info record area */
int iRoadLnkNum /* I/ Number of Road Link Node */
)
{
int iFWriteItem = 0;
int iLoopCnt = 0;
BYTE* pbMemBlock = NULL; /* Memory block for route link data*/
BYTE* pbCurBlock = NULL; /* Current pointer to memory block */
FILE* pFileAnalyse = NULL; /* File for the data after Analyseing */
S_LNKTBL_REC* pstCurLnk = NULL; /* Current node pointer */
/* Exception prevention */
if( NULL == pstLnkRecArray )
{
return RET_FAILED;
}
/* Open the file for analyse data writting(In order to create a new file) */
pFileAnalyse = fopen( RTL_ANALYSEDAT_FILENAME, "wb" );
if( NULL == pFileAnalyse )
{
return RET_FAILED;
}
/* Memory block allocation */
pbMemBlock = malloc( FILEREAD_BLOCKSIZE );
if( NULL == pbMemBlock )
{
fclose( pFileAnalyse );
pFileAnalyse = NULL;
return RET_FAILED;
}
else
{
/* Memory initialization */
memset( pbMemBlock, 0, FILEREAD_BLOCKSIZE );
}
/* Current memory header address set*/
pbCurBlock = pbMemBlock;
/* Result output promption */
printf( "Analyse result output..." );
do
{
/* Get Current data record */
pstCurLnk = &pstLnkRecArray[iLoopCnt];
/* Copy the routelink data into the consecutive memory */
if( NULL != pstCurLnk->pvRtLnk )
{
memcpy( pbCurBlock,
(BYTE*)pstCurLnk->pvRtLnk, pstCurLnk->uwRecSize );
}
/* Current pointer move to the next record */
pbCurBlock += pstCurLnk->uwRecSize;
pstCurLnk = &pstLnkRecArray[iLoopCnt + 1];
/* The left memory is less than the next record size, file write */
if( (pbCurBlock + pstCurLnk->uwRecSize) >
(pbMemBlock + FILEREAD_BLOCKSIZE) )
{
/* Data after analysing writting */
iFWriteItem = fwrite( pbMemBlock,
((pbCurBlock - pbMemBlock) * sizeof(BYTE)), 1, pFileAnalyse );
/* Write data failed, prompt info print */
if( iFWriteItem <= 0 )
{
free( pbMemBlock );
pbMemBlock = NULL;
fclose( pFileAnalyse );
pFileAnalyse = NULL;
printf( "\nFail to write the analyse data into the file!\n" );
return RET_FAILED;
}
/* Current memory pointer reset */
pbCurBlock = pbMemBlock;
memset( pbCurBlock, 0, FILEREAD_BLOCKSIZE );
}
/* Counter changes */
iLoopCnt++;
/* Current process status promption */
if( 0 == (iLoopCnt % 1000) )
{
printf( "." );
}
}while( iLoopCnt < iRoadLnkNum );
/* Output OK promption */
printf( "Search result output OK!\n" );
printf( "\nLink data analyse and output ok!\n" );
/* Close the file for data analyse */
fclose( pFileAnalyse );
pFileAnalyse = NULL;
/* Memory block free */
free( pbMemBlock );
pbMemBlock = NULL;
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_analyse_slinkanalyse */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL_REC** : Link data info record area[IN] */
/* int : Number of Road Link Node[IN] */
/* */
/* -----------------------------------------------------------------------*/
/* Output: */
/* RETURN : RET_SUCCESS */
/* */
/* -----------------------------------------------------------------------*/
/* Outline: */
/* Free single link table. */
/* */
/* -----------------------------------------------------------------------*/
/* Others: */
/* */
/***************************************************************************/
int routelink_analyse_slinkfree(
S_LNKTBL** pstHeaderLnk, /* I/ Header node pointer */
int iRoadLnkNum /* I/ Number of Road Link Node */
)
{
S_LNKTBL* pNewHeader = NULL; /* New header node pointer */
S_LNKTBL* pstDelLnk = NULL; /* The next delete node */
/* Exception prevention */
if( (NULL == pstHeaderLnk) || (0 == iRoadLnkNum) )
{
return RET_SUCCESS;
}
/* Current node pointer initialization */
pstDelLnk = *pstHeaderLnk;
while( NULL != pNewHeader )
{
pNewHeader = pstDelLnk->pNxtNode;
free( pstDelLnk );
pstDelLnk = pNewHeader;
}
*pstHeaderLnk = NULL;
return RET_SUCCESS;
}
/***************************************************************************/
/* routelink_analyse_slink2array */
/* -----------------------------------------------------------------------*/
/* Input: */
/* S_LNKTBL* : Header node pointer[IN] */
/* int : Number of Road Link Node[IN] */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -