pusca.f90 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. program pusca
  2. implicit none
  3. integer :: nstep
  4. integer :: nlev
  5. integer :: nloni,nlono
  6. integer :: nlati,nlato
  7. integer :: nrspi,nrspo
  8. integer :: ntrui,ntruo
  9. integer :: narg,io
  10. character (len=1024) :: yarg,yfni,yfno
  11. character (len=16) :: yid
  12. narg = iargc()
  13. if (narg /= 3) then
  14. print *,"Usage: pusca.x <newlats> <inputfile> <outputfile>"
  15. stop
  16. endif
  17. call getarg(1,yarg)
  18. call getarg(2,yfni)
  19. call getarg(3,yfno)
  20. read(yarg,*) nlato
  21. nlono = 2 * nlato
  22. ntruo = (nlono - 1) / 3
  23. nrspo = (ntruo + 1) * (ntruo + 2)
  24. open(10,file=yfni,form='unformatted',status='old',iostat=io)
  25. if (io /= 0) then
  26. print *,"Error opening file <",trim(yfni),">"
  27. stop
  28. endif
  29. open(20,file=yfno,form='unformatted')
  30. call get_restart_integer('nstep',nstep)
  31. call get_restart_integer('nlat' ,nlati)
  32. call get_restart_integer('nlon' ,nloni)
  33. call get_restart_integer('nlev' ,nlev )
  34. call get_restart_integer('nrsp' ,nrspi)
  35. ntrui = (nloni - 1) / 3
  36. write (*,'(/,56("*"))')
  37. write (*,'("* * ",a20," * ",a20," *")') trim(yfni),trim(yfno)
  38. write (*,'(56("*"))')
  39. write (*,'("* NLAT * ",i20," * ",i20," *")') nlati,nlato
  40. write (*,'("* NLON * ",i20," * ",i20," *")') nloni,nlono
  41. write (*,'("* NTRU * ",i20," * ",i20," *")') ntrui,ntruo
  42. write (*,'("* NRSP * ",i20," * ",i20," *")') nrspi,nrspo
  43. write (*,'("* NLEV * ",i20," * ",i20," *")') nlev,nlev
  44. write (*,'("* NSTEP * ",i20," * ",i20," *")') nstep,nstep
  45. write (*,'(56("*"))')
  46. call put_restart_integer('nstep',nstep)
  47. call put_restart_integer('nlat' ,nlato)
  48. call put_restart_integer('nlon' ,nlono)
  49. call put_restart_integer('nlev' ,nlev )
  50. call put_restart_integer('nrsp' ,nrspo)
  51. call convert_restart_array('sz' ,ntrui,ntruo,nlev)
  52. call convert_restart_array('sd' ,ntrui,ntruo,nlev)
  53. call convert_restart_array('st' ,ntrui,ntruo,nlev)
  54. call convert_restart_array('st2',ntrui,ntruo,nlev)
  55. call convert_restart_array('st3',ntrui,ntruo,nlev)
  56. call convert_restart_array('sr1',ntrui,ntruo,nlev)
  57. call convert_restart_array('sr2',ntrui,ntruo,nlev)
  58. call convert_restart_array('sp' ,ntrui,ntruo, 1)
  59. call convert_restart_array('sp2',ntrui,ntruo, 1)
  60. call convert_restart_array('sp3',ntrui,ntruo, 1)
  61. call convert_restart_array('so' ,ntrui,ntruo, 1)
  62. call convert_restart_array('szm',ntrui,ntruo,nlev)
  63. call convert_restart_array('sdm',ntrui,ntruo,nlev)
  64. call convert_restart_array('stm',ntrui,ntruo,nlev)
  65. call convert_restart_array('spm',ntrui,ntruo, 1)
  66. close (10)
  67. close (20)
  68. stop
  69. end
  70. subroutine convert_restart_array(yn,ntrui,ntruo,nlev)
  71. character (len=*) :: yn
  72. character (len=16) :: yi
  73. real, allocatable :: fi(:,:)
  74. real, allocatable :: fo(:,:)
  75. real, allocatable :: fx(:,:)
  76. real, allocatable :: fy(:,:)
  77. ntrux = max(ntrui,ntruo) + 1
  78. nrspi = (ntrui + 1) * (ntrui + 2)
  79. nrspo = (ntruo + 1) * (ntruo + 2)
  80. allocate(fi(nrspi,nlev))
  81. allocate(fo(nrspo,nlev))
  82. allocate(fx(ntrux,ntrux))
  83. allocate(fy(ntrux,ntrux))
  84. read (10,iostat=io) yi
  85. if (io /= 0) then
  86. print *,"I/O Error reading ",trim(yn)
  87. stop
  88. endif
  89. if (trim(yi) /= trim(yn)) then
  90. print *,"Looking for: <",trim(yn),"> found: <",trim(yi),">"
  91. stop
  92. endif
  93. read (10) fi(1:nrspi,1:nlev)
  94. do jlev = 1 , NLEV
  95. fx(:,:) = 0.0
  96. fy(:,:) = 0.0
  97. k = 0
  98. do m = 1 , ntrui+1
  99. do n = m , ntrui+1
  100. fx(n,m) = fi(k+1,jlev)
  101. fy(n,m) = fi(k+2,jlev)
  102. k = k + 2
  103. enddo
  104. enddo
  105. k = 0
  106. do m = 1 , ntruo+1
  107. do n = m , ntruo+1
  108. fo(k+1,jlev) = fx(n,m)
  109. fo(k+2,jlev) = fy(n,m)
  110. k = k + 2
  111. enddo
  112. enddo
  113. enddo
  114. write (20) yi
  115. write (20) fo
  116. print *,"Converted array: ",trim(yi)
  117. deallocate(fi)
  118. deallocate(fo)
  119. deallocate(fx)
  120. deallocate(fy)
  121. return
  122. end
  123. ! ==============================
  124. ! SUBROUTINE GET_RESTART_INTEGER
  125. ! ==============================
  126. subroutine get_restart_integer(yn,kv)
  127. character (len=* ) :: yn
  128. character (len=16) :: yi
  129. integer :: kv
  130. read (10) yi
  131. read (10) kv
  132. if (trim(yi) /= trim(yn)) then
  133. print *,'*** Error in get_restart_integer ***'
  134. print *,'Requested integer {',yn,'} was not found'
  135. stop
  136. endif
  137. return
  138. end subroutine get_restart_integer
  139. ! ==============================
  140. ! SUBROUTINE PUT_RESTART_INTEGER
  141. ! ==============================
  142. subroutine put_restart_integer(yn,kv)
  143. character (len=* ) :: yn
  144. character (len=16) :: yi
  145. integer :: kv
  146. yi = yn
  147. write (20) yi
  148. write (20) kv
  149. return
  150. end subroutine put_restart_integer