How to create a new directory from Force Fortran 2.0 -


i need create new directory code able write data file it.

i using force fortran 2.0 windows 8 , wondering if syntax going vary 1 operating system other due front/backslash issue.

force fortran uses older compilers (g77, g95, gfortran [unknown version]), i'll present solution system. compilers support it, it's better use standard-conforming execute_command_line.

you can use mkdir, present on both windows , unix machines. default, mkdir creates folder , (non-existing) parent folders on windows. has explicitly given on unix (-p). using system can execute fortran:

program test   implicit none #ifdef _win32   character(len=*),parameter :: mkdir = 'mkdir '   !                                           ^   !                    blank intentional!  #else   character(len=*),parameter :: mkdir = 'mkdir -p '   !                                              ^   !                       blank intentional!  #endif   integer :: stat    stat = system( mkdir // 'testfolder' )   if ( stat /= 0 )     print *, 'mkdir: failed create folder! '   endif end program 

you still need create routine takes care of correct folder delimiter, here quick&dirty example:

module conv_mod contains   function conv2win(str) result(res)     implicit none     character(len=*),intent(in) :: str     character(len=len(str))     :: res     integer                     ::      res = str     i=1,len(res)       if ( res(i:i) == '/' ) res(i:i) = '\'     enddo !   end function    function conv2unix(str) result(res)     implicit none     character(len=*),intent(in) :: str     character(len=len(str))     :: res     integer                     ::      res = str     i=1,len(res)       if ( res(i:i) == '\' ) res(i:i) = '/'     enddo !   end function end module  program conv   use conv_mod   print *,conv2win('some/path')   print *,conv2win('some\path')   print *,conv2unix('some\path') end program 

this doesn't take care of things c:\, though... @vladimirf noted, can use / in windows, too. still need convert backslash / in unix.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -