WRITE_XY_DATA writes X(1:N), Y(1:N) data to a file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*) | :: | data_file_name | ||||
integer | :: | n | ||||
real | :: | x(n) | ||||
real | :: | y(n) | ||||
integer | :: | ierror |
subroutine write_xy_data ( data_file_name, n, x, y, ierror ) ! !******************************************************************************* ! !! WRITE_XY_DATA writes X(1:N), Y(1:N) data to a file. ! ! ! Modified: ! ! 23 February 2001 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Input, character ( len = * ) DATA_FILE_NAME, the name of the data file. ! ! Input, integer N, the number of data items. ! ! Input, real X(N), Y(N), the X and Y data ! ! Output, integer IERROR, nonzero if an error occurred. ! implicit none ! integer n ! character ( len = * ) data_file_name integer file_unit integer i integer ierror integer ios real x(n) real y(n) ! ierror = 0 call get_unit ( file_unit ) if ( file_unit == 0 ) then ierror = 1 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WRITE_XY_DATA - Fatal error!' write ( *, '(a)' ) ' Could not get a free FORTRAN unit.' return end if open ( unit = file_unit, file = data_file_name, status = 'replace', & iostat = ios ) if ( ios /= 0 ) then ierror = 2 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WRITE_XY_DATA - Fatal error!' write ( *, '(a)' ) ' Could not open the output file.' return end if do i = 1, n write ( file_unit, * ) x(i), y(i) end do close ( unit = file_unit ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'WRITE_XY_DATA:' write ( *, '(a)' ) ' Wrote the GNUPLOT XY data file "' // & trim ( data_file_name ) // '"' return endsubroutine write_xy_data