/*
 *	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(strSafe(lexNext(in)),"DSAA")
	{
		/* Isn't Surfer grid */
		return NULL;
	}
	rows=atoi(lexNext(in));
	cols=atoi(lexNext(in));
	for(i=0;i<3;i++)
	{
		mins[i]=atof(lexNext(in));
		maxs[i]=atof(lexNext(in));
	}
	res=matAlloc(rows,cols);
	for(i=0;i<rows;i++)
		for(j=0;j<cols;j++)
			matrix->cells[i][j]=atof(lexNext(in));
	tokFree(in);
	return res;
}
