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

Multiple Output files

Ross_B_1
Beginner
362 Views

I've written a 3D finite difference diffusion code in Microsoft Visual studio and I need to output the concentrations are certain time step values. I need multiple output files that include the concentration array in the domain for specific time steps throughout the program. The format I have right now is listed below.

open(71,file='Conc.out',status='unknown')

if(NumTS.eq.TS)then
do k=1,NZ
   do j=1,NY
     do i=1,NX
        m=i+(j-1)*NX+(k-1)*NX*NY
        write (71,'(TS)',ADVANCE = "NO")TS
        write (71,'(TS)',ADVANCE = "NO")Cold(m)
     end do
   end do
end do
end if

close(unit=71)

NumTS is the time step value I wish to output i.e NumTS=100,150,200 etc. TS is the updated time step value that has an increase in time step size added to the previous time step value that is included in the main loop i.e 50 is added each time. So my desired output files would be Conc100.out, Conc150.out and so on. OR how can I output the concentrations for each time step in one file that is column listed. Any help would be awesome! Thanks.

Note: This output command is within a subroutine and Cold(m) is the concentration array

0 Kudos
4 Replies
mecej4
Honored Contributor III
362 Views

It would be far more economical to use a single I/O statement. Secondly, TS does not vary with i,j,k, so why output millions of copies inside the loop? Suggested replacement:

character(20) fmt
...
if(NumTS.eq.TS)then
   write(fmt,'(A,I,A)')'(',nx*ny*nz+1,'E12.4)'
   write(71,fmt)TS,(((Cold(i+(j-1)*NX+(k-1)*NX*NY,i=1,NX),j=1,NY),k=1,NZ)
endif

You would have to check whether the output file is fit to receive long records, and adjust the OPEN statement if necessary. Since the first number in each line is the time value, you could output the concentration profiles to a single file, if you prefer. In making these decisions you should keep in mind the needs of the software that will read this file and, perhaps, present a graphical display of the results.

0 Kudos
Ross_B_1
Beginner
362 Views

I found a syntax error in the first write statement (listed below). An example output that I need for the file is listed below. Where the header is the time step size Numts/TS and below that are the array of concentrations. Also why do you have the nx*ny*nz+1 listed? Thank you!

     100                 150               200             250      etc..  

   1495.222         12453            16463          13564
   1494.811         134546          13658          13565
   1494.206         136563          13564          13567
   1493.420         114543          16743          13569
   **********          ********          ********         *******

forrt1: infor(58):format sytax error at or near 159153E12.4

0 Kudos
mecej4
Honored Contributor III
362 Views

A format string should begin and end with parentheses (I have corrected the snippets in #2 to suit). The +1 in the repeat count is for the time value.

Since character mode output is line-by-line, you cannot directly output a file in the format that you showed in #3. My suggestion will help you to write the first column of the table as the first line of the file, etc. You can post-process the file to produce the "transpose".

0 Kudos
Ross_B_1
Beginner
362 Views

OK I'm fine with having multiple output files that have just one array in them but I think there may be an error in the formatting or something else. The output is not a one column array as seen below( only a snippet of the total file) and only one file is opened instead of multiple ones for updated time step. Thank you very much again for your time.

  0.1000E+03  0.2681E+06  0.1865E+01  0.6853E-05  0.1689E-04  0.2299E+01  0.1707E+02  0.6609E+05  0.4597E+00  0.2230E-05  0.1472E+00  0.2117E+05  0.1473E+00  0.1352E+00  0.2300E-05  0.1778E+00  0.1307E-05  0.3097E-04  0.3162E-04  0.2678E+00  0.3851E+05  0.2678E+00  0.9842E-06  0.2545E-11  0.4820E-10  0.6214E-05  0.4820E-10  0.1698E-11  0.9095E-16  0.7234E-21  0.4873E-21  0.1110E-15  0.1358E-10  0.1111E-15  0.1296E-14  0.7914E-10  0.7914E-10  0.7914E-10  0.8085E-10  0.6601E-06  0.1796E+00  0.2582E+05  0.1796E+00  0.6601E-06  0.8094E-10  0.7923E-10  0.7161E-15  0.2031E-10  0.4031E-05  0.3845E+00  0.5965E-05  0.8544E+00  0.1228E+06  0.1282E+01  0.1762E+00  0.2533E+05  0.1762E+00  0.4527E+00  0.3327E-05  0.1290E-10  0.6008E-11  0.1660E-05  0.2709E+00  0.1296E+05  0.9017E-01  0.1658E-05  0.1805E+00  0.1327E-05  0.5146E-11  0.1403E-16  0.1486E-15  0.2367E-10  0.3052E-05  0.4030E-10  0.8918E-11  0.1147E-15  0.5107E-11  0.8353E-16  0.5107E-11  0.4176E-16  0.6119E-21  0.6027E-22  0.2099E-16  0.5133E-11 

0 Kudos
Reply