Exemplo n.º 1
0
Node* loadFile(char *filename, int num_nodes,int* first_pair,int* second_pair){
	int i;

	FILE *fptr = getFilePtr(filename);

	Node *node_arr = (Node*)malloc(sizeof(Node)*((num_nodes)+1));

	fseek(fptr,2,SEEK_CUR);

	for(i = 1; i <= num_nodes;i++){
		fscanf(fptr,"%d",&node_arr[i].thisnode);
		fscanf(fptr,"%f",&node_arr[i].width);
		fscanf(fptr,"%f",&node_arr[i].height);
	}

	for(i = 1;i <= num_nodes;i++){
		 fscanf(fptr,"%d",&first_pair[i]);
	}

	for(i = 1;i <= num_nodes;i++){
		fscanf(fptr,"%d",&second_pair[i]);
	}

	return node_arr;
}
Exemplo n.º 2
0
int getSize(char *filename){
	int size = 0;

	FILE *fptr = getFilePtr(filename);
	fscanf(fptr,"%d",&size);

	fclose(fptr);
	return size;

}
Exemplo n.º 3
0
bool SACfxCsv2DDataParser::parser()
{
    QFile* file = getFilePtr ();
    if(nullptr == file)
        return false;
    m_dataSeries.clear ();
    file->seek (0);
    QTextStream inStream(file);
    QString strLine;
    QString strTemp;
    double x,y;
    bool isOK;
    QStringList splitLine;
    do{
        strLine = inStream.readLine();
        splitLine = SACsvParser::fromCsvLine(strLine);
        if(splitLine.size () <= 0)
            continue;
        if("[Name]" == splitLine[0])
            break;//说明遇到"[Name]"
    }while(!inStream.atEnd());
    do
    {
        QString name = inStream.readLine();//读取[Name]的下一行
        std::shared_ptr<dataContainer> seriesData = std::make_shared<dataContainer>();
        seriesData->m_name = name;
        inStream.readLine();//读取下一行
        strTemp = inStream.readLine();//读取下一行 - [Data]
        qDebug()<<strTemp;
        if("[Data]" != strTemp)
            continue;
        strLine = inStream.readLine();//标题
        qDebug()<<strLine;
        splitLine = SACsvParser::fromCsvLine(strLine);
        qDebug()<<splitLine;
        if(splitLine.size ()>=2)
        {
            seriesData->m_xName = splitLine[0];
            seriesData->m_yName = splitLine[1];
        }
        //开始读取数据
        while (!inStream.atEnd())
        {
            strLine = inStream.readLine();
            splitLine = SACsvParser::fromCsvLine(strLine);
            if(splitLine.size ()>=2)
            {
                x = splitLine[0].toDouble (&isOK);
                if(!isOK)
                    continue;
                y = splitLine[1].toDouble (&isOK);
                if(!isOK)
                    continue;
                seriesData->m_series.push_back (QPointF(x,y));
            }
            else if(1 == splitLine.size ())
            {
                if("[Name]" == splitLine[0])
                    break;
            }
        }
        if(m_rowCount < (seriesData->m_series.size ()) )
            m_rowCount = seriesData->m_series.size ();//记录行数
        m_dataSeries.push_back (seriesData);
    }while(!inStream.atEnd());
    return true;
}