简体   繁体   中英

How to declare a complex type array in fortran 90

I need some help to initialize a complex type 1-D array in Fortran on linux

complex(kind=dp),dimension(8),public:: zc = (/(0.0_dp,0.0_dp) ,(-3.496991526333D001,0.0_dp) ,
( -3.944481647220D+000 , 0.0_dp ) , (-4.294180799072D+000 , 0.0_dp ) , 
(-4.294180799072D+000, -1.0_dp) , ( -3.944481647220D+000,-1.0_dp ) , 
(-3.496991526333D-           001,-1.0_dp ) , (0.0_dp,-1.0_dp)/) ! z computational 

Above statement works in Fortran Power Station( for Windows ) but not on Linux. It gives the following error

Missing ')' in statement at or before (1) 

NOTE : The '1' is the comma b/w 3rd and 4th complex no. The extension of the program is .f90

You must use the correct way of continuing lines. If you use fixed form (usually .f , .form ) place any character on the sixth column of the new line and then your statement. You probably use this, otherwise -3.496991526333D- 001 coudn't work, because spaces are important in the free form. But ! denotes comments in the free form. If you use the free form, correct the number. Be sure to not go past column 72 in the fixed form.

For example:

      complex(kind=dp),dimension(8),public:: zc = (/(0.0_dp,0.0_dp) ,(-3.496991526333D001,0.0_dp) ,
     *  ( -3.944481647220D+000 , 0.0_dp ) , (-4.294180799072D+000 , 0.0_dp ) , 
     *  (-4.294180799072D+000, -1.0_dp) , ( -3.944481647220D+000,-1.0_dp ) , 
     *  (-3.496991526333D-001,-1.0_dp ) , (0.0_dp,-1.0_dp)/) 
C z computational 

In the free form (usually .f90 ) use & at the of the line to continue on the next one.

complex(kind=dp),dimension(8),public:: zc = (/(0.0_dp,0.0_dp) ,(-3.496991526333D001,0.0_dp) , &
( -3.944481647220D+000 , 0.0_dp ) , (-4.294180799072D+000 , 0.0_dp ) , &
(-4.294180799072D+000, -1.0_dp) , ( -3.944481647220D+000,-1.0_dp ) , &
(-3.496991526333D-001,-1.0_dp ) , (0.0_dp,-1.0_dp)/) !z computational

You should read more about the correct soource form in any Fortran tutorial.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM