// ################################################################# // bool convMxN::exec() { if( m_myRank == 0 ) { printf("Convert M x N\n"); } // 出力ファイル形式クラスのインスタンス convOutput *ConvOut = convOutput::OutputInit(m_param->Get_OutputFormat()); // InputParamのインスタンス if( !ConvOut->importInputParam(m_param) ) { //Exit(0); return false; } //出力ファイル名の取得 //vector<std::string> out_dfi_name = m_InputCntl->Get_OutdfiNameList(); std::string prefix,outfile; FILE *fp; int dummy; CDM::E_CDM_DTYPE d_type; CDM::E_CDM_ERRORCODE ret; double rtime; unsigned idummy = 0; double ddummy = 0.0; float fminmax[8]; double dminmax[8]; bool mio; mio = false; if( m_numProc > 1 ) mio=true; //間引き数のセット int thin_count = m_param->Get_ThinOut(); //入力領域指示のセット int IndexStart[3]; int IndexEnd[3]; for(int i=0; i<3; i++) IndexStart[i]=m_Head[i]; for(int i=0; i<3; i++) IndexEnd[i]=m_Tail[i]; if( m_param->Get_CropIndexStart_on() ) { const int *cropIndexStart = m_param->Get_CropIndexStart(); for(int i=0; i<3; i++) { if( IndexStart[i] < cropIndexStart[i] ) IndexStart[i]=cropIndexStart[i]; } } if( m_param->Get_CropIndexEnd_on() ) { const int *cropIndexEnd = m_param->Get_CropIndexEnd(); for(int i=0; i<3; i++) { if( IndexEnd[i] > cropIndexEnd[i] ) IndexEnd[i]=cropIndexEnd[i]; } } //自ノードのボクセルサイズの取得 int sz[3]; const int* tmp = m_paraMngr->GetLocalVoxelSize(); for(int i=0; i<3; i++) sz[i]=tmp[i]; //自ノードのボクセルサイズを入力指示を考慮して更新 for(int i=0; i<3; i++) { if( sz[i] > (IndexEnd[i]-IndexStart[i]+1) ) sz[i]=(IndexEnd[i]-IndexStart[i]+1); } //出力workareaのサイズ int szS[3]; const int *cropIndexStart = m_param->Get_CropIndexStart(); for(int i=0; i<3; i++) { szS[i]=sz[i]/thin_count; if( szS[i] < 1 ) { printf("\toutput domain size error\n"); return false; } if( m_param->Get_CropIndexStart_on() ) { if( IndexStart[i] == cropIndexStart[i] ) { if( sz[i]%thin_count != 0 ) szS[i]++; } } else { if( sz[i]%thin_count != 0 ) szS[i]++; } } int head[3],tail[3]; for(int i=0; i<3; i++) { head[i]=(m_Head[i]-1)/thin_count; if( (m_Head[i]-1)%thin_count != 0 ) head[i]++; tail[i]=(m_Tail[i]-1)/thin_count; } const double* dtmp; double pit[3],org[3]; dtmp = m_paraMngr->GetPitch(); for(int i=0; i<3; i++) pit[i]=dtmp[i]*double(thin_count); dtmp = m_paraMngr->GetGlobalOrigin(); for(int i=0; i<3; i++) org[i]=dtmp[i]+0.5*pit[i]; for(int i=0; i<3; i++) org[i]+=double(head[i])*pit[i]; const cdm_FileInfo* DFI_FInfo = m_in_dfi[0]->GetcdmFileInfo(); //dfiのループ for (int i=0; i<m_in_dfi.size(); i++) { int nVari = m_in_dfi[i]->GetNumVariables(); int outGc=0; if( m_param->Get_OutputGuideCell() > 0 ) outGc = m_param->Get_OutputGuideCell(); if( outGc > 0 ) { const cdm_FileInfo* DFI_FInfo = m_in_dfi[i]->GetcdmFileInfo(); if( outGc > DFI_FInfo->GuideCell ) outGc = DFI_FInfo->GuideCell; } if( thin_count > 1 ) outGc=0; if( m_param->Get_Interp_flag() ) outGc=0; //読込みバッファのインスタンス cdm_Array* buf = cdm_Array::instanceArray ( m_in_dfi[i]->GetDataType(), m_in_dfi[i]->GetArrayShape(), sz, //0, outGc, //m_in_dfi[i]->GetNumVariables()); nVari); //20160425.fub.s //fubファイルのとき読み込み座標値バッファのインスタンス cdm_FieldFileNameFormat * Ffformat = (cdm_FieldFileNameFormat *)m_in_dfi[i]->GetcdmFieldFileNameFormat(); cdm_DFI_FUB *dfi_fub = dynamic_cast<cdm_DFI_FUB*>(m_in_dfi[i]); cdm_Array * buf_xyz = NULL; if( dfi_fub || m_param->Get_OutputFormat() == CDM::E_CDM_FMT_FUB ) { buf_xyz = cdm_Array::instanceArray ( m_in_dfi[i]->GetDataType(), m_in_dfi[i]->GetArrayShape(), sz, outGc, 3); } //20160425.fub.e //出力タイプのセット if( m_param->Get_OutputDataType() == CDM::E_CDM_DTYPE_UNKNOWN ) { d_type = m_in_dfi[i]->GetDataType(); } else { d_type = m_param->Get_OutputDataType(); } //出力バッファのインスタンス cdm_Array* src = cdm_Array::instanceArray ( d_type, //m_in_dfi[i]->GetArrayShape(), m_param->Get_OutputArrayShape(), szS, //0, outGc, //m_in_dfi[i]->GetNumVariables()); nVari); //20160425.fub.s cdm_Array* src_xyz = NULL; //20160425.fub.e //DFI_FInfoクラスの取得 //20160425.fub.s //const cdm_FileInfo* DFI_FInfo = m_in_dfi[i]->GetcdmFileInfo(); cdm_FileInfo* DFI_FInfo = (cdm_FileInfo *)m_in_dfi[i]->GetcdmFileInfo(); const cdm_Domain* DFI_Domain = m_in_dfi[i]->GetcdmDomain(); //20160425.fub.e prefix=DFI_FInfo->Prefix; //TimeSliceクラスの取得 const cdm_TimeSlice* TSlice = m_in_dfi[i]->GetcdmTimeSlice(); //ステップ数のループ for ( int j=0; j<TSlice->SliceList.size(); j++ ) { //MxNの読込み ret = m_in_dfi[i]->ReadData(buf, (unsigned)TSlice->SliceList[j].step, //0, outGc, m_Gvoxel, m_Gdiv, m_Head, m_Tail, rtime, true, idummy, ddummy); if( ret != CDM::E_CDM_SUCCESS ) { printf("ReadData Error\n"); return false; } //20160425.fub.s if( m_param->Get_OutputFormat() == CDM::E_CDM_FMT_FUB ) { if( dfi_fub ) { CDM::E_CDM_FORMAT t_fmt = DFI_FInfo->FileFormat; DFI_FInfo->FileFormat = CDM::E_CDM_FMT_FUB_COD; int t_val = DFI_FInfo->NumVariables; DFI_FInfo->NumVariables = 3; ret = m_in_dfi[i]->ReadData(buf_xyz, (unsigned)TSlice->SliceList[j].step, //0, outGc, m_Gvoxel, m_Gdiv, m_Head, m_Tail, rtime, true, idummy, ddummy); DFI_FInfo->FileFormat = t_fmt; DFI_FInfo->NumVariables = t_val; src_xyz = NULL; if( ret == CDM::E_CDM_SUCCESS ) { //座標値出力バッファのインスタンス src_xyz = cdm_Array::instanceArray ( d_type, m_param->Get_OutputArrayShape(), szS, outGc, 3); } } if( src_xyz == NULL && j==0 ) { //座標値出力バッファのインスタンス src_xyz = cdm_Array::instanceArray ( d_type, m_param->Get_OutputArrayShape(), szS, outGc, 3); if( d_type == CDM::E_CDM_FLOAT64 ) { double *buf_p = (double *)buf_xyz->getData(); //座標値を計算する for(int k=0-outGc, kk=m_Head[2]; kk<=m_Tail[2]; k++, kk++ ) { for(int j=0-outGc, jj=m_Head[1]; jj<=m_Tail[1]; j++, jj++ ) { for(int i=0-outGc, ii=m_Head[0]; ii<=m_Tail[0]; i++, ii++ ) { buf_p[_CDM_IDX_IJKN(i,j,k,0,sz[0],sz[1],sz[2],outGc)] = DFI_Domain->CellX(ii-1); buf_p[_CDM_IDX_IJKN(i,j,k,1,sz[0],sz[1],sz[2],outGc)] = DFI_Domain->CellY(jj-1); buf_p[_CDM_IDX_IJKN(i,j,k,2,sz[0],sz[1],sz[2],outGc)] = DFI_Domain->CellZ(kk-1); }}} } else if( d_type == CDM::E_CDM_FLOAT32 ) { float *buf_p = (float *)buf_xyz->getData(); //座標値を計算する for(int k=0-outGc, kk=m_Head[2]; kk<=m_Tail[2]; k++, kk++ ) { for(int j=0-outGc, jj=m_Head[1]; jj<=m_Tail[1]; j++, jj++ ) { for(int i=0-outGc, ii=m_Head[0]; ii<=m_Tail[0]; i++, ii++ ) { buf_p[_CDM_IDX_IJKN(i,j,k,0,sz[0],sz[1],sz[2],outGc)] = DFI_Domain->CellX(ii-1); buf_p[_CDM_IDX_IJKN(i,j,k,1,sz[0],sz[1],sz[2],outGc)] = DFI_Domain->CellY(jj-1); buf_p[_CDM_IDX_IJKN(i,j,k,2,sz[0],sz[1],sz[2],outGc)] = DFI_Domain->CellZ(kk-1); }}} } } } //20160425.fub.e //読込みバッファのheadIndexのセット int headB[3]; for(int k=0; k<3; k++) headB[k]=m_Head[k]-1; buf->setHeadIndex( headB ); //間引き及び型変換がない場合 if( thin_count == 1 && buf->getDataType() == src->getDataType() && buf->getArrayShape() == src->getArrayShape() ) { src=buf; } else { //間引きまたは型変換がある場合 //出力バッファの間引きなしでのHeadIndex,TailIndex int headS[3],tailS[3]; for(int k=0; k<3; k++) { headS[k]=m_Head[k]-1; tailS[k]=m_Tail[k]-1; } //出力バッファのHeadIndexセット int headS0[3]; if( m_param->Get_CropIndexStart_on() ) { for(int k=0; k<3; k++) { headS0[k]=headS[k]/thin_count; } } else { for(int k=0; k<3; k++) { headS0[k]=headS[k]/thin_count; if( headS[k]%thin_count != 0 ) headS0[k]++; } } src->setHeadIndex( headS0 ); for(int n=0; n<nVari; n++) convertXY(buf,src,headS,tailS,n); //20160425.s if( src_xyz ) { for(int n=0; n<3; n++) convertXY(buf_xyz,src_xyz,headS,tailS,n); } //20160425.e } CDM::E_CDM_OUTPUT_FNAME output_fname = m_param->Get_OutputFilenameFormat(); m_out_dfi[i]->set_output_fname(output_fname); //minmaxの初期化 int nsize = nVari; if( nVari > 1 ) nsize++; double *min = new double[nsize]; double *max = new double[nsize]; for(int n=0; n<nsize; n++) { min[n]=DBL_MAX; max[n]=-DBL_MAX; } //minmaxを求める if( !DtypeMinMax(src,min,max) ) return false; //if( out_dfi_name.size() > 1 ) { if( m_param->Get_Outputdfi_on() ) { //ランク間で通信してMINMAXを求めてランク0に送信 int nbuff = nsize*1; //minの通信 double *send1 = min; double *recv1 = new double[nbuff]; MPI_Reduce(send1, recv1, nbuff, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); min = recv1; //maxの通信 double *send2 = max; double *recv2 = new double[nbuff]; MPI_Reduce(send2, recv2, nbuff, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); max = recv2; } //出力処理 double *tmp_minmax = new double[nsize*2]; for(int n=0; n<nsize; n++ ) { tmp_minmax[n*2+0] = min[n]; tmp_minmax[n*2+1] = max[n]; } m_out_dfi[i]->SetcdmTimeSlice(*TSlice); ret = m_out_dfi[i]->WriteData( (unsigned)TSlice->SliceList[j].step, //0, outGc, rtime, src, tmp_minmax, true, idummy, ddummy); //20160425.fub.s if( src_xyz ) { //out DFI_FInfoクラスの取得 //20160425.fub.s cdm_FileInfo* out_DFI_FInfo = (cdm_FileInfo *)m_out_dfi[i]->GetcdmFileInfo(); //20160425.fub.e CDM::E_CDM_FORMAT t_fmt = out_DFI_FInfo->FileFormat; out_DFI_FInfo->FileFormat = CDM::E_CDM_FMT_FUB_COD; int t_val = out_DFI_FInfo->NumVariables; out_DFI_FInfo->NumVariables = 3; ret = m_out_dfi[i]->WriteData( (unsigned)TSlice->SliceList[j].step, outGc, rtime, src_xyz, tmp_minmax, true, idummy, ddummy); out_DFI_FInfo->FileFormat = t_fmt; out_DFI_FInfo->NumVariables = t_val; } //20160425.fub.e } delete src; //20160425.fub.s if( src_xyz ) delete src_xyz; //20160425.fub.e } return true; }
// ################################################################# // bool convMxN::exec() { if( m_myRank == 0 ) { printf("Convert M x N\n"); } // 出力ファイル形式クラスのインスタンス convOutput *ConvOut = convOutput::OutputInit(m_param->Get_OutputFormat()); // InputParamのインスタンス if( !ConvOut->importInputParam(m_param) ) { //Exit(0); return false; } //出力ファイル名の取得 //vector<std::string> out_dfi_name = m_InputCntl->Get_OutdfiNameList(); std::string prefix,outfile; FILE *fp; int dummy; CIO::E_CIO_DTYPE d_type; CIO::E_CIO_ERRORCODE ret; double rtime; unsigned idummy; double ddummy; float fminmax[8]; double dminmax[8]; bool mio; mio = false; if( m_numProc > 1 ) mio=true; //間引き数のセット int thin_count = m_param->Get_ThinOut(); //入力領域指示のセット int IndexStart[3]; int IndexEnd[3]; for(int i=0; i<3; i++) IndexStart[i]=m_Head[i]; for(int i=0; i<3; i++) IndexEnd[i]=m_Tail[i]; if( m_param->Get_CropIndexStart_on() ) { const int *cropIndexStart = m_param->Get_CropIndexStart(); for(int i=0; i<3; i++) { if( IndexStart[i] < cropIndexStart[i] ) IndexStart[i]=cropIndexStart[i]; } } if( m_param->Get_CropIndexEnd_on() ) { const int *cropIndexEnd = m_param->Get_CropIndexEnd(); for(int i=0; i<3; i++) { if( IndexEnd[i] > cropIndexEnd[i] ) IndexEnd[i]=cropIndexEnd[i]; } } //自ノードのボクセルサイズの取得 int sz[3]; const int* tmp = m_paraMngr->GetLocalVoxelSize(); for(int i=0; i<3; i++) sz[i]=tmp[i]; //自ノードのボクセルサイズを入力指示を考慮して更新 for(int i=0; i<3; i++) { if( sz[i] > (IndexEnd[i]-IndexStart[i]+1) ) sz[i]=(IndexEnd[i]-IndexStart[i]+1); } //出力workareaのサイズ int szS[3]; const int *cropIndexStart = m_param->Get_CropIndexStart(); for(int i=0; i<3; i++) { szS[i]=sz[i]/thin_count; if( szS[i] < 1 ) { printf("\toutput domain size error\n"); return false; } if( m_param->Get_CropIndexStart_on() ) { if( IndexStart[i] == cropIndexStart[i] ) { if( sz[i]%thin_count != 0 ) szS[i]++; } } else { if( sz[i]%thin_count != 0 ) szS[i]++; } } int head[3],tail[3]; for(int i=0; i<3; i++) { head[i]=(m_Head[i]-1)/thin_count; if( (m_Head[i]-1)%thin_count != 0 ) head[i]++; tail[i]=(m_Tail[i]-1)/thin_count; } const double* dtmp; double pit[3],org[3]; dtmp = m_paraMngr->GetPitch(); for(int i=0; i<3; i++) pit[i]=dtmp[i]*double(thin_count); dtmp = m_paraMngr->GetGlobalOrigin(); for(int i=0; i<3; i++) org[i]=dtmp[i]+0.5*pit[i]; for(int i=0; i<3; i++) org[i]+=double(head[i])*pit[i]; const cio_FileInfo* DFI_FInfo = m_in_dfi[0]->GetcioFileInfo(); //dfiのループ for (int i=0; i<m_in_dfi.size(); i++) { int nComp = m_in_dfi[i]->GetNumComponent(); int outGc=0; if( m_param->Get_OutputGuideCell() > 1 ) outGc = m_param->Get_OutputGuideCell(); if( outGc > 0 ) { const cio_FileInfo* DFI_FInfo = m_in_dfi[i]->GetcioFileInfo(); if( outGc > DFI_FInfo->GuideCell ) outGc = DFI_FInfo->GuideCell; } if( thin_count > 1 ) outGc=0; if( m_bgrid_interp_flag ) outGc=0; //読込みバッファのインスタンス cio_Array* buf = cio_Array::instanceArray ( m_in_dfi[i]->GetDataType(), m_in_dfi[i]->GetArrayShape(), sz, //0, outGc, //m_in_dfi[i]->GetNumComponent()); nComp); //出力タイプのセット if( m_param->Get_OutputDataType() == CIO::E_CIO_DTYPE_UNKNOWN ) { d_type = m_in_dfi[i]->GetDataType(); } else { d_type = m_param->Get_OutputDataType(); } //出力バッファのインスタンス cio_Array* src = cio_Array::instanceArray ( d_type, //m_in_dfi[i]->GetArrayShape(), m_param->Get_OutputArrayShape(), szS, //0, outGc, //m_in_dfi[i]->GetNumComponent()); nComp); //DFI_FInfoクラスの取得 const cio_FileInfo* DFI_FInfo = m_in_dfi[i]->GetcioFileInfo(); prefix=DFI_FInfo->Prefix; //TimeSliceクラスの取得 const cio_TimeSlice* TSlice = m_in_dfi[i]->GetcioTimeSlice(); //ステップ数のループ for ( int j=0; j<TSlice->SliceList.size(); j++ ) { //MxNの読込み ret = m_in_dfi[i]->ReadData(buf, (unsigned)TSlice->SliceList[j].step, //0, outGc, m_Gvoxel, m_Gdiv, m_Head, m_Tail, rtime, true, idummy, ddummy); if( ret != CIO::E_CIO_SUCCESS ) { printf("ReadData Error\n"); return false; } //読込みバッファのheadIndexのセット int headB[3]; for(int k=0; k<3; k++) headB[k]=m_Head[k]-1; buf->setHeadIndex( headB ); //間引き及び型変換がない場合 if( thin_count == 1 && buf->getDataType() == src->getDataType() && buf->getArrayShape() == src->getArrayShape() ) { src=buf; } else { //間引きまたは型変換がある場合 //出力バッファの間引きなしでのHeadIndex,TailIndex int headS[3],tailS[3]; for(int k=0; k<3; k++) { headS[k]=m_Head[k]-1; tailS[k]=m_Tail[k]-1; } //出力バッファのHeadIndexセット int headS0[3]; if( m_param->Get_CropIndexStart_on() ) { for(int k=0; k<3; k++) { headS0[k]=headS[k]/thin_count; } } else { for(int k=0; k<3; k++) { headS0[k]=headS[k]/thin_count; if( headS[k]%thin_count != 0 ) headS0[k]++; } } src->setHeadIndex( headS0 ); for(int n=0; n<nComp; n++) convertXY(buf,src,headS,tailS,n); } CIO::E_CIO_OUTPUT_FNAME output_fname = m_param->Get_OutputFilenameFormat(); m_out_dfi[i]->set_output_fname(output_fname); //minmaxの初期化 int nsize = nComp; if( nComp > 1 ) nsize++; double *min = new double[nsize]; double *max = new double[nsize]; for(int n=0; n<nsize; n++) { min[n]=DBL_MAX; max[n]=-DBL_MAX; } //minmaxを求める if( !DtypeMinMax(src,min,max) ) return false; //if( out_dfi_name.size() > 1 ) { if( m_param->Get_Outputdfi_on() ) { //ランク間で通信してMINMAXを求めてランク0に送信 int nbuff = nsize*1; //minの通信 double *send1 = min; double *recv1 = new double[nbuff]; MPI_Reduce(send1, recv1, nbuff, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); min = recv1; //maxの通信 double *send2 = max; double *recv2 = new double[nbuff]; MPI_Reduce(send2, recv2, nbuff, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); max = recv2; } //出力処理 double *tmp_minmax = new double[nsize*2]; for(int n=0; n<nsize; n++ ) { tmp_minmax[n*2+0] = min[n]; tmp_minmax[n*2+1] = max[n]; } m_out_dfi[i]->SetcioTimeSlice(*TSlice); ret = m_out_dfi[i]->WriteData( (unsigned)TSlice->SliceList[j].step, //0, outGc, rtime, src, tmp_minmax, true, idummy, ddummy); } delete src; } return true; }