WANtaroHP (Fortran90 tips)

toJA

Outline of this page

Contents


Set the Value of π (pi)

real(8),parameter::pi=3.14159265358979323846D0


Get the character strings from command line

call getarg(1,dummy)
call getarg(2,fnameR)
call getarg(3,fnameW)


Convert the character string to the figure

read(dummy,*) negv


Convert the figure to character string

write(dummy,'(",",e15.7)') vec(i)


Create the sequence named file and write down the data

do n=1,ntout+1
    write (filename,'("_inp_xyz_",i2.2,".txt")') n
    open(13,file=filename,status='replace')
    do ne=1,NELT
        i=kakom(ne,1)
        write(13,*) x(i),y(i),tempe_s(i,n)
    end do
    close(13)
end do


Read the data from the file with unknown row numbers

    integer,parameter::nn=1000,mm=100
    character(len=mm)::str(1:nn)
    integer::i,io,nd
    character(len=50)::fnameR

    call getarg(1,fnameR)

    open(11,file=fnameR,status='old')
        do i=1,nn
            read(11,'(a)',iostat=io) str(i)
            if(io<0)exit
        end do
    close(11)
    nd=i-1


Write the data to the file

open(12, file=fnameW, status='replace')
do i=1,nd
    write(12,'(a)') trim(adjustl(str(i)))
end do
close(12)


Specify the output format

fmt3="(i5,2(',',e15.7),3(',',e15.7))"
write(linebuf,FMT=fmt3) i,x(i),z(i),hvec(i),q0vec(i),hvec(i)


Delete all blanks (spaces) in character string

call del_spaces(linebuf)
write (12,'(a)') trim(linebuf)
subroutine del_spaces(s)
    character (*), intent (inout) :: s
    character (len=len(s)) tmp
    integer i, j
    j = 1
    do i = 1, len(s)
       if (s(i:i)==' ') cycle
        tmp(j:j) = s(i:i)
        j = j + 1
    end do
    s = tmp(1:j-1)
end subroutine del_spaces


Convert the under-bar to blank in character string

dummy=str1(i)
call rep_ub(dummy)
str1(i)=dummy
subroutine rep_ub(s)
    !Replacing underbar with space
    character (*), intent (inout) :: s
    integer i
    do i = 1, len(s)
        if (s(i:i)=='_') s(i:i)=' '
    end do
end subroutine rep_ub


Set the Value of π (pi) using module

module defpi
    implicit none
    real(8),parameter::pi=3.14159265358979323846D0
end module defpi

program f90_test
    use defpi
    implicit none
    .... .... ....
end program

toJA
inserted by FC2 system