/*
 *	Data maps for GoldenSoftware "Surfer"
 */

vboolean
grdSave(char *filename,matrix_t *grid,vec3_t mins,vec3_t maxs)
{
	out=fileOpenWrite(filename);
	filePuts(out,"DSAA\n");
	filePrintf("%d %d\n",grid->rows,grid->cols);
	for(i=0;i<3;i++)
		filePrintf(out,"%g %g\n",mins[i],max[i]);
	for(i=0;i<rows;i++)
	{
		for(j=0;j<cols;j++)
			filePrintf(out,"%g ",matrix->cells[i][j]);
		filePuts(out,"\n");
	}
	fileClose(out);
	return true;
}

matrix_p
grdLoad(char *filename,vec3_t mins,vec3_t maxs)
{
	parser_t in;
	in=tokStartFile(filename,NULL);
	if(strcmp(dbs(tokNext(in)),"DSAA")
	{
		/* Isn't Surfer grid */
		return NULL;
	}
	rows=atoi(tokNext(in));
	cols=atoi(tokNext(in));
	for(i=0;i<3;i++)
	{
		mins[i]=atof(tokNext(in));
		maxs[i]=atof(tokNext(in));
	}
	res=matAlloc(rows,cols);
	for(i=0;i<rows;i++)
		for(j=0;j<cols;j++)
			matrix->cells[i][j]=atof(tokNext(in));
	tokFree(in);
	return res;
}
