Reputation: 432
i have a very odd problem, it seems that, somehow some of my reals are getting changed.
i've got a Modul:
c\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
module Koordinaten
implicit none
save
real(kind=8),allocatable,dimension(:) :: xi, yi, zi
integer,allocatable,dimension(:) :: setnodes, st
real(8),allocatable, dimension(:) :: sx,sy,sz
Integer :: setdaten
end
c/////////////////////////////////////////////////////////
which is used in most of the suroutines and the main subroutine (this subroutine is called and the end of each simulation Increment, an does nothing but my code.). There, in the main program, all are allocated.
SUBROUTINE UEDINC (INC,INCSUB)
use Koordinaten
implicit none
c ** Start of generated type statements **
include 'dimen'
include 'jname'
include 'statistics'
include 'spaceset'
integer inc, incsub
integer :: i, nsets,k
character(265), dimension(ndset) :: setname
c ** End of generated type statements **
write(0,*)"NUMNP: ",NUMNP
allocate(xi(NUMNP))
allocate(yi(NUMNP))
allocate(zi(NUMNP))
allocate(setnodes(NUMNP))
allocate(st(NUMNP))
allocate(sx(NUMNP))
allocate(sy(NUMNP))
allocate(sz(NUMNP))
allocate(ri(NUMNP))
allocate(delta_r(NUMNP))
allocate(dummy(NUMNP))
Where NUMNP comes from 'dimen'. (Creating the dimensions with NUMNP as size in the Modul doesn't work, i dont know why, but thats not my problem for now)
next a subroutine is called doing this:
c#########################################################
subroutine einlesen ()
use Koordinaten
use zyl_para
implicit none
c ** Start of generated type statements **
include 'dimen'
integer :: i, j
integer :: token1, token2
real(8), dimension(3) :: nodein, nodedis
c ** End of generated type statements **
write(0,*)"--- lese Koordinaten ein ---"
write(0,*)"Anzahl der Datenpunkte: ", NUMNP
do i=1,NUMNP
call NODVAR(0,i,nodein,token1,token2)
call NOdVAR(1,i,nodedis,token1,token2)
xi(i)=nodein(1)+nodedis(1)
yi(i)=nodein(2)+nodedis(2)
zi(i)=nodein(3)+nodedis(3)
end do
write(0,*)"--- Koordinaten eingelesen ---"
do i=1, NUMNP
write(0,*)xi(i),yi(i),zi(i)
end do
write(0,*)"§§§§§§§§§§§§§§§§§"
write(0,*)xi(i),yi(i),zi(i)
return
end subroutine einlesen
c#########################################################
Here is the strange part: Thr subroutine 'NODVAR' gives back the Koordinates and the Displacement of a node; calling it works just fine and the values are stored correct in nodein(1:3) and nodedis(1:3).
But
write(0,*)xi,yi,zi
gives out 3 columns of the values stored in xi, so basically yi and zi have the values of xi
Update The Values are not exact equal, they differ a bit:
....
-20.0000765815728 -20.0000760759377 -20.0000751985753
-20.0000726178150 -20.0000671623785 -20.0000576162833
-20.0000427864046 -20.0000214978710 -19.9999932382105
-19.9999590389013 -18.9999215100902 -18.9998779514709
-18.9998277903388 -18.9997725557635 -18.9997146854248
-18.9996577298267 -18.9996059540004 -18.9995633069003
-18.9995325241422 -18.9995144999731 -18.9995087694121
-18.9995144999742 -18.9995325241444 -18.9995633069036
-18.9996059540045 -18.9996577298314 -18.9997146854297
-18.9997725557682 -18.9998277903431 -18.9998779514747
-18.9999215100934 -18.9999598955851 -18.9999939247953
-19.0000218363084 -19.0000426285757 -19.0000570432278
-19.0000664612509 -19.0000719811992 -19.0000746027515
-19.0000754299370 -19.0000747701169 -19.0000754299373
-19.0000746027519 -19.0000719811998 -19.0000664612514
-19.0000570432280 -19.0000426285755 -19.0000218363074
-18.9999939247935 -18.9999598955826 -17.9999226880232
-17.9998792166917 -17.9998290553161 -17.9997737084839
-17.9997156002768 -17.9996582203842 -17.9996058186853
....
END update
do i=1, NUMNP
write(0,*)xi(i),yi(i),zi(i)
end do
prints the values for xi, yi, and zi.
I do not deallocate the array till the end of the main subroutine
The printing is not the Problem, the Problem is, that the next subroutines uses this koordinates, but seem to have the same Problem.
The subroutine worked fine as i gave the xi,yi and zi as parameters during calling, but now i have to work with subroutins where i cannot pass them during calling.
So, why does this happen?
Thanks you for your time... and sorry for my errors.
UPDATE
I use the Subruotine 'UEDINC' euqivalent to a main Program. It works like an API to the FEM-Programm i use. This subroutine is called at the end of each increment and all my code and my subroutines are within this subroutine / called in this subroutine.
'NODVAR' is provided by the FEM-Program and dokumented. It is called for each node i and gives back the values in an arry of dim(3), here nodein and nodedis, the 0/1 indicates what is given back: koordinates or their displacement, token1 and token2 give back some Information i do not need.
I verified, that the values given back form 'NODVAR' are the ones i expect by printing them out. I also printetd out the values during the loop where they are stored vom 'NODVAR' to my array, by printing the values storred in my arry, here they where also right.
I know, that Kind=8 isn't portable, but it works for ifort, and the code doesn't have to be portable at all.
Further investigation
I modifed my code some bit, i now have the following subroutine:
c##########################################################
implicit none
c ** Start of generated type statements **
integer :: ndaten, i, j
integer :: token1, token2
real(8), dimension(3) :: nodein, nodedis
real(8), dimension(ndaten) :: x,y,z
c ** End of generated type statements **
write(0,*)"--- lese Koordinaten ein ---"
write(0,*)"Anzahl der Datenpunkte: ", ndaten
do i=1,ndaten
call NODVAR(0,i,nodein,token1,token2)
call NOdVAR(1,i,nodedis,token1,token2)
x(i)=nodein(1)+nodedis(1)
y(i)=nodein(2)+nodedis(2)
z(i)=nodein(3)+nodedis(3)
write(0,*)x(i),y(i),z(i) ***(1)
end do
write(0,*)"*****************"
write(0,*)x,y,z ***(2)
write(0,*)"--- Koordinaten eingelesen ---"
return
end subroutine einlesen
c#########################################################
The arrys x,y,z have the dim(NUMNP) and are basically empty, i do nothing with them beofre calling this subroutine, ndaten=NUMNP
(1) gives me, as i expect:
-19.9999205042055 4.174743870006559E-005 -2.49993530375797
-19.9998768725013 0.362341804670311 -2.47354036781631
-19.9998267169371 0.734574978337486 -2.38959111446343
-19.9997716931358 1.10321804323537 -2.24337882624597
-19.9997141644151 1.45282900896610 -2.03451636821160
-19.9996575908584 1.76783665097058 -1.76773205553564
-19.9996061583064 2.03464970008098 -1.45274943026036
-19.9995638755175 2.24353899096506 -1.10315640708085
-19.9995334705205 2.38977079851914 -0.734524030614783
-19.9995156926493 2.47372965346901 -0.362296534411106
-19.9995100448173 2.50012385767524 4.865608618193709E-010
....
(2) gives me:
-19.9999205042055 -19.9998768725013 -19.9998267169371
-19.9997716931358 -19.9997141644151 -19.9996575908584
-19.9996061583064 -19.9995638755175 -19.9995334705205
-19.9995156926493 -19.9995100448173 -19.9995156926504
-19.9995334705227 -19.9995638755208 -19.9996061583105
-19.9996575908630 -19.9997141644199 -19.9997716931404
-19.9998267169414 -19.9998768725051 -19.9999205042086
-19.9999590389038 -19.9999932382123 -20.0000214978720
-20.0000427864049 -20.0000576162831 -20.0000671623780
-20.0000726178145 -20.0000751985748 -20.0000760759375
-20.0000765815728 -20.0000760759378 -20.0000751985753
-20.0000726178150 -20.0000671623785 -20.0000576162833
-20.0000427864046 -20.0000214978710 -19.9999932382105
-19.9999590389013 -18.9999215100902 -18.9998779514709
-18.9998277903388 -18.9997725557635 -18.9997146854248
-18.9996577298267 -18.9996059540004 -18.9995633069003
-18.9995325241422 -18.9995144999731 -18.9995087694121
-18.9995144999742 -18.9995325241444 -18.9995633069036
-18.9996059540045 -18.9996577298314 -18.9997146854297
-18.9997725557682 -18.9998277903431 -18.9998779514747
-18.9999215100934 -18.9999598955851 -18.9999939247953
-19.0000218363084 -19.0000426285757 -19.0000570432278
...
['(1)', and '(2)' are obviously not in the code i compile and only some Markers for demonstration]
Upvotes: 0
Views: 2698
Reputation: 78316
In your second output read the values across then down, in your first read the values down then across and you will find that they are the same numbers. This statement
write(0,*)x,y,z
writes vector x
, then vector y
, then vector z
. The format clause (ie the *
) tells the compiler to write the numbers as it sees fit. By lucky chance it has chosen to write 3 values on each line, in the order x(1),x(2),x(3),newLine,x(4),...,y(1),y(2),...
This has tricked you into thinking that it is writing (incorrectly) x(i),y(i),z(i)
but it is your thinking which is incorrect here, not the program.
If you want the values written x(1),y(1),z(1),newLine,x(2),...
you have to write the statements to do that, as your first output statement does.
Upvotes: 2
Reputation: 29381
I find your question a rather confusing. Are you saying that you find the values in the arrays xi, yi, zi
to be unexpected? What is your evidence that the values have changed?
If values of a variable are changing outside of your expectations, in Fortran there are two likely errors to cause such a problem: 1) array subscripts out of bounds, or 2) disagreement between actual and dummy procedure arguments. The easiest and first step and hunting down such errors and turning on all error and warning options of your compiler, especially run-time subscript bounds checking. Also be sure to place all procedures (subroutines and functions) in modules and use
them so that the compiler can check argument consistency.
What compiler are you using?
P.S. real (kind=8)
is not guaranteed to be an 8-byte real. Numeric values of kinds are not portable and differ between compilers.
Upvotes: 1