加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Fortran代码自动创建文件夹

(2016-02-02 20:51:45)
标签:

it

fortran

分类: 编程
       在Fortran代码中,在指定路径中自动创建文件夹。首先,使用内部函数“inquire”查询,指定路径中将要创建的文件夹是否存在;然后,根据“inquire”反馈的结果,用系统命令中创建文件夹的命令进行相应文件夹的自动创建。另外,在Fortran中,若要输入单引号或者双引号,则需连续输入两次单引号或双引号即可。

示例代码:

! 输出路径
!----------------
    module Path
    implicit none
    character(len=100) :: out_path="D:\Code\Routine Code\Interface\2016-01-29\"  
                         !- 查询目录文件夹状态或使用目录文件夹,允许字符串中存在空格 
    character(len=100) :: out_path1="D:\Code\""Routine Code""\Interface\2016-01-29\"
                         !- 调用系统命令自动创建目录文件夹,字符串中空格需用引号处理
    end module Path

    program Main
    use Path
    implicit none
    character(len=100) :: path_result,path_result0,path_result11,path_result10
    real(kind=4) :: Time_cost,TA(2),ETIME  
                    !- 内部函数ETIME长度只能是4字节,即kind=4,见Intel Visual Fortran帮助文件
 
!...调用系统命令自动创建目录文件夹(计算结果输出目录)
!------------------------------------------

    print*,'Check and creat the file directionary: '
    print*,' '
    path_result=trim(adjustl(out_path))//"Result\"
    path_result0=trim(adjustl(out_path1))//"Result\"
    call Createfolder(path_result,path_result0)

!...程序运行所耗总时间
!------------------------------------------
    write(*,'(/)')
    Time_cost=ETIME(TA)
    write(*,*) 'Program has used',Time_cost,'seconds of CPU time.'
    write(*,*) 'This includes',TA(1),'seconds of user time and',   &
                TA(2),'seconds of system time.'
   
    write(*,*) ' '
    stop ' Calculation is over'
    end program Main


! 创建目录文件夹路径
!-----------------------
    subroutine Createfolder(path_inquire,path_create)
    use IFPORT
    use Path
    implicit none
    integer(kind=4) :: istatus1,errnum
    logical(kind=4) :: ierr1
    character(len=100) :: path_inquire,path_create
   
    inquire(DIRECTORY=trim(adjustl(path_inquire)), EXIST=ierr1)
    print*,ierr1
    if(ierr1) then
        print*,'The directory have existed and not been needed to create'
        write(*,'(/)')
    else
        print*,'The directory not exist and creat it'
        write(*,'(/)')
        istatus1=SYSTEM('md '//trim(adjustl(path_create)))
        if(istatus1==-1) then
            errnum=ierrno()
            print*,'Error=',errnum,' inquire the Intel Visual Fortran help document'
            print*,' '
            stop ' Folder creating is fail'
        end if
    end if
    
    return
    end subroutine Createfolder




0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有