I'm trying to read and use a matrix market file, but my current attempts haven't produced anything. I'm extremely new to C++ so be gentle. Here's what I've got so far:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <algorithm>
using namespace std;
int main()
{
ifstream f("GX30.mtx");
int m,n,l;
while(f.peek()=='%') f.ignore(2048, '\n');
f>>m>>n>>l;
cout<<l;
int I[m],J[n],val[l];
int mat[m][n];
for(int i=1;i<=l;i++)
{
f>>I[i]>>J[i]>>val[i];
}
for(int k=1; k<=l;k++)
{
mat[I[k]][J[k]]=val[k];
cout<<"test";
}}
My test output produces nothing, and none of the variables determining the matrix parameters initialize properly. The first few lines from the file I'm reading from are as follows:
%%MatrixMarket matrix coordinate integer general
%% X {5,5} [[30,8,3]] [ (b*a^-1)^3 ]
12 30 60
1 1 1
1 3 1
1 4 1
The first line not proceeded by % indicates the number of rows, then columns, then lastly the number of non zero entries (I think) Then the following lines index the row and column position of each entry, with its corresponding value.