Пример #1
0
 virtual void BeforeBackprop(const std::vector<layer::Node<xpu>*> &nodes_in,
                             const std::vector<layer::Node<xpu>*> &nodes_out) {
   if (fullc_gather != 0) {
     utils::Check(update_on_server == 0, "GatherUpdate can not use update_on_server");
     utils::Check(nodes_in.size() == 1, "fullc_gather can only work with fullc");
     utils::Check(nodes_out.size() == 1, "fullc_gather can only work with fullc");
     mshadow::Tensor<xpu, 2> in = nodes_in[0]->mat();
     mshadow::Tensor<xpu, 2> out = nodes_out[0]->mat();
     num_in = in.size(1); num_out = out.size(1);
     tnode.Resize(mshadow::Shape2(total_batch_size, num_in + num_out));      
     // manually hslice
     mshadow::Tensor<xpu, 2> tin(tnode.dptr_,
                                 mshadow::Shape2(total_batch_size, num_in),
                                 tnode.stride_, tnode.stream_);
     mshadow::Tensor<xpu, 2> tout(tnode.dptr_ + num_in,
                                  mshadow::Shape2(total_batch_size, num_out),
                                  tnode.stride_, tnode.stream_);
     local_batch_size = in.size(0);
     utils::Check(local_batch_size <= total_batch_size,
                  "local_batch_size bigger than total_batch_size");
     utils::Check(total_batch_size % local_batch_size == 0,
                  "when you use fullc_gather mode, the batch_size "\
                  "must be multiple of number of devices");
     mshadow::Copy(tin.Slice(0, local_batch_size), in, tnode.stream_);
     mshadow::Copy(tout.Slice(0, local_batch_size), out, tnode.stream_);      
   }
 }
Пример #2
0
main(int argc, char* argv[]){ 

    int k,n,i,j;

    std::string op=argv[1], prob=argv[3];
    std::istringstream tin(argv[2]);
    val t; tin>>t;

	val dx=1.0/K, dt=(val)T/N, xk, tn, tmp;
    val R=NU*dt/dx;    // R = NU*dt/dx
    val alpha, beta;
    
    static banded_matrix<val> U(K+2, K+2, 2, 4);
    vector<fortran_int_t> p(K+2);    
    
    static vec u(K+2), w(K+2), z(K+2), v(K+2);

    if(prob=="a"){
    // Tridiagonal Matrix U
    for(i=0; i<U.size1(); i++){
            U(i,i)=1.0-R-2*r; 
            k=std::max(i-1,0);
            U(k,k+1)=r;
            U(k+1,k)=R+r;
    }
    // Boundary Conditions
    U(0,0)+=r; U(K+1,K+1)+=(R+r); 
   
    w(0)=1.0; w(K+1)=-1.0; z(0)=r; z(K+1)=-(R+r); // Sherman-Morrison
    }
   
    // Test Boundary Conditions
    if(op=="test"){ 
        mat wzt = outer_prod(w, z);
        mat B = U - wzt; 
        printf("Matrix Q1\n"); matprintf(B);
        printf("Matrix B\n"); matprintf(U);
        printf("Matrix wz^T\n"); matprintf(wzt);
    }
   
    // Initial conditions
    for(k=0;k<u.size();k++){
        xk=k*dx;
        u(k)=f(xk);
    }
   
    lapack::gbtrf(U, p); // LU-decompostion
    lapack::gbtrs(U, p, w); //B^-1w
    alpha=1.0/(1.0-inner_prod(z, w)); // alpha = 1/(1-z^T(b^-1w))

    for(n=0;n<=N;n++){
        tn=n*dt;
        lapack::gbtrs(U, p, u); // B^-1u
        beta=alpha*inner_prod(z, u); // beta = alpha*z^T(B^-1u)
        u+=beta*w;
        if(op=="pipe") plotu(u, tn, K);
        if(op=="approx" && tn==t) printu(u, tn, K);
    }
    return 0;
}
Пример #3
0
bool KMLpdManager::savePrinttoolCfgFile(const QString& templatefile, const QString& dirname, const QMap<QString,QString>& options)
{
	// defines input and output file
	QString	fname = QFileInfo(templatefile).fileName();
	fname.replace(QRegExp("\\.in$"),QString::fromLatin1(""));
	QFile	fin(templatefile);
	QFile	fout(dirname + "/" + fname);
	if (fin.exists() && fin.open(IO_ReadOnly) && fout.open(IO_WriteOnly))
	{
		QTextStream	tin(&fin), tout(&fout);
		QString		line, name;
		int		p(-1);
		while (!tin.eof())
		{
			line = tin.readLine().stripWhiteSpace();
			if (line.isEmpty() || line[0] == '#')
			{
				tout << line << endl;
				continue;
			}
			if (line.startsWith("export "))
			{
				tout << "export ";
				line.replace(0,7,QString::fromLatin1(""));
			}
			if ((p=line.find('=')) != -1)
			{
				name = line.left(p);
				tout << name << '=' << options[name] << endl;
			}
		}
		return true;
	}
	else return false;
}
Пример #4
0
int analyzeOutput(const std::string& filename) {
    MCSat solver;
    {
        io::file_descriptor_source inFile(filename.c_str(), std::ios_base::in | std::ios_base::binary);
        if (!inFile.is_open()) {
            std::cerr << "unable to open file " + filename + " for model reading" << std::endl;
            return EXIT_FAILURE;
        } else {
            io::filtering_istream dataIn;
            dataIn.push(io::gzip_decompressor());
            dataIn.push(inFile);
            boost::archive::text_iarchive tin(dataIn);
            registerAllPELTypes(tin);
            tin >> solver;
        }
    }
    std::cout << "number of samples: " << solver.numSamples() << std::endl;

    boost::shared_ptr<Sentence> ballContactS = getAsSentence("BallContact(them)");
    Proposition ballContactProp(static_cast<const Atom&>(*ballContactS), true);

    std::cout << "counts:" << std::endl;
    Interval maxInterval = solver.domain()->maxInterval();
    unsigned int counts[maxInterval.finish() - maxInterval.start() + 1];

    for (unsigned int j = maxInterval.start(); j <= maxInterval.finish(); j++) {
        counts[j] = solver.countProps(ballContactProp, Interval(j,j));
        std::cout << counts[j];
        if (j != maxInterval.finish()) std::cout << ", ";
    }
    std::cout << std::endl;

    return EXIT_SUCCESS;
}
void ApprExpansionDatabase::doRead(wxInputStream& in) {
	wxTextInputStream tin(in);
	while (!in.Eof()) {
		String l = tin.ReadLine();
		if (l.size() < 3) continue;
		order.push_back(l.substr(0,2));
		expansions[l.substr(0,2)] = l.substr(3);
	}
}
Пример #6
0
 inline void CalcDelta(mshadow::Stream<xpu> *stream) {
   dw.set_stream(stream);
   mshadow::Tensor<xpu, 2> tin(tnode.dptr_,
                               mshadow::Shape2(total_batch_size, num_in),
                               tnode.stride_, stream);
   mshadow::Tensor<xpu, 2> tout(tnode.dptr_ + num_in,
                                mshadow::Shape2(total_batch_size, num_out),
                                tnode.stride_, stream);
   dw += dot(tout.T(), tin);
 }
Пример #7
0
        std::string DeflateFrame::Inflate(const std::string& in)
        {
            /*
             * inflate the incoming payload
             */
            std::string tin(in);
            tin.append(2, '\0');
            tin.append(2, '\xff');
            //z_stream zs_in;
            zs_in.next_in = (uint8_t*)tin.c_str();
            zs_in.avail_in = tin.length();

            int32_t out_buf_len = 32;
            uint8_t* out_buf = (uint8_t*)malloc(out_buf_len);
            zs_in.avail_out = out_buf_len;
            zs_in.next_out = out_buf;

            while (1) 
            {
                int n = inflate(&zs_in, Z_SYNC_FLUSH);
                switch (n)
                {
                    case Z_NEED_DICT:
                    case Z_STREAM_ERROR:
                    case Z_DATA_ERROR:
                    case Z_MEM_ERROR:
                        /*
                         * screwed.. close the connection...
                         * we will get a destroy callback to take care
                         * of closing nicely
                         */
                        free(out_buf);
                        throw std::runtime_error("zlib error inflate " + std::to_string(n) + ", " + zs_in.msg);
                }

                if (zs_in.avail_out)
                    break;

                out_buf_len *= 2;
                out_buf = (unsigned char *)realloc(out_buf, out_buf_len);
                if (!out_buf)
                {
                    throw std::runtime_error("Out of memory");
                }
                zs_in.next_out = out_buf + (out_buf_len/2);
                zs_in.avail_out = out_buf_len/2;
            }

            /* rewrite the buffer pointers and length */
            std::string out_str((const char*)out_buf, out_buf_len - zs_in.avail_out);
            free(out_buf);
            return out_str;
        }
Пример #8
0
void ReachingDefAna::ComputeINOUTIterative(){
    BasicBlock* entry = *pr->get_begin();
    bool changed = true;
    int i = 0;
    do{
        map <BasicBlock*,bool> visitedFlag;
        queue <BasicBlock*> toVisit;    
        toVisit.push(entry);
        visitedFlag[entry] = true;
        cout<<"\n## Iteration "<<i++<<" ##\n";

        while(!toVisit.empty()){
            BasicBlock* cBB = toVisit.front();
            toVisit.pop();
            for(list<BasicBlock*>::iterator it = cBB->get_begin_succ(), end = cBB->get_end_succ(); it != end; ++it){
                if(visitedFlag.find(*it) == visitedFlag.end()){
                    toVisit.push(*it);
                    visitedFlag[*it] = true;
                }
            }
            bitvec in = cBB->getIn();
            bitvec out = cBB->getOut();
            bitvec tin(in.getSize()); 
            bitvec tout(out.getSize());
            for(list<BasicBlock*>::iterator pit = cBB->get_begin_pred(), pend = cBB->get_end_pred(); pit != pend; ++pit){
                tin = tin | (*pit)->getOut();
            }
            tout = tin - cBB->getKill();
            tout = tout | cBB->getGen();
            if( (in == tin) && (out == tout) )
                changed = false;
            else{
                changed = true;
                cBB->setIn(tin);
                cBB->setOut(tout);
            }
            printBB(cBB);
        } 
        //ts.append("1");
        string ts("Iteration");
        createDotFile(ts.append(std::to_string(i)));

    }while(changed);

}
Пример #9
0
void ReachingDefAna::ComputeINOUTWtList(){
    map <BasicBlock*,bool> visitedFlag;
    queue <BasicBlock*> toVisit;    
    for( list<BasicBlock*>::iterator it = pr->get_begin(), end = pr->get_end(); it != end; ++it){
        toVisit.push(*it);
        visitedFlag[*it] = true;
    }
    while( !toVisit.empty() ){
        BasicBlock* cBB = toVisit.front();
        cout << "\n::VISITING " << cBB->getBBLabel() << " ::\n";
        toVisit.pop();
        visitedFlag[cBB] = false;
        bitvec in = cBB->getIn();
        bitvec out = cBB->getOut();
        bitvec tin(in.getSize()); 
        bitvec tout(out.getSize());
        for(list<BasicBlock*>::iterator pit = cBB->get_begin_pred(), pend = cBB->get_end_pred(); pit != pend; ++pit){
            tin = tin | (*pit)->getOut();
        }
        tout = tin - cBB->getKill();
        tout = tout | cBB->getGen();
        cBB->setIn(tin);
        if( out != tout ){
            cBB->setOut(tout);
            for(list<BasicBlock*>::iterator it = cBB->get_begin_succ(), end = cBB->get_end_succ(); it != end; ++it){
                if(visitedFlag[*it] == false){
                    visitedFlag[*it] = true;
                    toVisit.push(*it);
                }
            }
        }
        printBB(cBB);
    }
    string ts("ReachingDefWtList");
    createDotFile(ts);
}
Пример #10
0
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::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_ );
}
Пример #12
0
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_ );
}