write_xy_data Subroutine

public 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.

Arguments

Type IntentOptional Attributes Name
character(len=*) :: data_file_name
integer :: n
real :: x(n)
real :: y(n)
integer :: ierror

Calls

proc~~write_xy_data~~CallsGraph proc~write_xy_data write_xy_data proc~get_unit get_unit proc~write_xy_data->proc~get_unit

Called by

proc~~write_xy_data~~CalledByGraph proc~write_xy_data write_xy_data proc~test01 test01 proc~test01->proc~write_xy_data program~test_gnufor test_gnufor program~test_gnufor->proc~test01

Source Code

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