Recently,I dive into a set of somehow ancient Fortran codes and try to fully understand them. A large fraction of these codes are multiple layers of loops over many state variable dimensions, which are aiming to find policy function(fixed point). That's OK, but what's really annoyed me is the messy expression of the grid node index. For example,
do z=1,notimes do i=1,weignosims do t=1,nt ! main body of operations ! nodes index below node = (i-1)*(nt+ntr) + t ! To keep track of an individual's life index = (begnosims -1)*notimes + weignosims*(z-1) + i ! To keep track of which individual in which economy enddo enddo endo
It seems the author want to stack all index into one array and keep track each of them. However, it's naturally a multiple array. Such expression is both confusing and error-prone. Moreover, in later case, the author also write something like
asset(index,age) or even define three dimension array to represent 1 state/node. So why he bother to write in the above way
What I want to know is whether is just a matter of programming style or this kind of style can gain some benefit (at least w.r.t Fortran)? If the second reason holds, then can I have some alternative way to "trace node" when I switch to some more modern scientific computation language, like Julia?