Is there an easier way to do all of this?

data[chan][0] = atoi(red); doesn't work.

What does that mean?
It doesn't like data because rows and cols are declared after you used them?

Or because of this
chan = atoi(chan); ?