Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!ub!acsu.buffalo.edu From: stein-c@acsu.buffalo.edu (Craig Steinberger) Newsgroups: comp.lang.fortran Subject: Pointers in FORTRAN Message-ID: <57829@eerie.acsu.Buffalo.EDU> Date: 5 Feb 91 00:48:18 GMT Sender: news@acsu.Buffalo.EDU Reply-To: stein-c@eng.buffalo.edu Organization: SUNY at Buffalo-CFD Lab Lines: 53 Nntp-Posting-Host: fractal.eng.buffalo.edu Hey Kids! I am trying to use pointers in SunOS 4.1 Fortran. Below are two code segments, and the output from each. Can anyone with experience tell me what is happening and what I did wrong? This program writes a number equal to the index of the array into each array position, i.e. a(3,2,1)=321.0 It then writes it out to a file. program writeme real a(3,3,3) do 12 i=1,3 do 11 j=1,3 do 10 k=1,3 a(i,j,k)=100.*float(i)+10.*float(j)+float(k) 10 continue 11 continue 12 continue write(1,*)(((a(i,j,k),i=1,3),j=1,3),k=1,3) And the output: 111.000 211.000 311.000 121.000 221.000 321.000 131.000 231.000 331.000 112.000 212.000 312.000 122.000 222.000 322.000 132.000 232.000 332.000 113.000 213.000 313.000 123.000 223.000 323.000 133.000 233.000 333.000 OK, so far so good. Now here's a program to read it back in. It then writes the same thing right out again. program readme pointer(pa, a) real a(1,1,*) size=27*8 pa=malloc(size) pia=malloc(size) read(1,*)(((a(i,j,k),i=1,3),j=1,3),k=1,3) write(2,*)(((a(i,j,k),i=1,3),j=1,3),k=1,3) Here is the output from that: 111.000 112.000 113.000 112.000 113.000 123.000 113.000 123.000 133.000 112.000 113.000 123.000 113.000 123.000 133.000 123.000 133.000 233.000 113.000 123.000 133.000 123.000 133.000 233.000 133.000 233.000 333.000 Now, obviously either I screwed up or I don't understand how the pointer concept works in FORTRAN, (Sun Fortran to be specific). My suspicion is that I am off by one somehow. Can anyone help? -- Craig Steinberger stein-c@eng.buffalo.edu SUNY at Buffalo, Computational Fluid Dynamics Lab