Kausik you've double posted this.
You left your former discussion adrift, labeled in many groups, and not updated it to show the progress of this discussion. This has lead me to comment there on out of date information.
You will struggle to develop and debug your nested do loops. Other users will find it near impossible as we do not know your intent.
I suggest reducing to where you see a problem: run your program to generate 'fd' and your other variables. Output these and check they behave as you'd expect. Then check that for the first instance of 'i' and 'j' iterators your code does as you'd expect.