[Gridflow-cvs] [svn] commit: r5482 - /trunk/src/formats.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Mon Apr 19 17:14:11 EDT 2010

Author: matju
Date: Mon Apr 19 17:14:08 2010
New Revision: 5482

[#in grid]: bang: report end-of-file, report read error (strerror); in case of error, pad grid with zeroes and finish outputting


Modified: trunk/src/formats.cxx
--- trunk/src/formats.cxx (original)
+++ trunk/src/formats.cxx Mon Apr 19 17:14:08 2010
@@ -209,14 +209,17 @@
 		if (head.reserved!=0) RAISE("unsupported grid reserved field %d in file",head.reserved);
 		if (head.dimn>16) RAISE("unsupported grid number of dimensions %d in file",head.dimn);
 		int32 dimv[head.dimn];
-		;
 		if (fread(dimv,1,head.dimn*4,f)<size_t(head.dimn*4)) RAISE("can't read dimension list");
 		if (endian != is_le()) swap32(head.dimn,(uint32 *)dimv);
 		dim = new Dim(head.dimn,dimv);
 	GridOutlet out(this,0,dim,nt);
 	long nn = dim->prod();
-#define FOO(T) {T data[nn]; if (fread(data,1,nn*sizeof(T),f)<nn*sizeof(T)) RAISE("can't read grid data (body)"); out.send(nn,(T *)data);}
+#define FOO(T) {T data[nn]; size_t nnn = fread(data,1,nn*sizeof(T),f); \
+	if (nnn<nn*sizeof(T)) pd_error(bself,"can't read grid data (body): %s", feof(f) ? "end of file" : strerror(ferror(f))); \
+	CLEAR(data+nnn/sizeof(T),nn-nnn/sizeof(T)); \
+	out.send(nn,(T *)data);}
 #undef FOO

More information about the Gridflow-cvs mailing list