Exemplo n.º 1
0
//-------------------------------------------------------------------------------
void MetarWidgetFactory::read_metar_list ()
{
	char buf [512];
	ZUFILE *f;
	Airport a;
	mapAirports.clear ();
	mapCountries.clear ();
	mapStates.clear ();
 	f = zu_open (qPrintable(Util::pathGis()+"stations_metar.txt.gz"), "rb");
    if (f != NULL) {
		while (zu_fgets(buf, 512, f)) {
			if (strlen(buf)>0) {
				QString line = QString (buf);
				QStringList ls = line.split(";");
				if (ls.size() >= 7) {
					a.icao     = ls[0].trimmed();
					a.country  = ls[1].trimmed();
					a.state    = ls[2].trimmed();
					a.lat      = ls[3].toDouble();
					a.lon      = ls[4].toDouble();
					a.altitude = ls[5].toDouble();
					a.name     = ls[6].trimmed();
					mapAirports.insert (a.icao, a);
				}
			}
		}
        zu_close(f);
    }
 	f = zu_open (qPrintable(Util::pathGis()+"countries_en.txt.gz"), "rb");
    if (f != NULL) {
		while (zu_fgets(buf, 512, f)) {
			if (strlen(buf)>0) {
				QString line = QString (buf);
				QStringList ls = line.split(";");
				if (ls.size() >= 2) {
					mapCountries.insert (ls[0].trimmed(), ls[1].trimmed());
				}
			}
		}
        zu_close(f);
    }
 	f = zu_open (qPrintable(Util::pathGis()+"states_en.txt.gz"), "rb");
    if (f != NULL) {
		while (zu_fgets(buf, 512, f)) {
			if (strlen(buf)>0) {
				QString line = QString (buf);
				QStringList ls = line.split(";");
				if (ls.size() >= 3) {
					mapStates.insert (QPair<QString,QString>(ls[0].trimmed(),ls[1].trimmed()), ls[2].trimmed());
				}
			}
		}
        zu_close(f);
    }
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------
void GshhsReader::setQuality(int quality_) // 5 levels: 0=low ... 4=full
{
    std::string fname;
    ZUFILE *file;
    bool   ok;

    quality = quality_;
    if (quality < 0) quality = 0;
    else if (quality > 4) quality = 4;
    
    gshhsRangsReader->setQuality(quality);

    if (!isUsingRangsReader) {
	    readGshhsFiles();
    }
        
    // Frontières politiques
    if (lsPoly_boundaries[quality]->size() == 0) { // on ne lit qu'une fois le fichier
        fname = getFileName_boundaries(quality);
        file = zu_open(fname.c_str(), "rb");
        if (file != NULL) {
            ok = true;
            while (ok) {
                GshhsPolygon *poly = new GshhsPolygon_WDB(file);
                ok = poly->isOk();
                if (ok) {
                    if (poly->getLevel() < 2) 
                        lsPoly_boundaries[quality]->push_back(poly);
                }

            }
            zu_close(file);
        }
    }
    // Rivières
    if (lsPoly_rivers[quality]->size() == 0) { // on ne lit qu'une fois le fichier
        fname = getFileName_rivers(quality);
        file = zu_open(fname.c_str(), "rb");
        if (file != NULL) {
            ok = true;
            while (ok) {
                GshhsPolygon *poly = new GshhsPolygon_WDB(file);
                ok = poly->isOk();
                if (ok) {
                    lsPoly_rivers[quality]->push_back(poly);
                }

            }
            zu_close(file);
        }
    }
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------
void GshhsReader::readGshhsFiles()
{
    std::string fname;
    ZUFILE *file;
    bool   ok;

	// Bordures des continents (4 niveaux) (gshhs_[clihf].b)
	if (lsPoly_level1[quality]->size() == 0) { // on ne lit qu'une fois le fichier
		fname = getFileName_gshhs(quality);
		file = zu_open(fname.c_str(), "rb");
		if (file != NULL) {
			
			ok = true;
			while (ok) {
				GshhsPolygon *poly = new GshhsPolygon(file);
				ok = poly->isOk();
				if (ok) {
					switch (poly->getLevel()) {
						case 1: lsPoly_level1[quality]->push_back(poly); break;
						case 2: lsPoly_level2[quality]->push_back(poly); break;
						case 3: lsPoly_level3[quality]->push_back(poly); break;
						case 4: lsPoly_level4[quality]->push_back(poly); break;
					}
				}
			}
			zu_close(file);
		}
		//printf("GshhsReader::readGshhsFiles(%d)\n", quality);
	}
}
Exemplo n.º 4
0
//----------------------------------------------------
int    zu_can_read_file(const char *fname)
{
    ZUFILE *f;
    f = zu_open(fname, "rb");
    if (f == NULL) {
        return 0;
    }
    else {
        zu_close(f);
        return 1;
    }
}
Exemplo n.º 5
0
//-------------------------------------------------------------------------------
// Lecture complète d'un fichier GRIB
//-------------------------------------------------------------------------------
void GribReader::openFile(const wxString fname)
{
    debug("Open file: %s", (const char *)fname.mb_str());
    fileName = fname;
    ok = false;
    clean_all_vectors();
    //--------------------------------------------------------
    // Open the file
    //--------------------------------------------------------
    file = zu_open((const char *)fname.mb_str(), "rb", ZU_COMPRESS_AUTO);
    if (file == NULL) {
        erreur("Can't open file: %s", (const char *)fname.mb_str());
        return;
    }
    readGribFileContent();

    // Look for compressed files with alternate extensions
 	if (! ok) {
    	if (file != NULL)
			zu_close(file);
    	file = zu_open((const char *)fname.mb_str(), "rb", ZU_COMPRESS_BZIP);
    	if (file != NULL)
    		readGribFileContent();
    }
 	if (! ok) {
    	if (file != NULL)
			zu_close(file);
      file = zu_open((const char *)fname.mb_str(), "rb", ZU_COMPRESS_GZIP);
    	if (file != NULL)
    		readGribFileContent();
    }
 	if (! ok) {
    	if (file != NULL)
			zu_close(file);
      file = zu_open((const char *)fname.mb_str(), "rb", ZU_COMPRESS_NONE);
    	if (file != NULL)
    		readGribFileContent();
    }
}
Exemplo n.º 6
0
//---------------------------------------------------
void MbzFile::read_MbzFile (const char *fname, LongTaskProgress *taskProgress)
{
	ok = true;
	vlines.clear ();
	vcodes.clear ();
	
	ZUFILE *fin = zu_open (fname, "rb");
	if (!fin) {
		DBG ("Error: Can't open file %s", fname);
		ok = false;
		return;
	}
	read_header (fin);
	if (!ok) {
		//DBG ("Error: Can't read header from %s", fname);
		zu_close (fin);
		return;
	}
	read_data_codes (fin);
	if (!ok) {
		DBG ("Error: Can't read data codes from %s", fname);
		zu_close (fin);
		return;
	}
	
// DBG("version mbz %d", version);	

	read_data_lines (fin, taskProgress);
	if (!ok) {
		DBG ("Error: Can't read data lines from %s", fname);
		zu_close (fin);
		return;
	}


	zu_close (fin);
}
Exemplo n.º 7
0
bool BoatPlan::Open(const char *filename, wxString &message)
{
    wind_speeds.clear();
    degree_steps.clear();

    if(filename[0] == 0)
        return false;
    
    int linenum = 0;
    ZUFILE *f = zu_open(filename, "r");
    char line[1024];
    double lastentryW = -1;
    char *token, *saveptr;
    const char delim[] = ";, \t\r\n";

    if(!f)
        PARSE_ERROR(_("Failed to open."));

    // polar file has optional first line which is description
    for(;;) {
        if(!zu_gets(f, line, sizeof line))
            PARSE_ERROR(_("Failed to read."));

        token = strtok_r(line, delim, &saveptr);
        linenum++;

        /* chomp invisible bytes */
        while(*token < 0) token++;

        if(!strcasecmp(token, "twa/tws") ||
           !strcasecmp(token, "twa\\tws") ||
           !strcasecmp(token, "twa"))
            break;

        if(linenum == 2)
            PARSE_ERROR(_("Unrecognized format."));
    }
    
    while((token = strtok_r(NULL, delim, &saveptr))) {
        wind_speeds.push_back(SailingWindSpeed(strtod(token, 0)));
        if(wind_speeds.size() > MAX_WINDSPEEDS_IN_TABLE)
            PARSE_ERROR(_("Too many wind speeds."));
    }

    wind_speed_step = (int)round(wind_speeds.back().VW / wind_speeds.size());

    while(zu_gets(f, line, sizeof line)) {
        linenum++;

#if 0
        /* strip newline/linefeed */
        for(unsigned int i=0; i<strlen(line); i++)
            if(line[i] == '\r' || line[i] == '\n')
                line[i] = '\0';
#endif

        if(!(token = strtok_r(line, delim, &saveptr)))
            break;

        double W = strtod(token, 0);

        if(W < 0 || W > 180) {
            PARSE_WARNING(_("Wind direction out of range."));
            continue;
        }

        if(W <= lastentryW) {
            PARSE_WARNING(_("Wind direction out of order."));
            continue;
        }

        // add zero speed for all wind speeds going against wind if not specified
        if(degree_steps.empty() && W > 0)
        {
            degree_steps.push_back(0);

            for(int VWi = 0; VWi < (int)wind_speeds.size(); VWi++)
                wind_speeds[VWi].speeds.push_back(SailingWindSpeed::SailingSpeed(0, 0));
        }

        degree_steps.push_back(W);
        lastentryW = W;

        {
            for(int VWi = 0; VWi < (int)wind_speeds.size(); VWi++) {
                double s = 0;
                if((token = strtok_r(NULL, delim, &saveptr)))
                    s = strtod(token, 0);
                else
                    PARSE_WARNING(_("Too few tokens."));

                wind_speeds[VWi].speeds.push_back
                    (SailingWindSpeed::SailingSpeed(s, W));
            }

            if(strtok_r(NULL, delim, &saveptr))
                PARSE_WARNING(_("Too many tokens."));
        }
    }

    zu_close(f);

    /* fill in port tack assuming symmetric */
    {
        int Win = degree_steps.size()-1;
        if(degree_steps[Win] == 180) Win--;
        for(; Win >= 0; Win--) {
            if(degree_steps[Win] == 0)
                break;
            
            degree_steps.push_back(DEGREES - degree_steps[Win]);
            
            for(unsigned int VWi = 0; VWi < wind_speeds.size(); VWi++)
                wind_speeds[VWi].speeds.push_back(wind_speeds[VWi].speeds[Win]);
        }
    }
        
    UpdateDegreeStepLookup();
    wind_degree_step = degree_steps.size() ? 360 / degree_steps.size() : 0;

    for(unsigned int VWi = 0; VWi < wind_speeds.size(); VWi++)
        CalculateVMG(VWi);

    fileFileName = wxString::FromUTF8(filename);
    polarmethod = FROM_FILE;
    return true;
    
failed:
    wind_speeds.clear();
    degree_steps.clear();

    zu_close(f);
    return false;
}
CelestialNavigationDialog::CelestialNavigationDialog(wxWindow *parent)
    : CelestialNavigationDialogBase(parent),
      m_FixDialog(this),
      m_ClockCorrectionDialog(this)
{
    wxFileConfig *pConf = GetOCPNConfigObject();

    pConf->SetPath( _T("/PlugIns/CelestialNavigation") );

//#ifdef __WXGTK__
//    Move(0, 0);        // workaround for gtk autocentre dialog behavior
//#endif
//    Move(pConf->Read ( _T ( "DialogPosX" ), 20L ), pConf->Read ( _T ( "DialogPosY" ), 20L ));
    wxPoint p = GetPosition();
    pConf->Read ( _T ( "DialogX" ), &p.x, p.x);
    pConf->Read ( _T ( "DialogY" ), &p.y, p.y);
    SetPosition(p);

    wxSize s = GetSize();
    pConf->Read ( _T ( "DialogWidth" ), &s.x, s.x);
    pConf->Read ( _T ( "DialogHeight" ), &s.y, s.y);
    SetSize(s);

// create a image list for the list with just the eye icon
    wxImageList *imglist = new wxImageList(20, 20, true, 1);
    imglist->Add(wxBitmap(eye));
    m_lSights->AssignImageList(imglist, wxIMAGE_LIST_SMALL);

    m_lSights->InsertColumn(rmVISIBLE, wxT(""));
    m_lSights->SetColumnWidth(0, 28);

    m_lSights->InsertColumn(rmTYPE, _("Type"));
    m_lSights->InsertColumn(rmBODY, _("Body"));
    m_lSights->InsertColumn(rmTIME, _("Time (UT)"));
    m_lSights->InsertColumn(rmMEASUREMENT, _("Measurement"));
    m_lSights->InsertColumn(rmCOLOR, _("Color"));

    m_sights_path = celestial_navigation_pi::StandardPath() + _T("Sights.xml");

    if(!OpenXML(m_sights_path, false)) {
        /* create directory for plugin files if it doesn't already exist */
        wxFileName fn(m_sights_path);
        wxFileName fn2 = fn.GetPath();
        if(!fn.DirExists()) {
            fn2.Mkdir();
            fn.Mkdir();
        }
    }

    
    wxString filename = DataDirectory() + "vsop87d.txt";
    wxFileName fn(filename);
    if(!fn.Exists())
        filename = UserDataDirectory() + "vsop87d.txt";
    
    astrolabe::globals::vsop87d_text_path = (const char *)filename.mb_str();

    
#ifndef WIN32 // never hit because data is distribued easier to not compile compression support
    wxMessageDialog mdlg(this, _("Astrolab data unavailable.\n")
                         + _("\nWould you like to download?"),
                         _("Failure Alert"), wxYES | wxNO | wxICON_ERROR);
    if(mdlg.ShowModal() == wxID_YES) {
        wxString url = "https://cfhcable.dl.sourceforge.net/project/opencpnplugins/celestial_navigation_pi/";
        wxString path = UserDataDirectory();
        wxString fn = "vsop87d.txt.gz";
        
        _OCPN_DLStatus status = OCPN_downloadFile(
            url+fn, path+fn, _("downloading celestial navigation data file"),
            "downloading...",
            *_img_celestial_navigation, this,
            OCPN_DLDS_CAN_ABORT|OCPN_DLDS_ELAPSED_TIME|OCPN_DLDS_ESTIMATED_TIME|OCPN_DLDS_REMAINING_TIME|OCPN_DLDS_SPEED|OCPN_DLDS_SIZE|OCPN_DLDS_URL|OCPN_DLDS_AUTO_CLOSE, 20);
        if(status == OCPN_DL_NO_ERROR) {            
            // now decompress downloaded file
            ZUFILE *f = zu_open(path+fn.mb_str(), "rb", ZU_COMPRESS_AUTO);
            if(f) {
                FILE *out = fopen(path+"vsop87d.txt", "w");
                if(out) {
                    char buf[1024];
                    for(;;) {
                        size_t size = zu_read(f, buf, sizeof buf);
                        fwrite(buf, size, 1, out);
                        if(size != sizeof buf)
                            break;
                    }
                    fclose(out);
                }
                zu_close(f);
            }
        }
    }
#endif
    
#ifdef __OCPN__ANDROID__
    GetHandle()->setStyleSheet( qtStyleSheet);
    Move(0, 0);
#endif
}