Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

array change while another array is been assigning

Moslemi_Pak__Armin
323 Views

Hi everyone

I am using Intel Visual Fortran parallel studio 2015 with integration of Visual Studio 2013. I have faced a absolutely weird scenario!!!! I have developed a subroutine. The code is:

======================================================================================

  1. Subroutine Read_2DMeshSU2(Dim,MeshDim,NC,Corn,NP,X,Y,NBC,BCName,NEC,BEP)
  2.     Implicit None
  3. !*******************************************************************************************
  4.     Intent(In   )                           ::  Dim
  5.     Intent(Out  )                           ::  MeshDim,NC,Corn,NP,X,Y,NBC,BCName,NEC,BEP
  6.     Integer                                 ::  Dim,IO,MeshDim,NC,i,j,NP,NBC,NBE,Dumy
  7.     Character*100                           ::  Temp
  8.     Character*100,Dimension(1:10)           ::  BCName
  9.     Integer,Dimension(1:Dim,1:10)           ::  Corn
  10.     Integer,Dimension(1:Dim,1:3)            ::  BEP
  11.     Integer,Dimension(1:10)                 ::  NEC
  12.     Real(8),Dimension(1:Dim)                ::  X,Y
  13. !*******************************************************************************************
  14.     !Part 1: Opening the SU2 Mesh File
  15.     Open(1,File='Mesh.su2')
  16.    
  17.     !Part 2: Read dimension of the space
  18.     Read(1,*) Temp
  19.     Do While (Temp(1:5) /= 'NDIME')
  20.         Read(1,'(A100)',IOSTAT = IO) Temp
  21.     End Do
  22.     Read(Temp(7:100),*) MeshDim
  23.    
  24.     !Part 3: Read Number of the elements
  25.     Read(1,*) Temp
  26.     Do While (Temp(1:5) /= 'NELEM')
  27.         Read(1,'(A100)',IOSTAT = IO) Temp
  28.     End Do
  29.     Read(Temp(7:100),*) NC
  30.    
  31.     !Part 4: The node number connectivity
  32.     Corn(1:NC,1:5) = 0
  33.     Do i=1,NC
  34.         Read(1,"(I2,I2)",ADVANCE='NO') Corn(i,1)
  35.         !Check the 'VTK' format
  36.         If (Corn(i,1) == 5) Then
  37.             !This is a triangular element and it contains only three nodes
  38.             Read(1,*) Corn(i,2), Corn(i,3), Corn(i,4)
  39.         Else If (Corn(i,1) == 9) Then
  40.             !This is a quadrilateral element and it contains only four nodes
  41.             Read(1,*) Corn(i,2), Corn(i,3), Corn(i,4), Corn(i,5)
  42.         Else If (Corn(i,1) == 3) Then
  43.             !This is a line element and it contains only two nodes
  44.             Read(1,*) Corn(i,2), Corn(i,3)
  45.         End If
  46.         !Adding 1 for fitting the format for the tecplot
  47.         Corn(i,2:5) = Corn(i,2:5) + 1
  48.     End Do
  49.    
  50.     !Part 5: Read the Points Coordinates
  51.     Read(1,*) Temp
  52.     Do While (Temp(1:5) /= 'NPOIN')
  53.         Read(1,'(A100)',IOSTAT = IO) Temp
  54.     End Do
  55.     Read(Temp(7:100),*) NP
  56.    
  57.     Do i=1,NP
  58.         Read(1,*) X(i) , Y(i)
  59.     End Do
  60.    
  61.     !Part 6: Reading the Boundaries data
  62.     Read(1,*) Temp
  63.     Do While (Temp(1:5) /= 'NMARK')
  64.         Read(1,'(A100)',IOSTAT = IO) Temp
  65.     End Do
  66.     Read(Temp(7:100),*) NBC
  67.    
  68.     NBE = 0
  69.     Do i=1,NBC
  70.         !Read the boundary name
  71.         Read(1,'(A100)',IOSTAT = IO) Temp
  72.         Read(Temp(13:100),*) BCName(i)
  73.         !Read the number of parts of each boundary
  74.         Read(1,'(A100)',IOSTAT = IO) Temp
  75.         Read(Temp(15:100),*) NEC(i)
  76.         Do j=(1+NBE),(NBE+NEC(i))
  77.             Read(1,*) BEP(j,1), BEP(j,2), BEP(j,3)
  78.             BEP(j,2:3) = BEP(j,2:3) + 1
  79.         End Do
  80.         NBE = NBE + NEC(i)
  81.     End Do
  82.     Close(1)
  83.    
  84. End Subroutine Read_2DMeshSU2
===================================================================
 
In line 34 the Corn(i,1) has been assigned through a specific file. Then in line 77 while I was reading that file for assigning the "BEP" variable, by assigning the BEP(j,3), the Corn(i,1) will be changed and get the value of BEP(j,3).
​Does anyone know where the problem is?
 
 
0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
323 Views

A couple of possibilities:

  1. The dimensions you pass in for BEP and Corn are incorrect, causing overwrites
  2. You are passing the same variable for both arguments, which is not legal in Fortran (with some exceptions)

We would, at a minimum, need to see the call to the subroutine and the declarations of all its arguments. 

View solution in original post

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
324 Views

A couple of possibilities:

  1. The dimensions you pass in for BEP and Corn are incorrect, causing overwrites
  2. You are passing the same variable for both arguments, which is not legal in Fortran (with some exceptions)

We would, at a minimum, need to see the call to the subroutine and the declarations of all its arguments. 

0 Kudos
Moslemi_Pak__Armin
323 Views

Thanks is a simple a word for your precious advice, Mr.Lionel

The first point was the solution. I defined BEP in the main differently. I changed it and it works.

Again, Thanks a lot

0 Kudos
Reply