Dimension of arrays (RESHAPE) in Fortran 90

In summary, The conversation discusses the use of the RESHAPE function in FORTRAN and its purpose of converting FORTRAN-type arrays to C-type arrays. The conversation also mentions an error that occurred while using the function and the speaker's attempt to find a solution online. The conversation ends with the speaker expressing gratitude for the help provided.
  • #1
MahdiI84
22
1
TL;DR Summary
Hello everyone. I am new to Fortran. The following coding is for a 2x2 matrix whose original diameter is zero and its non-original diameter requires writing a loop. The code I wrote now has an error that I am unable to fix. Please help me solve it. Thanks
Fortran:
program testmatek
implicit none
integer :: Nc=1000 ,k
integer,parameter :: N=2
REAL :: kx ,a0=1.0 ,t0=0.25
DOUBLE PRECISION :: pi=4*ATAN(1.)
COMPLEX , PARAMETER :: i=(0,1)
complex :: ek1 ,ek2
complex ::  MATRIX_ek(N,N)  
   
 open(1,file='matek.txt')  
 
    MATRIX_ek(N,N)=(0,0)
 
 DO k=-Nc,+Nc
    
    kx=(pi*k)/(1000*a0) 
    ek1=t0*(1+EXP(-2*i*kx*a0))
    ek2=t0*(1+EXP(2*i*kx*a0))
   
    MATRIX_ek=RESHAPE((/0.0,eK2,ek1,0.0/ ) , (/2,2/))
    write(1,*) MATRIX_ek
   
 end do
 end program testmatek
1>C:\Users\mahdi\Documents\Visual Studio 2012\Projects\Console4\Console4\Source1.f90(21): error #5082: Syntax error, found ')' when expecting one of: ( <IDENTIFIER> <CHAR_CON_KIND_PARAM> <CHAR_NAM_KIND_PARAM> <CHARACTER_CONSTANT> <INTEGER_CONSTANT> ...
 
Technology news on Phys.org
  • #2
The error appears at line 20. Have you searched online for examples of using the RESHAPE function?
 
  • Like
Likes MahdiI84
  • #3
Why in heaven's name are you using RESHAPE?

RESHAPE is there to convert FORTRAN-type arrays to C-type arrays, so you can pass them to C functions.
 
  • Like
Likes MahdiI84
  • #4
jedishrfu said:
The error appears at line 20. Have you searched online for examples of using the RESHAPE function?
Yes, I know where the error is. Of course, I searched the internet. But since I am new to Fortran, I did not understand how I could fix the error. Thank you for your help
 
  • #5
Vanadium 50 said:
Why in heaven's name are you using RESHAPE?

RESHAPE is there to convert FORTRAN-type arrays to C-type arrays, so you can pass them to C functions.
Thank you for your help
 

FAQ: Dimension of arrays (RESHAPE) in Fortran 90

What is the purpose of the RESHAPE function in Fortran 90?

The RESHAPE function in Fortran 90 allows for the reorganization of array elements into a different shape or size. This can be useful for manipulating data and performing operations on arrays that require a specific shape or size.

How do you use the RESHAPE function in Fortran 90?

To use the RESHAPE function, you must first declare an array with the desired shape and size. Then, you can use the RESHAPE function to assign the elements of another array to the new array, following the syntax RESHAPE(array, shape). The shape argument can be specified as a single integer or an array of integers.

Can the RESHAPE function be used to change the rank of an array?

Yes, the RESHAPE function can be used to change the rank of an array. For example, if you have a 1D array with 10 elements, you can use the RESHAPE function to convert it into a 2D array with 5 rows and 2 columns.

Are there any restrictions on the shape argument in the RESHAPE function?

Yes, there are some restrictions on the shape argument in the RESHAPE function. The total number of elements in the new array must be equal to the total number of elements in the original array. Additionally, the shape argument cannot have a negative value or a value of 0.

Is it possible to use the RESHAPE function to create a non-contiguous array?

Yes, the RESHAPE function can be used to create a non-contiguous array. This means that the elements of the new array do not have to be physically adjacent to each other in memory. However, it is important to note that non-contiguous arrays may have a negative impact on performance.

Similar threads

Replies
16
Views
2K
Replies
20
Views
3K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
21
Views
2K
Replies
13
Views
3K
Replies
8
Views
3K
Replies
1
Views
7K
Replies
5
Views
9K
Back
Top