Exemple #1
0
void Location_File::Add_User_Fields (Location_File *file)
{
	int i, offset, nfield;
	bool convert, binary;
	Field_Ptr fld;

	if (file == 0) return;

	if (Dbase_Format () == DEFAULT_FORMAT) {
		Dbase_Format (DEFAULT_FORMAT);
	}
	convert = (file->Dbase_Format () != Dbase_Format () || Num_Fields () > 0);
	binary = (file->Record_Format () == BINARY);

	offset = END_OF_RECORD;
	nfield = file->Num_Fields ();

	for (i=0; i < nfield; i++) {
		fld = file->Field (i);
		if (fld == 0) continue;

		//---- skip standard fields ----

		if (fld->Name ().Equals ("LOCATION") || fld->Name ().Equals ("ID") || fld->Name ().Equals ("LINK") ||
			fld->Name ().Equals ("OFFSET") || fld->Name ().Equals ("SETBACK") || fld->Name ().Equals ("ZONE") ||
			fld->Name ().Equals ("TAZ") || fld->Name ().Equals ("DIR") || fld->Name ().Equals ("NODE") ||
			fld->Name ().Equals ("X_COORD") || fld->Name ().Equals ("EASTING") || fld->Name ().Equals ("X") ||
			fld->Name ().Equals ("Y_COORD") || fld->Name ().Equals ("NORTHING") || fld->Name ().Equals ("Y") ||
			fld->Name ().Equals ("NOTES")) continue;

		if (!convert) {
			offset = fld->Offset ();
		}
		Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Units (), binary, NO_NEST, offset);
	}
	Write_Fields ();
	Write_Header ();
}
Exemple #2
0
// #################################################################
// DFIファイルを出力する
bool DFI::Write_File(const std::string dfi_name, const std::string prefix, const unsigned step, int& dfi_mng, const bool mio)
{
  if ( dfi_name.empty() ) return false;
  if ( prefix.empty() ) return false;

  FILE* fp = NULL;
  
  // File exist ?
  bool flag = false;
  if ( fp = fopen(dfi_name.c_str(), "r") )
  {
    flag = true;
    fclose(fp);
  }

  
  if ( (dfi_mng == 0) || !flag || (start_type == coarse_restart) ) // カウントゼロ=セッションの開始、または既存ファイルが存在しない、または粗格子リスタート
  {
    if( !(fp = fopen(dfi_name.c_str(), "w")) )
    {
      fprintf(stderr, "Can't open file.(%s)\n", dfi_name.c_str());
      return false;
    }
    
    if (fp) fprintf(fp, "Distributed_File_Info {\n");
    if (fp) fprintf(fp, "\n");
    
    if( !Write_Header(fp, 0, prefix) )
    {
      if (fp) fclose(fp);
      return false;
    }
    
    if (fp) fprintf(fp, "\n");
    
    if (fp) Write_Tab(fp, 1);
    if (fp) fprintf(fp, "FileInfo {\n");

    if ( !Write_OutFileInfo(fp, 1, prefix, step, mio) )
    {
      if (fp) fclose(fp);
      return false;
    }
    
    if (fp) Write_Tab(fp, 1);
    if (fp) fprintf(fp, "}\n");
    if (fp) fprintf(fp, "}\n");
    if (fp) fclose(fp);
    
  }
  else // 既存ファイルが存在する、あるいはセッションが始まり既に書き込み済み >> 追記
  {
    
    // ファイルの内容をバッファ
    fp = fopen(dfi_name.c_str(), "r");
    
    std::string str;
    while( !feof(fp) ){
      int c = fgetc(fp);
      if( !feof(fp) ) str += c;
    }
    fclose(fp);
    
    register int i = str.size() - 1;
    while( --i > 0 ) {
      if( str[i] == '\n' ) { str[i+1] = '\0'; break; }
    }
    
    while( --i > 0 ) {
      if( str[i] == '\n' ) { str[i+1] = '\0'; break; }
    }
    
    // 新規ファイルを生成し、バッファを書きだしたあとにファイル情報を追記
    if( !(fp = fopen(dfi_name.c_str(), "w")) )
    {
      fprintf(stderr, "Can't open file.(%s)\n", dfi_name.c_str());
      return false;
    }
    
    if ( fp && fwrite(str.c_str(), sizeof(char), strlen(str.c_str()), fp) != strlen(str.c_str()) )
    {
      if (fp) fclose(fp);
      return false;
    }
    
    if ( !Write_OutFileInfo(fp, 1, prefix, step, mio) )
    {
      if (fp) fclose(fp); 
      return false;
    }
    
    if (fp) Write_Tab(fp, 1);
    if (fp) fprintf(fp, "}\n");
    if (fp) fprintf(fp, "}\n");
    if (fp) fclose(fp);
    
  }
  
  dfi_mng++;
  
  return true;
}