예제 #1
0
void write_points(const char *fname, DATA *d, DPOINT *where, double *est,
	int n_outfl) {

	static FILE *f = NULL;
#ifdef HAVE_LIBGIS
	static Site *site = NULL;
	static int dim = 2;
	int i;
#endif 

	if (! grass()) {
		if (where == NULL) {
			if (fname != NULL) {
				f = efopen(fname, "w");
				write_ascii_header(f, d, n_outfl);
			} else
				efclose(f);
		} else {
			if (f == NULL)
				ErrMsg(ER_NULL, "write_points(): f");
			output_line(f, d, where, est, n_outfl);
		}
	} else {
#ifdef HAVE_LIBGIS
		if (where == NULL) {
			if (fname != NULL) { /* initialize: */
				DUMP("opening grass sites list\n");
				if (d->mode & Z_BIT_SET)
					dim++;
				if ((f = G_sites_open_new((char *) fname)) == NULL)
					G_fatal_error("%s: cannot open sites file %f for writing\n",
						G_program_name());
				site = G_site_new_struct(CELL_TYPE, dim, 0, n_outfl);
			} else { /* close: */
				DUMP("closing grass sites list\n");
				fclose(f);
				dim = 2;
				G_site_free_struct(site);
				site = NULL;
			}
		} else {
			assert(site != NULL);
			assert(d != NULL);
			/* fill site: */
			site->east = where->x;
			site->north = where->y;
			if (d->mode & Z_BIT_SET)
				site->dim[0] = where->z;
			if (d->mode & S_BIT_SET)
				site->ccat = where->u.stratum + strata_min;
			else
				site->ccat = GET_INDEX(where) + 1;
			for (i = 0; i < n_outfl; i++) {
				if (is_mv_double(&(est[i]))) {
					site->dbl_att[i] = -9999.0;
					if (DEBUG_DUMP)
						printlog(" [%d]:mv ", i);
				} else {
					site->dbl_att[i] = est[i];
					if (DEBUG_DUMP)
						printlog(" value[%d]: %g ", i, site->dbl_att[i]);
				}
			}
			if (DEBUG_DUMP)
				printlog("\n");
			G_site_put(f, site);
		}
#else 
		ErrMsg(ER_IMPOSVAL, "gstat/grass error: libgis() not linked");
#endif 
	}
}
예제 #2
0
// #################################################################
// fileld data 出力
CIO::E_CIO_ERRORCODE
cio_DFI::WriteData(const unsigned step,
                   const int gc,
                   double time,
                   cio_Array* val,
                   double* minmax,
                   const bool avr_mode,
                   const unsigned step_avr,
                   double time_avr)
{

  //printf("WriteData RankID : %d\n",m_RankID);

  bool mio=false;
  if( DFI_MPI.NumberOfRank > 1 ) mio=true;

  std::string outFile,tmp;
//FCONV 20131128.s
  if( m_output_fname != CIO::E_CIO_FNAME_RANK_STEP ) {
    tmp = Generate_FieldFileName(m_RankID,step,mio);
    if( CIO::cioPath_isAbsolute(DFI_Finfo.DirectoryPath) ){
      outFile = tmp;
    } else {
      outFile = m_directoryPath + "/"+ tmp;
    }
  } else {
    std::string ext;
    if( DFI_Finfo.FileFormat == CIO::E_CIO_FMT_SPH ) {
      ext = D_CIO_EXT_SPH;
    } else if( DFI_Finfo.FileFormat == CIO::E_CIO_FMT_BOV ) {
      ext = D_CIO_EXT_BOV;
    } else if( DFI_Finfo.FileFormat == CIO::E_CIO_FMT_AVS ) {
      //ext = D_CIO_EXT_SPH;
      ext = D_CIO_EXT_BOV;
    } else if( DFI_Finfo.FileFormat == CIO::E_CIO_FMT_VTK ) {
      ext = D_CIO_EXT_VTK;
    } else if( DFI_Finfo.FileFormat == CIO::E_CIO_FMT_PLOT3D ) {
      ext = D_CIO_EXT_FUNC;
    }
    tmp = Generate_FileName(DFI_Finfo.Prefix,
                            m_RankID,
                            step,ext,
                            m_output_fname,
                            mio,
                            DFI_Finfo.TimeSliceDirFlag);
    if( CIO::cioPath_isAbsolute(DFI_Finfo.DirectoryPath) ){
      outFile = DFI_Finfo.DirectoryPath +"/"+ tmp;
    } else {
      outFile = m_directoryPath + "/" + DFI_Finfo.DirectoryPath +"/"+ tmp;
    }
  }
//FCONV 20131128.e

  std::string dir = CIO::cioPath_DirName(outFile);

  if( MakeDirectory(dir) != 1 ) return CIO::E_CIO_ERROR_MAKEDIRECTORY;

  cio_Array *outArray = val;
  if( gc != DFI_Finfo.GuideCell ) {
    //出力用バッファのインスタンス
    outArray = cio_Array::instanceArray
               ( DFI_Finfo.DataType
               , DFI_Finfo.ArrayShape
               , DFI_Process.RankList[m_RankID].VoxelSize
               , DFI_Finfo.GuideCell
               , DFI_Finfo.Component); 
    //配列のコピー val -> outArray
    int ret = val->copyArray(outArray);
  }

  // フィールドデータの出力
  CIO::E_CIO_ERRORCODE err = CIO::E_CIO_SUCCESS;
  err = WriteFieldData(outFile, step, time, outArray, avr_mode, step_avr, time_avr);

  //出力バッファのメモリ解放
  if( val != outArray ) {
    delete outArray;
  }

  if( err != CIO::E_CIO_SUCCESS ) return err;

//FCONV 20131218.s
  if( m_indexDfiName != "" ) {
    //index dfi ファイルのディレクトリ作成
    cio_DFI::MakeDirectory(m_directoryPath);
    std::string dfiname = CIO::cioPath_FileName(m_indexDfiName,".dfi");
    std::string fname = CIO::cioPath_ConnectPath( m_directoryPath, dfiname );

    //Slice へのセット
    DFI_TimeSlice.AddSlice(step, time, minmax, DFI_Finfo.Component, avr_mode,
                           step_avr, time_avr);

    //index dfi のファイル出力
    if( m_RankID == 0 ) {
      err = WriteIndexDfiFile(fname);
    }
  }
//FCONV 20131218.e
//FCONV 20131125.s
  if( !write_ascii_header(step,time) ) return CIO::E_CIO_ERROR;
//FCONV 20131125.e

  return err;
}