1

I need the code to write the data of two circles in order to export it as an animation (vmd). This should give me around 6000 data(3000 per circle).

When I run the program it only writes the data of the first circle. How do I write the two sets of data in the same file? Here is the code I used

       Program circulo
       implicit double precision(A-H,O-Z)
       Character*4 W1,W6
       Character*4 W2,W7   
       Open(3,file='circular.xyz',access='append',action='readwrite')
       open(9,file='circular.dat',form='formatted',action='readwrite')
       Call Circular1
       Call Circular2
       Stop
       End 
c*******************************************************************************

       Subroutine Circular1
       implicit double precision(A-H,O-Z)
       Dimension x(9000),y(9000),z(9000)
       Character*4 W1,W6
       W1='Rb'
       W6='   '
       Natomos = 1


       rewind(3)
       rewind(9)

       write(6,*) 'dame el valor del radio'
       read(5,*)Radio
       write(6,*) 'dame el valor del angulo inicial'
       read(5,*) Phio
       write(6,*) 'dame el valor de la velocidad angular'
       read(5,*) wo
       write(6,*) 'dame el valor de la aceleracion angular'
       read(5,*) alpha
       write(6,*) 'Estoy trabajando'

       Pi      = 3.1416
       Fact    = Pi/180.0d0
       Phio    = Phio*Fact
       Nciclos = 3000
       t       = 0.0
       dt      =0.005
       do i = 1,Nciclos
            write(3,*)Natomos
            write(3,*)
            Phi  = Phio + wo*t +.5*alpha*t*t
            x(i) = Radio*cos(Phi)
            y(i) = Radio*sin(Phi)
            z(i) = 0.0
            t    = t + dt
            write(9,23)x(i),y(i)
            write(3,12)w1,w6,x(i),y(i),z(i)       
       end do
23     FORMAT(2F15.6)
12     FORMAT(A4,A8,3F22.6)

       close(9)
       close(3)

       RETURN
       END subroutine
c**************************************************************************

       Subroutine Circular2
       implicit double precision(A-H,O-Z)
       Dimension a(9000),b(9000),c(9000)
       Character*4 W2,W7
       W2='Hg'
       W7='   '
       Natomos = 1


       rewind(3)
       rewind(9)

       write(6,*) 'dame el valor del radio2'
       read(5,*)Radio2
       write(6,*) 'dame el valor del angulo inicial2'
       read(5,*) Phio2
       write(6,*) 'dame el valor de la velocidad angular2'
       read(5,*) wo2
       write(6,*) 'dame el valor de la aceleracion angular2'
       read(5,*) alpha2
       write(6,*) 'Estoy trabajando'

       Pi      = 3.1416
       Fact    = Pi/180.0d0
       Phio2    = Phio2*Fact
       Nciclos = 3000
       t       = 0.0
       dt      =0.005
       do i = 1,Nciclos
            write(3,*)Natomos
            write(3,*)
            Phi  = Phio2 + wo2*t +.5*alpha2*t*t
            a(i) = Radio2*cos(Phi)
            b(i) = Radio2*sin(Phi)
            c(i) = 0.0
            t    = t + dt
            write(9,23)a(i),b(i)
            write(3,12)w2,w7,a(i),b(i),c(i)       
       end do
23     FORMAT(2F15.6)
12     FORMAT(A4,A8,3F22.6)

       close(9)
       close(3)

       RETURN
       END subroutine
  • 2
    In Fortran, you can write the the unit '*' and read from the unit '*' for command-line interaction. The hardcoded 3 and 9 might be wrong on some platforms. Similarly, it is recommended to avoid "low" (say below 10) file unit numbers as they might conflict with some preset units. – Pierre de Buyl Sep 10 '18 at 07:03
  • In your code, the `close(9)` in `Circular1` means that `Circular2` will not write to the file named in the open statement. Instead, it will go to a platform dependent file name (often fort.9). – Pierre de Buyl Sep 10 '18 at 07:04
  • And the rewind will positioning at the top of the file, so when omitting the close statements it still will give problems. A small redesign of this old code (implicit none is advised not the 'implicit double precision' and friends), maybe use some arguments as well in the subroutines. – albert Sep 10 '18 at 08:39
  • In first comment, I meant to write the unit `'*'` but that got eaten up by the markup. – Pierre de Buyl Sep 10 '18 at 08:42
  • The code looks very ugly, use `implicit none`, do not use units 5 and 6 but `*`, use indentation in every subroutine or function to make the structure visible, `return` and `stop` are useless before the `end`, format strings are better than labeled `format` statements. – Vladimir F Героям слава Sep 10 '18 at 09:12
  • The code is maybe an old f77 code. For those of us who grew up on f77, this code is certainly not ugly! lol – Natsfan Sep 11 '18 at 19:25
  • The existing generation of computer people would probably do this task in python. I would have done it in F77 because of that's what I knew best. For a code with this general purpose, f77 is fine. It's just a "simple script" to use one or 2 times. It is no better or worse than using python or perl. – Natsfan Sep 11 '18 at 19:33

0 Answers0