MOLBMP.F 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. PROGRAM MOLBMP
  2. C
  3. C THIS ROUTINE MAKES CONVERSIONS BETWEEN ASCII AND DIRECT-ACCESS
  4. C BINARY MODTRAN4 MOLECULAR BAND MODEL PARAMETER FILES.
  5. C THE DATA IS CALCULATED FROM THE HITRAN96 LINE COMPILATION.
  6. C
  7. C DECLARE VARIABLES, ARRAYS AND FUNCTIONS
  8. INTEGER MXTEMP
  9. PARAMETER(MXTEMP=11)
  10. CHARACTER ANSWER*1,ASCNAM*150,BINNAM*150,ACCESS*12,MESSAG*7
  11. LOGICAL LEXIST
  12. INTEGER IBNDWD,NTEMP,IT,J,IASCII,IBNARY,NDIVID,NREC,LENASC,
  13. 1 LENBIN,IRECLN,MXRCLN,IBIN,IALF,IMOL,IF1ST,IFLAST,LSTREC
  14. REAL DEDGE,DEDGEB,TBAND(MXTEMP),SD(MXTEMP),OD(MXTEMP)
  15. C
  16. C FOR COMPARING BINARY AND ASCII FILES
  17. REAL SDASC(MXTEMP,3),ODASC(MXTEMP,3),SDBIN(MXTEMP,3),
  18. 1 ODBIN(MXTEMP,3),TBANDB(MXTEMP)
  19. INTEGER IWDBIN,NTEMPB,IF1STB,IFLASB,NDIVDB,LSTRCB
  20. INTEGER IBINB(3),IALFB(3),IMOLB(3),IBINA(3),IALFA(3),IMOLA(3)
  21. INTEGER MINLEN
  22. C
  23. C LIST DATA
  24. DATA IASCII/9/,IBNARY/10/
  25. C
  26. C SELECT ACTION
  27. WRITE(*,'(/2A,/(17X,A))')' PROGRAM MOLBMP: ',
  28. 1 ' CONVERTS BETWEEN THE SEQUENTIAL-ACCESS ASCII',
  29. 2 ' (FORMATTED) AND THE DIRECT-ACCESS BINARY (UNFORMATTED)',
  30. 3 ' MODTRAN4 MOLECULAR BAND MODEL PARAMETER FILES',
  31. 4 ' (THE FILE FROM WHICH DATA IS READ IS NOT DELETED).'
  32. 10 WRITE(*,'(/(2A))')' ENTER 1 TO CREATE BINARY (UNFORMATTED)',
  33. 1 ' FILE FROM ASCII (FORMATTED) FILE',' 2 TO CREATE',
  34. 2 ' ASCII (FORMATTED) FILE FROM BINARY (UNFORMATTED) FILE'
  35. READ(*,'(A1)',END=10,ERR=10)ANSWER
  36. IF(ANSWER.EQ.'1')THEN
  37. C
  38. C ENTER NAME AND OPEN OLD ASCII FILE
  39. 20 WRITE(*,'(/(A))')
  40. 1 ' ENTER ASCII BAND MODEL FILE NAME (MAX 150 CHARACTERS)',
  41. 2 ' [ENTER 0 FOR NAME = "BMP99_01.ASC"]',
  42. 3 ' [ENTER 1 FOR NAME = "BMP99_15.ASC"]'
  43. READ(*,'(A)',END=20,ERR=20)ASCNAM
  44. LENASC=MINLEN(ASCNAM)
  45. IF(LENASC.EQ.0)GOTO20
  46. IF(LENASC.EQ.1)THEN
  47. C
  48. C CHECK FOR DEFAULT NAMES.
  49. IF(ASCNAM(1:1).EQ.'0')THEN
  50. LENASC=12
  51. ASCNAM(1:LENASC)='BMP99_01.ASC'
  52. ELSEIF(ASCNAM(1:1).EQ.'1')THEN
  53. LENASC=12
  54. ASCNAM(1:LENASC)='BMP99_15.ASC'
  55. ENDIF
  56. ENDIF
  57. INQUIRE(FILE=ASCNAM(1:LENASC),EXIST=LEXIST)
  58. IF(.NOT.LEXIST)THEN
  59. WRITE(*,'(/3A)')' FILE "',ASCNAM(1:LENASC),
  60. 1 '" DOES NOT EXIST. PLEASE RE-ENTER.'
  61. GOTO20
  62. ENDIF
  63. OPEN(IASCII,FILE=ASCNAM(1:LENASC),STATUS='OLD')
  64. C
  65. C READ THE NUMBER OF TEMPERATURES (NTEMP) FROM HEADER.
  66. MESSAG=' HEADER'
  67. READ(IASCII,'(I3)',END=130,ERR=130)NTEMP
  68. IF(NTEMP.LE.0 .OR. NTEMP.GT.MXTEMP)THEN
  69. WRITE(*,'(/2A,I3,A,/8X,2A,I3,A)')
  70. 1 ' ERROR: INPUT NUMBER OF TEMPERATURES',
  71. 2 ' (NTEMP =',NTEMP,' MUST BE',' POSITIVE AND',
  72. 3 ' CAN NOT EXCEED PARAMETER MXTEMP (=',MXTEMP,').'
  73. STOP 'NTEMP OUT OF RANGE'
  74. ENDIF
  75. REWIND(IASCII)
  76. C
  77. C SET INITIAL AND MAXIMUM RECORD LENGTH
  78. C INTEGER AND REAL VARIABLES ON HP ARE OF RECORD LENGTH 4
  79. C ON IBM VM/CMS, IT IS 4; THERE IS ALSO A 4 BYTE PADDING
  80. C INTEGER AND REAL VARIABLES ON SGI & DEC ARE OF RECORD LENGTH 1
  81. IRECLN=2*NTEMP+3
  82. MXRCLN=4*IRECLN+4
  83. C
  84. C ENTER NAME AND OPEN NEW BINARY FILE
  85. 30 WRITE(*,'(/(A))')
  86. 1 ' ENTER BINARY BAND MODEL FILE NAME (MAX 150 CHARACTERS)',
  87. 2 ' [ENTER 0 FOR NAME = "BMP99_01.BIN"]',
  88. 3 ' [ENTER 1 FOR NAME = "BMP99_15.BIN"]'
  89. READ(*,'(A)',END=30,ERR=30)BINNAM
  90. LENBIN=MINLEN(BINNAM)
  91. IF(LENBIN.EQ.0)GOTO30
  92. IF(LENBIN.EQ.1)THEN
  93. IF(BINNAM(1:1).EQ.'0')THEN
  94. LENBIN=12
  95. BINNAM(1:LENBIN)='BMP99_01.BIN'
  96. ELSEIF(BINNAM(1:1).EQ.'1')THEN
  97. LENBIN=12
  98. BINNAM(1:LENBIN)='BMP99_15.BIN'
  99. ENDIF
  100. ENDIF
  101. INQUIRE(FILE=BINNAM(1:LENBIN),EXIST=LEXIST)
  102. IF(LEXIST)THEN
  103. WRITE(*,'(/4A,/11X,A)')' WARNING: ',
  104. 1 'THE FILE "',BINNAM(1:LENBIN),'" ALREADY EXISTS.',
  105. 2 'DO YOU WISH TO OVERWRITE THE PRE-EXISTING FILE (Y/N)?'
  106. READ(*,'(A1)')ANSWER
  107. IF(ANSWER.NE.'Y' .AND. ANSWER.NE.'y')GOTO30
  108. OPEN(IBNARY,FILE=BINNAM(1:LENBIN),STATUS='OLD')
  109. CLOSE(IBNARY,STATUS='DELETE')
  110. ENDIF
  111. 40 CONTINUE
  112. OPEN(IBNARY,FILE=BINNAM(1:LENBIN),STATUS='NEW',
  113. 1 FORM='UNFORMATTED',ACCESS='DIRECT',RECL=IRECLN)
  114. C
  115. C READ THE BAND MODEL FILE HEADER:
  116. C IBNDWD BIN WIDTH [CM-1].
  117. C IF1ST BEGINNING FREQUENCY [CM-1].
  118. C IFLAST FINAL FREQUENCY [CM-1].
  119. C LSTREC RECORD NUMBER OF FINAL RECORD.
  120. C DEDGE DISTANCE FROM BIN EDGE TO LINE CENTER [CM-1].
  121. MESSAG=' HEADER'
  122. READ(IASCII,*,END=130,ERR=130)NTEMP,(TBAND(IT),IT=1,NTEMP)
  123. READ(IASCII,'(5I8,F8.3)',ERR=41)
  124. 1 IBNDWD,IF1ST,IFLAST,LSTREC,NDIVID,DEDGE
  125. GOTO42
  126. C
  127. C OLD FORMAT
  128. 41 CONTINUE
  129. REWIND(IASCII)
  130. READ(IASCII,*,END=130,ERR=130)NTEMP,(TBAND(IT),IT=1,NTEMP)
  131. READ(IASCII,'(4I8,F8.3)')IBNDWD,IF1ST,IFLAST,LSTREC,DEDGE
  132. NDIVID=1
  133. 42 CONTINUE
  134. C
  135. C WRITE THE MOLECULAR BAND MODEL PARAMETER HEADER TO BINARY FILE
  136. NREC=1
  137. WRITE(IBNARY,REC=NREC,ERR=120)NTEMP,(TBAND(IT),IT=1,NTEMP),
  138. 1 IBNDWD,IF1ST,IFLAST,LSTREC,NDIVID,DEDGE
  139. C
  140. C ECHO HEADER INFO
  141. WRITE(*,'(/5X,A,/I3,0P11F7.0)')
  142. 1 'NTEMP,(TBAND(IT),IT=1,NTEMP)',NTEMP,(TBAND(IT),IT=1,NTEMP)
  143. WRITE(*,'(/2(A,I7,5X),A,I7,/2(A,I7,5X),A,F7.3)')
  144. 1 'IBNDWD=',IBNDWD,' IF1ST=', IF1ST,'IFLAST=',IFLAST,
  145. 2 'LSTREC=',LSTREC,'NDIVID=',NDIVID,' DEDGE=', DEDGE
  146. C
  147. C READ AND WRITE BAND MODEL DATA - ONE LINE OR ONE RECORD AT
  148. C A TIME. A "LINE" OR A "RECORD" CONSISTS OF: IBIN, IMOL,
  149. C SD(1), ..., SD(NTEMP), IALF, ..., OD(1), ..., OD(NTEMP).
  150. MESSAG=' DATA '
  151. 50 READ(IASCII,*,END=70,ERR=130)
  152. 1 IBIN,IMOL,(SD(IT),IT=1,NTEMP),IALF,(OD(IT),IT=1,NTEMP)
  153. NREC=NREC+1
  154. WRITE(IBNARY,REC=NREC,ERR=120)
  155. 1 IBIN,IMOL,(SD(IT),IT=1,NTEMP),IALF,(OD(IT),IT=1,NTEMP)
  156. C
  157. C SAVE THE FIRST 2 AND THE LAST BAND MODEL RECORDS FOR TESTING
  158. IF(NREC.LE.3)THEN
  159. IBINA(NREC-1)=IBIN
  160. IMOLA(NREC-1)=IMOL
  161. IALFA(NREC-1)=IALF
  162. DO 60 IT=1,NTEMP
  163. SDASC(IT,NREC-1)=SD(IT)
  164. ODASC(IT,NREC-1)=OD(IT)
  165. 60 CONTINUE
  166. IF(NREC.EQ.2)
  167. 1 WRITE(*,'(/A)')' THE FIRST TWO BAND MODEL RECORDS ARE:'
  168. WRITE(*,'(I6,I5,1P11E11.3)')IBIN,IMOL,(SD(IT),IT=1,NTEMP)
  169. WRITE(*,'(6X,I5,1P11E11.3)')IALF,(OD(IT),IT=1,NTEMP)
  170. ENDIF
  171. IF(8000*(NREC/8000).EQ.NREC)THEN
  172. C
  173. C WRITE EACH 8000 RECORDS TO KEEP USER AWARE OF PROGRESS.
  174. WRITE(*,'(/A,I7,A)')' BAND MODEL RECORD',NREC,' IS:'
  175. WRITE(*,'(I6,I5,1P11E11.3)')IBIN,IMOL,(SD(IT),IT=1,NTEMP)
  176. WRITE(*,'(6X,I5,1P11E11.3)')IALF,(OD(IT),IT=1,NTEMP)
  177. ENDIF
  178. GOTO50
  179. 70 CONTINUE
  180. C
  181. C SAVE LAST RECORD FOR TESTING.
  182. IBINA(3)=IBIN
  183. IMOLA(3)=IMOL
  184. IALFA(3)=IALF
  185. DO 80 IT=1,NTEMP
  186. SDASC(IT,3)=SD(IT)
  187. ODASC(IT,3)=OD(IT)
  188. 80 CONTINUE
  189. WRITE(*,'(/A,I7,A)')'THE LAST RECORD, ',NREC,', IS:'
  190. WRITE(*,'(I6,I5,1P11E11.3)')IBIN,IMOL,(SD(IT),IT=1,NTEMP)
  191. WRITE(*,'(6X,I5,1P11E11.3)')IALF,(OD(IT),IT=1,NTEMP)
  192. C
  193. C TEST BINARY FILE
  194. CLOSE(IBNARY,STATUS='KEEP')
  195. WRITE(*,'(/A)')' TESTING BINARY TAPE'
  196. OPEN(IBNARY,FILE=BINNAM(1:LENBIN),STATUS='OLD',
  197. 1 FORM='UNFORMATTED',ACCESS='DIRECT',RECL=IRECLN)
  198. C
  199. READ(IBNARY,REC=1,ERR=120)NTEMPB,(TBANDB(IT),IT=1,NTEMP),
  200. 1 IWDBIN,IF1STB,IFLASB,LSTRCB,NDIVDB,DEDGEB
  201. IF(NTEMPB.NE.NTEMP .OR. IWDBIN.NE.IBNDWD .OR. IF1STB.NE.IF1ST
  202. 1 .OR. IFLASB.NE.IFLAST .OR. NDIVDB.NE.NDIVID
  203. 2 .OR. LSTRCB.NE.LSTREC .OR. DEDGEB.NE.DEDGE)GOTO120
  204. DO 90 IT=1,NTEMP
  205. IF(TBANDB(IT).NE.TBAND(IT))GOTO120
  206. 90 CONTINUE
  207. READ(IBNARY,REC=2,ERR=120)IBINB(1),IMOLB(1),
  208. 1 (SDBIN(IT,1),IT=1,NTEMP),IALFB(1),
  209. 2 (ODBIN(IT,1),IT=1,NTEMP)
  210. READ(IBNARY,REC=3,ERR=120)IBINB(2),IMOLB(2),
  211. 1 (SDBIN(IT,2),IT=1,NTEMP),IALFB(2),
  212. 2 (ODBIN(IT,2),IT=1,NTEMP)
  213. READ(IBNARY,REC=NREC,ERR=120)IBINB(3),IMOLB(3),
  214. 1 (SDBIN(IT,3),IT=1,NTEMP),IALFB(3),
  215. 2 (ODBIN(IT,3),IT=1,NTEMP)
  216. DO 110 J=1,3
  217. IF(IBINA(J).NE.IBINB(J))GOTO120
  218. IF(IMOLA(J).NE.IMOLB(J))GOTO120
  219. IF(IALFA(J).NE.IALFB(J))GOTO120
  220. DO 100 IT=1,NTEMP
  221. IF(SDASC(IT,J).NE.SDBIN(IT,J))GOTO120
  222. IF(ODASC(IT,J).NE.ODBIN(IT,J))GOTO120
  223. 100 CONTINUE
  224. 110 CONTINUE
  225. C
  226. C SUCCESSFUL WRITE
  227. WRITE(*,'(/A,I7,A,I6,A)')
  228. 1 ' BAND MODEL PARAMETER FILE CONTAINS',NREC,
  229. 2 ' RECORDS (LAST FREQUENCY IS',IFLAST,' CM-1)'
  230. CLOSE(IASCII,STATUS='KEEP')
  231. CLOSE(IBNARY,STATUS='KEEP')
  232. WRITE(*,'(/3A,/5X,A)')' SUCCESSFULLY CREATED',
  233. 1 ' THE DIRECT-ACCESS, BINARY (UNFORMATTED)',
  234. 2 ' BAND MODEL FILE:',BINNAM(1:LENBIN)
  235. WRITE(*,'(/10X,A,/10X,A,/(10X,A,I6,A))')
  236. 1 ' *************************************************',
  237. 2 ' * THIS MACHINE REQUIRES THAT OPTION "RECL" BE *',
  238. 3 ' * SET EQUAL TO',IRECLN,' IN ROUTINE "openbm.f" *',
  239. 4 ' *************************************************'
  240. STOP
  241. C
  242. C INCREASE RECORD LENGTH AND START OVER
  243. 120 CONTINUE
  244. CLOSE(IBNARY,STATUS='DELETE')
  245. IF(IRECLN.GE.MXRCLN)THEN
  246. WRITE(*,'(/3A,/A,I8)')' ERROR: UNABLE TO WRITE',
  247. 1 ' DIRECT-ACCESS BINARY FILE: ',BINNAM(1:LENBIN),
  248. 2 ' LARGEST RECORD LENGTH TRIED WAS',IRECLN
  249. STOP
  250. ENDIF
  251. WRITE(*,FMT='(/(2A,I8,A))')' AN ERROR OCCURRED',
  252. 1 ' WHEN A RECORD LENGTH OF',IRECLN,' WAS USED.'
  253. IF(IRECLN.EQ.MXRCLN-4)THEN
  254. IRECLN=MXRCLN
  255. ELSE
  256. IRECLN=2*IRECLN
  257. ENDIF
  258. WRITE(*,FMT='((A,I8,A))')
  259. 1 ' A RECORD LENGTH OF',IRECLN,' WILL NOW BE TRIED.'
  260. REWIND(IASCII)
  261. GOTO40
  262. C
  263. C UNABLE TO READ ASCII FILE
  264. 130 CONTINUE
  265. IF(LENASC.GT.0)WRITE(*,'(/(5A))')' ERROR: UNABLE',
  266. 1 ' TO READ',MESSAG,' FROM ASCII FILE: ',ASCNAM(1:LENASC),
  267. 2 ' NO BINARY FILE WAS CREATED.'
  268. CLOSE(IASCII,STATUS='KEEP')
  269. CLOSE(IBNARY,STATUS='DELETE')
  270. STOP
  271. ELSEIF(ANSWER.EQ.'2')THEN
  272. C
  273. C ENTER NAME OF OLD BINARY FILE
  274. 140 WRITE(*,'(/2A,/(A))')' ENTER NAME OF BINARY',
  275. 1 ' BAND MODEL FILE (MAX 150 CHARACTERS)',
  276. 2 ' [ENTER 0 FOR NAME = "BMP99_01.BIN"]',
  277. 3 ' [ENTER 1 FOR NAME = "BMP99_15.BIN"]'
  278. READ(*,'(A)',END=140,ERR=140)BINNAM
  279. LENBIN=MINLEN(BINNAM)
  280. IF(LENBIN.EQ.0)GOTO140
  281. IF(LENBIN.EQ.1)THEN
  282. IF(BINNAM(1:1).EQ.'0')THEN
  283. LENBIN=12
  284. BINNAM(1:LENBIN)='BMP99_01.BIN'
  285. ELSEIF(BINNAM(1:1).EQ.'1')THEN
  286. LENBIN=12
  287. BINNAM(1:LENBIN)='BMP99_15.BIN'
  288. ENDIF
  289. ENDIF
  290. C INQUIRE(FILE=BINNAM(1:LENBIN),EXIST=LEXIST,DIRECT=ACCESS)
  291. INQUIRE(FILE=BINNAM(1:LENBIN),EXIST=LEXIST)
  292. IF(.NOT.LEXIST)THEN
  293. WRITE(*,'(/3A)')' FILE "',BINNAM(1:LENBIN),
  294. 1 '" DOES NOT EXIST. PLEASE RE-ENTER.'
  295. GOTO140
  296. ENDIF
  297. C IF(ACCESS(1:1).EQ.CHAR(78).OR.ACCESS(1:1).EQ.CHAR(110))THEN
  298. C WRITE(*,'(/(3A))')' FILE "',BINNAM(1:LENBIN),
  299. C 1 '" CAN NOT BE CONNECTED FOR DIRECT-ACCESS.',
  300. C 2 ' IS IT THE WRONG FILE?'
  301. C GOTO140
  302. C ENDIF
  303. C
  304. C READ THE NUMBER OF TEMPERATURES (NTEMP) FROM HEADER.
  305. IRECLN=8
  306. OPEN(IBNARY,FILE=BINNAM(1:LENBIN),STATUS='OLD',
  307. 1 FORM='UNFORMATTED',ACCESS='DIRECT',RECL=IRECLN,ERR=200)
  308. NREC=1
  309. MESSAG=' HEADER'
  310. READ(IBNARY,REC=NREC,ERR=200)NTEMP
  311. CLOSE(IBNARY,STATUS='KEEP')
  312. IF(NTEMP.LE.0 .OR. NTEMP.GT.MXTEMP)THEN
  313. WRITE(*,'(/2A,I3,A,/8X,2A,I3,A)')
  314. 1 ' ERROR: INPUT NUMBER OF TEMPERATURES',
  315. 2 ' (NTEMP =',NTEMP,' MUST BE',' POSITIVE AND',
  316. 3 ' CAN NOT EXCEED PARAMETER MXTEMP (=',MXTEMP,').'
  317. STOP 'NTEMP OUT OF RANGE'
  318. ENDIF
  319. C
  320. C SET INITIAL AND MAXIMUM RECORD LENGTH
  321. C INTEGER AND REAL VARIABLES ON HP ARE OF RECORD LENGTH 4
  322. C ON IBM VM/CMS, IT IS 4; THERE IS ALSO A 4 BYTE PADDING
  323. C INTEGER AND REAL VARIABLES ON SG & DEC ARE OF RECORD LENGTH 1
  324. IRECLN=2*NTEMP+3
  325. MXRCLN=4*IRECLN+4
  326. C
  327. C ENTER NAME OF NEW ASCII FILE
  328. 150 WRITE(*,'(/(A))')
  329. 1 ' ENTER ASCII BAND MODEL FILE NAME (MAX 150 CHARACTERS)',
  330. 2 ' [ENTER 0 FOR NAME = "BMP99_01.ASC"]',
  331. 3 ' [ENTER 1 FOR NAME = "BMP99_15.ASC"]'
  332. READ(*,'(A)',END=150,ERR=150)ASCNAM
  333. LENASC=MINLEN(ASCNAM)
  334. IF(LENASC.EQ.0)GOTO150
  335. IF(LENASC.EQ.1)THEN
  336. IF(ASCNAM(1:1).EQ.'0')THEN
  337. LENASC=12
  338. ASCNAM(1:LENASC)='BMP99_01.ASC'
  339. ELSEIF(ASCNAM(1:1).EQ.'1')THEN
  340. LENASC=12
  341. ASCNAM(1:LENASC)='BMP99_15.ASC'
  342. ENDIF
  343. ENDIF
  344. INQUIRE(FILE=ASCNAM(1:LENASC),EXIST=LEXIST)
  345. IF(LEXIST)THEN
  346. WRITE(*,'(/4A,/11X,A)')' WARNING: ',
  347. 1 'THE FILE "',ASCNAM(1:LENASC),'" ALREADY EXISTS.',
  348. 2 'DO YOU WISH TO OVERWRITE THE PRE-EXISTING FILE (Y/N)?'
  349. READ(*,'(A1)')ANSWER
  350. IF(ANSWER.NE.CHAR(89).AND.ANSWER.NE.CHAR(121))GOTO150
  351. OPEN(IASCII,FILE=ASCNAM(1:LENASC),STATUS='OLD')
  352. CLOSE(IASCII,STATUS='DELETE')
  353. ENDIF
  354. 160 CONTINUE
  355. OPEN(IASCII,FILE=ASCNAM(1:LENASC),STATUS='NEW')
  356. OPEN(IBNARY,FILE=BINNAM(1:LENBIN),STATUS='OLD',
  357. 1 FORM='UNFORMATTED',ACCESS='DIRECT',RECL=IRECLN,ERR=190)
  358. C
  359. C READ THE BAND MODEL FILE HEADER. IBNDWD IS THE WIDTH (CM-1)
  360. NREC=1
  361. MESSAG=' HEADER'
  362. READ(IBNARY,REC=NREC,ERR=161)NTEMP,(TBAND(IT),IT=1,NTEMP),
  363. 1 IBNDWD,IF1ST,IFLAST,LSTREC,NDIVID,DEDGE
  364. IF(DEDGE.EQ.0.)GOTO161
  365. GOTO162
  366. C
  367. C OLD FORMAT
  368. 161 CONTINUE
  369. READ(IBNARY,REC=NREC,ERR=190)NTEMP,(TBAND(IT),IT=1,NTEMP),
  370. 1 IBNDWD,IF1ST,IFLAST,LSTREC,DEDGE
  371. NDIVID=1
  372. 162 CONTINUE
  373. WRITE(IASCII,'(I3,0P11F7.0:,/(3X,0P11F7.0))')
  374. 1 NTEMP,(TBAND(IT),IT=1,NTEMP)
  375. WRITE(IASCII,'(5I8,F8.3)')
  376. 1 IBNDWD,IF1ST,IFLAST,LSTREC,NDIVID,DEDGE
  377. C
  378. C ECHO HEADER INFO
  379. WRITE(*,'(/5X,A,/I3,0P11F7.0)')
  380. 1 'NTEMP,(TBAND(IT),IT=1,NTEMP)',
  381. 2 NTEMP,(TBAND(IT),IT=1,NTEMP)
  382. WRITE(*,'(/2(A,I7,5X),A,I7,/2(A,I7,5X),A,F7.3)')
  383. 1 'IBNDWD=',IBNDWD,' IF1ST=', IF1ST,'IFLAST=',IFLAST,
  384. 2 'LSTREC=',LSTREC,'NDIVID=',NDIVID,' DEDGE=', DEDGE
  385. C
  386. C READ DATA
  387. MESSAG=' DATA '
  388. NREC=NREC+1
  389. READ(IBNARY,REC=NREC,ERR=190)
  390. 1 IBIN,IMOL,(SD(IT),IT=1,NTEMP),IALF,(OD(IT),IT=1,NTEMP)
  391. WRITE(IASCII,'(I6,I5,1P11E11.3)')IBIN,IMOL,(SD(IT),IT=1,NTEMP)
  392. WRITE(IASCII,'(6X,I5,1P11E11.3)')IALF,(OD(IT),IT=1,NTEMP)
  393. 170 NREC=NREC+1
  394. READ(IBNARY,REC=NREC,ERR=180)
  395. 1 IBIN,IMOL,(SD(IT),IT=1,NTEMP),IALF,(OD(IT),IT=1,NTEMP)
  396. WRITE(IASCII,'(I6,I5,1P11E11.3)')IBIN,IMOL,(SD(IT),IT=1,NTEMP)
  397. WRITE(IASCII,'(6X,I5,1P11E11.3)')IALF,(OD(IT),IT=1,NTEMP)
  398. IF(8000*(NREC/8000).EQ.NREC)THEN
  399. C
  400. C WRITE EACH 8000 RECORDS TO KEEP USER AWARE OF PROGRESS.
  401. WRITE(*,'(/A,I7,A)')' BAND MODEL RECORD',NREC,' IS:'
  402. WRITE(*,'(I6,I5,1P11E11.3)')IBIN,IMOL,(SD(IT),IT=1,NTEMP)
  403. WRITE(*,'(6X,I5,1P11E11.3)')IALF,(OD(IT),IT=1,NTEMP)
  404. ENDIF
  405. GOTO170
  406. 180 CONTINUE
  407. NREC=NREC-1
  408. WRITE(*,'(/3(A,I7))')
  409. 1 ' BAND MODEL PARAMETER FILE CONTAINS',NREC,
  410. 2 ' RECORDS (LAST FREQUENCY IS',IFLAST,' CM-1)'
  411. CLOSE(IASCII,STATUS='KEEP')
  412. CLOSE(IBNARY,STATUS='KEEP')
  413. WRITE(*,'(/2A,/5X,A)')' SUCCESSFULLY CREATED THE ASCII',
  414. 1 ' (FORMATTED) BAND MODEL FILE:',ASCNAM(1:LENASC)
  415. STOP
  416. C
  417. C UNABLE TO READ BINARY FILE
  418. 190 CONTINUE
  419. CLOSE(IASCII,STATUS='DELETE')
  420. CLOSE(IBNARY,STATUS='KEEP')
  421. IF(IRECLN.LT.MXRCLN)THEN
  422. WRITE(*,FMT='(/(2A,I8,A))')' AN ERROR OCCURRED',
  423. 1 ' WHEN A RECORD LENGTH OF',IRECLN,' WAS USED.'
  424. IF(IRECLN.EQ.MXRCLN-4)THEN
  425. IRECLN=MXRCLN
  426. ELSE
  427. IRECLN=2*IRECLN
  428. ENDIF
  429. WRITE(*,FMT='((A,I8,A))')
  430. 1 ' A RECORD LENGTH OF',IRECLN,' WILL NOW BE TRIED.'
  431. GOTO160
  432. ENDIF
  433. 200 CONTINUE
  434. IF(LENBIN.GT.0)WRITE(*,'(/(5A))')' ERROR: UNABLE',
  435. 1 ' TO READ',MESSAG,' FROM BINARY FILE: ',BINNAM(1:LENBIN),
  436. 2 ' NO ASCII FILE WAS CREATED.'
  437. WRITE(*,'(/A,I8)')
  438. 1 ' LAST (AND LARGEST) RECORD LENGTH TRIED WAS',IRECLN
  439. STOP
  440. ELSE
  441. GOTO10
  442. ENDIF
  443. END
  444. INTEGER FUNCTION MINLEN(STRING)
  445. C
  446. C THIS ROUTINE ELIMINATES LEADING BLANKS FROM STRING, AND
  447. C DETERMINES LENGTH OF FIRST CHARACTER STRING.
  448. C
  449. C DECLARE VARIABLES
  450. CHARACTER*(*) STRING
  451. INTEGER LENGTH,ISTART,I
  452. C
  453. C POSITION OF FIRST NON-BLANK CHARACTER
  454. LENGTH=LEN(STRING)
  455. DO 10 ISTART=1,LENGTH
  456. IF(STRING(ISTART:ISTART).NE.' ')GOTO20
  457. 10 CONTINUE
  458. C
  459. C BLANK STRING
  460. MINLEN=0
  461. RETURN
  462. C
  463. C ELIMINATE LEADING BLANKS
  464. 20 CONTINUE
  465. STRING(1:LENGTH-ISTART+1)=STRING(ISTART:LENGTH)
  466. C
  467. C ADD TRAILING BLANKS
  468. DO 30 I=LENGTH-ISTART+2,LENGTH
  469. STRING(I:I)=' '
  470. 30 CONTINUE
  471. C
  472. C DETERMINE LENGTH OF FIRST CHARACTER STRING BY FINDING FIRST BLANK
  473. MINLEN=INDEX(STRING,' ')-1
  474. IF(MINLEN.LT.0)MINLEN=LENGTH
  475. RETURN
  476. END