void DescrGeneratorInterface::slotCrea() { if (verificaCampi()) { if (worker_thread == 0 && generator == 0) { saveConfig(); openDB::BackendConnector* connector = &parentWindow->backendConnector(); std::string cat_merc = editCatMerc->text().toStdString(); std::string natura = editNatura->text().toStdString(); std::string mainTemFile = editMainTemplate->text().toStdString(); std::string resTempFile = editResourcesTemplate->text().toStdString(); std::string videoResTempFile = editVideoResourcesTemplate->text().toStdString(); std::string videoTempFile = editVideoTemplate->text().toStdString(); std::string destinationFile = editFile->text().toStdString(); generator = new DescrGenerator(connector, cat_merc, natura, mainTemFile, resTempFile, videoResTempFile, videoTempFile, destinationFile); worker_thread = new QThread; generator->moveToThread(worker_thread); connect (worker_thread, SIGNAL(started()), generator, SLOT(start())); connect (generator, SIGNAL(totalRecords(unsigned int)), this, SLOT(slotTotal(unsigned int))); connect (generator, SIGNAL(incProgress()), this, SLOT(slotIncProgress())); connect (generator, SIGNAL(done()), this, SLOT(slotDone())); worker_thread->start(); } else
void QFExtensionManager::init(QFPluginServices* services, QWidget* parentWidget) { QMapIterator<QString, QFExtension*> i(items); while (i.hasNext()) { i.next(); i.value()->init(services, parentWidget); emit incProgress(); QApplication::processEvents(); } }
int MainWindow::readAreaDataBaseFile( const QString &FilenameADB, QVector<AreaItem> &v_Area, QVector<PositionItem> &v_Position ) { int i = 0; int n = 0; int stopProgress = 0; int i_NumOfAreas = 0; int i_NumOfPositions = 0; QStringList sl_Input; // ********************************************************************************************** // read file if ( ( n = readFile( FilenameADB, sl_Input, _SYSTEM_, 1, -1 ) ) < 1 ) return( n ); // ********************************************************************************************** i_NumOfAreas = sl_Input.at( 2 ).section( "\t", 1, 1 ).toInt(); i_NumOfPositions = sl_Input.at( 3 ).section( "\t", 1, 1 ).toInt(); for ( i=7; i<i_NumOfAreas+7; i++ ) v_Area.append( AreaItem( sl_Input.at( i ).section( "\t", 0, 0 ), sl_Input.at( i ).section( "\t", 1, 1 ).toInt(), sl_Input.at( i ).section( "\t", 2, 2 ).toInt(), sl_Input.at( i ).section( "\t", 5, 5 ).toFloat(), sl_Input.at( i ).section( "\t", 3, 3 ).toFloat(), sl_Input.at( i ).section( "\t", 6, 6 ).toFloat(), sl_Input.at( i ).section( "\t", 4, 4 ).toFloat() ) ); initProgress( 2, FilenameADB, tr( "Finding area database (read data) ..." ), i_NumOfPositions ); i = i_NumOfAreas+10; i_NumOfPositions += i; while ( ( i < i_NumOfPositions ) && ( stopProgress != _APPBREAK_ ) ) { v_Position.append( PositionItem( sl_Input.at( i ).section( "\t", 0, 0 ).toDouble(), sl_Input.at( i ).section( "\t", 1, 1 ).toDouble() ) ); stopProgress = incProgress( 2, ++i ); } resetProgress( 2 ); return( i_NumOfAreas ); }
Window::Window(Controller * c, QWidget *parent) : QWidget(parent), IView(c) { int width = controller->getWidth(); int height = controller->getHeight(); trace_run = false; menu = new QMenuBar(this); createMenu(); area = new ImageArea(controller, this); connect(area, SIGNAL(pixelPainted()), this, SLOT(incProgress())); connect(area, SIGNAL(finish()), this, SLOT(finish())); pr_bar = new QProgressBar(this); pr_bar->setRange(0, width*height); pr_bar->setValue(0); pr_bar->setDisabled(true); render_button = new QPushButton(tr("&Render"), this); render_button->setDefault(true); connect(render_button, SIGNAL(clicked()), this, SLOT(render())); QHBoxLayout * hlayot = new QHBoxLayout; hlayot->setMargin(5); hlayot->addWidget(pr_bar); hlayot->addWidget(render_button); QVBoxLayout * vlayout = new QVBoxLayout(this); vlayout->setMargin(0); vlayout->setSpacing(0); vlayout->setSizeConstraint(QLayout::SetFixedSize); vlayout->setMenuBar(menu); vlayout->addWidget(area); vlayout->addLayout(hlayot); setWindowTitle(tr("Ray Tracer")); }
int MainWindow::convertSPE( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_NumOfFiles ) { int i = 1; int j = 0; int k = 0; int n = 0; int stopProgress = 0; bool b_datafound = false; QString tempStr = ""; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( -10 ); // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting SPE data..." ), sl_Input.count() ); // ********************************************************************************************** while ( ( b_datafound == false ) && ( i<sl_Input.count() ) && ( stopProgress != _APPBREAK_ ) ) { if ( sl_Input.at( i ).startsWith( "$DATA:") == true ) b_datafound = true; stopProgress = incProgress( i_NumOfFiles, ++i ); } if ( b_datafound == true ) { tempStr = sl_Input.at( i++ ).split( QRegularExpression( "\\s+" ) ).join( "\t" ); k = tempStr.section( "\t", 1, 1 ).toInt(); tout << "Channel" << "\t" << "cps" << s_EOL; while ( ( i<sl_Input.count() ) && ( stopProgress != _APPBREAK_ ) ) { tempStr = sl_Input.at( i ).split( QRegularExpression( "\\s+" ) ).join( "\t" ); n = NumOfSections( tempStr ); for ( j=1; j<n; j++ ) tout << QString( "%1\t%2" ).arg( k++ ).arg( tempStr.section( "\t", j, j ) ) << s_EOL; stopProgress = incProgress( i_NumOfFiles, ++i ); } } else { tout << "No data found! Wrong format." << s_EOL; } // ********************************************************************************************** fout.close(); resetProgress( i_NumOfFiles ); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
int MainWindow::addLine( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const QStringList &sl_Text, const int i_LineNo, const bool b_AddFilename, const bool b_AddFullPath, const bool b_AddOrdinalNumber, const bool b_PrependMetadataColumn, const bool b_AppendMetadataColumn, const bool b_SkipEmptyLines, const bool b_SkipCommentLines, const int i_NumOfFiles ) { int i = 0; int k = 0; int n = 0; int e = 0; int stopProgress = 0; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( n ); // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } QFileInfo fi( s_FilenameIn ); // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Adding lines..." ), sl_Input.count() ); e = i_LineNo - 1; if ( b_PrependMetadataColumn == true ) { if ( b_AddFilename == true ) tout << "Event label" << "\t"; if ( b_AddFullPath == true ) tout << "Filename" << "\t"; if ( b_AddOrdinalNumber == true ) tout << "No" << "\t"; } tout << sl_Input.at( 0 ); if ( b_AppendMetadataColumn == true ) { if ( b_AddFilename == true ) tout << "\t" << "Event label"; if ( b_AddFullPath == true ) tout << "\t"<< "Filename"; if ( b_AddOrdinalNumber == true ) tout << "\t" << "No"; } tout << s_EOL; stopProgress = incProgress( i_NumOfFiles, ++i ); while ( ( i<e ) && ( stopProgress != _APPBREAK_ ) ) { if ( LineCanBeWritten( sl_Input.at( i ), b_SkipEmptyLines, b_SkipCommentLines ) == true ) { if ( b_PrependMetadataColumn == true ) { if ( b_AddFilename == true ) tout << fi.baseName() << "\t"; if ( b_AddFullPath == true ) tout << fi.absoluteFilePath() << "\t"; if ( b_AddOrdinalNumber == true ) tout << QString( "%1" ).arg( ++k ) << "\t"; } tout << sl_Input.at( i ); if ( b_AppendMetadataColumn == true ) { if ( b_AddFilename == true ) tout << "\t" << fi.baseName(); if ( b_AddFullPath == true ) tout << "\t" << fi.absoluteFilePath(); if ( b_AddOrdinalNumber == true ) { if ( b_PrependMetadataColumn == false ) tout << "\t" << QString( "%1" ).arg( ++k ); else tout << "\t" << QString( "%1" ).arg( k ); } } tout << s_EOL; } stopProgress = incProgress( i_NumOfFiles, ++i ); } for ( int j=0; j<sl_Text.count(); j++ ) { if ( b_PrependMetadataColumn == true ) { if ( b_AddFilename == true ) tout << fi.baseName() << "\t"; if ( b_AddFullPath == true ) tout << fi.absoluteFilePath() << "\t"; if ( b_AddOrdinalNumber == true ) tout << QString( "%1" ).arg( ++k ) << "\t"; } tout << sl_Text.at( j ); if ( b_AppendMetadataColumn == true ) { if ( b_AddFilename == true ) tout << "\t" << fi.baseName(); if ( b_AddFullPath == true ) tout << "\t" << fi.absoluteFilePath(); if ( b_AddOrdinalNumber == true ) { if ( b_PrependMetadataColumn == false ) tout << "\t" << QString( "%1" ).arg( ++k ); else tout << "\t" << QString( "%1" ).arg( k ); } } tout << s_EOL; } while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) ) { if ( LineCanBeWritten( sl_Input.at( i ), b_SkipEmptyLines, b_SkipCommentLines ) == true ) { if ( b_PrependMetadataColumn == true ) { if ( b_AddFilename == true ) tout << fi.baseName() << "\t"; if ( b_AddFullPath == true ) tout << fi.absoluteFilePath() << "\t"; if ( b_AddOrdinalNumber == true ) tout << QString( "%1" ).arg( ++k ) << "\t"; } tout << sl_Input.at( i ); if ( b_AppendMetadataColumn == true ) { if ( b_AddFilename == true ) tout << "\t" << fi.baseName(); if ( b_AddFullPath == true ) tout << "\t" << fi.absoluteFilePath(); if ( b_AddOrdinalNumber == true ) { if ( b_PrependMetadataColumn == false ) tout << "\t" << QString( "%1" ).arg( ++k ); else tout << "\t" << QString( "%1" ).arg( k ); } } tout << s_EOL; } stopProgress = incProgress( i_NumOfFiles, ++i ); } resetProgress( i_NumOfFiles ); // ********************************************************************************************** fout.close(); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
int MainWindow::findArea( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, QVector<AreaItem> &v_Area, QVector<PositionItem> &v_Position, const bool b_DeleteInputFile, const int i_NumOfFiles) { int i = 1; int j = 0; int n = 0; int m = 0; int i_LatID = -1; int i_LongID = -1; int stopProgress = -1; double d_Latitude_dummy = -1000.; double d_Longitude_dummy = -1000.; double d_Latitude = -1000.; double d_Longitude = -1000.; QString s_AreaName = "???"; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( n ); m = NumOfSections( sl_Input.at( 0 ) ); j = 0; while ( ( i_LatID < 0 ) && ( j < m ) ) { if ( sl_Input.at( 0 ).section( "\t", j, j ).contains( "Latitude", Qt::CaseInsensitive ) == true ) i_LatID = j; else j++; } j = 0; while ( ( i_LongID < 0 ) && ( j < m ) ) { if ( sl_Input.at( 0 ).section( "\t", j, j ).contains( "Longitude", Qt::CaseInsensitive ) == true ) i_LongID = j; else j++; } if ( ( i_LatID < 0 ) || ( i_LongID < 0 ) ) return( -40 ); // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Finding areas..." ), sl_Input.count() ); // ********************************************************************************************** tout << "Area\t" << sl_Input.at( 0 ) << s_EOL; while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) ) { d_Latitude = (double) qMin( sl_Input.at( i ).section( "\t", i_LatID, i_LatID ).toFloat() + 90., 179.99 ); // 0 - 179.99 d_Longitude = (double) qMin( sl_Input.at( i ).section( "\t", i_LongID, i_LongID ).toFloat() + 180., 359.99 ); // 0 - 359.99 if ( ( d_Latitude-d_Latitude_dummy > 0.001 ) || ( d_Longitude-d_Longitude_dummy > 0.001 ) || ( d_Latitude-d_Latitude_dummy < -0.001 ) || ( d_Longitude-d_Longitude_dummy < -0.001 ) ) { int j = 0; int k = 0; int i_InPolygon = 0; while ( j < v_Area.count() ) { if ( ( v_Area.at( j ).maxLatitude() > d_Latitude ) && ( d_Latitude > v_Area.at( j ).minLatitude() ) ) { if ( ( v_Area.at( j ).maxLongitude() > d_Longitude ) && ( d_Longitude > v_Area.at( j ).minLongitude() ) ) { i_InPolygon = PtInPolygon( d_Latitude, d_Longitude, v_Area.at( j ).StartPosition(), v_Area.at( j ).NumOfPoints(), v_Position ); if ( i_InPolygon == 1 ) { s_AreaName = v_Area.at( j ).AreaName(); s_AreaName.replace( ", western part", "" ); s_AreaName.replace( ", eastern part", "" ); d_Latitude_dummy = d_Latitude; d_Longitude_dummy = d_Longitude; tout << s_AreaName << "\t" << sl_Input.at( i ) << s_EOL; j = v_Area.count() - 1; } } } k += v_Area.at( j ).NumOfPoints(); j += 1; } if ( i_InPolygon < 1 ) { d_Latitude_dummy = d_Latitude; d_Longitude_dummy = d_Longitude; if ( d_Latitude > 160. ) s_AreaName = "Arctic Ocean"; else s_AreaName = "???"; tout << s_AreaName << "\t" << sl_Input.at( i ) << s_EOL; } } else { tout << s_AreaName << "\t" << sl_Input.at( i ) << s_EOL; } stopProgress = incProgress( i_NumOfFiles, ++i ); } //-------------------------------------------------------------------------------------------- resetProgress( i_NumOfFiles ); fout.close(); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); if ( b_DeleteInputFile == true ) removeFile( s_FilenameIn ); return( _NOERROR_ ); }
int MainWindow::buildAreaDatabase( const QString &s_FilenameIn, const int i_CodecInput, const int i_NumOfFiles ) { int n = 0; int stopProgress = 0; int i = 0; int i_NumOfAreas = 0; int i_NumOfPositions = 0; int i_StartPosition = 0; int i_AreaNamePosition = -1; int i_LatitudePosition = -1; int i_LongitudePosition = -1; double d_Lat = 0.; double d_Long = 0.; double d_minLat = 180.; double d_maxLat = 0.; double d_minLong = 360.; double d_maxLong = 0.; QString s_AreaName = ""; QString s_Header = ""; QStringList sl_Input; QVector<AreaItem> v_Area; QVector<PositionItem> v_Position; // ********************************************************************************************** QFileInfo fi( s_FilenameIn ); QFile fout( fi.absolutePath() + "/" + fi.baseName() + ".adb" ); if ( fout.open( QIODevice::WriteOnly ) == false ) return( -20 ); // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( n ); if ( sl_Input.at( i ).contains( "/*" ) == true ) { while ( ( i < n ) && ( sl_Input.at( i ).contains( "*/" ) == false ) ) i++; } // ********************************************************************************************** // check file format (plain text or doi:10.1594/PANGAEA.777975) if ( i > 0 ) { if ( n-i++ < 4 ) return ( -40 ); } else { if ( n < 4 ) return ( -40 ); } s_Header = sl_Input.at( i++ ); for ( int j=0; j<s_Header.count(); j++ ) { if ( ( s_Header.section( "\t", j, j ) == "Name" ) || ( s_Header.section( "\t", j, j ) == "Name of area" ) || ( s_Header.section( "\t", j, j ) == "Campaign" ) ) i_AreaNamePosition = j; if ( s_Header.section( "\t", j, j ) == "Latitude" ) i_LatitudePosition = j; if ( s_Header.section( "\t", j, j ) == "Longitude" ) i_LongitudePosition = j; } if ( ( i_AreaNamePosition < 0 ) || ( i_LatitudePosition < 0 ) || ( i_LongitudePosition < 0 ) ) return( -40 ); // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Building area database (read data) ..." ), n ); while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) ) { d_minLat = 1000.0; d_maxLat = -1000.0; d_minLong = 1000.0; d_maxLong = -1000.0; i_NumOfPositions = 0; i_StartPosition = v_Position.count(); s_AreaName = sl_Input.at( i ).section( "\t", i_AreaNamePosition, i_AreaNamePosition ); while ( ( i < n ) && ( ( sl_Input.at( i ).section( "\t", i_AreaNamePosition, i_AreaNamePosition ) == s_AreaName ) || ( sl_Input.at( i ).section( "\t", i_AreaNamePosition, i_AreaNamePosition ).isEmpty() == true ) ) && ( stopProgress != _APPBREAK_ ) ) { i_NumOfPositions++; d_Lat = (double) qMin( sl_Input.at( i ).section( "\t", i_LatitudePosition, i_LatitudePosition ).toFloat() + 90., 179.99 ); d_Long = (double) qMin( sl_Input.at( i ).section( "\t", i_LongitudePosition, i_LongitudePosition ).toFloat() + 180., 359.99 ); v_Position.append( PositionItem( d_Lat, d_Long ) ); d_minLat = qMin( d_minLat, v_Position.last().Latitude() ); d_maxLat = qMax( d_maxLat, v_Position.last().Latitude() ); d_minLong = qMin( d_minLong, v_Position.last().Longitude() ); d_maxLong = qMax( d_maxLong, v_Position.last().Longitude() ); stopProgress = incProgress( i_NumOfFiles, ++i ); } v_Area.append( AreaItem( s_AreaName, i_StartPosition, i_NumOfPositions, d_minLat, d_maxLat, d_minLong, d_maxLong ) ); } resetProgress( i_NumOfFiles ); //---------------------------------------------------------------------------------------------------- if ( stopProgress != _APPBREAK_ ) { i_NumOfAreas = v_Area.count(); i_NumOfPositions = v_Position.count(); QByteArray ba( "PanTool area database\n" ); // 0 ba.append( QString( "Created:\t%1\n" ).arg( QDateTime::currentDateTime().toString( Qt::ISODate ) ) ); // 1 ba.append( QString( "Number of areas:\t%1\n" ).arg( i_NumOfAreas ) ); // 2 ba.append( QString( "Number of positions:\t%1\n" ).arg( i_NumOfPositions ) ); // 3 ba.append( "\n[Areas]\n" ); ba.append( "Name of area\tStart position\tNumber of positions\tmax Lat\tmax Long\tmin Lat\tmin Long\n" ); // 4 for ( i=0; i<i_NumOfAreas; i++ ) { ba.append( v_Area.at( i ).AreaName() + "\t" ); ba.append( QString( "%1\t%2\t%3\t%4\t%5\t%6\n" ).arg( v_Area.at( i ).StartPosition() ).arg( v_Area.at( i ).NumOfPoints() ).arg( v_Area.at( i ).maxLatitude() ).arg( v_Area.at( i ).maxLongitude() ).arg( v_Area.at( i ).minLatitude() ).arg( v_Area.at( i ).minLongitude() ) ); } initProgress( i_NumOfFiles, s_FilenameIn, tr( "Building area database (write data) ..." ), i_NumOfPositions ); i = 0; ba.append( "\n[Positions]\n" ); ba.append( "Latitude\tLongitude\n" ); while ( ( i<i_NumOfPositions ) && ( stopProgress != _APPBREAK_ ) ) { ba.append( QString( "%1\t%2\n" ).arg( v_Position.at( i ).Latitude(), 0, 'f', 6 ).arg( v_Position.at( i ).Longitude(), 0, 'f', 6 ) ); stopProgress = incProgress( i_NumOfFiles, ++i ); } resetProgress( i_NumOfFiles ); fout.write( qCompress( ba, 9 ) ); fout.close(); } return( _NOERROR_ ); }
int MainWindow::replaceCharactersAtPosition( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const QString &s_CharacterPositionsList, const QString &ReplaceStr, const bool b_SkipEmptyLines, const bool b_SkipCommentLines, const int i_NumOfFiles ) { int i = 0; int n = 0; int m = 0; int stopProgress = 0; QString s_Output = ""; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; QList<int> il_PositionList; // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( n ); if ( ( m = sl_Input.at( 0 ).length() ) < 1 ) return( -80 ); il_PositionList = scanList( _REPLACECHARS, 99999, s_CharacterPositionsList ); if ( il_PositionList.count() < 1 ) { QFile::remove( s_FilenameOut ); // if exists from older run return( -81 ); } // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Replace characters at position..." ), sl_Input.count() ); while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) ) { s_Output = sl_Input.at( i ).left( il_PositionList.at( 0 ) ); for ( int j=0; j<il_PositionList.count()-1; j++ ) s_Output.append( ReplaceStr + sl_Input.at( i ).mid( il_PositionList.at( j ) + 1, il_PositionList.at( j+1 ) - il_PositionList.at( j ) - 1 ) ); s_Output.append( ReplaceStr + sl_Input.at( i ).mid( il_PositionList.last() + 1 ) ); s_Output.replace( "^t", "\t" ); s_Output.replace( "^n", "\n" ); if ( LineCanBeWritten( s_Output, b_SkipEmptyLines, b_SkipCommentLines ) == true ) tout << s_Output << s_EOL; stopProgress = incProgress( i_NumOfFiles, ++i ); } resetProgress( i_NumOfFiles ); // ********************************************************************************************** fout.close(); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
int MainWindow::createKmlFile( const QString &s_FilenameIn, int &i_IconColor, int &i_IconSize, int &i_TracklineColor, int &i_TracklineWidth, QString &s_FilenameGoogleEarthProgram, bool &b_startGoogleEarth, QString &s_FilenameOut, const int i_NumOfFiles ) { int i = 0; int n = 0; int stopProgress = 0; int i_ID = 0; int i_StartID = 0; int i_EndID = 0; double d_Distance = 0.0; double d_Speed = 0.0; double d_Latitude = 0.0; double d_Longitude = 0.0; double d_Latitude_old = 0.0; double d_Longitude_old = 0.0; double d_Seconds_old = 0.0; double d_PlotDistance = 100.0; QString s_Date = ""; QString s_Time = ""; QString s_Latitude = ""; QString s_Longitude = ""; QString s_TrackName = ""; QStringList sl_Input; QFileInfo fi( s_FilenameIn ); // ********************************************************************************************** // read file QFile fin( s_FilenameIn ); if ( fin.open( QIODevice::ReadOnly | QIODevice::Text ) == false ) return( -10 ); QTextStream tin( &fin ); while ( tin.atEnd() == false ) sl_Input.append( tin.readLine().replace( QChar( 0x00 ), "" ) ); fin.close(); n = sl_Input.count(); // ********************************************************************************************** if ( ( n<2 ) || ( sl_Input.at( i++ ) != "INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE E/W,HEIGHT,SPEED,HEADING,VOX" ) ) return( _APPBREAK_ ); i_StartID = sl_Input.at( 1 ).section( ",", 0, 0 ).toInt(); i_EndID = sl_Input.at( sl_Input.count() - 1 ).section( ",", 0, 0 ).toInt(); s_TrackName = fi.baseName(); if ( doGPStoKmlOptionsDialog( i_StartID, i_EndID, i_IconColor, i_IconSize, i_TracklineColor, i_TracklineWidth, s_TrackName, s_FilenameGoogleEarthProgram, b_startGoogleEarth ) == QDialog::Rejected ) return( _APPBREAK_ ); // ********************************************************************************************** // open output file s_FilenameOut = fi.absolutePath() + "/" + s_TrackName + ".kml"; QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) { s_FilenameOut = ""; return( -20 ); } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Creating KML file..." ), 2*sl_Input.count() ); // ********************************************************************************************** QTextStream tout( &fout ); tout.setCodec( "UTF-8" ); tout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; tout << "<kml xmlns=\"http://earth.google.com/kml/2.1\">" << endl; tout << "<Document>" << endl; /* tout << " <ScreenOverlay>" << endl; tout << " <name>Pan2Applic logo</name>" << endl; tout << " <Icon><href>http://epic.awi.de/40953/121/Pan2Applic_logo.png</href></Icon>" << endl; tout << " <overlayXY x=\"0\" y=\"1\" xunits=\"fraction\" yunits=\"fraction\"/>" << endl; tout << " <screenXY x=\"5\" y=\"5\" xunits=\"pixels\" yunits=\"insetPixels\"/>" << endl; tout << " <size x=\"200\" y=\"88\" xunits=\"pixel\" yunits=\"pixel\"/>" << endl; tout << " </ScreenOverlay>" << endl; */ tout << " <Style id=\"circle-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/1/circle-blue.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"circle-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/2/circle-green.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"circle-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/3/circle-orange.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"circle-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/4/circle-red.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"circle-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/5/circle-white.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"circle-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/6/circle-yellow.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"square-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/7/square-blue.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"square-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/8/square-green.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"square-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/9/square-orange.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"square-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/10/square-red.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"square-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/11/square-white.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"square-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/12/square-yellow.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"star-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/13/star-blue.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"star-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/14/star-green.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"star-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/15/star-orange.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"star-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/16/star-red.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"star-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/17/star-white.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"star-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/18/star-yellow.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"triangle-blue\"><IconStyle><Icon><href>http://epic.awi.de/40953/19/triangle-blue.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"triangle-green\"><IconStyle><Icon><href>http://epic.awi.de/40953/20/triangle-green.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"triangle-orange\"><IconStyle><Icon><href>http://epic.awi.de/40953/21/triangle-orange.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"triangle-red\"><IconStyle><Icon><href>http://epic.awi.de/40953/22/triangle-red.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"triangle-white\"><IconStyle><Icon><href>http://epic.awi.de/40953/23/triangle-white.png</href></Icon></IconStyle></Style>" << endl; tout << " <Style id=\"triangle-yellow\"><IconStyle><Icon><href>http://epic.awi.de/40953/24/triangle-yellow.png</href></Icon></IconStyle></Style>" << endl; // ********************************************************************************************** // Way points tout << "<Folder>" << endl; tout << "<name>Point Set</name>" << endl; tout << "<open>0</open>" << endl; while ( ( i<n ) && ( stopProgress != _APPBREAK_ ) ) { if ( sl_Input.at( i ).section( ",", 1, 1 ) == "T" ) { i_ID = sl_Input.at( i ).section( ",", 0, 0 ).toInt(); if ( ( i_StartID <= i_ID ) && ( i_ID <= i_EndID ) ) { s_Time = sl_Input.at( i ).section( ",", 3, 3 ).left( 2 ) + ":" + sl_Input.at( i ).section( ",", 3, 3 ).mid( 2, 2 ) + ":" + sl_Input.at( i ).section( ",", 3, 3 ).mid( 4, 2 ); s_Date = "20" + sl_Input.at( i ).section( ",", 2, 2 ).left( 2 ) + "-" + sl_Input.at( i ).section( ",", 2, 2 ).mid( 2, 2 ) + "-" + sl_Input.at( i ).section( ",", 2, 2 ).mid( 4, 2 ); s_Latitude = extractLatitude( sl_Input.at(i) ); s_Longitude = extractLongitude( sl_Input.at(i) ); d_Latitude = s_Latitude.toDouble(); d_Longitude = s_Longitude.toDouble(); d_Distance = calculateDistance( d_Latitude, d_Longitude, d_Latitude_old, d_Longitude_old ); // [m] if ( ( i_ID == i_StartID ) || ( i_ID == i_EndID ) || ( d_Distance > d_PlotDistance ) ) { d_Speed = 3.6 * d_Distance/( (double) i - d_Seconds_old ); // [m/s] -> [km/h] tout << "<Placemark>"; // tout << "<name>" << s_Time << "</name>"; switch ( i_IconColor ) { case _RED_: tout << "<styleUrl>#red</styleUrl>"; break; case _GREEN_: tout << "<styleUrl>#green</styleUrl>"; break; case _BLUE_: tout << "<styleUrl>#blue</styleUrl>"; break; case _ORANGE_: tout << "<styleUrl>#orange</styleUrl>"; break; case _YELLOW_: tout << "<styleUrl>#yellow</styleUrl>"; break; default: tout << "<styleUrl>#red</styleUrl>"; break; } tout << "<Style><IconStyle>" << QString( "<scale>%1</scale>" ).arg( (float) i_IconSize/100. ) << "</IconStyle></Style>"; tout << "<Point><coordinates>" << s_Longitude << "," << s_Latitude << "</coordinates></Point>"; tout << "<description>" << endl; tout << "<![CDATA[Time: " << s_Time << "<br />Date: " << s_Date << "<br />Latitude: " << d_Latitude << "° N<br />Longitude: " << d_Longitude << "° E<br />Altitude: " << sl_Input.at( i ).section( ",", 6, 6 ).simplified() << " m<br />Speed: " << d_Speed << " km/h<br />ID: " << i_ID << "<br />]]>" << endl; tout << "</description>" << endl; tout << "</Placemark>" << endl; d_Latitude_old = d_Latitude; d_Longitude_old = d_Longitude; d_Seconds_old = (double) i; if ( d_Speed < 50. ) d_PlotDistance = 100; else d_PlotDistance = 1000; } } } stopProgress = incProgress( i_NumOfFiles, ++i ); } tout << "</Folder>" << endl; // ********************************************************************************************** // Track line tout << "<Placemark><name>Trackline</name>" << endl; switch ( i_TracklineColor ) { case _RED_: tout << "<Style><LineStyle><color>ff0000ff</color>"; break; case _GREEN_: tout << "<Style><LineStyle><color>ff00ff00</color>"; break; case _BLUE_: tout << "<Style><LineStyle><color>ffff0000</color>"; break; case _ORANGE_: tout << "<Style><LineStyle><color>ff0099ff</color>"; break; case _YELLOW_: tout << "<Style><LineStyle><color>ff33ffff</color>"; break; default: tout << "<Style><LineStyle><color>ff0099ff</color>"; break; } tout << "<width>" << (float) i_TracklineWidth/10. << "</width></LineStyle></Style>" << endl; tout << "<LineString>" << endl; tout << "<tessellate>1</tessellate>" << endl; tout << "<coordinates>" << endl; i = 1; while ( ( i<n ) && ( stopProgress != _APPBREAK_ ) ) { if ( sl_Input.at( i ).section( ",", 1, 1 ) == "T" ) { i_ID = sl_Input.at( i ).section( ",", 0, 0 ).toInt(); if ( ( i_StartID <= i_ID ) && ( i_ID <= i_EndID ) ) { s_Latitude = extractLatitude( sl_Input.at(i) ); s_Longitude = extractLongitude( sl_Input.at(i) ); tout << s_Longitude << "," << s_Latitude << "," << sl_Input.at( i ).section( ",", 6, 6 ).simplified() << endl; } } stopProgress = incProgress( i_NumOfFiles, ++i+n ); } tout << "</coordinates>" << endl; tout << "</LineString>" << endl; tout << "</Placemark>" << endl; tout << "</Document>" << endl; tout << "</kml>" << endl; fout.close(); resetProgress( i_NumOfFiles ); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
int MainWindow::convertTSG( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_NumOfFiles ) { int i = 1; int n = 0; int stopProgress = 0; QString s = ""; QString s_DateTime = ""; QString s_Position = ""; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( -10 ); // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting TSG data..." ), sl_Input.count() ); // ********************************************************************************************** tout << "Event label" << "\t" << "Date/Time" << "\t" << "Latitude" << "\t" << "Longitude" << "\t"; tout << "Depth, water [m]" << "\t" << "Temperature, water [C]@ITS-90" << "\t" << "Salinity []" << s_EOL; tout << "PS-track"; while ( ( i<sl_Input.count() ) && ( stopProgress != _APPBREAK_ ) ) { s_DateTime = sl_Input.at( i ).section( "\t", 0, 0 ); s_DateTime.replace( " ", "T" ); s_Position = sl_Input.at( i ).section( "\t", 1, 2 ); s_Position.replace( " ", "" ); s = sl_Input.at( i ).section( "\t", 3, 4 ); s.replace( " ", "" ); s.replace( "-999.000000", "" ); if ( s != "\t" ) tout << "\t" + s_DateTime << "\t" << s_Position << "\t5\t" << s << s_EOL; s = sl_Input.at( i ).section( "\t", 5, 6 ); s.replace( " ", "" ); s.replace( "-999.000000", "" ); if ( s != "\t" ) tout << "\t" + s_DateTime << "\t" << s_Position << "\t11\t" << s << s_EOL; stopProgress = incProgress( i_NumOfFiles, ++i ); } fout.close(); resetProgress( i_NumOfFiles ); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
int MainWindow::createOceanDataViewFile( QStringList &sl_MetadataList, QStringList &sl_ParameterList, const QString &s_FilenameOut, const int i_CodecInput, const int i_Env, const int i_DeviceTypeOceanDataView, const bool b_showShortName, const bool b_showMethod, const bool b_showComment, const bool b_usePANGAEAQualityFlags, const bool b_setGeocode, const bool b_addLineNo, const float f_GEOCODE_min, const float f_GEOCODE_max, const QString &s_GEOCODE_min, const QString &s_GEOCODE_max, const bool b_setGearID, const int i_GearID, const int i_NumOfFiles ) { QVector<int> vi_pos; QVector<int> vi_posQV; QVector<int> vi_SpecialPos; int i_NumOfRemovedLines = 0; int i_NumOfHeaderItems = 0; int i_GeocodePos = -1; int i_GearIDPos = -1; int i_File = 0; int i_stopFileProgress = 0; int stopProgress = 0; int err = _NOERROR_; int i = 0; int n = 0; bool b_containsDOI = false; QString s_FieldDelimiter = "\t"; QString s_Environment = ""; QString s_DeviceType = "*"; QString s_Output = ""; QString s_FilenameIn = sl_MetadataList.at( 1 ).section( "\t", _FILENAMEPOS, _FILENAMEPOS ); QStringList sld_ParameterList; QStringList sl_Input; QStringList sl_Output; QDateTime dt_GEOCODE_min( QDateTime::fromString( (QString) s_GEOCODE_min, Qt::ISODate ) ); QDateTime dt_GEOCODE_max( QDateTime::fromString( (QString) s_GEOCODE_max, Qt::ISODate ) ); //----------------------------------------------------------------------------------------------------------------------- if ( sl_ParameterList.count() == 0 ) return( -60 ); //----------------------------------------------------------------------------------------------------------------------- i_NumOfHeaderItems = buildODVHeader( sl_Output, sl_ParameterList, vi_posQV, i_Env, b_showShortName, b_showMethod, b_showComment, b_usePANGAEAQualityFlags ); if ( i_NumOfHeaderItems < 0 ) return( i_NumOfHeaderItems ); // return as error, -70 = Latitude/Longitude not given, -71 = Latitude not given, -72 = Longitude not given //----------------------------------------------------------------------------------------------------------------------- QFile ftext( s_FilenameOut ); if ( ftext.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &ftext ); //----------------------------------------------------------------------------------------------------------------------- initFileProgress( i_NumOfFiles, s_FilenameIn, tr( "Creating Ocean Data View file..." ) ); //----------------------------------------------------------------------------------------------------------------------- // write header tout << "//<Version>ODV Spreadsheet V4.0</Version>" << endl; tout << "//<Creator>" << "</Creator>" << endl; tout << "//<CreateTime>" << QDateTime::currentDateTime().toString( "yyyy-MM-ddThh:mm" ) << "</CreateTime>" << endl; tout << "//<Software>" << getApplicationName( true ) << " " << _VERSION_ << "</Software>" << endl; tout << "//<Source>" << QDir::toNativeSeparators( s_FilenameOut ) << "</Source>" << endl; tout << "//<SourceLastModified>" << QDateTime::currentDateTime().toString( "yyyy-MM-ddThh:mm" ) << "</SourceLastModified>" << endl; tout << "//<DataField>GeneralField</DataField>" << endl; tout << "//<DataType>GeneralType</DataType>" << endl; tout << "//" << endl; //----------------------------------------------------------------------------------------------------------------------- i_GeocodePos = getGeocodePosition( sl_ParameterList, i_Env ); i_GearIDPos = getGearIDPosition( sl_ParameterList ); b_containsDOI = sl_Output.contains( "DOI:METAVAR:TEXT:51" ); tout << sl_Output.join( s_FieldDelimiter ) << endl; //----------------------------------------------------------------------------------------------------------------------- // find position of date/time parameters getSpecialPos( sl_ParameterList, vi_SpecialPos ); //----------------------------------------------------------------------------------------------------------------------- s_DeviceType = setDeviceType( i_DeviceTypeOceanDataView ); //----------------------------------------------------------------------------------------------------------------------- i_File = 1; while ( ( i_File <= i_NumOfFiles ) && ( err == _NOERROR_ ) && ( i_stopFileProgress != _APPBREAK_ ) ) { if ( containsSelectedEnvironment( _SELECTPARAMETER, sl_MetadataList.at( i_File ).section( "\t", _ENVIRONMENTPOS, _ENVIRONMENTPOS ).toInt(), i_Env ) == true ) { s_FilenameIn = sl_MetadataList.at( i_File ).section( "\t", _FILENAMEPOS, _FILENAMEPOS ); if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) > 0 ) { i = 0; sld_ParameterList.clear(); vi_pos.clear(); initProgress( i_NumOfFiles, s_FilenameIn, tr( "Ocean Data View converter is working..." ), n ); setStatusBarFileInProgress( s_FilenameIn ); //----------------------------------------------------------------------------------------------------------------------- // read header and find position of parameter s_Environment = sl_MetadataList.at( i_File ).section( "\t", _ENVIRONMENTPOS, _ENVIRONMENTPOS ) + _PSEPARATOR_; stopProgress = incProgress( i_NumOfFiles, i ); if ( sl_Input.at( i ).startsWith( "/* DATA DESCRIPTION:" ) == true ) // file starts with PANGAEA header { while ( ( i < n ) && ( sl_Input.at( i ).startsWith( "*/" ) == false ) ) { if ( sl_Input.at( i ).startsWith( "Parameter(s):" ) == true ) { while ( ( i < n ) && ( ( sl_Input.at( i ).startsWith( "Parameter(s):" ) == true ) || ( sl_Input.at( i ).startsWith( "\t" ) == true ) ) ) { sld_ParameterList.append( s_Environment + buildParameter( sl_Input.at( i ).section( "\t", 1, 1 ) ) ); if ( ++i < n ) stopProgress = incProgress( i_NumOfFiles, i ); } } if ( ++i < n ) stopProgress = incProgress( i_NumOfFiles, i ); } for ( int j=0; j<sl_ParameterList.count(); ++j ) vi_pos.append( containsParameter( true, sld_ParameterList, sl_ParameterList.at( j ), b_showShortName, b_showMethod, b_showComment ) ); if ( ++i < n ) stopProgress = incProgress( i_NumOfFiles, i ); } else { sld_ParameterList = buildParameterList( s_Environment, sl_Input.at( i ) ); // not a PANGAEA dataset for ( int j=0; j<sl_ParameterList.count(); ++j ) vi_pos.append( containsParameter( false, sld_ParameterList, sl_ParameterList.at( j ), b_showShortName, b_showMethod, b_showComment ) ); } //----------------------------------------------------------------------------------------------------------------------- // write output string if ( ( b_setGeocode == true ) || ( b_setGearID == true ) ) { while ( ( ++i < n ) && ( stopProgress != _APPBREAK_ ) ) { sl_Output = buildODVOutputStr( i+1, b_addLineNo, sl_Input.at( i ), sl_MetadataList.at( i_File ), vi_pos, vi_posQV, vi_SpecialPos, b_usePANGAEAQualityFlags, b_containsDOI, s_DeviceType, s_FieldDelimiter ); if ( writeDataLine( b_setGeocode, b_setGearID, i_GeocodePos, i_GearIDPos, sl_Output, i_Env, dt_GEOCODE_min, dt_GEOCODE_max, f_GEOCODE_min, f_GEOCODE_max, i_GearID ) == true ) { s_Output = sl_Output.join( s_FieldDelimiter ); if ( s_Output.contains( "delete line" ) == false ) tout << s_Output << endl; else ++i_NumOfRemovedLines; } stopProgress = incProgress( i_NumOfFiles, i ); } } else { while ( ( ++i < n ) && ( stopProgress != _APPBREAK_ ) ) { sl_Output = buildODVOutputStr( i+1, b_addLineNo, sl_Input.at( i ), sl_MetadataList.at( i_File ), vi_pos, vi_posQV, vi_SpecialPos, b_usePANGAEAQualityFlags, b_containsDOI, s_DeviceType, s_FieldDelimiter ); s_Output = sl_Output.join( s_FieldDelimiter ); if ( s_Output.contains( "delete line" ) == false ) tout << s_Output << endl; else ++i_NumOfRemovedLines; stopProgress = incProgress( i_NumOfFiles, i ); } } resetProgress( i_NumOfFiles ); } } i_stopFileProgress = incFileProgress( i_NumOfFiles, i_File++ ); } //----------------------------------------------------------------------------------------------------------------------- resetFileProgress( i_NumOfFiles ); ftext.close(); return( i_NumOfRemovedLines ); }
int MainWindow::RadiosondeEquipmentConverter( const QString &s_FilenameIn, QStringList &sl_FilenameOut, structMethod *Method_ptr, structStation *Station_ptr, const int i_NumOfFiles ) { int i_Year = 2000; int i_Month = 1; int i_Day = 1; int i_StationNumber = 0; int i_MethodID = 0; QString InputStr = ""; QString s_RadiosondeIdentification = ""; QString SearchString1 = "*C0005"; QString SearchString2 = "*U0005"; QString s_StationName = ""; QString s_EventLabel = ""; unsigned int ui_length = 1; unsigned int ui_filesize = 1; bool b_Stop = false; // *********************************************************************************************************************** QFileInfo fi( s_FilenameIn ); if ( ( fi.exists() == false ) || ( fi.suffix().toLower() == "zip" ) || ( fi.suffix().toLower() == "gz" ) ) return( _FILENOEXISTS_ ); // *********************************************************************************************************************** QFile fin( s_FilenameIn ); if ( fin.open( QIODevice::ReadOnly | QIODevice::Text ) == false ) return( -10 ); ui_filesize = fin.size(); // *********************************************************************************************************************** QTextStream tin( &fin ); // *********************************************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Radiosonde equipment converter working ..." ), 100 ); // *********************************************************************************************************************** InputStr = tin.readLine(); ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr ); if ( ( InputStr.startsWith( "*C0001" ) == false ) && ( InputStr.startsWith( "*U0001" ) == false ) ) { resetProgress( i_NumOfFiles ); fin.close(); return( -40 ); } // *********************************************************************************************************************** InputStr = tin.readLine(); ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr ); i_StationNumber = InputStr.left( 3 ).toInt(); s_StationName = findStationName( i_StationNumber, Station_ptr ); s_EventLabel = findEventLabel( i_StationNumber, Station_ptr ); // *********************************************************************************************************************** i_Day = 1; i_Month = InputStr.mid( 4, 2 ).toInt(); i_Year = InputStr.mid( 7, 4 ).toInt(); QDateTime dt = QDateTime().toUTC(); dt.setDate( QDate( i_Year, i_Month, i_Day ) ); dt.setTime( QTime( 0, 0, 0 ) ); // *********************************************************************************************************************** if ( checkFilename( fi.fileName(), s_EventLabel, InputStr.mid( 4, 2 ), InputStr.mid( 9, 2 ) ) == false ) { resetProgress( i_NumOfFiles ); fin.close(); return( -41 ); } // *********************************************************************************************************************** QFile fout( fi.absolutePath() + "/" + s_EventLabel + "_" + dt.toString( "yyyy-MM" ) + "_0005.txt" ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text ) == false ) { resetProgress( i_NumOfFiles ); fin.close(); return( -20 ); } QTextStream tout( &fout ); appendItem( sl_FilenameOut, fout.fileName() ); // *********************************************************************************************************************** // LR0005 tout << "File name\tStation ID\tEvent label\tStation\tYYYY-MM\t"; tout << "Manufacturer\tLocation\tDistance from radiation site [km]\t"; tout << "Time of 1st launch [hh]\tTime of 2nd launch [hh]\tTime of 3rd launch [hh]\t"; tout << "Time of 4th launch [hh]\tIdentification of radiosonde\tRemarks\t"; tout << "PANGAEA method\tPANGAEA method ID" << endl; while ( ( tin.atEnd() == false ) && ( ui_length != (unsigned int) _APPBREAK_ ) && ( b_Stop == false ) ) { InputStr = tin.readLine(); ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr ); if ( ( InputStr.startsWith( SearchString1 ) == true ) || ( InputStr.startsWith( SearchString2 ) == true ) ) { tout << s_EventLabel.toLower() << dt.toString( "MMyy" ) << ".dat" << "\t"; tout << i_StationNumber << "\t" << s_EventLabel << "\t" << s_StationName << "\t" << dt.toString( "yyyy-MM" ) << "\t"; InputStr = tin.readLine(); ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr ); if ( InputStr.simplified().right( 1 ) == "Y" ) { InputStr = tin.readLine(); ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr ); tout << InputStr.left( 30 ).simplified() << "\t"; tout << InputStr.mid( 30, 25 ).simplified() << "\t"; tout << InputStr.mid( 57, 3 ) << "\t"; tout << InputStr.mid( 61, 2 ) << "\t"; tout << InputStr.mid( 64, 2 ) << "\t"; tout << InputStr.mid( 67, 2 ) << "\t"; tout << InputStr.mid( 70, 2 ) << "\t"; tout << InputStr.mid( 73, 5 ).simplified() << "\t"; s_RadiosondeIdentification = InputStr.left( 30 ).simplified(); if ( InputStr.mid( 73, 5 ).simplified().isEmpty() == false ) s_RadiosondeIdentification += ", " + InputStr.mid( 73, 5 ).simplified(); i_MethodID = findMethodID( s_RadiosondeIdentification, Method_ptr ); InputStr = tin.readLine(); ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr ); tout << InputStr.simplified() << "\t" << "Radiosonde, " << s_RadiosondeIdentification << "\t"; tout << i_MethodID << endl; } b_Stop = true; } // Abort if first data record reached if ( ( InputStr.startsWith( "*C0100" ) == true ) || ( InputStr.startsWith( "*U0100" ) == true ) ) b_Stop = true; } //--------------------------------------------------------------------------------------------------- resetProgress( i_NumOfFiles ); fin.close(); fout.close(); if ( ui_length == (unsigned int) _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
int MainWindow::CliwocConverter( const QString &s_FilenameIn, const QString &s_FilenameOut, const QString &s_FilenameConf, const int i_NumOfFiles ) { int k = 0; int n = 0; QString InputStr = ""; QString s_EventLabel = ""; QStringList sl_Conf; unsigned int ui_length = 1; unsigned int ui_filesize = 1; // ********************************************************************************************** n = readFile( s_FilenameConf, sl_Conf ); if ( n < 9 ) return( _ERROR_ ); // ********************************************************************************************** // open input file QFile fin( s_FilenameIn ); if ( fin.open( QIODevice::ReadOnly | QIODevice::Text ) == false ) return( -10 ); ui_filesize = fin.size(); QTextStream tin( &fin ); // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text ) == false ) return( -20 ); QTextStream tout( &fout ); // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting..." ), 100 ); // ********************************************************************************************** // read file // Header tout << k++ << "\t" << "Event label" << "\t" << "Date/Time" << "\t" << "Latitude" << "\t" << "Longitude"; for ( int i=9; i<n; i++ ) { if ( sl_Conf.at( i ).section( "\t", 0, 0 ) == "x" ) tout << "\t" << sl_Conf.at( i ).section( "\t", 3, 3 ); // Column no 4: Parameter name } tout << endl; while ( ( tin.atEnd() == false ) && ( ui_length != (unsigned int) _APPBREAK_ ) ) { InputStr = tin.readLine(); ui_length = incProgress( i_NumOfFiles, ui_filesize, ui_length, InputStr ); // Event label s_EventLabel = "@" + InputStr.mid( 34, 9 ).simplified() + "_" + InputStr.mid( 2597, 8 ).simplified() + "_" + InputStr.mid( 297, 30 ).simplified(); s_EventLabel.replace( "EXTRACT ", "" ); s_EventLabel.replace( ",", "" ); s_EventLabel.replace( ".", "" ); s_EventLabel.replace( "(", "-" ); s_EventLabel.replace( ")", "" ); s_EventLabel.replace( " ", "_" ); s_EventLabel.replace( "_-_", "_" ); s_EventLabel.replace( "_-", "_" ); s_EventLabel.replace( "-_", "_" ); s_EventLabel.replace( "__", "_" ); s_EventLabel.replace( "'", "" ); tout << k++ << "\t" << s_EventLabel << "\t"; // Date/Time QString s_DateTime = InputStr.mid( 0, 4 ) + tr( "-" ) + InputStr.mid( 4, 2 ) + tr( "-" ) + InputStr.mid( 6, 2 ) + tr( "T" ) + InputStr.mid( 8, 2 ) + tr( ":" ) + InputStr.mid( 10, 2 ); s_DateTime.replace( " ", "0" ); tout << s_DateTime << "\t"; // Position // Latitude if ( InputStr.mid( 12, 5 ) != " " ) tout << InputStr.mid( 12, 5 ).toFloat()/100. << "\t"; else tout << "\t"; // Longitude if ( InputStr.mid( 17, 6 ) != " " ) { float f_Longitude = InputStr.mid( 17, 6 ).toFloat()/100.; if ( f_Longitude > 180. ) f_Longitude -=360; tout << f_Longitude; } else tout << ""; for ( int i=9; i<n; i++ ) { if ( sl_Conf.at( i ).section( "\t", 0, 0 ) == "x" ) { QString s_Factor = sl_Conf.at( i ).section( "\t", 1, 1 ); QString s_Entry = InputStr.mid( sl_Conf.at( i ).section( "\t", 4, 4 ).toInt()-1, sl_Conf.at( i ).section( "\t", 6, 6 ).toInt() ).simplified(); if ( s_Entry.isEmpty() == true ) { tout << "\t"; } else { if ( s_Factor == "T" ) { s_Entry.replace( "\"", "''" ); tout << "\t~@" << s_Entry; } else { if ( s_Factor.isEmpty() == false ) tout << "\t" << s_Entry.toFloat()*s_Factor.toFloat(); else tout << "\t" << s_Entry; } } } } tout << endl; } resetProgress( i_NumOfFiles ); fin.close(); fout.close(); // ********************************************************************************************** if ( ui_length == (unsigned int) _APPBREAK_ ) return( _APPBREAK_ ); return( _NOERROR_ ); }
int MainWindow::getDataMetadata( const int i_CodecInput, const int i_OutputFormat, const QString &s_MetadataIn, QStringList &sl_DataMetadataList, structURL URL[], const int i_NumOfFiles ) { int n = 0; int j = 0; int i_line = 0; int stopProgress = 0; int i_DatePos = -1; int i_TimePos = -1; int i_DateTimePos = -1; int i_ElevationPos = -1; int i_EventLabelPos = -1; int i_CampaignLabelPos = -1; int i_AreaNamePos = -1; int i_GearNamePos = -1; int i_LatitudePos = -1; int i_LongitudePos = -1; QStringList sl_Input; QString s_Metadata = ""; QString s_EventLabel = ""; QString s_Header = ""; QString s_LatLon = ""; bool b_containsPosition = false; sl_DataMetadataList.clear(); //----------------------------------------------------------------------------------------------------------------------- b_containsPosition = getDataMetadataPosition( s_MetadataIn, i_DatePos, i_TimePos, i_DateTimePos, i_ElevationPos, i_EventLabelPos, i_CampaignLabelPos, i_AreaNamePos, i_GearNamePos, i_LatitudePos, i_LongitudePos ); //----------------------------------------------------------------------------------------------------------------------- if ( ( n = readFile( s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), sl_Input, i_CodecInput ) ) < 1 ) return( n ); //----------------------------------------------------------------------------------------------------------------------- switch ( i_OutputFormat ) { case _FORMAT_KMLFILE: initProgress( i_NumOfFiles, s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), tr( "Creating Google Earth import file" ), n ); break; case _FORMAT_SHAPE_METADATA: case _FORMAT_SHAPE_DATA: initProgress( i_NumOfFiles, s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), tr( "Creating shapefile" ), n ); break; default: initProgress( i_NumOfFiles, s_MetadataIn.section( "\t", _FILENAMEPOS, _FILENAMEPOS ), tr( "Creating file" ), n ); break; } //----------------------------------------------------------------------------------------------------------------------- i_line = s_MetadataIn.section( "\t", _NUMOFHEADERLINESPOS, _NUMOFHEADERLINESPOS ).toInt()-1; if ( sl_Input.at( i_line ) == "*/" ) ++i_line; for ( int i=0; i<NumOfSections( sl_Input.at( i_line ) ); ++i ) { s_Header = sl_Input.at( i_line ).section( "\t", i, i ); if ( ( s_Header.startsWith( "url", Qt::CaseInsensitive ) == true ) || ( s_Header.startsWith( "uri", Qt::CaseInsensitive ) == true ) || ( s_Header.startsWith( "persistent identifier", Qt::CaseInsensitive ) == true ) ) { if ( ++j <= _MAX_NUM_OF_URLS ) { URL[j].position = i; if ( s_Header.contains( "@" ) == true ) URL[j].TitleURL = s_Header.section( "@", 1, 1 ); else URL[j].TitleURL = s_Header; } } } stopProgress = incProgress( i_NumOfFiles, i_line ); //----------------------------------------------------------------------------------------------------------------------- ++i_line; parseData( i_line, sl_Input.at( i_line ), s_MetadataIn, i_AreaNamePos, i_CampaignLabelPos, i_EventLabelPos, i_GearNamePos, i_DatePos, i_TimePos, i_DateTimePos, i_LatitudePos, i_LongitudePos, i_ElevationPos, URL, s_Metadata ); addToMetadataList( s_Metadata, s_EventLabel, s_LatLon, sl_DataMetadataList ); stopProgress = incProgress( i_NumOfFiles, i_line ); if ( b_containsPosition == true ) { while ( ( ++i_line < n ) && ( stopProgress != _APPBREAK_ ) ) { parseData( i_line, sl_Input.at( i_line ), s_MetadataIn, i_AreaNamePos, i_CampaignLabelPos, i_EventLabelPos, i_GearNamePos, i_DatePos, i_TimePos, i_DateTimePos, i_LatitudePos, i_LongitudePos, i_ElevationPos, URL, s_Metadata ); addToMetadataList( s_Metadata, s_EventLabel, s_LatLon, sl_DataMetadataList ); stopProgress = incProgress( i_NumOfFiles, i_line ); } } //----------------------------------------------------------------------------------------------------------------------- resetProgress( i_NumOfFiles ); return( _NOERROR_ ); }
int MainWindow::GaussKruegerConverter( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_ColumnLatitude, const int i_ColumnLongitude, const int i_ColumnHoch, const int i_ColumnRechts, const int i_ColumnStreifen, const int i_NumOfDigits, const int i_DecimalSeparator, const bool b_DeleteInputFile, const int i_NumOfFiles ) { int i = 0; int n = 0; int mode = -1; int stopProgress = 0; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; convertPosition *llc = new convertPosition( i_NumOfDigits, i_DecimalSeparator ); // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( n ); // ********************************************************************************************** if ( ( i_ColumnHoch > 0 ) && ( i_ColumnRechts > 0 ) && ( i_ColumnStreifen > 0 ) ) mode = _GKLL_; if ( ( i_ColumnLatitude > 0 ) && ( i_ColumnLongitude > 0 ) ) mode = _LLGK_; if ( mode < 0 ) return( mode ); // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Converting positions..." ), n ); switch( mode ) { case _GKLL_: tout << "Latitude\tLongitude\t" << sl_Input.at( i++ ) << s_EOL; break; case _LLGK_: tout << "Hoch [m]\tRechts [m]\tStreifen\t" << sl_Input.at( i++ ) << s_EOL; break; } while ( ( i < n ) && ( stopProgress != _APPBREAK_ ) ) { switch( mode ) { case _GKLL_: llc->convertGKtoLL( sl_Input.at( i ).section( "\t", i_ColumnStreifen-1, i_ColumnStreifen-1 ), sl_Input.at( i ).section( "\t", i_ColumnRechts-1, i_ColumnRechts-1 ), sl_Input.at( i ).section( "\t", i_ColumnHoch-1, i_ColumnHoch-1 ) ); tout << sl_Input.at( i ) << "\t" << llc->Latitude() << "\t" << llc->Longitude() << s_EOL; break; case _LLGK_: if ( ( llc->getMode( sl_Input.at( i ).section( "\t", i_ColumnLatitude-1, i_ColumnLatitude-1 ) ) == 1 ) || ( llc->getMode( sl_Input.at( i ).section( "\t", i_ColumnLongitude-1, i_ColumnLongitude-1 ) ) == 1 ) ) { llc->setNumOfDigitsLL( 7 ); llc->convertLLtoLL( sl_Input.at( i ).section( "\t", i_ColumnLatitude-1, i_ColumnLatitude-1 ), sl_Input.at( i ).section( "\t", i_ColumnLongitude-1, i_ColumnLongitude-1 ) ); llc->convertLLtoGK( llc->Latitude(), llc->Longitude() ); } else { llc->convertLLtoGK( sl_Input.at( i ).section( "\t", i_ColumnLatitude-1, i_ColumnLatitude-1 ), sl_Input.at( i ).section( "\t", i_ColumnLongitude-1, i_ColumnLongitude-1 ) ); } tout << QString( "%1" ).arg( llc->Hoch(), 0, 'f', i_NumOfDigits ) << "\t" << QString( "%1" ).arg( llc->Rechts(), 0, 'f', i_NumOfDigits ) << "\t" << llc->Streifen() << "\t" << sl_Input.at( i ) << s_EOL; break; } stopProgress = incProgress( i_NumOfFiles, ++i ); } resetProgress( i_NumOfFiles ); // ********************************************************************************************** fout.close(); if ( stopProgress == _APPBREAK_ ) return( _APPBREAK_ ); if ( b_DeleteInputFile == true ) removeFile( s_FilenameIn ); return( _NOERROR_ ); }
int MainWindow::transposeTable( const QString &s_FilenameIn, const QString &s_FilenameOut, const int i_CodecInput, const int i_CodecOutput, const int i_EOL, const int i_NumOfFiles ) { int j = 0; int n = 0; int m = 0; int stopProgress = 0; QString s_EOL = setEOLChar( i_EOL ); QStringList sl_Input; // ********************************************************************************************** // read file if ( ( n = readFile( s_FilenameIn, sl_Input, i_CodecInput ) ) < 1 ) return( n ); // ********************************************************************************************** // open output file QFile fout( s_FilenameOut ); if ( fout.open( QIODevice::WriteOnly | QIODevice::Text) == false ) return( -20 ); QTextStream tout( &fout ); switch ( i_CodecOutput ) { case _SYSTEM_: break; case _LATIN1_: tout.setCodec( QTextCodec::codecForName( "ISO 8859-1" ) ); break; case _APPLEROMAN_: tout.setCodec( QTextCodec::codecForName( "Apple Roman" ) ); break; default: tout.setCodec( QTextCodec::codecForName( "UTF-8" ) ); break; } // ********************************************************************************************** initProgress( i_NumOfFiles, s_FilenameIn, tr( "Transposing table..." ), n ); for ( int i=0; i<n; i++ ) m = qMax( m, NumOfSections( sl_Input.at( i ) ) ); while ( ( j < m ) && ( stopProgress != _APPBREAK_ ) ) { QString s_Output = sl_Input.at( 0 ).section( "\t", j, j ); for ( int i=1; i<n; i++ ) s_Output.append( "\t" ).append( sl_Input.at( i ).section( "\t", j, j ) ); tout << s_Output << s_EOL; stopProgress = incProgress( i_NumOfFiles, ++j ); } resetProgress( i_NumOfFiles ); // ********************************************************************************************** fout.close(); if ( stopProgress == _APPBREAK_ ) { fout.remove(); return( _APPBREAK_ ); } return( stopProgress ); }