The Computer Language
Benchmarks Game

reverse-complement Fortran Intel #2 program

source code

! The Computer Language Benchmarks Game
! http://benchmarksgame.alioth.debian.org/
!
! contributed by Steve Decker, modified from the version by Simon Geard
! compilation:
!   g95 -O3 reverse.f90
!   ifort -ipo -O3 -static reverse.f90

program revcomp
  implicit none

  character, parameter :: EndStr = ">"
  integer,   parameter :: LineWidth = 60

  character(len=LineWidth), dimension(:), allocatable :: data, w
  logical                  :: insection = .false.
  integer                  :: stat, bcount
  character(len=LineWidth) :: line, title

  ! Read and process
  allocate(data(100))  ! Allocate enough lines so that we don't have to grow the array for the test
  readFile: do
     read(*, "(a)", iostat=stat) line
     if (stat /= 0) exit readFile
     if (line(1:1) == EndStr) then
        if (insection) then
           write(*, "(a)") trim(title)
           call printReverseFasta
        else
           insection = .true.
        end if
        title = line
        bcount = 0
        cycle readFile
     end if
     bcount = bcount + 1
     if (bcount > size(data)) then ! Included for completeness - it shouldn't be called in the test
        allocate(w(size(data)))
        w = data
        deallocate(data)
        allocate(data(2*size(w)))
        data(1:size(w)) = w
        deallocate(w)
     end if
     data(bcount) = line
  end do readFile

  write(*, "(a)") trim(title)
  call printReverseFasta
  
contains

  subroutine printReverseFasta
    ! Output the data in reverse order and with the complement
    character, dimension(65:121), parameter :: Complement = (/ "T", "V", "G", &
         "H", "E", "F", "C", "D", "I", "J", "M", "L", "K", "N", "O", "P",  &
         "Q", "Y", "S", "A", "A", "B", "W", "X", "R", (" ", stat = 90, 96),  &
         "T", "V", "G", "H", "E", "F", "C", "D", "I", "J", "M", "L", "K",  &
         "N", "O", "P", "Q", "Y", "S", "A", "A", "B", "W", "X", "R" /)

    integer :: fLine, fChar, bLine, bChar
    character :: c

    fLine = 1
    fChar = 1
    bLine = bcount
    bChar = len_trim(data(bLine))
    do
       if (fLine > bLine .or. fLine == bLine .and. fChar >= bChar) exit
       c = data(fLine)(fChar:fChar)
       data(fLine)(fChar:fChar) = Complement(iachar(data(bLine)(bChar:bChar)))
       data(bLine)(bChar:bChar) = Complement(iachar(c))
       fChar = fChar + 1
       if (fChar > LineWidth) then
          fChar = 1
          fLine = fLine + 1
       end if
       bChar = bChar - 1
       if (bChar == 0) then
          bChar = LineWidth
          bLine = bLine - 1
       end if
    end do
    if (fLine == bLine .and. fChar == bChar)  &
         data(fLine)(fChar:fChar) = Complement(iachar(data(fLine)(fChar:fChar)))
    do fLine = 1, bcount-1
       write(*, "(a)") data(fLine)
    end do
    write(*, "(a)") trim(data(bcount))
  end subroutine printReverseFasta
end program revcomp
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.0.128 Build 20170811
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.
FOR NON-COMMERCIAL USE ONLY


Mon, 26 Mar 2018 19:05:53 GMT

MAKE:
/opt/src/intel/bin/ifort -O3 -fast revcomp.ifc-2.f90 -o revcomp.ifc-2.ifc_run

Error: Product support for your (Comp-FL) license has expired.
License file(s) used were (in this order):
**  1.  /home/dunham/intel/licenses/l_CGJ7XCFZ.lic
**  2.  /opt/src/intel/compilers_and_libraries_2018.0.128/linux/bin/intel64/../../Licenses
**  3.  /home/dunham/Licenses
**  4.  /opt/intel/licenses
**  5.  /Users/Shared/Library/Application Support/Intel/Licenses
**  6.  /opt/src/intel/compilers_and_libraries_2018.0.128/linux/bin/intel64/*.lic

Please refer https://software.intel.com/en-us/faq/purchasing-renewing-upgrading#support-expiration  for more information..

ifort: error #10052: could not checkout FLEXlm license
/home/dunham/benchmarksgame/nanobench/makefiles/u64q.programs.Makefile:329: recipe for target 'revcomp.ifc-2.ifc_run' failed
make: [revcomp.ifc-2.ifc_run] Error 1 (ignored)
rm revcomp.ifc-2.f90

0.38s to complete and log all make actions

COMMAND LINE:
./revcomp.ifc-2.ifc_run 0 < revcomp-input250000.txt

MAKE ERROR