<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkEnSightCompoundReader.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 1993-2002 <NAME>, <NAME>, <NAME> 
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkEnSightCompoundReader.h"

#include "vtkCollection.h"
#include "vtkFloatArray.h"
#include "vtkObjectFactory.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkUnstructuredGrid.h"
#include "vtkString.h"

vtkCxxRevisionMacro(vtkEnSightCompoundReader, "1.1");
vtkStandardNewMacro(vtkEnSightCompoundReader);

//----------------------------------------------------------------------------
vtkEnSightCompoundReader::vtkEnSightCompoundReader()
{
  this->PieceCaseFileName = 0;
  this->MaxNumberOfPieces = 0;
  this->CurrentPiece      = -1;
}

//----------------------------------------------------------------------------
vtkEnSightCompoundReader::~vtkEnSightCompoundReader()
{
  this->SetPieceCaseFileName(0);
}

//----------------------------------------------------------------------------
void vtkEnSightCompoundReader::Execute()
{
  if ( !this->MaxNumberOfPieces )
    {
    vtkErrorMacro("No pices to read");
    return;
    }

  if ( this->CurrentPiece < 0 || 
       this->CurrentPiece >= this->MaxNumberOfPieces )
    {
    vtkErrorMacro("Current piece has to be set before reading the file");
    return;
    }
  if ( this->DetermineFileName(this->CurrentPiece) != VTK_OK )
    {
    vtkErrorMacro("Cannot update piece: " << this->CurrentPiece);
    return;
    }
  //cout << "Updating piece: " << this->CurrentPiece 
  //     << " which is in the file: " 
  //     << this->PieceCaseFileName << endl;
  if ( !this->Reader )
    {
    this->Reader = vtkGenericEnSightReader::New();
    }
  this->Reader->SetCaseFileName(this->PieceCaseFileName);
  this->Superclass::Execute();
}

//----------------------------------------------------------------------------
void vtkEnSightCompoundReader::ExecuteInformation()
{  
  if ( this->DetermineFileName(-1) != VTK_OK )
    {
    vtkErrorMacro("Problem parsing the case file");
    return;
    }  
}

int vtkEnSightCompoundReader::DetermineFileName(int piece)
{
  char line[1024];

  if (!this->CaseFileName)
    {
    vtkErrorMacro("A case file name must be specified.");
    return VTK_ERROR;
    }
  if (this->FilePath)
    {
    strcpy(line, this->FilePath);
    strcat(line, this->CaseFileName);
    vtkDebugMacro("full path to case file: " << line);
    }
  else
    {
    strcpy(line, this->CaseFileName);
    }

  //cout << "ExecuteInformation" << endl;
  this->IS = new ifstream(line, ios::in);;
  if ( this->IS->fail() )
    {
    //cout << "Cannot open file: " << line << endl;
    return VTK_ERROR;
    }
  char result[1024];

  int servers       = 0;
  int numberservers = 0;
  int currentserver = 0;

  while ( this->ReadNextDataLine(result) )
    {
    if ( vtkString::Equals(result, "FORMAT") )
      {
      // Format
      }
    else if ( vtkString::Equals(result, "SERVERS") )
      {
      servers = 1;
      }
    else if ( servers && vtkString::StartsWith(result, "number of servers:") )
      {
      sscanf(result, "number of servers: %i", &numberservers);
      if ( !numberservers )
        {
        vtkErrorMacro("The case file is corrupted");
        break;
        }
      }
    else if ( servers && vtkString::StartsWith(result, "casefile:") )
      {
      if ( currentserver == piece )
        {
        char filename[1024] = "";
        sscanf(result, "casefile: %s", filename);
        if ( filename[0] == 0 )
          {
          //cout << "Problem parsing file name from: " << result << endl;
          return VTK_ERROR;
          }
        this->SetPieceCaseFileName(filename);
        }
      else
        {
        currentserver ++;
        }
      }
    //cout << "Read: " << result << endl;
    }
  if ( piece == -1 && currentserver != numberservers )
    {
    //cout << "Number of servers (" << numberservers 
    //<< ") is not equal to the actual number of servers (" 
    //<< currentserver << ")" << endl;
    return VTK_ERROR;
    }
  //cout << "Number of servers is: " << numberservers << endl;
  this->MaxNumberOfPieces = numberservers;
  delete this->IS;
  this->IS = 0;
  if ( this->GetOutput() )
    {
    this->GetOutput()->Print(cout);
    }
  return VTK_OK;
}

//----------------------------------------------------------------------------
void vtkEnSightCompoundReader::UpdateInformation()
{
  this->ExecuteInformation();
}

void vtkEnSightCompoundReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
}<commit_msg>Remove print<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkEnSightCompoundReader.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 1993-2002 <NAME>, <NAME>, <NAME> 
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include "vtkEnSightCompoundReader.h"

#include "vtkCollection.h"
#include "vtkFloatArray.h"
#include "vtkObjectFactory.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkUnstructuredGrid.h"
#include "vtkString.h"

vtkCxxRevisionMacro(vtkEnSightCompoundReader, "1.2");
vtkStandardNewMacro(vtkEnSightCompoundReader);

//----------------------------------------------------------------------------
vtkEnSightCompoundReader::vtkEnSightCompoundReader()
{
  this->PieceCaseFileName = 0;
  this->MaxNumberOfPieces = 0;
  this->CurrentPiece      = -1;
}

//----------------------------------------------------------------------------
vtkEnSightCompoundReader::~vtkEnSightCompoundReader()
{
  this->SetPieceCaseFileName(0);
}

//----------------------------------------------------------------------------
void vtkEnSightCompoundReader::Execute()
{
  if ( !this->MaxNumberOfPieces )
    {
    vtkErrorMacro("No pices to read");
    return;
    }

  if ( this->CurrentPiece < 0 || 
       this->CurrentPiece >= this->MaxNumberOfPieces )
    {
    vtkErrorMacro("Current piece has to be set before reading the file");
    return;
    }
  if ( this->DetermineFileName(this->CurrentPiece) != VTK_OK )
    {
    vtkErrorMacro("Cannot update piece: " << this->CurrentPiece);
    return;
    }
  //cout << "Updating piece: " << this->CurrentPiece 
  //     << " which is in the file: " 
  //     << this->PieceCaseFileName << endl;
  if ( !this->Reader )
    {
    this->Reader = vtkGenericEnSightReader::New();
    }
  this->Reader->SetCaseFileName(this->PieceCaseFileName);
  if ( !this->Reader->GetFilePath() )
    {
    this->Reader->SetFilePath( this->GetFilePath() );
    }
  this->Superclass::Execute();
}

//----------------------------------------------------------------------------
void vtkEnSightCompoundReader::ExecuteInformation()
{  
  if ( this->DetermineFileName(-1) != VTK_OK )
    {
    vtkErrorMacro("Problem parsing the case file");
    return;
    }  
}

int vtkEnSightCompoundReader::DetermineFileName(int piece)
{
  char line[1024];

  if (!this->CaseFileName)
    {
    vtkErrorMacro("A case file name must be specified.");
    return VTK_ERROR;
    }
  if (this->FilePath)
    {
    strcpy(line, this->FilePath);
    strcat(line, this->CaseFileName);
    vtkDebugMacro("full path to case file: " << line);
    }
  else
    {
    strcpy(line, this->CaseFileName);
    }

  //cout << "ExecuteInformation" << endl;
  this->IS = new ifstream(line, ios::in);;
  if ( this->IS->fail() )
    {
    //cout << "Cannot open file: " << line << endl;
    return VTK_ERROR;
    }
  char result[1024];

  int servers       = 0;
  int numberservers = 0;
  int currentserver = 0;

  while ( this->ReadNextDataLine(result) )
    {
    if ( vtkString::Equals(result, "FORMAT") )
      {
      // Format
      }
    else if ( vtkString::Equals(result, "SERVERS") )
      {
      servers = 1;
      }
    else if ( servers && vtkString::StartsWith(result, "number of servers:") )
      {
      sscanf(result, "number of servers: %i", &numberservers);
      if ( !numberservers )
        {
        vtkErrorMacro("The case file is corrupted");
        break;
        }
      }
    else if ( servers && vtkString::StartsWith(result, "casefile:") )
      {
      if ( currentserver == piece )
        {
        char filename[1024] = "";
        sscanf(result, "casefile: %s", filename);
        if ( filename[0] == 0 )
          {
          //cout << "Problem parsing file name from: " << result << endl;
          return VTK_ERROR;
          }
        this->SetPieceCaseFileName(filename);
        }
      else
        {
        currentserver ++;
        }
      }
    //cout << "Read: " << result << endl;
    }
  if ( piece == -1 && currentserver != numberservers )
    {
    //cout << "Number of servers (" << numberservers 
    //<< ") is not equal to the actual number of servers (" 
    //<< currentserver << ")" << endl;
    return VTK_ERROR;
    }
  //cout << "Number of servers is: " << numberservers << endl;
  this->MaxNumberOfPieces = numberservers;
  delete this->IS;
  this->IS = 0;
  return VTK_OK;
}

//----------------------------------------------------------------------------
void vtkEnSightCompoundReader::UpdateInformation()
{
  this->ExecuteInformation();
}

void vtkEnSightCompoundReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
}
{'fraction_non_alphanumeric': 0.2281885758998435, 'fraction_numerical': 0.007042253521126761, 'mean_word_length': 2.258444869343531, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7296272', 'n_tokens_mistral': 3171, 'n_tokens_neox': 3049, 'n_words': 648}