示例#1
0
// Method reads all (interesting)directory entries from Iges Cad-file
// and stores them into attribute "directory" (container)
int
InputIges::readDirectory()
{
  fieldBuffer[1+DIR_FLD_LEN] = '\0';
  lineBuffer[SEC_ID_POS] = ' ';

  while (!infile.eof() && lineBuffer[SEC_ID_POS] != 'D')
    readFileLine(infile, lineBuffer);

  if (infile.eof())
    return 0;

  IgesDirectoryEntry* de;
  int cur_file_pos = infile.tellg();

  while (!infile.eof() && lineBuffer[SEC_ID_POS] == 'D') {
    de = readDirectoryEntry(lineBuffer);

    //-Add geometry-use types to directory
    //if (de->status.useFlag == 0)
    //  addToDirectory(de);

    // Currently all entries are added to directory.
    // The problem is: what entries could be excluded? !!!
    addToDirectory(de);

    //-Read the first line of next entry
    cur_file_pos = infile.tellg();
    readFileLine(infile, lineBuffer);
  }
  return cur_file_pos;
}
// Method reads a line-segment-element from Ideas univ. file (801)
bool
InputIdeasWF::readLine(Body* body, char* buffer)
{
  static Point3 p1, p2;

  // First read Record-3 away.
  // (it is : 1 1 and doesn't contain useful info)
  readFileLine(infile, buffer);

  // Next read the two vertices from infile.

  // -first vertex-point
  readFileLine(infile,buffer);
  readPoint(buffer, p1);

  // -second vertex-point
  readFileLine(infile,buffer);
  readPoint(buffer, p2);

  int body_layer = 0;

  // Create a new 2D element into the body
  createBodyElement2D(body, body_layer, p1, p2);

  return true;
}
示例#3
0
void readFileValues()
//
//  Input:   none
//  Output:  none
//  Purpose: reads next month's worth of data from climate file.
//
{
    int  i, j;
    int  y, m;

    // --- initialize FileData array to missing values
    for ( i=0; i<MAXCLIMATEVARS; i++)
    {
        for (j=0; j<MAXDAYSPERMONTH; j++) FileData[i][j] = MISSING;
    }

    while ( !ErrorCode )
    {
        // --- return when date on line is after current file date
        if ( feof(Fclimate.file) ) return;
        readFileLine(&y, &m);
        if ( y > FileYear || m > FileMonth ) return;

        // --- parse climate values from file line
        switch (FileFormat)
        {
        case  USER_PREPARED: parseUserFileLine();   break;
        case  TD3200:        parseTD3200FileLine();  break;
        case  DLY0204:       parseDLY0204FileLine(); break;
        }
        strcpy(FileLine, "");
    }
}
示例#4
0
// Method locates the starting position of the paramter lines
// (data lines) where the argument directory entry is pointing to.
// First line is read int global buffer "lineBuffer"
void
InputIges::locateParamEntry(IgesDirectoryEntry* de)
{
  int delta = de->startLine - paramSecLine;
  if (delta  == 0)
    return;
  else if (delta > 0) {
    paramSecLine += delta;
    readFileLine(infile, lineBuffer, delta);
    return;
  }
  else {
    infile.seekg(paramSecStart, ios::beg);
    paramSecLine = de->startLine;
    readFileLine(infile, lineBuffer, paramSecLine - 1);
  }
}
示例#5
0
bool processIsRuning(int pid)
{
    QString fn;
    QString s = readFileLine(fn.sprintf("/proc/%d/cmdline", pid));
    if(s.isEmpty())
        return false;
    else
        return true;
}
示例#6
0
// Method reads one data-line into buffer "data_buf" from Iges Cad-file.
// NOTE: end character (like ;) for the group of data lines
// is not read from the file.
void
InputIges::readDataLine(char* line_buf, char* data_buf)
{
  readFileLine(infile, line_buf);

  char* tmp = line_buf;
  int i = 0;
  // Copy data-part into data_buf. Don't copy data-end
  // separator character (normally ';')
  while (i < DATA_PART_LEN && *tmp != DATA_END)
    data_buf[i++] = *tmp++;

  data_buf[i] = '\0';

  // If we working om parameters-section, increase the
  // line counter.
  if (paramSecLine > 0)
    paramSecLine++;
}
示例#7
0
void climate_openFile()
//
//  Input:   none
//  Output:  none
//  Purpose: opens a climate file and reads in first set of values.
//
{
    int i, m, y;

    // --- open the file
    if ( (Fclimate.file = fopen(Fclimate.name, "rt")) == NULL )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_OPEN, Fclimate.name);
        return;
    }

    // --- initialize values of file's climate variables
    //     (Temp.ta was previously initialized in project.c)
    FileValue[TMIN] = Temp.ta;
    FileValue[TMAX] = Temp.ta;
    FileValue[EVAP] = 0.0;
    FileValue[WIND] = 0.0;

    // --- find climate file's format
    FileFormat = getFileFormat();
    if ( FileFormat == UNKNOWN_FORMAT )
    {
        report_writeErrorMsg(ERR_CLIMATE_FILE_READ, Fclimate.name);
        return;
    }

    // --- position file to begin reading climate file at either user-specified
    //     month/year or at start of simulation period.
    rewind(Fclimate.file);
    strcpy(FileLine, "");
    if ( Temp.fileStartDate == NO_DATE )
        datetime_decodeDate(StartDate, &FileYear, &FileMonth, &FileDay); 
    else
        datetime_decodeDate(Temp.fileStartDate, &FileYear, &FileMonth, &FileDay);
    while ( !feof(Fclimate.file) )
    {
        strcpy(FileLine, "");
        readFileLine(&y, &m);
        if ( y == FileYear && m == FileMonth ) break;
    }
    if ( feof(Fclimate.file) )
    {
        report_writeErrorMsg(ERR_CLIMATE_END_OF_FILE, Fclimate.name);
        return;
    }
    
    // --- initialize file dates and current climate variable values 
    if ( !ErrorCode )
    {
        FileElapsedDays = 0;
        FileLastDay = datetime_daysPerMonth(FileYear, FileMonth);
        readFileValues();
        for (i=TMIN; i<=WIND; i++)
        {
            if ( FileData[i][FileDay] == MISSING ) continue;
            FileValue[i] = FileData[i][FileDay];
        }
    }
}
// Method reads one wireframe body-element from Ideas univ. file dataset
// and adds body-element into body/model.   
// Returns: 1=new body was created, 0=old body was updateds, -1 = end-of-odataset.
int
InputIdeasWF::readWireFrameBody()
{
  Body* body;

  // We want to start from this position, when the body-read loop is started!
  //streampos cur_pos = infile.tellg();
 
  // =====Read body ID, CODE and NAME (from color code!) ( Record-1).
  readFileLine(infile, read_buffer);

  // However, check first that ***end-of-datset*** (-1) is not encountered
  // In this case dataset is empty!
  if (endofDataset(read_buffer))
    return -1;

  // Now read id, code and name.
  //char* name = readBodyName(read_buffer);
  int id_nbr = readBodyNbr(read_buffer);
  char* name = NULL;

  // =====Read CURVE-TYPE information ( Record-2).
  readFileLine(infile, read_buffer);
  ecif_geometryType g_type = readGeomType(read_buffer);

  // Back to body's starting position!
  //infile.seekg(cur_pos);

  // We check if we are reading new pieces for an old body!
  // Checking is based on a *local table* where we have id-numbers
  // from the file (id_nbr) and system (automagically) generated
  // technical id-numbers (body->Tag()) as pairs.
  bool isNewBody = false;
  IdNumberTable::iterator itr = bodyNumbers.find(id_nbr);

  // Old body
  if (itr != bodyNumbers.end())
    body = model->getBodyByTag((*itr).second);

  // Create a new body  
  else {
    colorIndices color = (colorIndices)id_nbr; // id_nbr is read from color code!

    //2D geometry
    if (modelDimension == ECIF_2D)
      body = new Body2D(GEOM_BODY, id_nbr, name, color);

    //3D geometry
    else if (modelDimension == ECIF_3D)
        body = new Body3D(GEOM_BODY, id_nbr, name, color);

    model->addBody(body);

    isNewBody = true;
    bodyNumbers[id_nbr] = body->Tag();
  }

  // How to read depends on the geometry-type:
  switch (g_type) {
  case ECIF_LINE:
    readLine(body, read_buffer);
    break;
  case ECIF_NURBS:
    readNurbs(body, read_buffer);
    break;
  default:
    break;
  }

  if (isNewBody)
    return 1;
  else
    return 0;
}
// Method reads a spline-segment-element in nurbs-form from Ideas univ. file (801)
bool
InputIdeasWF::readNurbs(Body* body, char* buffer)
{
  static ecif_EdgeGeometry_X edge;
  init_trx_data(edge);

  int i,j,pos;
  // *** Control-point section.
  int nf_vec[NF_SIZE];

  // Read curve-desrcribing vector.
  readFileLine(infile, buffer);
  istrstream strline(buffer);
  for (i = 0; i < NF_SIZE; i++) {
    strline >> nf_vec[i];
  }
  
  // Pick curve-defining factors from nf-vector.
  int nf_dim  = nf_vec[NFI_DIM];  // Dimension of control-points.
  int nf_len  = nf_vec[NFI_LEN];  // Length of data.
  int nf_n  = nf_vec[NFI_N];    // Nof control points.
  int nf_nk   = nf_vec[NFI_NK];   // Nof knot points.
  int nf_k  = nf_vec[NFI_K];    // Order of basis.

  // Read nurbs-curve defining data into a temporary data-vector.
  double* ct_data = new double[nf_len]; // a temporary data vector.
  
  int nf_rows; // nof data-rows in this section.
  if ( NF_COLS > 0 )
    nf_rows = nf_len / NF_COLS;
  else
    nf_rows = nf_len;

  pos = 0;

  for (i = 0; i < nf_rows; i++) {
    readFileLine(infile, buffer);
    istrstream strline(buffer);
    for (j = 0; j < NF_COLS; j++) {
      strline >> ct_data[pos++];
    }
  }

  // Now create final data-structures for nurbs-curve and
  // read them from temporary data-vector *ct_data*.

  // *** Control points (at the beginning of the data)
  Point4* ct_points = new Point4[nf_n];

  pos = 0;
  for (i = 0; i < nf_n; i++) {

    //We use always 4D-points
    int pos = 4 * i;
    ct_points[i][0] = 0.0;
    ct_points[i][1] = 0.0;
    ct_points[i][2] = 0.0;
    ct_points[i][3] = 1.0;

    for (j = 0; j < nf_dim; j++) {
      //Note: coordinates are scaled by unit
      ct_points[i][j] = model->unit.conv[j] * ct_data[pos++];
    }
  }

  // *** Next come knot-points
  double* knots = new double[nf_nk]; 

  pos = nf_n * nf_dim;
  for (i = 0; i < nf_nk; i++) {
    knots[i] = ct_data[pos + i];
  }

  //---Create a nurbs-curve body-element

  //-Two vertices
  // first vertex from the first control-point
  // second vertex from the last control-point
  edge.start = new Point3[1]; 
  edge.end = new Point3[1];

  for (i = 0; i < 3; i++) {
    edge.start[0][i] = ct_points[0][i] / ct_points[0][3];
    edge.end[0][i] = ct_points[nf_n - 1][i] / ct_points[nf_n - 1][3];
  }

  //-Other parameters
  edge.type = ECIF_NURBS;
  edge.isRational = (nf_dim == 4); // Is this ok !!!###!!!
  edge.degree = nf_k - 1;
  edge.nofKnots = nf_nk;
  edge.nofCpoints = nf_n;
  edge.knots = knots;
  edge.cpoints = ct_points;
  
  //-Create a new 2D element into the body
  int body_layer = 0;
  createBodyElement2D(body, body_layer, edge);

  // *** Defining points section.
  // Read nof defining point
  // NOT IN USE in practice. Used only to read 'off' the data from file !!!***!!!
  int df_n;
  readFileLine(infile, buffer);
  strline >> df_n;

  // Read defining-points desrcibing vector. All data on a single line.
  // This is a table where there are three items per defining-point:
  // 1. curve passes through point flag (0=no, 1=yes).
  // 2. tangent/derivative vector specified (0=no, 1=tangent, 2=derivative).
  // 3. curvature specified (0=no, 1=yes).
  readFileLine(infile, buffer);

  // Jump to the end of defining points section.
  readFileLine(infile, buffer, df_n);

  reset_trx_data(edge);

  return true;
}
示例#10
0
IgesDirectoryEntry*
InputIges::readDirectoryEntry(char* dir_line)
{
  char* tmp;
  IgesDirectoryEntry* dir_entry = new IgesDirectoryEntry;

  // First directory-entry line
  // ==========================

  //--Entity type number
  getDirectoryField(1, dir_line, fieldBuffer);
  dir_entry->entNbr = atoi(fieldBuffer);

  //--Id
  getDirectoryField(10, dir_line, fieldBuffer);
  tmp = fieldBuffer;
  dir_entry->id = atoi(++tmp);

  //--Start-line in par-section
  getDirectoryField(2, dir_line, fieldBuffer);
  dir_entry->startLine = atol(fieldBuffer);

  //--Tranformation matrix id
  getDirectoryField(7, dir_line, fieldBuffer);
  dir_entry->transfId = atol(fieldBuffer);

  //--Status field
  getDirectoryField(9, dir_line, fieldBuffer);
  dir_entry->status.setValues(fieldBuffer);


  // Second directory-entry line
  // ===========================
  readFileLine(infile, dir_line);

  //--Color number
  getDirectoryField(3, dir_line, fieldBuffer);
  dir_entry->colorNbr = (colorIndices)atoi(fieldBuffer);

  //--Number of lines in par-section
  getDirectoryField(4, dir_line, fieldBuffer);
  dir_entry->nofLines = atoi(fieldBuffer);

  //--Form number
  getDirectoryField(5, dir_line, fieldBuffer);
  dir_entry->formNbr = atoi(fieldBuffer);

  //--Check if this entry could be a body
  switch (dir_entry->entNbr) {
  case 100:
  case 102:
  case 106:
  case 141:
  case 142:
  case 143:
  case 144:
    dir_entry->canBeBody = true;
    break;
  }

  return dir_entry;
}
示例#11
0
struct renderstate *renderstateInitFromFile(FILE * file)
{
	char *line = 0;
	size_t lineLength = 0;
	char *title = 0;
	size_t titleLength = 0;

	int width, height;

	struct renderstate *render;

	// get title
	if (readFileLine(&title, &titleLength, file) == -1) {
		free(line);
		free(title);
		return 0;
	}
	// get width/height
	if (readFileLine(&line, &lineLength, file) == -1) {
		free(line);
		free(title);
		return 0;
	}
	if (sscanf(line, "%d %d", &width, &height) != 2) {
		free(line);
		free(title);
		return 0;
	}
	// init the render so far
	if (!(render = renderstateInit(title, width, height))) {
		free(line);
		free(title);
		return render;
	}
	// get scale
	if (readFileLine(&line, &lineLength, file) == -1) {
		freeRenderstate(render);
		free(line);
		free(title);
		return 0;
	}
	if (sscanf(line, "%f", &render->scale) != 1) {
		freeRenderstate(render);
		free(line);
		free(title);
		return 0;
	}
	// get x/y pos
	if (readFileLine(&line, &lineLength, file) == -1) {
		freeRenderstate(render);
		free(line);
		free(title);
		return 0;
	}
	if (sscanf(line, "%lf %lf", &render->xPos, &render->yPos) != 2) {
		freeRenderstate(render);
		free(line);
		free(title);
		return 0;
	}

	free(line);
	free(title);

	return render;
}