Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange Indexing in Fortran

Status
Not open for further replies.

mushi82

Programmer
Feb 7, 2012
1
Hi all,

I am totally new to fortran. I have to convert a code that is actually written in the fortran to matlab. There is only one subroutine that is totally mysterious for me. I am posting the part of code I have problem with, below:


1. subroutine cciri(xMODIP,mth,UT,R12,alat,along,foF2,M3000)
2. implicit real*8 (a-h,o-z)
3. real*8 M3000
4. character*10 filena
5. character*2 cm
6. dimension FF0(988),xm0(441),F2(13,76,2),FM3(9,49,2)
7. integer QM(7),QF(9)

8. save

9. data QF/11,11,8,4,1,0,0,0,0/,QM/6,7,5,2,1,0,0/
10. data montha,monthb,Rga/13,14,-10.0D0/

11. if (mth.ne.montha) then
12. write(cm,'(I2.2)') mth+10
13. filena='ccir'//cm//'.asc'
14. open(77,file=filena,status='OLD')

15. read(77,'(4E16.8)') F2,FM3

16. close(77)
17. montha=mth
18. endif

19. if (R12.ne.Rga.or.mth.ne.monthb) then
20. RR2=R12/100.0D0
21. RR1=1.0D0-RR2

22. do i=1,76
23. do j=1,13
24. k=j+13*(i-1)
25. FF0(k)=F2(j,i,1)*RR1+F2(j,i,2)*RR2
26. enddo
27. enddo

28. do i=1,49
29. do j=1,9
30. k=j+9*(i-1)
31. xm0(k)=FM3(j,i,1)*RR1+FM3(j,i,2)*RR2
32. enddo
33. enddo

34. Rga=R12
35. monthb=mth
36. endif

Just for reference, here are few lines taken from the files ccirXX.asc

0.56421361E+01 -0.81572428E-01 0.20138618E+00 0.42779669E-01
0.44377025E-01 0.38025160E-02 -0.87150786E-03 0.21708569E-01
-0.23025220E-01 -0.33594195E-02 0.21446483E-03 -0.18263943E-02
-0.12104558E-01 -0.10026588E+01 -0.77602589E+00 0.80115181E+00
-0.27182043E+00 0.54614949E+00 -0.18997940E+00 0.82413152E-01
-0.38998052E-01 -0.97885408E-01 0.13837354E+00 0.10652158E+00

Can anybody please explain lines 15 & 25 & 31 to me. I mean on line 15, variables F2 and FM3 are loaded as variables while on line 25 & 31 they are treated as 3D arrays? How is this possible? What is the logic behind this code? Mind you that the code is running absolutely fine in frotran.
Please help!.
 
read(77,'(4E16.8)') F2,FM3

If there is no subscript to an array in input or output, than it means that all elements of the array are to be read or written. So the statement above means that the two arrays F2 and FM3 are read from file, first all elements of F2, then then all of FM3. These values are read from lines of four elements in exponent-format as you see them in the lines of ccirXX.asc. You would receive an errormessage if there were not enough lines in this file to fill all the elements of both arrays, which would require more than numbers.

Line 25 and 31 adress individual elements of the arrays.

Norbert
 
should have been
.... more than 2800 numbers.

sorry, this got lost in typing somehow.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top