//------------------------------------------------------------
// $Id: PRC_readDistInfo.cc,v 1.1.1.1 1999/11/25 06:26:09 yamauchi Exp $
//------------------------------------------------------------
//	readDistInfoPC.cc
//	
//	(C) Copyright 1998 Mayumi  TOKUNAGA
//			   Hitoshi YAMAUCHI
//------------------------------------------------------------
#include <fstream.h>
#include "mpi2_funcs.h"
#include "myString.h"
#include "mpi2exit.h"

//------------------------------------------------------------
// tokunaga changed
// reader implementation
//------------------------------------------------------------
// distance Data reader
//------------------------------------------------------------
YorN readDistanceDataInfo(const char *pDistFname, IntVec3 *pDefSpcVolNum,
			  char	*pDistanceMap, int size)
{
    int		x, y, z;
    ifstream	fin;
    fin.open(pDistFname);
    if (!fin)
    {
	return(NO);
    }
          
    int		x_num, y_num, z_num;
    char	map_type[64];

    // 1行目は x, y, z 軸方向の空間分割数
    fin >> x_num >> y_num >> z_num;
    if (x_num != size || y_num != size || z_num != size)
    {
	cout << "Error! : illegal space subdivision number, " <<
	    pDistFname << "." << endl;
	commMpi2_exit(1);
    }
    // 2行目はマップの種類
    fin >> map_type;
    if (myString(map_type) != myString("Chess_Board"))
    {
	cout << "Error! : unsupported map type, " << map_type << "." << endl;
	commMpi2_exit(1);
    }
    // fin.ignore(128, '\n');		// 3行無視
    // fin.ignore(128, '\n');		// 3行無視
    // fin.ignore(128, '\n');		// 3行無視

    assert(size >= pDefSpcVolNum->get(IntVec3::X) &&
	   size >= pDefSpcVolNum->get(IntVec3::Y) &&
	   size >= pDefSpcVolNum->get(IntVec3::Z));

    for (x = 0; x < size ; x++)
    {
	for (y = 0; y < size ; y++)
	{ 
	    for (z = 0; z < size ; z++)
	    {
		int	distance;
		// int distance = fin.get();
		fin >> distance;
		pDistanceMap[x * size * size + y * size + z] = distance;
	    }
	}
    }
    return(YES);
}


//------------------------------------------------------------
// for read test
//------------------------------------------------------------
#ifdef READ_DISTINFO_TEST 

// このようにすれば私のファイルを変更する必要はなくなりますね．YAMAUCHI
int main()
{

}

#endif				// #ifdef READ_DISTINFO_TEST 
