I haven't tried it in a while, but I don't think you can use index in a reference. i.e. var(1:var2(ix)) won't compile (probably).
and there is an functional error as well with the code provided : any number in file starting with 1 will equal your second entry in the table. You should use the size of the filein-nif to test. : varA(1:sizeofvarA) = varB(1:sizeofvarB)
I can explain it to you, but i can not understand it for you.