m_Filename.F90 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  3. !-----------------------------------------------------------------------
  4. ! CVS m_Filename.F90,v 1.3 2004-04-21 22:54:44 jacob Exp
  5. ! CVS MCT_2_8_0
  6. !BOP -------------------------------------------------------------------
  7. !
  8. ! !MODULE: m_Filename - Filename manipulation routines
  9. !
  10. ! !DESCRIPTION:
  11. !
  12. ! !INTERFACE:
  13. module m_Filename
  14. implicit none
  15. private ! except
  16. public :: Filename_base ! basename()
  17. public :: Filename_dir ! dirname()
  18. interface Filename_base; module procedure base_; end interface
  19. interface Filename_dir; module procedure dir_; end interface
  20. ! !REVISION HISTORY:
  21. ! 14Feb00 - Jing Guo <guo@dao.gsfc.nasa.gov>
  22. ! - initial prototype/prolog/code
  23. !EOP ___________________________________________________________________
  24. character(len=*),parameter :: myname='MCT(MPEU)::m_Filename'
  25. contains
  26. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  28. !BOP -------------------------------------------------------------------
  29. !
  30. ! !IROUTINE: base_ - basename
  31. !
  32. ! !DESCRIPTION:
  33. !
  34. ! !INTERFACE:
  35. function base_(cstr,sfx)
  36. implicit none
  37. character(len=*) ,intent(in) :: cstr
  38. character(len=*),optional,intent(in) :: sfx
  39. character(len=len(cstr)) :: base_
  40. ! !REVISION HISTORY:
  41. ! 14Feb00 - Jing Guo <guo@dao.gsfc.nasa.gov>
  42. ! - initial prototype/prolog/code
  43. !EOP ___________________________________________________________________
  44. character(len=*),parameter :: myname_=myname//'::base_'
  45. integer :: l,lb,le
  46. l =index(cstr,'/',back=.true.)
  47. lb=l+1 ! correct either a '/' is in the string or not.
  48. le=len_trim(cstr)
  49. if(present(sfx)) then
  50. l=le-len_trim(sfx)
  51. if(sfx==cstr(l+1:le)) le=l
  52. endif
  53. base_=cstr(lb:le)
  54. end function base_
  55. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. ! NASA/GSFC, Data Assimilation Office, Code 910.3, GEOS/DAS !
  57. !BOP -------------------------------------------------------------------
  58. !
  59. ! !IROUTINE: dir_ - dirname
  60. !
  61. ! !DESCRIPTION:
  62. !
  63. ! !INTERFACE:
  64. function dir_(cstr)
  65. implicit none
  66. character(len=*),intent(in) :: cstr
  67. character(len=len(cstr)) :: dir_
  68. ! !REVISION HISTORY:
  69. ! 14Feb00 - Jing Guo <guo@dao.gsfc.nasa.gov>
  70. ! - initial prototype/prolog/code
  71. !EOP ___________________________________________________________________
  72. character(len=*),parameter :: myname_=myname//'::dir_'
  73. integer :: l
  74. l =index(cstr,'/',back=.true.)
  75. select case(l)
  76. case(0)
  77. dir_='.'
  78. case(1)
  79. dir_='/'
  80. case default
  81. dir_=cstr(1:l-1)
  82. end select
  83. end function dir_
  84. end module m_Filename