//--------------------------------------------------- // Rectangle de la zone couverte par les données bool GribReader::getZoneExtension(double *x0,double *y0, double *x1,double *y1) { std::vector<GribRecord *> *ls = getFirstNonEmptyList(); if (ls != NULL) { GribRecord *rec = ls->at(0); if (rec != NULL) { *x0 = rec->getX(0); *y0 = rec->getY(0); *x1 = rec->getX( rec->getNi()-1 ); *y1 = rec->getY( rec->getNj()-1 ); if (*x0 > *x1) { double tmp = *x0; *x0 = *x1; *x1 = tmp; } if (*y0 > *y1) { double tmp = *y0; *y0 = *y1; *y1 = tmp; } } return true; } else { return false; } }
//------------------------------------------------------------- // Grille GRIB void GribPlot::draw_GridPoints (const DataCode &dtc, QPainter &pnt, const Projection *proj) { if (gribReader == NULL) { return; } // GribRecord *rec = gribReader->getFirstGribRecord (); DataCode dd; if (dtc.dataType == GRB_PRV_WIND_XY2D) dd = DataCode (GRB_WIND_VX, dtc.levelType, dtc.levelValue); else if (dtc.dataType == GRB_PRV_CUR_XY2D) dd = DataCode (GRB_CUR_VX, dtc.levelType, dtc.levelValue); else dd = dtc; GribRecord *rec = gribReader->getRecord (dd, getCurrentDate()); if (! rec) return; int px,py, i,j, dl=2; for (i=0; i<rec->getNi(); i++) for (j=0; j<rec->getNj(); j++) { //if (rec->hasValue(i,j)) { proj->map2screen(rec->getX(i), rec->getY(j), &px,&py); pnt.drawLine(px-dl,py, px+dl,py); pnt.drawLine(px,py-dl, px,py+dl); proj->map2screen(rec->getX(i)-360.0, rec->getY(j), &px,&py); pnt.drawLine(px-dl,py, px+dl,py); pnt.drawLine(px,py-dl, px,py+dl); } } }
//--------------------------------------------------------------------------------- void GribReader::readGribFileContent() { fileSize = zu_filesize(file); readAllGribRecords(); createListDates(); // hoursBetweenRecords = computeHoursBeetweenGribRecords(); //----------------------------------------------------- // Are dewpoint data in file ? // If no, compute it with Magnus-Tetens formula, if possible. //----------------------------------------------------- dewpointDataStatus = DATA_IN_FILE; if (getNumberOfGribRecords(GRB_DEWPOINT, LV_ABOV_GND, 2) == 0) { dewpointDataStatus = NO_DATA_IN_FILE; if ( getNumberOfGribRecords(GRB_HUMID_REL, LV_ABOV_GND, 2) > 0 && getNumberOfGribRecords(GRB_TEMP, LV_ABOV_GND, 2) > 0) { dewpointDataStatus = COMPUTED_DATA; std::set<time_t>::iterator iter; for (iter=setAllDates.begin(); iter!=setAllDates.end(); iter++) { time_t date = *iter; GribRecord *recModel = getGribRecord(GRB_TEMP,LV_ABOV_GND,2,date); if (recModel != NULL) { // Crée un GribRecord avec les dewpoints calculés GribRecord *recDewpoint = new GribRecord(*recModel); if (recDewpoint != NULL) { recDewpoint->setDataType(GRB_DEWPOINT); for (zuint i=0; i<(zuint)recModel->getNi(); i++) for (zuint j=0; j<(zuint)recModel->getNj(); j++) { double x = recModel->getX(i); double y = recModel->getY(j); double dp = computeDewPoint(x, y, date); recDewpoint->setValue(i, j, dp); } storeRecordInMap(recDewpoint); } } } } } //----------------------------------------------------- }
//================================================================================== // Flèches de direction du current //================================================================================== void GribPlot::draw_CURRENT_Arrows ( Altitude altitude, QColor arrowsColor, QPainter &pnt, const Projection *proj ) { if (gribReader == NULL) { return; } currentAltitude = altitude; currentArrowColor = arrowsColor; GribRecord *recx = gribReader->getRecord (DataCode(GRB_CUR_VX,altitude),currentDate); GribRecord *recy = gribReader->getRecord (DataCode(GRB_CUR_VY,altitude),currentDate); if (recx == NULL || recy == NULL) return; int i, j; double x, y, vx, vy; int W = proj->getW(); int H = proj->getH(); int space; space = drawCurrentArrowsOnGrid ? currentArrowSpaceOnGrid : currentArrowSpace; if (drawCurrentArrowsOnGrid) { // Flèches uniquement sur les points de la grille int oldi=-1000, oldj=-1000; for (int gi=0; gi<recx->getNi(); gi++) { x = recx->getX(gi); y = recx->getY(0); proj->map2screen(x,y, &i,&j); if (true || abs(i-oldi)>=space) { oldi = i; for (int gj=0; gj<recx->getNj(); gj++) { x = recx->getX(gi); y = recx->getY(gj); proj->map2screen(x,y, &i,&j); //---------------------------------------------------------------------- if (! recx->isXInMap(x)) x += 360.0; // tour du monde ? if (recx->isPointInMap(x,y)) { if (true || abs(j-oldj)>=space) { oldj = j; vx = recx->getInterpolatedValue(x, y, mustInterpolateValues); vy = recy->getInterpolatedValue(x, y, mustInterpolateValues); if (vx != GRIB_NOTDEF && vy != GRIB_NOTDEF) { drawCurrentArrow(pnt, i,j, vx,vy); } } } } } } } else { // Flèches uniformément réparties sur l'écran for (i=0; i<W; i+=space) { for (j=0; j<H; j+=space) { proj->screen2map(i,j, &x,&y); //---------------------------------------------------------------------- if (! recx->isXInMap(x)) x += 360.0; // tour du monde ? if (recx->isPointInMap(x,y)) { vx = recx->getInterpolatedValue(x, y, mustInterpolateValues); vy = recy->getInterpolatedValue(x, y, mustInterpolateValues); if (vx != GRIB_NOTDEF && vy != GRIB_NOTDEF) { drawCurrentArrow(pnt, i,j, vx,vy); } } //---------------------------------------------------------------------- } } } }