Reading a 2D array from a file and comparing values ?

I am converting a C program to its equivalent CUDA version. I am not sure how to read a 2D array from a file.

Here’s how we would read a 2D array in C:

[codebox]if ((image1 = fopen(“image1.txt”, “r”)) == NULL)

{

	printf("\n ERROR - Cannot open the designated file\n");

}

else

{

	do {

		for(j = 0; j < pix2; ++j)

		{

			for(i = 0; i < pix1; ++i)

			{

				fscanf(image1, "%lf", &im1[i][j]);

			}

		}

	} while(!feof(image1));

	printf("\nSUCCESS - Files can be read\n");

}

/* Check values */

for(i = 64; i < 65; ++i)

{

	for(j = 1; j < 65; ++j)

	{

		printf("im1[%d][%d] = %lf \n",i,j,im1[i][j]);

	}

}

[/codebox]

CUDA equivalent for reading files?

[codebox]

unsigned int data_read = pix1 * pix2;

cutReadFiled(“image1.txt”, &im1, &data_read, true); // reading double values [/codebox]

How do I check the values of im1? any pointers? [:P]

Also I would like to compare the values of 2D arrays and thought of using this function from cutil.h

[codebox]

// Check values

CUTBoolean res = cutComparefe(in1, in2, nx * ny, 0.0001f); // in1 and in2 are 2D arrays of size nx * ny

printf(“Test %s\n”, (1 == res) ? “PASSED” : “FAILED”);

[/codebox]

Is this the correct way ??