1c=======================================================================
2c
3!> \brief Scale the coordinates and box size in a PDB file
4!>
5!> This program scales the atomic coordinates and the box size in a
6!> PBD file. The scale factor is provided on the command line.
7!> Negative scale factors are allowed but it is not clear what that
8!> means if the PDB file has a CRYST1 record.
9!>
10!> The PDB file is read from standard input and the result written
11!> to standard output.
12!>
13      program pdb_scale
14      character(len=32) :: arg      ! command line argument
15      character(len=80) :: line_in  ! line of input file
16      character(len=80) :: line_out ! line for output file
17      integer :: iline              ! counts lines of input file
18      integer :: i                  ! generic counter
19      double precision :: factor    ! scale factor
20      double precision :: xyz(3)    ! coordinates or lattice parameters
21      iline = 0
22      if (command_argument_count().ne.1) then
23        write(0,*)"ERROR: Invalid invocation of pdb_scale."
24        write(0,*)"       The program expects 1 command line argument"
25        write(0,*)"       that is the scale factor."
26      endif
27      call get_command_argument(1,arg)
28      read(arg,*)factor
29      do while (.true.)
30        iline = iline + 1
31        read(*,'(a80)',err=999,end=888)line_in
32        line_out = line_in
33        select case(line_in(1:6))
34        case("ATOM  ","HETATM")
35          read(line_in(31:54),'(3f8.3)')(xyz(i),i=1,3)
36          do i = 1, 3
37            xyz(i) = factor*xyz(i)
38          enddo
39          write(line_out(31:54),'(3f8.3)')(xyz(i),i=1,3)
40        case("CRYST1")
41          read(line_in(7:33),'(3f9.3)')(xyz(i),i=1,3)
42          do i = 1, 3
43            xyz(i) = factor*xyz(i)
44          enddo
45          write(line_out(7:33),'(3f9.3)')(xyz(i),i=1,3)
46        case default
47          ! do nothing: the input is echoed to the ouput
48        end select
49        write(*,'(a80)')line_out
50      enddo
51 999  write(0,*)"ERROR: I/O error reading line ",iline
52 888  continue
53      end program pdb_scale
54c
55c=======================================================================
56