XiaoGongWei / MG_APP

MG-APP (https://link.springer.com/article/10.1007/s10291-020-00976-1);
https://xiaogongwei10.blog.csdn.net/
95 stars 52 forks source link

Problem in QTideEffect::readOCEANFile #12

Open LucaFibbi opened 4 years ago

LucaFibbi commented 4 years ago

The function QTideEffect::readOCEANFile cannot read the coefficients from blq file. The function not find the station name in the blq file. In the following block of code I explain the problem:

....
308   while (!m_readOCEANClass.atEnd())
    {
        //2-6 per line is empty, it means the data will start "$$" and the length is 4
        while (4 != tempLine.length()) //<--- The program exit of this cycle only at end of file. The lines length is always different from 4.
        {
            tempLine = m_readOCEANClass.readLine();
            if (m_readOCEANClass.atEnd()) 
            {
                isOCEANTide = false;
                oceaData.isRead = false;
                break;  
            }
        }

        //Read station data
        tempLine = m_readOCEANClass.readLine();//Read header file line
        if (m_readOCEANClass.atEnd()) 
        {
            isOCEANTide = false;
            oceaData.isRead = false;
            break;  
        }
        tempStationName = tempLine.mid(2,4).trimmed().toUpper();
        if (tempStationName != StationName) continue;
               //Find the station
           tempOCEANData.StationName = tempStationName;
        //Skip comments (can read station BLH, not read here)
        tempLine = m_readOCEANClass.readLine();//Read comment
        while (tempLine.mid(0,2).contains("$"))
337         tempLine = m_readOCEANClass.readLine();//Read comment
....

Here how I would have built the block of code:

...
    while (!m_readOCEANClass.atEnd())
    {
        // Skip comments
        while (tempLine.startsWith("$$"))
        {
            tempLine = m_readOCEANClass.readLine();
            if (m_readOCEANClass.atEnd())
            {
                isOCEANTide = false;
                oceaData.isRead = false;
                break;
            }
        }

        // Possible line with station name
        tempStationName = tempLine.mid(2,4).trimmed().toUpper();
        if (tempStationName != StationName) {
            tempLine = m_readOCEANClass.readLine();
            if (m_readOCEANClass.atEnd())
            {
                isOCEANTide = false;
                oceaData.isRead = false;
                break;
            }
            continue;
        }
        //Find the station
        tempOCEANData.StationName = tempStationName;
        //Skip comments
        tempLine = m_readOCEANClass.readLine();//Read comment
        while (tempLine.startsWith("$$"))
            tempLine = m_readOCEANClass.readLine();//Read comment
...
XiaoGongWei commented 4 years ago

Thank you for your contribution. I have submitted an update on MG-APP. :)