CKBIN.F 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. PROGRAM CKBIN
  2. C
  3. C ROUTINE TO CREATE CORRELATED-K DISTRIBUTION DATA BINARY FILE.
  4. C
  5. C LIST PARAMETERS:
  6. C MXKSUB DIMENSION OF K-DISTRIBUTION SUB-INTERVAL ARRAY.
  7. C MXGAML DIMENSION OF LORENTZ HALF-WIDTH ARRAY.
  8. C MXGAMD DIMENSION OF DOPPLER HALF-WIDTH ARRAY.
  9. C MXNUML DIMENSION OF EFFECTIVE NUMBER OF LINES ARRAY.
  10. INCLUDE 'PARAM.LST'
  11. C
  12. C LIST COMMONS
  13. C
  14. C COMMON /CORKDT/
  15. C WTKSUB SPECTRAL BIN SUB-INTERVAL FRACTIONAL WIDTHS.
  16. C DEPLAY INCREMENTAL OPTICAL DEPTHS
  17. C TRNLAY INCREMENTAL TRANSMITTANCES
  18. C TRNCUM CUMULATIVE TRANSMITTANCES
  19. REAL WTKSUB,DEPLAY,TRNLAY,TRNCUM
  20. COMMON/CORKDT/WTKSUB(MXKSUB),DEPLAY(MXKSUB),
  21. 1 TRNLAY(MXKSUB),TRNCUM(MXKSUB)
  22. SAVE /CORKDT/
  23. C
  24. C COMMON /CORKTB/
  25. C GAMLIN LORENTZ HALF-WIDTH BOUNDARY VALUES [CM-1].
  26. C GAMDIN DOPPLER HALF-WIDTH BOUNDARY VALUES [CM-1].
  27. C RLININ EFFECTIVE NUMBER OF LINES BOUNDARY VALUES.
  28. C VAL ABSORPTION COEFFICIENT TABLE [ATM-1 CM-1].
  29. INTEGER NGAML,NGAMD,NNUML
  30. REAL GAMLIN,GAMDIN,RLININ,VAL
  31. COMMON/CORKTB/NGAML,NGAMD,NNUML,GAMLIN(MXGAML),GAMDIN(MXGAMD),
  32. 1 RLININ(MXNUML),VAL(1:MXGAML,1:MXGAMD,1:MXNUML,0:MXKSUB)
  33. SAVE /CORKTB/
  34. C
  35. C DECLARE LOCAL VARIABLES
  36. CHARACTER FILNAM*130,YESNO*1
  37. INTEGER IKSUB,IFILE,ITEST,IKSBM1,IGAML,IGAMD,INUML,I
  38. LOGICAL LTEST
  39. REAL WTKSB0,GAML,GAMD,RLIN,VALOLD,VALNEW
  40. C
  41. C LIST DATA
  42. DATA IFILE/9/
  43. C
  44. C READ ASCII FILE NAME
  45. 10 WRITE(*,'(/A)')' Enter name of Correlated-K ASCII data file'
  46. READ(*,'(A)')FILNAM
  47. C
  48. C TEST FOR EXISTENCE OF FILE
  49. INQUIRE(FILE=FILNAM,EXIST=LTEST)
  50. IF(.NOT.LTEST)THEN
  51. WRITE(*,'(/(A))')
  52. 1 'No file named',FILNAM,'was found.','Please try again.'
  53. GOTO10
  54. ENDIF
  55. C
  56. C OPEN CORRELATED-K DATA FILE
  57. OPEN(IFILE,FILE=FILNAM,STATUS='OLD')
  58. WRITE(*,'(/(A))')' Reading file',FILNAM
  59. C
  60. C READ IN K-DISTRIBUTION WEIGHTS
  61. READ(IFILE,'(//I10,7F10.7:,/(10X,7F10.7:))')
  62. 1 NKSUB,WTKSB0,(WTKSUB(IKSUB),IKSUB=1,NKSUB-1)
  63. NKSUB=NKSUB-1
  64. IF(NKSUB.GT.MXKSUB)THEN
  65. WRITE(*,'(/2A,I3,A,/A)')
  66. 1 ' ERROR: Parameter MXKSUB (in PARAM.LST) must',
  67. 2 ' equal or exceed',NKSUB,' to use file',FILNAM
  68. STOP
  69. ELSEIF(WTKSB0.NE.0. .AND. WTKSUB(NKSUB).NE.1.)THEN
  70. STOP ' ERROR: Incorrect cumulative distribution values'
  71. ENDIF
  72. IKSUB=NKSUB
  73. DO 20 IKSBM1=NKSUB-1,1,-1
  74. WTKSUB(IKSUB)=WTKSUB(IKSUB)-WTKSUB(IKSBM1)
  75. IF(WTKSUB(IKSUB).LE.0.)STOP
  76. 1 ' ERROR: Incorrect cumulative distribution values'
  77. 20 IKSUB=IKSBM1
  78. C
  79. C READ IN LORENTZ HALF-WIDTHS [CM-1]
  80. READ(IFILE,'(/I5,5X,6E12.6:,/(10X,6E12.6:))')
  81. 1 NGAML,(GAMLIN(IGAML),IGAML=1,NGAML)
  82. IF(NGAML.GT.MXGAML)THEN
  83. WRITE(*,'(/2A,I3,A,/A)')
  84. 1 ' ERROR: Parameter MXGAML (in PARAM.LST) must',
  85. 2 ' equal or exceed',NGAML,' to use file',FILNAM
  86. STOP
  87. ENDIF
  88. I=1
  89. DO 30 IGAML=2,NGAML
  90. IF(GAMLIN(IGAML).GE.GAMLIN(I))STOP
  91. 1 ' ERROR: LORENTZ HALF-WIDTHS NOT IN DECREASING ORDER'
  92. 30 I=IGAML
  93. C
  94. C READ IN DOPPLER HALF-WIDTHS [CM-1]
  95. READ(IFILE,'(/I5,5X,6E12.6:,/(10X,6E12.6:))')
  96. 1 NGAMD,(GAMDIN(IGAMD),IGAMD=1,NGAMD)
  97. IF(NGAMD.GT.MXGAMD)THEN
  98. WRITE(*,'(/2A,I3,A,/A)')
  99. 1 ' ERROR: Parameter MXGAMD (in PARAM.LST) must',
  100. 2 ' equal or exceed',NGAMD,' to use file',FILNAM
  101. STOP
  102. ENDIF
  103. I=1
  104. DO 40 IGAMD=2,NGAMD
  105. IF(GAMDIN(IGAMD).GE.GAMDIN(I))STOP
  106. 1 ' ERROR: DOPPLER HALF-WIDTHS NOT IN DECREASING ORDER'
  107. 40 I=IGAMD
  108. C
  109. C READ IN EFFECTIVE NUMBER OF LINES.
  110. READ(IFILE,'(/I10,7F10.2:,/(10X,7F10.2:))')
  111. 1 NNUML,(RLININ(INUML),INUML=1,NNUML)
  112. IF(NNUML.GT.MXNUML)THEN
  113. WRITE(*,'(/2A,I3,A,/A)')
  114. 1 ' ERROR: Parameter MXNUML (in PARAM.LST) must',
  115. 2 ' equal or exceed',NNUML,' to use file',FILNAM
  116. STOP
  117. ENDIF
  118. I=1
  119. DO 50 INUML=2,NNUML
  120. IF(RLININ(INUML).LE.RLININ(I))STOP 'ERROR:
  121. 1 EFFECTIVE NUMBER OF LINES NOT IN INCREASING ORDER'
  122. 50 I=INUML
  123. C
  124. C SKIP TWO LINES
  125. READ(IFILE,'(/20X,I10)')ITEST
  126. C
  127. C LOOP OVER LORENTZ HALF-WIDTHS
  128. DO 90 IGAML=1,NGAML
  129. C
  130. C LOOP OVER DOPPLER HALF-WIDTHS
  131. DO 80 IGAMD=1,NGAMD
  132. READ(IFILE,'(2E12.6)')GAML,GAMD
  133. IF(GAML.NE.GAMLIN(IGAML) .OR. GAMD.NE.GAMDIN(IGAMD))THEN
  134. WRITE(*,'(/A,/(8X,A,I2,A,2(E12.6,A)))')
  135. 1 ' ERROR: HALF-WIDTH MISMATCH.',
  136. 2 ' GAMLIN(',IGAML,') = ',GAMLIN(IGAML),
  137. 3 ' CM-1 GAML = ',GAML,' CM-1',
  138. 4 ' GAMDIN(',IGAMD,') = ',GAMDIN(IGAMD),
  139. 5 ' CM-1 GAMD = ',GAMD,' CM-1'
  140. STOP
  141. ENDIF
  142. C
  143. C LOOP OVER EFFECTIVE NUMBER OF LINES
  144. DO 70 INUML=1,NNUML
  145. C
  146. C READ IN NORMALIZED ABSORPTION COEFFIECIENTS
  147. READ(IFILE,'(F10.2,7E10.4:,/(10X,7E10.4))')
  148. 1 RLIN,(VAL(IGAML,IGAMD,INUML,IKSUB),IKSUB=0,NKSUB)
  149. IF(RLIN.NE.RLININ(INUML))THEN
  150. WRITE(*,'(/A,/8X,A,I2,2(A,F8.2))')
  151. 1 ' ERROR: EFFECTIVE NUMBER OF LINES MISMATCH.',
  152. 2 ' RLININ(',INUML,') = ',RLININ(INUML),
  153. 3 ' RLIN = ',RLIN
  154. STOP
  155. ENDIF
  156. C
  157. C CHECK MONOTONICITY OF ABSORPTION COEFFICIENTS
  158. VALOLD=VAL(IGAML,IGAMD,INUML,0)
  159. DO 60 IKSUB=1,NKSUB
  160. VALNEW=VAL(IGAML,IGAMD,INUML,IKSUB)
  161. IF(VALNEW.LT.VALOLD)THEN
  162. WRITE(*,'(/2A,2(/8X,A,E10.4),
  163. 1 /8X,A,F10.4,//8X,A,/(14X,6(1X,E9.4)))')
  164. 2 ' ERROR: DECREASING',
  165. 3 ' ABSORPTION COEFFICIENTS AT',
  166. 4 ' LORENTZ HALF-WIDTH [CM-1] =',GAML,
  167. 5 ' DOPPLER HALF-WIDTH [CM-1] =',GAMD,
  168. 6 ' EFFECTIVE NUMBER OF LINES =',RLIN,
  169. 7 ' NORMALIZED ABSORPTION COEFFICIENTS:',
  170. 8 (VAL(IGAML,IGAMD,INUML,I),I=0,NKSUB)
  171. STOP
  172. ENDIF
  173. 60 VALOLD=VALNEW
  174. 70 CONTINUE
  175. 80 CONTINUE
  176. 90 CONTINUE
  177. C
  178. C CLOSE CORRELATED-K DATA FILE
  179. CLOSE(IFILE)
  180. WRITE(* ,'(/(A))')'Successfully read file',FILNAM
  181. C
  182. C READ BINARY FILE NAME
  183. 100 WRITE(*,'(/A)')' Enter name of Correlated-K BINARY data file'
  184. READ(*,'(A)')FILNAM
  185. C
  186. C TEST FOR EXISTENCE OF FILE
  187. INQUIRE(FILE=FILNAM,EXIST=LTEST)
  188. IF(LTEST)THEN
  189. WRITE(*,'(/(A))')'A file named',FILNAM,'already exists.',
  190. 1 'Do you wish to overwrite it (Y/N).'
  191. READ(*,'(A)')YESNO
  192. IF(YESNO.NE.'Y' .AND. YESNO.NE.'y')GOTO100
  193. OPEN(IFILE,FILE=FILNAM,STATUS='OLD')
  194. CLOSE(IFILE,STATUS='DELETE')
  195. ENDIF
  196. C
  197. C OPEN BINARY FILE
  198. OPEN(IFILE,FILE=FILNAM,STATUS='NEW',FORM='UNFORMATTED')
  199. C
  200. C WRITE DATA TO BINARY FILE
  201. WRITE(IFILE)NKSUB,NGAML,NGAMD,NNUML
  202. WRITE(IFILE)
  203. 1 (WTKSUB(IKSUB),IKSUB=1,NKSUB),(GAMLIN(IGAML),IGAML=1,NGAML),
  204. 2 (GAMDIN(IGAMD),IGAMD=1,NGAMD),(RLININ(INUML),INUML=1,NNUML)
  205. DO 110 IKSUB=0,NKSUB
  206. WRITE(IFILE)(((VAL(IGAML,IGAMD,INUML,IKSUB),
  207. 1 IGAML=1,NGAML),IGAMD=1,NGAMD),INUML=1,NNUML)
  208. 110 CONTINUE
  209. C
  210. C STOP
  211. STOP 'SUCCESSFUL BINARY WRITE'
  212. END