⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 子程序(与本程序相关性不大).txt

📁 是一个接收永磁体磁场计算的程序
💻 TXT
字号:
subroutine ppma_write ( filename, ierror, nrow, ncol, r, g, b )
!
!*******************************************************************************
!
!! PPMA_WRITE writes an ASCII portable pixel map file.
!
!
!  Discussion:
!
!    PPM files can be viewed by XV.
!
!    Programs to convert files to this format include:
!
!      GIFTOPPM  - GIF file
!      PGMTOPPM  - Portable Gray Map file
!      PICTTOPPM - Macintosh PICT file
!      XPMTOPPM  - X11 pixmap file
!
!    Various programs can convert other formats to PPM format, including:
!
!      BMPTOPPM - Microsoft Windows BMP file.
!
!    A PPM file can also be converted to other formats, by programs:
!
!      PPMTOACAD - AutoCAD file
!      PPMTOGIF  - GIF file
!      PPMTOPGM  - Portable Gray Map file
!      PPMTOPICT - Macintosh PICT file
!      PPMTOPUZZ - X11 puzzle file
!      PPMTORGB3 - 3 Portable Gray Map files
!      PPMTOXPM  - X11 pixmap file
!      PPMTOYUV  - Abekas YUV file
!    
!  Example:
!
!    P3
!    # feep.ppm
!    4 4
!    15
!     0  0  0    0  0  0    0  0  0   15  0 15
!     0  0  0    0 15  7    0  0  0    0  0  0
!     0  0  0    0  0  0    0 15  7    0  0  0
!    15  0 15    0  0  0    0  0  0    0  0  0
!
!  Modified:
!
!    28 May 1999
!
!  Author:
!
!    John Burkardt
!
!  Parameters:
!
!    Input, character ( len = * ) FILENAME, the name of the file to which
!    the data should be written.
!
!    Output, integer IERROR, an error flag.
!    0, no error.
!    1, the data was illegal.
!    2, the file could not be opened.
!
!    Input, integer NROW, NCOL, the number of rows and columns of data.
!
!    Input, integer R(NROW,NCOL), G(NROW,NCOL), B(NROW,NCOL), contain
!    the red, green and blue values of each pixel.  These should
!    be positive.
!
  implicit none
!
  integer ncol
  integer nrow
!
  integer b(nrow,ncol)
  logical debug
  character ( len = * ) filename
  integer g(nrow,ncol)
  integer i
  integer ierror
  integer ios
  integer j
  integer jhi
  integer jlo
  character ( len = 2 ) magic
  integer maxcol
  integer output_unit
  integer r(nrow,ncol)
!
  debug = .false.
  ierror = 0
!
!  Compute the maximum color value.
!
  maxcol = r(1,1)

  do i = 1, nrow
    do j = 1, ncol

      maxcol = max ( maxcol, r(i,j) )
      maxcol = max ( maxcol, g(i,j) )
      maxcol = max ( maxcol, b(i,j) )

    end do
  end do
!
!  Check the data.
!
  call ppm_check_data ( r, g, b, ierror, maxcol, ncol, nrow )

  if ( ierror /= 0 ) then
    write ( *, * ) ' '
    write ( *, * ) 'PPMA_WRITE - Fatal error!'
    write ( *, * ) '  Bad data!'
    ierror = 1
    return
  end if
!
!  Open the file.
!
  call get_unit ( output_unit )

  open ( unit = output_unit, file = filename, status = 'replace', &
    form = 'formatted', access = 'sequential', iostat = ios )

  if ( ios /= 0 ) then
    write ( *, * ) ' '
    write ( *, * ) 'PPMA_WRITE - Fatal error!'
    write ( *, * ) '  Could not open the file.'
    ierror = 2
    return
  end if
!
!  Write the data.
!
  magic = 'P3'

  write ( output_unit, '(a2)' ) magic
  write ( output_unit, '(a)' ) '# ASCII PPM file created by PPMA_WRITE.'
  write ( output_unit, '(i5,2x,i5)' ) ncol, nrow
  write ( output_unit, '(i5)' ) maxcol

  do i = 1, nrow
    do jlo = 1, ncol, 4
      jhi = min ( jlo + 3, ncol )
      write ( output_unit, '(12i5)' ) ( r(i,j), g(i,j), b(i,j), j = jlo, jhi )
    end do
  end do
!
!  Close the file.
!
  close ( unit = output_unit )
!
!  Report
!
  if ( debug ) then
    write ( *, * ) ' '
    write ( *, * ) 'PPMA_WRITE - Note:'
    write ( *, * ) '  The data was checked and written.'
    write ( *, * ) '  Number of data rows NROW =    ', nrow
    write ( *, * ) '  Number of data columns NCOL = ', ncol
    write ( *, * ) '  Maximum color value MAXCOL =  ', maxcol
  end if

  return
end












subroutine ppm_check_data ( r, g, b, ierror, maxcol, ncol, nrow )
!
!*******************************************************************************
!
!! PPM_CHECK_DATA checks pixel data.
!
!
!  Modified:
!
!    28 May 1999
!
!  Author:
!
!    John Burkardt
!
!  Parameters:
!
!    Input, integer R(NROW,NCOL), G(NROW,NCOL), B(NROW,NCOL), contains the 
!    RGB pixel data.
!
!    Output, integer IERROR, error flag.
!    0, no error detected.
!    1, the data is illegal.
!
!    Input, integer MAXCOL, the maximum value.
!
!    Input, integer NCOL, NROW, the number of rows and columns of data.
!
  implicit none
!
  integer ncol
  integer nrow
!
  integer b(nrow,ncol)
  integer g(nrow,ncol)
  integer i
  integer ierror
  integer j
  integer maxcol
  integer r(nrow,ncol)
!
  ierror = 0
!
!  Make sure no color is negative nor greater than MAXCOL.
!
  do i = 1, nrow
    do j = 1, ncol

      if ( r(i,j) < 0 .or. g(i,j) < 0 .or. b(i,j) < 0 ) then

        ierror = 1
        return

      end if

     if ( r(i,j) > maxcol .or. g(i,j) > maxcol .or. b(i,j) > maxcol ) then

        ierror = 1
        return

      end if

    end do
  end do

  return
end





subroutine get_unit ( iunit )
!
!*******************************************************************************
!
!! GET_UNIT returns a free FORTRAN unit number.
!
!
!  Discussion:
!
!    A "free" FORTRAN unit number is an integer between 1 and 99 which
!    is not currently associated with an I/O device.  A free FORTRAN unit
!    number is needed in order to open a file with the OPEN command.
!
!  Modified:
!
!    02 March 1999
!
!  Author:
!
!    John Burkardt
!
!  Parameters:
!
!    Output, integer IUNIT.
!
!    If IUNIT = 0, then no free FORTRAN unit could be found, although
!    all 99 units were checked (except for units 5 and 6).
!
!    Otherwise, IUNIT is an integer between 1 and 99, representing a
!    free FORTRAN unit.  Note that GET_UNIT assumes that units 5 and 6
!    are special, and will never return those values.
!
  implicit none
!
  integer i
  integer ios
  integer iunit
  logical lopen

  iunit = 0

  do i = 1, 99

    if ( i /= 5 .and. i /= 6 ) then

      inquire ( unit = i, opened = lopen, iostat = ios )

      if ( ios == 0 ) then
        if ( .not. lopen ) then
          iunit = i
          return
        end if
      end if

    end if

  end do

  return
end























⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -