- #1
Sue Parks
- 38
- 0
I have a program "probe.f90" that reads in a text file. It runs. I am having trouble reading in the second text file (when prompted by user).
How could I turn this bit of code into a function? I was thinking about a function that strips the header from the fasta file. Then read into an array. Then compute amino acid frequency (last)!
I looked at some examples of character functions in fortran 90, but I see mostly integer functions.
Mod note: Edited the code so that the indentation matches the program structure.
How could I turn this bit of code into a function? I was thinking about a function that strips the header from the fasta file. Then read into an array. Then compute amino acid frequency (last)!
I looked at some examples of character functions in fortran 90, but I see mostly integer functions.
Mod note: Edited the code so that the indentation matches the program structure.
Fortran:
PROGRAM PROBE
implicit none
character(len=200) :: string
character, allocatable :: baseq(:), tmpstr(:), newstr(:)
integer :: nbase, errstat, tmplen, i
nbase = 0
errstat = 0
allocate( baseq(0) )
open(unit=101, file="TitinFastaFormat.txt", form="formatted", status="old")
do
read (101,*,iostat=errstat) string
if (errstat .ne. 0) exit
if ( string(1:1) .ne. ">" ) then
tmplen = len_trim(string)
nbase = nbase + tmplen
allocate ( tmpstr( tmplen ) )
do i=1,tmplen
tmpstr(i) = string(i:i)
end do
allocate( newstr( nbase ))
newstr(1:size(baseq)) = baseq
call move_alloc(newstr,baseq)
baseq(nbase-tmplen+1:nbase) = tmpstr
deallocate ( tmpstr )
end if
end do
close(101)
write (*,"(A6, tr1, 999999(A1))"),baseq
!write (*,"(A6, tr1, i0)") "NBASE:", nbase
deallocate (baseq)
end program probe
Attachments
Last edited by a moderator: