示例#1
0
//----------------------------------------------------
char *zu_gets(ZUFILE *f, char *buf, int len)
{
    int nb = 0;
    int bzerror=BZ_OK;
    char *ret = NULL;
    switch(f->type) {
        case ZU_COMPRESS_NONE :
            if((ret = fgets(buf, len, (FILE*)(f->zfile))))
                nb = strlen(buf);
            break;
        case ZU_COMPRESS_GZIP :
            if((ret = gzgets((gzFile)(f->zfile), buf, len)))
                nb = strlen(buf);
            break;
        case ZU_COMPRESS_BZIP :
            nb = BZ2_bzRead(&bzerror,(BZFILE*)(f->zfile), buf, len-1);
            for(int i=0; i<nb; i++)
                if(buf[i] == '\n') {
                    int seek = f->pos;
                    f->pos += nb;
                    buf[i+1] = '\0';
                    return zu_seek(f, seek + i + 1, SEEK_SET) == -1 ? NULL : buf;
                }
            if(nb > 0) {
                buf[nb] = '\0';
                ret = buf;
            }
    }
    f->pos += nb;
    return ret;
}
示例#2
0
//-------------------------------------------------------------------------------
GribV1Record::GribV1Record(ZUFILE* file) : GribRecord()
{
    seekStart = zu_tell(file);
    data    = NULL;
    BMSbits = NULL;
    eof     = false;
    isFull = false;
    knownData = true;

    ok = readGribSection0_IS(file);

    if (ok) {
        ok = readGribSection1_PDS(file);
        zu_seek(file, fileOffset1+sectionSize1, SEEK_SET);
    }
    if (ok) {
        ok = readGribSection2_GDS(file);
        zu_seek(file, fileOffset2+sectionSize2, SEEK_SET);
    }
    if (ok) {
        ok = readGribSection3_BMS(file);
        zu_seek(file, fileOffset3+sectionSize3, SEEK_SET);
    }
    if (ok) {
        ok = readGribSection4_BDS(file);
        zu_seek(file, fileOffset4+sectionSize4, SEEK_SET);
    }
    if (ok) {
        ok = readGribSection5_ES(file);
    }
    if (ok) {
        zu_seek(file, seekStart+totalSize, SEEK_SET);
    }

    if (ok) {
        if(dataType!=DATA_NOTDEF && levelType!=DATA_LV_NOTDEF) {
            knownData = true;
            unitConversion();
        }
        else {
            knownData = false;
            qWarning() << "Unknown data: dataType=" << dataType << ", levelType=" << levelType << ", levelValue=" << levelValue;
        }

        computeKey();
    }
}
示例#3
0
文件: zuFile.cpp 项目: nohal/qtVlm
//-----------------------------------------------------------------
void   zu_rewind(ZUFILE *f)
{
    zu_seek(f, 0, SEEK_SET);
}
示例#4
0
//==============================================================
// Lecture des donnees
//==============================================================
//----------------------------------------------
// SECTION 0: THE INDICATOR SECTION (IS)
//----------------------------------------------
bool GribV1Record::readGribSection0_IS(ZUFILE* file) {
    char    strgrib[4];
    memset (strgrib, 0, sizeof (strgrib));
    zuint initFoffset;
    fileOffset0 = zu_tell(file);
    initFoffset=fileOffset0;
#if 1
    char buf[1];
    memset (buf, 0, sizeof (buf));
    while(true)
    {
        if(zu_read(file,buf,1)!=1) break;
        ++fileOffset0;
        if(buf[0]!='G')
            continue;
        if(zu_read(file,buf,1)!=1) break;
        ++fileOffset0;
        if(buf[0]!='R')
        {
            if(buf[0]=='G')
                zu_seek(file,--fileOffset0,SEEK_SET);
            continue;
        }
        if(zu_read(file,buf,1)!=1) break;
        ++fileOffset0;
        if(buf[0]!='I')
        {
            if(buf[0]=='G')
                zu_seek(file,--fileOffset0,SEEK_SET);
            continue;
        }
        if(zu_read(file,buf,1)!=1) break;
        ++fileOffset0;
        if(buf[0]!='B')
        {
            if(buf[0]=='G')
                zu_seek(file,--fileOffset0,SEEK_SET);
            continue;
        }
        strgrib[0]='G';
        strgrib[1]='R';
        strgrib[2]='I';
        strgrib[3]='B';
        break;
    }
#else
    while((zu_read(file, strgrib, 4) == 4) &&
          (strgrib[0] != 'G' || strgrib[1] != 'R' ||
           strgrib[2] != 'I' || strgrib[3] != 'B')) {
          zu_seek(file,++fileOffset0,SEEK_SET);
    }
#endif
    if(strgrib[0] != 'G' || strgrib[1] != 'R' ||
            strgrib[2] != 'I' || strgrib[3] != 'B') {
        if((fileOffset0-10)>initFoffset) // displaying error msg only if we are really far from initial offset
            qWarning() << "Can't find next record / EOF - offset=" << fileOffset0 << ", initOffset=" << initFoffset ;
        ok = false;
        eof = true;
        return false;
    }


    seekStart=zu_tell(file)-4;
    totalSize = readInt3(file);


    //qWarning() << "Start = " << seekStart << ", size = " << totalSize;

    editionNumber = readChar(file);
    if (editionNumber != 1)  {
        ok = false;
        eof = true;
        return false;
    }

    return true;
}