Initilalising an array with a sequence in Fortran

后端 未结 1 856
迷失自我
迷失自我 2021-01-21 09:25

I am currently working on translating some legacy fortran code and I am having a hard time understanding a particular line in the code. The compiler also seems to find this line

1条回答
  •  时光说笑
    2021-01-21 10:10

    The syntax is incorrect and such code cannot be compiled by a Fortran compiler, unless it implements some non-standard extension.

    Intel Fortran accepts this:

     A colon-separated triplet (instead of an implied-DO loop) to specify a range of values and a stride; for example, the following two array constructors are equivalent:
    1       INTEGER D(3)
    2       D = (/1:5:2/)              ! Triplet form - also [1:5:2]
    3       D = (/(I, I=1, 5, 2)/)     ! implied-DO loop form
    

    from https://software.intel.com/en-us/node/678554

    To generate a sequence in a standard way one uses an implied do loop like

     (/ (i, i=1,9) /)
    

    the reshape than just changes the 1D array into a 2D one in column major order as you guessed.

    0 讨论(0)
提交回复
热议问题