Beispiel #1
0
/* virtual */
void XMLerLoadFileThread::run ()
{
  QFile xml( fileName() );
  if ( !xml.exists() ) {
    emit error ( tr("File %1 does not exists.").arg( fileName() ) );
    return;
  }

  /* QMap<QString, QString> info = getInformationFromFile(); */

  QXmlSimpleReader reader;
  XMLerInputSource *source = new XMLerInputSource ( &xml );

  /* connect source to slots in model */
  connect ( source, SIGNAL(beginRead(qint64)), this, SLOT(on_beginProgress(qint64)) );
  connect ( source, SIGNAL(readProgress(qint64)), this, SLOT(on_progress(qint64)) );
  connect ( source, SIGNAL(endRead()), this, SLOT(on_endProgress()) );

  reader.setContentHandler ( handler );
  reader.setErrorHandler ( handler );

  bool parseResult = reader.parse ( source, true );

  /* FIXME: this is partial read */
  if ( parseResult ) {
    bool partResult = parseResult;
    while ( partResult )
      partResult = reader.parseContinue();
  }
  if ( !parseResult ) {
    checkExceptionInHandler();
    on_endProgress();
    return;
  }

  /* set addition data (information) in document */
  if ( handler->document() )
    handler->document()->setFileName( fileName() );
  /* CLEANIT
  if ( !info.isEmpty() ) {
    if ( info.contains ( "encoding" ) )
      handler->document()->setCodec ( info.value ( "encoding" ) );
    if ( info.contains ( "version" ) )
      handler->document()->setVersion ( info.value ( "version" ) );
      }*/
  emit done ( handler->document() );
  checkExceptionInHandler ();

  /* clean */
  disconnect ( source, SIGNAL(beginRead(qint64)) );
  disconnect ( source, SIGNAL(readProgress(qint64)) );
  disconnect ( source, SIGNAL(endRead()) );
  delete source;
}
Beispiel #2
0
int Application::readParticles(int fd) //returns <0 on Error
{
    int i; //,nskip;
    if (beginRead(fd))
    {
        return (-1);
    }
    rb.init(blockLen, header.np, fd);
    for (i = 0; i < (header.np / pfactor); i++)
    {
        rb.skip(pfactor - 1); //skip some particles
        if (rb.read() < 0)
            return (-1);
        rb.readFloat(px[i]);
        rb.readFloat(py[i]);
        rb.readFloat(pz[i]);
        rb.skip(2, 2); // skip to floats and two ints
        rb.readFloat(pu[i]);
        rb.readFloat(pv[i]);
        rb.readFloat(pw[i]);
        rb.readFloat(ptemp[i]);
    }
    if ((header.np - (header.np / pfactor) * pfactor))
        rb.skip((header.np - (header.np / pfactor) * pfactor));
    if (endRead(fd))
    {
        return (-1);
    }
    return (0);
}
Beispiel #3
0
/*
 * GetNextThread -
 * NB - callers must continue to call this function until it returns FALSE
 */
BOOL GetNextThread( ThreadList *info, ThreadPlace *place,
                    DWORD pid, BOOL first )
{

    DWORD                       curpid;
    PERF_COUNTER_DEFINITION     *counter;
    BOOL                        error;

    error = FALSE;
    if( first ) {
        beginRead( FALSE );
        initObj( &regData, &threadObject, N_THREAD );
        if( threadObject == NULL ) error = TRUE;
        if( !error ) {
            place->index = 0;
            place->obj = threadObject;
            place->pid = pid;
            place->inst = getFirstInstance( threadObject );
        }
    } else {
        place->index ++;
        if( place->index < place->obj->NumInstances ) {
            place->inst = getNextInstance( place->inst );
        }
    }
    if( !error ) {
        counter = findCounter( place->obj, N_PROCID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        for( ; place->index < place->obj->NumInstances; place->index ++ ) {
            if( place->inst == NULL ) {
                error = TRUE;
                break;
            }
            curpid = getCounterDWORD( place->inst, counter );
            if( curpid == place->pid ) break;
            place->inst = getNextInstance( place->inst );
        }
    }
    if( !error && place->index >= place->obj->NumInstances ) error = TRUE;
    if( !error ) {
        counter = findCounter( place->obj, N_THREADID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->tid = getCounterDWORD( place->inst, counter );
        counter = findCounter( place->obj, N_BASE_PRIORITY );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->priority = getCounterDWORD( place->inst, counter );
    } else {
        endRead( FALSE );
    }
    return( !error );
}
 Result read(void* buffer, size_t size, Flags flags, size_t* readSize) override
 {
     const void* src = nullptr;
     Result result = beginRead(&src, flags, readSize);
     if (result != Ok)
         return result;
     *readSize = std::min(*readSize, size);
     memcpy(buffer, src, *readSize);
     return endRead(*readSize);
 }
Beispiel #5
0
/*
 * GetNextProcess
 * NB - callers must continue to call this function until it returns FALSE
 */
BOOL GetNextProcess( ProcList *info, ProcPlace *place, BOOL first ) {

    PERF_COUNTER_DEFINITION     *counter;
    BOOL                        error;

    error = FALSE;
    if( first ) {
        beginRead( FALSE );
        initObj( &regData, &processObject, N_PROCESS );
        if( processObject == NULL ) error = TRUE;
        if( !error ) {
            place->index = 0;
            place->obj = processObject;
            place->inst = getFirstInstance( processObject );
        }
    } else {
        place->index ++;
        if( place->index >= processObject->NumInstances ) {
            endRead( FALSE );
            return( FALSE );
        }
        place->inst = getNextInstance( place->inst );
    }
    if( place->inst == NULL ) error = TRUE;
    if( !error ) {
        counter = findCounter( place->obj, N_PROCID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->pid = getCounterDWORD( place->inst, counter );
        counter = findCounter( place->obj, N_BASE_PRIORITY );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->priority = getCounterDWORD( place->inst, counter );
        wsprintf( info->name, "%ls",
                  (char *)( place->inst ) + place->inst->NameOffset );
    } else {
        endRead( FALSE );
    }
    return( !error );
}
Beispiel #6
0
/*
 * GetThreadInfo
 */
BOOL GetThreadInfo( DWORD pid, DWORD tid, ThreadStats *info ) {

    PERF_COUNTER_DEFINITION     *pid_counter;
    PERF_COUNTER_DEFINITION     *tid_counter;
    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;
    DWORD                       curid;
    DWORD                       i;
    BOOL                        error;

    error = FALSE;
    beginRead( FALSE );
    initObj( &regData, &threadObject, N_THREAD );
    if( threadObject == NULL ) {
        error = TRUE;
    }
    if( !error ) {
        pid_counter = findCounter( threadObject, N_PROCID );
        tid_counter = findCounter( threadObject, N_THREADID );
        if( pid_counter == NULL || tid_counter == NULL ) error = TRUE;
    }
    if( !error ) {
        inst = getFirstInstance( threadObject );
        for( i=0; i < threadObject->NumInstances; i++ ) {
            if( inst == NULL ) {
                error = TRUE;
                break;
            }
            curid = getCounterDWORD( inst, tid_counter );
            if( curid == tid ) {
                curid = getCounterDWORD( inst, pid_counter );
                if( curid == pid ) break;
            }
            inst = getNextInstance( inst );
        }
    }
    if( !error && i == threadObject->NumInstances ) {
         error = TRUE;
    } else {
        info->tid = tid;
        info->pid = pid;
        counter = findCounter( threadObject, N_BASE_PRIORITY );
        info->base_pri = getCounterDWORD( inst, counter );
        counter = findCounter( threadObject, N_CUR_PRIORITY );
        info->cur_pri = getCounterDWORD( inst, counter );
        counter = findCounter( threadObject, N_THREAD_STATE );
        info->state = getCounterDWORD( inst, counter );
        counter = findCounter( threadObject, N_WAIT_REASON );
        info->wait_reason = getCounterDWORD( inst, counter );
    }
    endRead( FALSE );
    return( !error );
}
Beispiel #7
0
/*
 * GetProcessInfo
 */
BOOL GetProcessInfo( DWORD pid, ProcStats *info ) {

    DWORD                       i;
    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;
    DWORD                       curpid;
    BOOL                        error;

    beginRead( FALSE );
    error = FALSE;
    initObj( &regData, &processObject, N_PROCESS );
    if( processObject == NULL ) error = TRUE;
    if( !error ) {
        counter = findCounter( processObject, N_PROCID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        inst = getFirstInstance( processObject );
        for( i=0; i < processObject->NumInstances; i++ ) {
            if( inst == NULL ) {
                error = TRUE;
                break;
            }
            curpid = getCounterDWORD( inst, counter );
            if( curpid == pid ) break;
            inst = getNextInstance( inst );
        }
    }
    if( !error && curpid == pid && info != NULL ) {
        info->pid = curpid;
        counter = findCounter( processObject, N_BASE_PRIORITY );
        if( counter == NULL ) {
            error = TRUE;
        } else {
            info->priority = getCounterDWORD( inst, counter );
            wsprintf( info->name, "%ls",
                      (char *)inst + inst->NameOffset );
        }
    }
    endRead( FALSE );
    return( !error && curpid == pid );
}
Beispiel #8
0
std::streambuf::int_type IOBuffer::underflow()
{
    typedef IOBuffer::traits_type traits_type;

    if(!_ioDevice)
        return traits_type::eof();

    if(_ioDevice->isReading())
        endRead();

    if( gptr() < egptr() )
        return traits_type::to_int_type( *gptr() );

    if(_ioDevice->isEof())
        return traits_type::eof();

    if(!_ibuffer)
        _ibuffer = new char[_ibufferSize];

    std::size_t putback = _pbmax;

    if( gptr() )
    {
        putback = std::min<std::size_t>(gptr() - eback(), _pbmax);
        std::memmove(_ibuffer + (_pbmax - putback),
                     gptr() - putback,
                     putback );
    }

    std::size_t readSize = _ioDevice->read(_ibuffer + _pbmax, _ibufferSize - _pbmax);

    setg(_ibuffer + _pbmax - putback,    // start of get area
         _ibuffer + _pbmax,              // gptr position
         _ibuffer + _pbmax + readSize ); // end of get area

    if(_ioDevice->isEof())
        return traits_type::eof();

    return traits_type::to_int_type( *gptr() );
}
Beispiel #9
0
resultsOut(){
  int i;

  // get the results

  for(i=0; i<getNum(); i++){
    startRead(i);

    name=getName(1);
    x=getDouble("x", 0);
    y=getDouble("y", 0);
    z=getDouble("z", 0);
    theta=getDouble("theta", 0);
    phi=getDouble("phi", 0);
    t=getDouble("t", 0);
    e=getDouble("e", 0);

    x*=1.e-2; y*=1.e-2; z*=1.e-2; theta=180-theta; phi=phi<180?phi+180:phi-180; e*=1.e-3;
    printf("%s %g %g %g %g %g %g %g\n", name, x, y, z, theta, phi, t, e);

    endRead();
  }
}
Beispiel #10
0
std::streambuf::pos_type IOBuffer::seekoff(std::streambuf::off_type off, std::ios::seekdir dir, std::ios::openmode)
{
    typedef IOBuffer::pos_type pos_type;
    typedef IOBuffer::off_type off_type;

    pos_type ret = pos_type(off_type(-1));

    if( ! _ioDevice || ! _ioDevice->seekable() || off == 0)
        return ret;

    if(_ioDevice->isWriting())
        endWrite();

    if(_ioDevice->isReading())
        endRead();

    ret = _ioDevice->seek(off, dir);

    // Eliminate currently buffered sequence
    discard();

    return ret;
}
Beispiel #11
0
/*
 * GetMemInfo
 */
BOOL GetMemInfo( DWORD procid, MemInfo *info ) {

    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;
    DWORD                       curpid;
    DWORD                       i;

    beginRead( TRUE );
    initObj( &costlyData, &procAddrObject, N_PROCESS_ADDR_SPACE );
    if( procAddrObject == NULL ) {
        info->modlist = NULL;
        info->modcnt = 0;
        goto GETMEMINFO_ERROR;
    }

    info->modlist = GetModuleList( procid, &info->modcnt );
    if( info->modlist == NULL ) goto GETMEMINFO_ERROR;

    counter = findCounter( procAddrObject, N_PROCID );
    if( counter == NULL ) goto GETMEMINFO_ERROR;

    inst = getFirstInstance( procAddrObject );
    for( i=0; ; i++ ) {
        if( i >= procAddrObject->NumInstances || inst == NULL ) {
            goto GETMEMINFO_ERROR;
        }
        curpid = getCounterDWORD( inst, counter );
        if( curpid == procid ) break;
        inst = getNextInstance( inst );
    }

    counter = findCounter( procAddrObject, N_MAP_SPACE_NO_ACC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.noaccess = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_READ );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.read = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_WRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.write = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_COPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.copy = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXEC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.exec = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXECREAD );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.execread = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXECWRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.execwrite = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXECCOPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.execcopy = getCounterDWORD( inst, counter );

    info->mapped.tot = info->mapped.noaccess + info->mapped.read
                        + info->mapped.write + info->mapped.copy
                        + info->mapped.exec + info->mapped.execread
                        + info->mapped.execwrite + info->mapped.execcopy;


    counter = findCounter( procAddrObject, N_RES_SPACE_NO_ACC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.noaccess = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_READ );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.read = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_WRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.write = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_COPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.copy = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXEC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.exec = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXECREAD );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.execread = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXECWRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.execwrite = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXECCOPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.execcopy = getCounterDWORD( inst, counter );

    info->res.tot = info->res.noaccess + info->res.read
                    + info->res.write + info->res.copy
                    + info->res.exec + info->res.execread
                    + info->res.execwrite + info->res.execcopy;


    counter = findCounter( procAddrObject, N_IMAGE_SPACE_NO_ACC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.noaccess = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_READ );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.read = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_WRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.write = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_COPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.copy = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXEC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.exec = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECREAD );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.execread = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECWRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.execwrite = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECCOPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.execcopy = getCounterDWORD( inst, counter );

    info->image.tot = info->image.noaccess + info->image.read
                    + info->image.write + info->image.copy
                    + info->image.exec + info->image.execread
                    + info->image.execwrite + info->image.execcopy;

    endRead( TRUE );
    return( TRUE );

GETMEMINFO_ERROR:
    FreeModuleList( info->modlist, info->modcnt );
    endRead( TRUE );
    return( FALSE );
}
Beispiel #12
0
/*
 * GetImageMemInfo
 */
BOOL GetImageMemInfo( DWORD procid, char *imagename, MemByType *imageinfo ) {

    DWORD                       index;
    DWORD                       i;
    BOOL                        ret;
    char                        buf[ _MAX_PATH ];
    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;

    ret = FALSE;
    beginRead( FALSE );
    beginRead( TRUE );

    initObj( &costlyData, &imageObject, N_IMAGE );
    initObj( &regData, &processObject, N_PROCESS );
    if( imageObject == NULL || processObject == NULL ) goto GETIMAGEMEM_ERROR;

    inst = getFirstInstance( imageObject );
    if( !getProcessIndex( procid, &index ) ) goto GETIMAGEMEM_ERROR;

    for( i=0; i < imageObject->NumInstances; i += 1 ) {
        if( inst == NULL ) goto GETIMAGEMEM_ERROR;

        if( inst->ParentObjectInstance == index ) {
            wsprintf( buf, "%ls", (char *)inst + inst->NameOffset );
            if( !strcmp( buf, imagename ) ) {
                counter = findCounter( imageObject, N_NO_ACCESS );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->noaccess = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_READ_ONLY );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->read = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_READ_WRITE );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->write = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_WRITE_COPY );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->copy = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->exec = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC_READ );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->execread = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC_WRITE );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->execwrite = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC_COPY );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->execcopy = getCounterDWORD( inst, counter );

                imageinfo->tot = imageinfo->noaccess + imageinfo->read
                            + imageinfo->write + imageinfo->copy
                            + imageinfo->exec + imageinfo->execread
                            + imageinfo->execwrite + imageinfo->execcopy;
                ret = TRUE;
                break;
            }
        }
        inst = getNextInstance( inst );
    }
    endRead( TRUE );
    endRead( FALSE );
    return( ret);

GETIMAGEMEM_ERROR:
    endRead( TRUE );
    endRead( FALSE );
    return( FALSE );
}
Beispiel #13
0
int Application::readConn(int fd) //returns <0 on Error
{
    int i, i1, i2, i3, i4, i5, i6, i7, i8, *vlist, *elist, *tlist;
    if (beginRead(fd))
    {
        return (-1);
    }
    rb.init(blockLen, header.numCoords + header.ifirst - 1, fd);
    rb.skip(header.ifirst - 1); //skip some unused Vertices
    /*if(readDouble)
   {
       lseek(fd,((header.ifirst-1)*(7*4+3*8)),SEEK_CUR);
   }
   else
   {
       lseek(fd,((header.ifirst-1)*10*4),SEEK_CUR);
   }*/
    int *i1tab = new int[header.numCoords];
    int *i3tab = new int[header.numCoords];
    int *i8tab = new int[header.numCoords];

    for (i = 0; i < header.numCoords; i++)
    {
        if (rb.read() < 0)
            return (-1);
        rb.readInt(i1tab[i]);
        rb.readInt(i3tab[i]);
        rb.readInt(i8tab[i]);
        /*
      readInt(fd,i1tab[i]);
      readInt(fd,i3tab[i]);
      readInt(fd,i8tab[i]);
       if(readDouble)
       {
         lseek(fd,(4*4+3*8),SEEK_CUR);
       }
       else
       {
         lseek(fd,(7*4),SEEK_CUR);
      }*/
    }
    vlist = vl;
    elist = el;
    tlist = tl;
    for (i = 0; i < header.numElem; i++)
    {
        i1 = i1tab[i] - header.ifirst;
        i2 = i3tab[i1] - header.ifirst;
        i3 = i3tab[i] - header.ifirst;
        i4 = i;
        i5 = i8tab[i1] - header.ifirst;
        i6 = i8tab[i2] - header.ifirst;
        i7 = i8tab[i3] - header.ifirst;
        i8 = i8tab[i] - header.ifirst;
        *vlist = i1;
        vlist++;
        *vlist = i2;
        vlist++;
        *vlist = i3;
        vlist++;
        *vlist = i4;
        vlist++;
        *vlist = i5;
        vlist++;
        *vlist = i6;
        vlist++;
        *vlist = i7;
        vlist++;
        *vlist = i8;
        vlist++;
        *elist = i * 8;
        *tlist = TYPE_HEXAEDER;
        elist++;
        tlist++;
    }
    delete[] i1tab;
    delete[] i3tab;
    delete[] i8tab;

    if (endRead(fd))
    {
        return (-1);
    }
    return (0);
}
Beispiel #14
0
int Application::readData(int fd) //returns <0 on Error
{
    int i;
    if (beginRead(fd))
    {
        return (-1);
    }
    rb.init(blockLen, header.numCoords + header.ifirst - 1, fd);
    rb.skip(header.ifirst - 1); //skip some unused Vertices
    for (i = 0; i < header.numCoords; i++)
    {
        if (rb.read() < 0)
            return (-1);
        rb.skip(0, 2); // skip to floats (f +fv) and no ints
        if (i < header.numElem)
        {
            rb.readFloat(x_coord[i]);
            rb.readFloat(y_coord[i]);
            rb.readFloat(z_coord[i]);
            rb.readFloat(u[i]);
            rb.readFloat(v[i]);
            rb.readFloat(w[i]);
            rb.readFloat(p[i]);
            rb.readFloat(rho[i]);
            rb.readFloat(vol[i]);
            rb.readFloat(temp[i]);
            rb.readFloat(amu[i]);
            rb.readFloat(tke[i]);
            rb.readFloat(eps[i]);
        }
        else
        {
            rb.readFloat(x_coord[i]);
            rb.readFloat(y_coord[i]);
            rb.readFloat(z_coord[i]);
            rb.readFloat(u[i]);
            rb.readFloat(v[i]);
            rb.readFloat(w[i]);
        }
    }
    /*
   if(readDouble)
       lseek(fd,((header.ifirst-1)*15*8),SEEK_CUR);
   else
       lseek(fd,((header.ifirst-1)*15*4),SEEK_CUR);
   for(i=0;i<header.numCoords;i++)
   {
       if(i<header.numElem)
       {
        if(readDouble)
        {
   lseek(fd,(2*8),SEEK_CUR); //f + fv
   }
   else
   {
   lseek(fd,(2*4),SEEK_CUR); //f + fv
   }
   readFloat(fd,x_coord[i]);
   readFloat(fd,y_coord[i]);
   readFloat(fd,z_coord[i]);
   readFloat(fd,u[i]);
   readFloat(fd,v[i]);
   readFloat(fd,w[i]);
   readFloat(fd,p[i]);
   readFloat(fd,rho[i]);
   readFloat(fd,vol[i]);
   readFloat(fd,temp[i]);
   readFloat(fd,amu[i]);
   readFloat(fd,tke[i]);
   readFloat(fd,eps[i]);
   }
   else
   {
   if(readDouble)
   {
   lseek(fd,(2*8),SEEK_CUR); //f + fv
   }
   else
   {
   lseek(fd,(2*4),SEEK_CUR); //f + fv
   }
   readFloat(fd,x_coord[i]);
   readFloat(fd,y_coord[i]);
   readFloat(fd,z_coord[i]);
   readFloat(fd,u[i]);
   readFloat(fd,v[i]);
   readFloat(fd,w[i]);
   if(readDouble)
   {
   lseek(fd,(7*8),SEEK_CUR);
   }
   else
   {
   lseek(fd,(7*4),SEEK_CUR);
   }
   }
   }*/
    if (endRead(fd))
    {
        return (-1);
    }
    return (0);
}
Beispiel #15
0
int Application::readHeader(int fd) //returns <0 on Error or FORMAT_ASCII or FORMAT_BINARY
{
    if (beginRead(fd))
    {
        lseek(fd, 0, SEEK_SET);
        return (-2);
    }
    if (read(fd, header.dataDate, 24) < 24)
    {
        Covise::sendError("KIVA: unexpected end of file in header");
        return (-1);
    }
    if (read(fd, header.dataName, 80) < 80)
    {
        Covise::sendError("KIVA: unexpected end of file in header");
        return (-1);
    }
    header.dataName[80] = '\0';
    header.dataDate[24] = '\0';
    //Covise::sendInfo(header.dataName);
    //Covise::sendInfo(header.dataDate);
    if (readFloat(fd, header.time) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.ncyc) < 0)
    {
        return (-1);
    }
    if (readFloat(fd, header.crank) < 0)
    {
        return (-1);
    }
    if (read(fd, header.jnm, 8) < 8)
    {
        Covise::sendError("KIVA: unexpected end of file in header");
        return (-1);
    }
    header.jnm[8] = '\0';
    if (readInt(fd, header.ifirst) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.ncells) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.nverts) < 0)
    {
        return (-1);
    }
    if (readFloat(fd, header.cylrad) < 0)
    {
        return (-1);
    }
    if (readFloat(fd, header.zpistn) < 0)
    {
        return (-1);
    }
    if (readFloat(fd, header.zhead) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.np) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.nrk) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.nsp) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.irez) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.numBoundaryVertices) < 0)
    {
        return (-1);
    }
    header.boundaryVertices = new int[header.numBoundaryVertices];
    if (read(fd, header.boundaryVertices, header.numBoundaryVertices * sizeof(int)) < header.numBoundaryVertices * sizeof(int))
    {
        Covise::sendError("KIVA: unexpected end of file in header");
        return (-1);
    }
    if (readInt(fd, header.iper) < 0)
    {
        return (-1);
    }
    if (readFloat(fd, header.rhop) < 0)
    {
        return (-1);
    }
    if (readFloat(fd, header.cmueps) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.naxisj) < 0)
    {
        return (-1);
    }
    if (readInt(fd, header.nregions) < 0)
    {
        return (-1);
    }
    if (endRead(fd))
    {
        return (-1);
    }
    header.numCoords = (header.nverts - header.ifirst) + 1;
    header.numElem = (header.ncells - header.ifirst) + 1;
    // sk 21.06.2001
    //header.print();
    return (FORMAT_BINARY);
}