wander95
wander95

Reputation: 1366

How do I force fortran to write four elements per line of a two dimensional array?

Consider the following code. It writes "n" elements at a time. "n" was 5 for the intel compiler and "n" was 4 for pgi

         icels=128
         jcels=128
         imat=2 ! just for example
         write(ounit,*)
 x          ((real(pr(i,j,imat)),i=1,icels),j=1,jcels)

Where the "x" is a continuation character. I want the output to be formatted the same for both compilers. An example:

   6.2500001E-03   7.0312498E-03   7.8125000E-03   8.5937502E-03 
   9.3750004E-03   1.0156250E-02   1.0937500E-02   1.1718750E-02 
   .....
   .....

How do I replace the * with a correct format? Would prefer a fortran77 compliant answer.

Upvotes: 0

Views: 139

Answers (1)

Steve Lionel
Steve Lionel

Reputation: 7267

You can replace the * with '(4(E13.6,1X))' (including the quotes). This takes advantage of a Fortran feature called format reversion.

I will note that your code is already not Fortran 77 compliant, so I am not sure why you are concerned about that.

Upvotes: 1

Related Questions