// Read header
char buf[1024];
fgets(buf,1024,in);
sscanf(buf,"%d %d %d", &M, &N, &K);
// Read W
for (int i=0; i<M; i++)
for (int c=0; c<3; c++)
for (int k=0; k<K; k++)
fread(&(W[k][i*3+c]),sizeof(float),1,in)
// Read H
float *_H = (float *)malloc(sizeof(float)*K*N);
if ( K*N != fread(_H,sizeof(float),K*N,in) )
{
fprintf(stderr, "Unexpected EOF while reading file: %s\\n", argv[2]);
exit(1);
}
for (int i=0; i<K; i++)
for (int j=0; j<N; j++)
for (int c=0; c<3; c++)
H[i*N*3+j*3+c] = _H[i*N+j];
free(_H);