Exemplo n.º 1
0
bool wxTarHeaderBlock::Write(wxOutputStream& out)
{
    bool ok = true;

    for (int id = 0; id < TAR_NUMFIELDS && ok; id++)
        ok = WriteField(out, id);

    return ok;
}
Exemplo n.º 2
0
void PrintLine(void)
{
  CARDINAL i = 0;
  if (!linePrinted) {
    if (TextStart >= maxCols) {
      /*This is the silly line format case*/
      if (linePosition > TextStart) PutLine();
      else Tab(TextStart);
      while (currentLinePointer[i] != CR) PutCh(currentLinePointer[i++]);
    } else {
      /*This is the sensible case*/
      if ((linePosition > TextStart) && (currentLinePointer[i] != Space))
        PutLine();
      do {

        if ((currentLinePointer[i] == CommentSymbol) || (OpcodeStart >= maxCols))
         break;
        /*Write out the label*/
        WriteField(TextStart, FALSE, &i);

        if ((currentLinePointer[i] == CR) || (currentLinePointer[i] == CommentSymbol) || (OperandStart >= maxCols))
         break ;

        /*We have an opcode*/
        if (linePosition >= OpcodeStart) PutLine();
        WriteField(OpcodeStart, FALSE, &i);

        if ((currentLinePointer[i] == CR) || (currentLinePointer[i] == CommentSymbol) || (CommentStart >= maxCols))
         break ;

        /*We have an operand*/
        if (linePosition >= OperandStart) PutLine();
        WriteField(OperandStart, TRUE, &i);
      } while (1);
      if (currentLinePointer[i] != CR) WriteComment(&i);
    }; /* if */
    PutLine();
  }; /* if */
  linePrinted = TRUE;
  linePosition = 0;
  if (PollEscape()) abortFlag = TRUE;
} /* End PrintLine */
Exemplo n.º 3
0
void TigerFileBase::WriteFields(TigerRecordInfo *psRTInfo,
                                OGRFeature      *poFeature,
                                char            *szRecord)
{
  int i;
  for (i=0; i<psRTInfo->nFieldCount; ++i) {
    if (psRTInfo->pasFields[i].bWrite) {
      WriteField( poFeature,
                  psRTInfo->pasFields[i].pszFieldName,
                  szRecord, 
                  psRTInfo->pasFields[i].nBeg,
                  psRTInfo->pasFields[i].nEnd,
                  psRTInfo->pasFields[i].cFmt,
                  psRTInfo->pasFields[i].cType );
    }
  }
}
Exemplo n.º 4
0
bool CSVwrite::WriteRecord( const vector<string> &fields, bool terminate /* = true */ )
{
    if( _error )
        return false;

    if( !_output_ptr )
    {
        _error = true;
        _error_msg = "A stream is not associated with the object.";
        return false;
    }

    if( !_is_first_field )
    {
        if( !WriteTerminator() )
        {
            return false;
        }
    }

    if( !fields.size() && !(( _flags & CSVwrite::process_empty_records )) )
    {
        return true;
    }

    for( vector<string>::const_iterator it = fields.begin(); it != fields.end(); ++it )
    {
        if( !WriteField( *it ) )
        {
            return false;
        }
    }

    if( terminate )
    {
        if( !WriteTerminator() )
        {
            return false;
        }
    }

    return true;
}
Exemplo n.º 5
0
OGRErr TigerCompleteChain::CreateFeature( OGRFeature *poFeature )

{
    char        szRecord[OGR_TIGER_RECBUF_LEN];
    OGRLineString *poLine = (OGRLineString *) poFeature->GetGeometryRef();

    if( poLine == NULL 
        || (poLine->getGeometryType() != wkbLineString
            && poLine->getGeometryType() != wkbLineString25D) )
        return OGRERR_FAILURE;

    /* -------------------------------------------------------------------- */
    /*      Write basic data record ("RT1")                                 */
    /* -------------------------------------------------------------------- */
    if( !SetWriteModule( "1", psRT1Info->nRecordLength+2, poFeature ) )
        return OGRERR_FAILURE;
    memset( szRecord, ' ', psRT1Info->nRecordLength );
    WriteFields( psRT1Info, poFeature, szRecord );
    WritePoint( szRecord, 191, poLine->getX(0), poLine->getY(0) );
    WritePoint( szRecord, 210, 
                poLine->getX(poLine->getNumPoints()-1), 
                poLine->getY(poLine->getNumPoints()-1) );
    WriteRecord( szRecord, psRT1Info->nRecordLength, "1" );

    /* -------------------------------------------------------------------- */
    /*      Write geographic entity codes (RT3)                             */
    /* -------------------------------------------------------------------- */
    if (bUsingRT3) {
      memset( szRecord, ' ', psRT3Info->nRecordLength );
      WriteFields( psRT3Info, poFeature, szRecord );
      WriteRecord( szRecord, psRT3Info->nRecordLength, "3", fpRT3 );
    }

    /* -------------------------------------------------------------------- */
    /*      Write shapes sections (RT2)                                     */
    /* -------------------------------------------------------------------- */
    if( poLine->getNumPoints() > 2 )
    {
        int     nPoints = poLine->getNumPoints();
        int     iPoint, nRTSQ = 1;

        for( iPoint = 1; iPoint < nPoints-1; )
        {
            int         i;
            char        szTemp[5];

            memset( szRecord, ' ', psRT2Info->nRecordLength );

            WriteField( poFeature, "TLID", szRecord, 6, 15, 'R', 'N' );
            
            sprintf( szTemp, "%3d", nRTSQ );
            strncpy( ((char *)szRecord) + 15, szTemp, 4 );

            for( i = 0; i < 10; i++ )
            {
                if( iPoint < nPoints-1 )
                    WritePoint( szRecord, 19+19*i, 
                                poLine->getX(iPoint), poLine->getY(iPoint) );
                else
                    WritePoint( szRecord, 19+19*i, 0.0, 0.0 );

                iPoint++;
            }
            
            WriteRecord( szRecord, psRT2Info->nRecordLength, "2", fpShape );

            nRTSQ++;
        }
    }

    return OGRERR_NONE;
}
Exemplo n.º 6
0
void SocketWBuffer::WriteField(std::string field, char sep) {
    WriteField(field);
    WriteChar(sep);
}
Exemplo n.º 7
0
int main(int argc, char *argv[]) {
	float *collide_field=NULL, *stream_field=NULL, *collide_field_d=NULL, *stream_field_d=NULL,
			*swap=NULL, tau, wall_velocity[D_LBM], num_cells, mlups_sum;
	int *flag_field=NULL, *flag_field_d=NULL, xlength, t, timesteps, timesteps_per_plotting,
			gpu_enabled;
	clock_t mlups_time;
	size_t field_size;

	/* process parameters */
	ReadParameters(&xlength, &tau, wall_velocity, &timesteps, &timesteps_per_plotting, argc, argv,
			&gpu_enabled);

	/* check if provided parameters are legitimate */
	ValidateModel(wall_velocity, xlength, tau);

	/* initializing fields */
	num_cells = pow(xlength + 2, D_LBM);
	field_size = Q_LBM*num_cells*sizeof(float);
	collide_field = (float*) malloc(field_size);
	stream_field = (float*) malloc(field_size);
	flag_field = (int*) malloc(num_cells*sizeof(int));
	InitialiseFields(collide_field, stream_field, flag_field, xlength, gpu_enabled);
	InitialiseDeviceFields(collide_field, stream_field, flag_field, xlength, &collide_field_d, &stream_field_d, &flag_field_d);

	for (t = 0; t < timesteps; t++) {
		printf("Time step: #%d\n", t);
		if (gpu_enabled){
			DoIteration(collide_field, stream_field, flag_field, tau, wall_velocity, xlength,
					&collide_field_d, &stream_field_d, &flag_field_d, &mlups_sum);
			/* Copy data from devcice in memory only when we need VTK output */
			if (!(t%timesteps_per_plotting))
				CopyFieldsFromDevice(collide_field, stream_field, xlength,
						&collide_field_d, &stream_field_d);
		} else {
			mlups_time = clock();
			/* Copy pdfs from neighbouring cells into collide field */
			DoStreaming(collide_field, stream_field, flag_field, xlength);
			/* Perform the swapping of collide and stream fields */
			swap = collide_field; collide_field = stream_field; stream_field = swap;
			/* Compute post collision distributions */
			DoCollision(collide_field, flag_field, tau, xlength);
			/* Treat boundaries */
			TreatBoundary(collide_field, flag_field, wall_velocity, xlength);
			mlups_time = clock()-mlups_time;
			/* Print out the MLUPS value */
			mlups_sum += num_cells/(MLUPS_EXPONENT*(float)mlups_time/CLOCKS_PER_SEC);
			if(VERBOSE)
				printf("MLUPS: %f\n", num_cells/(MLUPS_EXPONENT*(float)mlups_time/CLOCKS_PER_SEC));
		}
		/* Print out vtk output if needed */
		if (!(t%timesteps_per_plotting))
			WriteVtkOutput(collide_field, flag_field, "img/lbm-img", t, xlength);
	}

	printf("Average MLUPS: %f\n", mlups_sum/(t+1));

	if (VERBOSE) {
		if(gpu_enabled)
	  	      CopyFieldsFromDevice(collide_field, stream_field, xlength, &collide_field_d, &stream_field_d);
		WriteField(collide_field, "img/collide-field", 0, xlength, gpu_enabled);
		writeFlagField(flag_field, "img/flag-field", xlength, gpu_enabled);
	}

	/* Free memory */
	free(collide_field);
	free(stream_field);
	free(flag_field);

	FreeDeviceFields(&collide_field_d, &stream_field_d, &flag_field_d);

	printf("Simulation complete.\n");
	return 0;
}
Exemplo n.º 8
0
/* DirFileWriter: separate thread: writes each field to disk */
void DirFileWriter(void)
{
  dtracevoid();
  unsigned short buffer[MAXBUF];
  unsigned int ibuffer[MAXBUF];
  int j, i;
  int i_in, i_out, i_buf;
  int i_in2, i_out2;
  int wrote_count = 0;
  int last_pass = 0;

  while (1) {
    /* slow data */
    for (i = 0; i < slowsPerBi0Frame; i++)
      for (j = 0; j < FAST_PER_SLOW; j++) {
        if (slow_fields[j][i].fp != -1) {
          i_in = slow_fields[j][i].i_in;
          i_out = slow_fields[j][i].i_out;
          i_buf = 0;
          if ((SlowChList[i][j].type == 'U') || (SlowChList[i][j].type == 'I')
              || (SlowChList[i][j].type == 'S'))
          {
            i_in2 = slow_fields[j][i + 1].i_in;
            i_out2 = slow_fields[j][i + 1].i_out;
            while (i_in != i_out && i_in2 != i_out2) {
              ibuffer[i_buf] = (unsigned)
                ((((unsigned short*)slow_fields[j][i + 1].b)[i_out2]) << 16)
                | (unsigned)
                (((unsigned short*)slow_fields[j][i].b)[i_out]);

              if (i == 0 && j == 0)
                wrote_count = ++slow_fields[j][i].nw * FAST_PER_SLOW;
              else if (wrote_count < ++slow_fields[j][i].nw * FAST_PER_SLOW)
                wrote_count = slow_fields[j][i].nw * FAST_PER_SLOW;

              i_out++;
              i_out2++;
              i_buf++;
              if (i_out >= MAXBUF)
                i_out = 0;
              if (i_out2 >= MAXBUF)
                i_out2 = 0;
            }

            WriteField(slow_fields[j][i].fp, i_buf * sizeof(unsigned), ibuffer);
            slow_fields[j][i].i_out = i_out;
            slow_fields[j][i + 1].i_out = i_out2;
          } else {
            while (i_in != i_out) {
              buffer[i_buf] = ((unsigned short*)slow_fields[j][i].b)[i_out];

              if (i == 0 && j == 0)
                wrote_count = ++slow_fields[j][i].nw * FAST_PER_SLOW;
              else if (wrote_count < ++slow_fields[j][i].nw * FAST_PER_SLOW)
                wrote_count = slow_fields[j][i].nw * FAST_PER_SLOW;

              i_out++;
              i_buf++;
              if (i_out >= MAXBUF)
                i_out = 0;
            }

            WriteField(slow_fields[j][i].fp, i_buf * sizeof(unsigned short),
                buffer);
            slow_fields[j][i].i_out = i_out;
          }
        } else if (i == 0 || ((SlowChList[i - 1][j].type != 'U')
              && (SlowChList[i - 1][j].type != 'I') &&
              (SlowChList[i - 1][j].type != 'S'))) {
          slow_fields[j][i].i_out = slow_fields[j][i].i_in;
        }
      }

    /* defile flags */
    i_in = defile_field.i_in;
    i_out = defile_field.i_out;
    i_buf = 0;

    while (i_in != i_out) {
      buffer[i_buf] = ((unsigned short*)defile_field.b)[i_out];

      if (wrote_count < ++defile_field.nw)
        wrote_count = defile_field.nw;

      i_out++;
      i_buf++;
      if (i_out >= MAXBUF)
        i_out = 0;
    }
    WriteField(defile_field.fp, i_buf * sizeof(unsigned short), buffer);
    defile_field.i_out = i_out;

    /**********************
     ** normal fast data **
     **********************/

    /* j = 0 (FASTSAMP) must be writen last if getdata is to return the proper
     * number of frames */
    for (j = 1; j < n_fast; j++) {
      i_in = normal_fast[j].i_in;
      i_out = normal_fast[j].i_out;
      i_buf = 0;
      if (normal_fast[j].size == 2) {
        while (i_in != i_out) {
          ibuffer[i_buf] = ((unsigned int*)normal_fast[j].b)[i_out];

          if (wrote_count < ++normal_fast[j].nw)
            wrote_count = normal_fast[j].nw;

          i_out++;
          i_buf++;
          if (i_out >= MAXBUF)
            i_out = 0;
        }

        WriteField(normal_fast[j].fp, i_buf * sizeof(unsigned), ibuffer);
      } else {
        while (i_in != i_out) {
          buffer[i_buf] = ((unsigned short*)normal_fast[j].b)[i_out];

          if (wrote_count < ++normal_fast[j].nw)
            wrote_count = normal_fast[j].nw;

          i_out++;
          i_buf++;
          if (i_out >= MAXBUF)
            i_out = 0;
        }
        WriteField(normal_fast[j].fp, i_buf * sizeof(unsigned short), buffer);
      }
      normal_fast[j].i_out = i_out;

    }

#if DAS_CARDS > 0
    /** Bolometer data */
    for (i = 0; i < DAS_CARDS; i++) {
      for (j = 0; j < DAS_CHS; j++) {
        i_in = bolo_fields[i][j].i_in;
        i_out = bolo_fields[i][j].i_out;

        i_buf = 0;
        while (i_in != i_out) {
          ibuffer[i_buf] =
            ((unsigned int*)bolo_fields[i][j].b)[i_out];

          if (wrote_count < bolo_fields[i][j].nw)
            wrote_count = bolo_fields[i][j].nw;

          i_out++;
          i_buf++;
          if (i_out >= MAXBUF)
            i_out = 0;
        }
        WriteField(bolo_fields[i][j].fp, i_buf * sizeof(unsigned), ibuffer);
        bolo_fields[i][j].i_out = i_out;
      }
    }
#endif

    /* Write FASTSAMP last */
    i_in = normal_fast[0].i_in;
    i_out = normal_fast[0].i_out;
    i_buf = 0;
    while (i_in != i_out) {
      ibuffer[i_buf] = ((unsigned int*)normal_fast[0].b)[i_out];

      if (wrote_count < ++normal_fast[0].nw)
        wrote_count = normal_fast[0].nw;

      i_out++;
      i_buf++;
      if (i_out >= MAXBUF)
        i_out = 0;
    }
    WriteField(normal_fast[0].fp, i_buf * sizeof(unsigned), ibuffer);
    normal_fast[0].i_out = i_out;

    /* Done writing */
    if (ri.wrote < wrote_count)
      ri.wrote = wrote_count;

    if (ri.reader_done) {
      if (ri.wrote == ri.read || last_pass) {
        ri.writer_done = 1;
        CleanUp();
        return;
      } else
        last_pass = 1;
    }

    usleep(10000);

    /* if dirfile_init is lowered, the reader has noticed a change in the
     * curfile: prepare for cycling the writer. */
    if (ri.dirfile_init == 0) {
      /* perform one last pass to ensure we've written all the data (the reader
       * has certainly stopped by now, so we should be fine with a single
       * last pass */
      if (!last_pass)
        last_pass = 1;
      else {
        /* Clean Up */
        CleanUp();

        bprintf(info, "Defiling `%s'\n    into `%s'\n", rc.chunk, rc.dirfile);
        if (rc.resume_at > 0)
          bprintf(info, "    starting at frame %li\n", rc.resume_at);
        bprintf(info, "\n");

        /* Re-initialise */
        wrote_count = 0;
        ri.read = ri.wrote = ri.old_total = 0;
        ri.frame_rate_reset = 1;
        InitialiseDirFile(1, 0);
        gettimeofday(&ri.last, &rc.tz);
        last_pass = 0;
      }
    }
  }
}