LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2013, 09:12 AM   #1
lehloks
LQ Newbie
 
Registered: May 2013
Posts: 12

Rep: Reputation: Disabled
Im am running a stress autocorrelation function,to calculate stress correlation funct


Hi
I am trying to run a stress autocorrelation function code to calculate the stress autocorrelation function,then from there I would like to calculate viscosity using Green -Kubo equation. Now the Fortran code I have does not read out my stress data in order to calculate stress auot-correlarion function. Anyone can please help me with this. I have attached my code and data I want to correlate. Hope to here from you soon.

Kind Regards
Lehloks

Data: has 9 columns
-9.568336E+00 -1.615161E+00 1.042644E+00 -1.615161E+00 -1.131916E+01 -6.979813E-01 1.042644E+00 -6.979813E-01 -1.182917E+01
-4.765572E-01 9.005122E-01 -2.282920E+00 9.005122E-01 -3.827857E+00 -3.206736E+00 -2.282920E+00 -3.206736E+00 -6.252462E+00
-1.012710E+01 4.672368E-01 8.791873E-02 4.672368E-01 -4.680832E+00 -5.271814E-01 8.791873E-02 -5.271814E-01 -1.898345E-01
-7.699012E+00 -9.906154E-01 7.450304E-01 -9.906154E-01 -1.061230E+00 -3.546956E+00 7.450304E-01 -3.546956E+00 -6.843898E+00
-3.544260E+00 4.254020E+00 -1.963602E+00 4.254020E+00 3.740858E+00 -4.587760E+00 -1.963602E+00 -4.587760E+00 -6.776258E+00
1.755595E-01 -9.625855E-01 -2.395960E+00 -9.625855E-01 -1.701399E+00 -8.483695E-01 -2.395960E+00 -8.483695E-01 -4.165223E+00
-3.244186E+00 5.540608E+00 -4.951768E-01 5.540608E+00 3.068601E+00 -1.613010E-01 -4.951768E-01 -1.613010E-01 -5.641277E+00
-8.985849E+00 1.870244E+00 -2.295795E-01 1.870244E+00 -4.635924E+00 -4.787461E+00 -2.295795E-01 -4.787461E+00 -3.014272E+00
-1.651073E-01 -6.326584E-01 -3.028051E+00 -6.326584E-01 -2.621833E+00 -2.640439E+00 -3.028051E+00 -2.640439E+00 1.668877E+00
1.250349E+00 3.054784E+00 -2.898975E+00 3.054784E+00 8.419503E-01 9.620184E-01 -2.898975E+00 9.620184E-01 1.479256E+00
-7.796195E-01 1.942983E+00 -2.736569E+00 1.942983E+00 6.073043E+00 -2.520281E+00 -2.736569E+00 -2.520281E+00 -9.600832E-01
4.697066E-01 3.138124E+00 -1.092573E+00 3.138124E+00 -2.099285E+00 -1.581031E+00 -1.092573E+00 -1.581031E+00 -6.285002E-01
3.017532E-01 -9.701574E-02 1.611936E+00 -9.701574E-02 -1.762075E+00 -3.401961E+00 1.611936E+00 -3.401961E+00 -6.889746E-01
1.177410E-01 5.090611E-01 1.452691E-01 5.090611E-01 5.695570E+00 -3.573245E+00 1.452691E-01 -3.573245E+00 -1.099615E+00
-5.180126E+00 -1.876409E-01 -2.067182E+00 -1.876409E-01 1.611177E+00 5.458450E-01 -2.067182E+00 5.458450E-01 1.026071E+00
1.477567E+00 1.598949E+00 -1.577546E+00 1.598949E+00 3.933810E+00 -2.698132E+00 -1.577546E+00 -2.698132E+00 3.485029E+00
-2.533324E+00 1.753033E+00 1.425241E-01 1.753033E+00 2.406501E+00 -1.147217E+00 1.425241E-01 -1.147217E+00 3.065603E-01
-2.360274E+00 1.312721E+00 -3.711419E-01 1.312721E+00 2.556935E+00 3.152605E-01 -3.711419E-01 3.152605E-01 3.378170E+00
-1.698217E+00 1.105760E+00 3.780822E-01 1.105760E+00 2.736574E+00 7.920578E-01 3.780822E-01 7.920578E-01 -6.596856E-01
-5.099544E+00 1.647542E-01 -1.036544E+00 1.647542E-01 3.845429E+00 -1.034068E+00 -1.036544E+00 -1.034068E+00 -3.152053E+00
-2.686567E+00 1.335786E+00 -1.889911E-01 1.335786E+00 9.755267E-01 9.322043E-01 -1.889911E-01 9.322043E-01 3.229615E-01
1.542994E-01 3.104663E+00 -1.634353E-01 3.104663E+00 4.090105E+00 -1.128244E+00 -1.634353E-01 -1.128244E+00 -2.909383E-01
-4.235419E-01 1.554157E+00 3.475430E+00 1.554157E+00 4.701173E+00 -1.789414E+00 3.475430E+00 -1.789414E+00 1.517218E+00
-8.054924E-01 -1.167935E+00 -1.123460E+00 -1.167935E+00 1.169303E+00 -2.171076E+00 -1.123460E+00 -2.171076E+00 -5.636150E+00
-1.617491E+00 4.003700E+00 1.378316E+00 4.003700E+00 -1.665934E+00 1.498592E-01 1.378316E+00 1.498592E-01 -1.206797E+00
5.260921E-01 1.651686E+00 -2.646774E-01 1.651686E+00 -1.762373E-01 -9.632670E-02 -2.646774E-01 -9.632670E-02 1.977057E+00
9.813598E-01 1.625447E+00 2.023088E+00 1.625447E+00 2.490276E+00 -2.670705E-01 2.023088E+00 -2.670705E-01 -1.870441E+00
-5.655597E+00 1.939740E+00 2.297268E+00 1.939740E+00 -8.480003E-02 -3.918615E+00 2.297268E+00 -3.918615E+00 -3.121072E+00
-7.801742E-01 1.287923E+00 -4.939918E-01 1.287923E+00 -2.809879E-02 -2.932175E+00 -4.939918E-01 -2.932175E+00 -4.770079E+00
2.002557E-01 8.336137E-01 -1.590110E-01 8.336137E-01 2.130667E+00 5.596286E-01 -1.590110E-01 5.596286E-01 -1.750873E-01
-3.372541E+00 4.301007E-01 1.537803E+00 4.301007E-01 5.802335E+00 -1.827391E+00 1.537803E+00 -1.827391E+00 -1.537462E+00
-4.435659E+00 2.030894E+00 1.370509E+00 2.030894E+00 1.393425E-01 -1.055499E+00 1.370509E+00 -1.055499E+00 1.771206E+00
2.098158E+00 2.583661E+00 8.791438E-01 2.583661E+00 9.032831E-01 -2.215565E+00 8.791438E-01 -2.215565E+00 2.043297E+00
-1.698410E+00 4.167409E+00 2.647075E-01 4.167409E+00 4.222395E+00 -3.055763E+00 2.647075E-01 -3.055763E+00 -1.391421E+00
-8.409078E-01 -4.928208E-01 1.081605E+00 -4.928208E-01 3.172158E+00 -9.652794E-01 1.081605E+00 -9.652794E-01 5.858850E+00
1.772945E+00 1.884536E+00 -1.227665E-02 1.884536E+00 4.133279E+00 -1.560894E+00 -1.227665E-02 -1.560894E+00 -2.180136E+00
1.374663E+00 -2.563897E-01 -3.531044E-01 -2.563897E-01 9.444892E-01 -1.131695E+00 -3.531044E-01 -1.131695E+00 8.410043E-02
-1.628314E+00 -2.282178E+00 -7.082837E-02 -2.282178E+00 4.717011E+00 -3.167291E+00 -7.082837E-02 -3.167291E+00 1.405460E-01
3.256577E+00 8.701485E-02 -3.349064E-01 8.701485E-02 2.750965E+00 -4.284773E+00 -3.349064E-01 -4.284773E+00 3.778049E+00
-2.295949E+00 3.331942E+00 1.116254E+00 3.331942E+00 3.989839E+00 -1.459957E+00 1.116254E+00 -1.459957E+00 4.521983E-02
-1.151068E+00 -7.641443E-01 -4.241038E-01 -7.641443E-01 4.304514E+00 -1.267603E+00 -4.241038E-01 -1.267603E+00 8.671564E-01
-4.160283E+00 -1.259369E+00 1.650666E+00 -1.259369E+00 3.044282E+00 -2.418003E+00 1.650666E+00 -2.418003E+00 -2.627127E+00
-1.179937E+00 2.183129E+00 -1.119143E+00 2.183129E+00 5.206284E+00 -2.993333E+00 -1.119143E+00 -2.993333E+00 -3.183130E+00
-2.359512E+00 2.115881E+00 -1.301282E+00 2.115881E+00 3.847385E+00 -2.485009E+00 -1.301282E+00 -2.485009E+00 -9.906069E-01
-2.942584E+00 -5.313706E-01 1.851732E+00 -5.313706E-01 2.745075E+00 -1.914543E+00 1.851732E+00 -1.914543E+00 -1.403970E+00
-2.509056E+00 5.086551E+00 1.357141E+00 5.086551E+00 9.473148E-01 3.850056E-01 1.357141E+00 3.850056E-01 -1.579436E+00
1.198187E+00 3.245621E+00 -2.229760E-01 3.245621E+00 3.240415E+00 -7.487642E-01 -2.229760E-01 -7.487642E-01 -2.924478E+00
-1.763899E+00 2.164231E+00 -2.238102E-01 2.164231E+00 -1.612804E-02 -3.096042E+00 -2.238102E-01 -3.096042E+00 -1.820712E-01
-3.938288E+00 3.098645E+00 3.011002E-01 3.098645E+00 -2.056060E-01


CODE:
C PROGRAM TCORR

COMMON / BLOCK1 / STORA, STORB, STORC, STORD,STORE,STORF,STORG,
& STORH, STORI
C COMMON / BLOCK2/STORB
COMMON / BLOCK2 / PA, PB, PC, PD, PE, PF, PG, PH , PI
c COMMON / BLOCK4/ VB
COMMON / BLOCK3 / PACF, ANORM

C *******************************************************************
C ** CALCULATION OF TIME CORRELATION FUNCTIONS. **
C ** **
C ** THIS PROGRAM ANALYZES DATA TO CALCULATE A TIME CORRELATION **
C ** FUNCTION IN ONE SWEEP (LOW MEMORY REQUIREMENT). IN THIS **
C ** EXAMPLE THE VELOCITY AUTO-CORRELATION FUNCTION IS CALCULATED. **
C ** **
C ** PRINCIPAL VARIABLES: **
C ** **
C ** INTEGER N NUMBER OF ATOMS
C ** INTEGER NSTEP NUMBER OF STEPS ON THE TAPE
C ** INTEGER IOR INTERVAL FOR TIME ORIGINS
C ** INTEGER NT CORRELATION LENGTH, INCLUDING T=0
C ** INTEGER NTIMOR NUMBER OF TIME ORIGINS
C ** INTEGER NLABEL LABEL FOR STEP (1,2,3...NSTEP)
C ** REAL VX(N),VY(N),VZ(N) VELOCITIES
C ** REAL VACF(NT) THE CORRELATION FUNCTION
C ** NSTEP AND NT SHOULD BE MULTIPLES OF IOR.
C ** PA,PB,PC = Pxx,Pxy,Pxz
C ** PD,PE,PF = Pyx,Pyy,Pyz
C ** PG,PH,PI = Pzx,Pzy,Pzz
C ** ROUTINES REFERENCED:
C ** **
C ** SUBROUTINE STORE (J1)
C ROUTINE TO STORE THE DATA FOR CORRELATION **
C SUBROUTINE CORR ( J1, J2, IT )
C ROUTINE TO CORRELATE THE STORED TIME ORIGINS **
C USAGE: **
C ** **
C DATA IN FILE DFILE ON FORTRAN UNIT DUNIT. **
C RESULTS IN FILE RFILE ON FORTRAN UNIT RUNIT. **
C *******************************************************************

INTEGER N, NSTEP, IOR, NT, NDIM, DUNIT, RUNIT, NTIMOR
INTEGER FULLUP
PARAMETER ( N = 78, NSTEP = 10, IOR = 4, NT = 8 )
PARAMETER ( DUNIT = 10, RUNIT = 11 )
PARAMETER ( NDIM = NT / IOR + 1, NTIMOR = NSTEP / IOR )
PARAMETER ( FULLUP = NDIM - 1 )

REAL PA(N), PB(N), PC(N), PD(N), PE(N), PF(N), PG(N), PH(N), PI(N)
REAL STORA(NDIM,N), STORB(NDIM,N), STORC(NDIM,N),STORD(NDIM,N),
& STORE(NDIM,N),STORF(NDIM,N),STORG(NDIM,N),STORH(NDIM,N),
& STORI(NDIM,N)
REAL PACF(NT), ANORM(NT)
INTEGER S(NTIMOR), TM(NTIMOR)
INTEGER TS, TSS, L, NINCOR, K, R, JA, IB, IN, IA, JO, I
INTEGER NLABEL
CHARACTER DUMMY * 5
CHARACTER DFILE * 30
CHARACTER RFILE * 30

C *******************************************************************

WRITE(*,'('' **** PROGRAM TCORR **** '')')
WRITE(*,'('' CALCULATION OF TIME CORRELATION FUNCTIONS '')')

C ** READ IN FILE NAMES **

WRITE(*,'('' ENTER DATA FILE NAME '')')
READ (*,'(A)') DFILE
WRITE (*,'('' ENTER RESULTS FILE NAME '')')
READ (*,'(A)') RFILE

C ** INITIALIZE COUNTERS **

NINCOR = FULLUP
JA = 1
IA = 1
IB = 1

C ** ZERO ARRAYS **

DO 5 I = 1, NT

PACF(I) = 0.0
ANORM(I) = 0.0
write(*,*) PACF(I)
5 CONTINUE


C ** OPEN DATA FILE AND RESULTS FILE **

OPEN ( UNIT = DUNIT, FILE = DFILE, STATUS = 'OLD',
: FORM = 'FORMATTED')

OPEN ( UNIT = RUNIT, FILE = RFILE, STATUS = 'NEW' )

C ** CALCULATION BEGINS **

DO 40 L = 1, NTIMOR

JA = JA + 1
S(L) = JA - 1

READ ( DUNIT, '(A5,I4)') DUMMY, NLABEL
DO 7 R = 1, N
READ (DUNIT,'(F9.6,8(9X,F9.6))')PA(R),PB(R),PC(R),PD(R),
& PE(R),PF(R),PG(R),PH(R),PI(R)
7 CONTINUE

TM(L) = NLABEL
write(*,*) TM(L)

C ** STORE STEP AS A TIME ORIGIN **
CALL STOREE ( JA )

C ** CORRELATE THE ORIGINS IN STORE **

DO 10 IN = IA, L

TSS = TM(L) - TM(IN)
TS = TSS + 1
JO = S(IN) + 1
CALL CORR ( JO, JA, TS )

10 CONTINUE

C ** READ IN DATA BETWEEN TIME ORIGINS. THIS CAN **
C ** BE CONVENIENTLY STORED IN ELEMENT 1 OF THE **
C ** ARRAYS STORX ETC. AND CAN THEN BEN CORRELATED **
C ** WITH THE TIME ORIGINS. **

DO 30 K = 1, IOR - 1

READ ( DUNIT, '(A5,I4)') DUMMY, NLABEL
DO 15 R = 1, N
READ ( DUNIT,'(F17.14,8(13X,F17.14))')PA(R),PB(R),PC(R),PD(R),
& PE(R),PF(R),PG(R),PH(R),PI(R)
15 CONTINUE

CALL STOREE ( 1 )

DO 20 IN = IA, L

TSS = NLABEL - TM(IN)
TS = TSS + 1
JO = S(IN) + 1
CALL CORR ( JO, 1, TS )

20 CONTINUE

30 CONTINUE

IF ( L .GE. FULLUP ) THEN

IF ( L .EQ. NINCOR ) THEN

NINCOR = NINCOR + FULLUP
JA = 1

ENDIF

IA = IA + 1

ENDIF

40 CONTINUE

CLOSE ( DUNIT )

C ** NORMALISE CORRELATION FUNCTIONS **

PACF(1) = PACF(1) / ANORM(1) / REAL ( N )

DO 50 I = 2, NT

PACF(I) = PACF(I) / ANORM(I) / REAL ( N ) / PACF(1)

50 CONTINUE

WRITE ( RUNIT, '('' VELOCITY ACF '')')
WRITE ( RUNIT, '(I6,E15.6)') ( I, PACF(I), I = 1, NT )

CLOSE ( RUNIT )

STOP
END



SUBROUTINE STOREE ( J1 )

c COMMON/ BLOCK1 / STORX, STORY, STORZ, STORA, STORB
COMMON / BLOCK1 / STORA, STORB, STORC, STORD,STORE,STORF,STORG,
& STORH,STORI
c COMMON/BLOCK2/STORB
COMMON/ BLOCK2 / PA, PB, PC, PD, PE, PF, PG, PH, PI

C *******************************************************************
C ** SUBROUTINE TO STORE TIME ORIGINS **
C *******************************************************************

INTEGER J1
INTEGER N, NT, IOR, NDIM
PARAMETER ( N = 78, NT = 8, IOR =4 )
PARAMETER ( NDIM = NT / IOR + 1 )

REAL STORA(NDIM,N), STORB(NDIM,N), STORC(NDIM,N),STORD(NDIM,N),
& STORE(NDIM,N),STORF(NDIM,N),STORG(NDIM,N),STORH(NDIM,N),
& STORI(NDIM,N)
REAL PA(N), PB(N), PC(N), PD(N), PE(N), PF(N),PG(N), PH(N), PI(N)
INTEGER I


DO 10 I = 1, N

STORA(J1,I) = PA(I)
STORB(J1,I) = PB(I)
STORC(J1,I) = PC(I)
STORD(J1,I) = PD(I)
STORE(J1,I) = PE(I)
STORF(J1,I) = PF(I)
STORG(J1,I) = PG(I)
STORH(J1,I) = PH(I)
STORI(J1,I) = PI(I)
10 CONTINUE

RETURN
END



SUBROUTINE CORR ( J1, J2, IT )

COMMON / BLOCK1 / STORA, STORB, STORC, STORD,STORE,STORF,STORG,
& STORH,STORI
c COMMON/ BLOCK1 / STORX, STORY, STORZ,STORA
COMMON/ BLOCK3 / PACF, ANORM

C *******************************************************************
C ** SUBROUTINE TO CORRELATE TIME ORIGINS **
C *******************************************************************

INTEGER J1, J2, IT
INTEGER N, NT, IOR, NDIM
PARAMETER ( N = 78, NT = 8, IOR = 4 )
PARAMETER ( NDIM = NT / IOR + 1 )

REAL STORA(NDIM,N), STORB(NDIM,N), STORC(NDIM,N),STORD(NDIM,N),
& STORE(NDIM,N),STORF(NDIM,N),STORG(NDIM,N),STORH(NDIM,N),
& STORI(NDIM,N)

c REAL STORX(NDIM,N), STORY(NDIM,N), STORZ(NDIM,N),STORA(NDIM,N),
c & STORB(NDIM,N)
REAL PACF(NT), ANORM(NT)
INTEGER I

C ********************************************************************

DO 10 I = 1, N

PACF(IT) = PACF(IT) + STORA(J1,I) * STORA(J2,I)
: + STORB(J1,I) * STORB(J2,I)
: + STORC(J1,I) * STORC(J2,I)
: + STORD(J1,I) * STORD(J2,I)
: + STORE(J1,I) * STORE(J2,I)
: + STORF(J1,I) * STORF(J2,I)
: + STORG(J1,I) * STORG(J2,I)
: + STORH(J1,I) * STORH(J2,I)
: + STORI(J1,I) * STORI(J2,I)
10 CONTINUE

ANORM(IT) = ANORM(IT) + 1.0

RETURN
END
 
Old 07-03-2013, 02:47 PM   #2
adelabarra
Member
 
Registered: May 2008
Location: Argentina
Distribution: Debian, Slackware
Posts: 49

Rep: Reputation: 3
Dear lehlok:
Hello:
Where did you store the data?
Did you store it in a file?
I can't see where did you assign the data to a variable.

Regards,

Alejandro.
 
Old 07-04-2013, 01:43 AM   #3
lehloks
LQ Newbie
 
Registered: May 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Dear Alej

I wanted to add an attachment for the data,but I didnt know how to attach it,then I pasted it on the thread .It is the one with title Data with 9 columns. If you put it on Vim and save it as DFILE.txt it aranges nicely.It is the one with many columns. If there is a way of attaching it please let me know.

Thanks a lot for replying to my message.
If there is anything you want to know please let me know.

Regards
Lehloks
 
Old 07-04-2013, 12:11 PM   #4
adelabarra
Member
 
Registered: May 2008
Location: Argentina
Distribution: Debian, Slackware
Posts: 49

Rep: Reputation: 3
Dear Lehloks:

It is 20 years I don't write a sentence in FORTRAN but I think you've got to do someting like this that I found in a FORTRAN's page:
Quote:
Read (from Files)
The read statement is used to read data from a file. Generally data is read from a file in the standard way, line-by-line and from left to right. But you must remember that each read statement begins reading a new line, whether or not the preceding read statement used all the data in the preceding line.

Suppose for example that a file is numbered 7, and that the first two lines of the file contain the data (separated by commas)

1.23 , 4.56 , 7.89
11, 13 , "Sally"

If the first two read statements in the program are

read (7,*) x, y, z
read (7,*) m, n, first ,

then the program assigns x = 1.23, y = 4.56, z = 7.89, m = 11, n = 13, first = "Sally". The variables will have to be declared in the program to correspond with the data assigned them by the read statements. For instance, in the above situation x, y, and z will have been declared real variables, m and n integers, and "first" a character variable. Failure to match variable types with data types will most likely lead to error messages.

It is possible that a program does not know beforehand the length of a file. If data is being read from a loop, there is a way to exit the loop when all data in the file has been read, thereby avoiding a program hang-up. One simply modifies the read statement to something like

read (7,*,end=10) .

This command instructs Fortran to read the next line in the file numbered 7, but to jump to the statement labelled 10 in the program in the event that the last line in that file has already been read.

You can also use format specifiers in read statements, but this can be somewhat tedious and we will not go into the details. As but one example, suppose you want to make the assignments

n = 77 , x = 123.45 , y = 67.8 ,

where n is an integer and x and y are real variables. Then you may use the read and format statements

read (7,5) n, x, y
5 format (i2,f5.2,f3.1) ,

and in file number 7 place the corresponding line of data

7712345678 .

Fortran will read and separate the data, insert appropriate decimal points, and assign it to the variables. But as you can see the method is confusing and perhaps not worth the effort.
http://www.math.hawaii.edu/~hile/fortran/fort7.htm

I think it will take you on the right direction.

Regards:

Alejandro
 
Old 07-08-2013, 05:59 AM   #5
lehloks
LQ Newbie
 
Registered: May 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Hi Alejandro

thanks a lot for your input. I was very helpful. The code is working however I think I need to change it some where to make it adaptable with the type of data im using.


Kind regards
Lehloks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Stress relief! polarbear20000 General 9 03-23-2009 11:11 PM
Stress Tools sehgalnamit Linux - Newbie 6 03-03-2009 10:04 AM
Stress relief DanTaylor General 17 04-02-2006 06:55 PM
Stress benchmarking linear Linux - General 0 01-13-2002 01:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration