Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing array contents to line

Status
Not open for further replies.

creilly

Technical User
Jul 29, 2013
1
CA
Hi,

I'm using Intel FORTRAN and trying to write an array to a file. the array is initialiesd so all values are equal to -9.

The array is not complete, meaning that i do not want to output all the array values, i only want to output those not equal to -9. I want to write the array to lines of 20 array values in a text file, with each value seperated by 2 spaces.

I have tried a few ways, including the below, but can't get the result I want.



The below writes out 20 values, however it always fills the last line with 20 values even if there are no values in the array. This means that i get the below as the final line in the file. I need the solution not to print anything for the last values instead of *********.

0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 0.1500000 ********* ********* ********* *********


c Write out J values
c
write(57,21) "# Y Values"
c
do 700 n=MIN_NODE,MAX_NODE,20
c
if (NODE_ARRAY(n,1).ne.-9)then
write(57,10) (NODE_ARRAY((n+i),2), i=0,19)
endif
c
700 enddo




To try and get around the above problems i tried the below, but it only outputs one value on a line, and only outputs 20 lines.

c
c Write out I values
c
21 format(A)
10 format(20(f9.7,2X))

write(57,21) "# X Values"
c
do 600 n=MIN_NODE,MAX_NODE,20
do 601 i=0,19
c
if(i+(n*20).gt.MAX_NODE) go to 125
c
if (NODE_ARRAY((n+i),1).ne.-9)then
write(57,10) (NODE_ARRAY((n+i),1))
endif
c
601 enddo
600 enddo
c
c
125 continue
c
 
how about something like this?
Code:
n=0
do i=min_node,max_node
    if ( node_array(i,1) .ne. -9 ) then
        write(57,'(2x,f9.7,$)') node_array(i,1)
        n = n+ 1
        if (mod(n,20).eq.0) then write(57,*)
    end if
end do
if the dollar sign does not work, try backslash; if backslash does not work, try the ADVANCE options with NO...I just like keeping it concise.

By the way, you do realize that you won't know which items in the array are the ones you are printing, right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top