PROGRAM CONVERT_DEM C C Version 1.3 (Released 10-15-2010 by John Ciolek Jr., AlphaTRAC, Inc.) C C This program converts ASCII formatted DEM data files to FORTRAN C unformatted files for use with the CAPARS V4.0 System. C C by John Ciolek Jr. 11-13-1996 C C Modified 3-10-2000 by John Ciolek Jr. to use the CAPARS v4.0 + DEM storage C mechanism. C C Modified 6-24-2002 by John Ciolek Jr. to read ascii grid file header C info in as a string and extract data fields from the string. C C Modified 9-4-2003 by John Ciolek Jr. to correct characters of input string C to read. (v1.2) C C Modified 10-15-2010 by John Ciolek Jr. for better error handling. (v1.3) C IMPLICIT NONE C C The MODEL_PARAMETERS include file must appear before any declarations C since it limits the size of most TRAC arrays. C INCLUDE 'MODEL_PARAMETERS.INC' INCLUDE 'DEM.INC' CHARACTER*80 OLD_FILE, NEW_FILE CHARACTER*15 STRING INTEGER STATUS, MISSING, GET_DEM, I, J, IOS CHARACTER*40 IN_STRING WRITE(6,*) 'Enter the old (ASCII) data file name: ' READ(5,11) OLD_FILE WRITE(6,*) 'Enter the new file name: ' READ(5,11) NEW_FILE 11 FORMAT(A80) GET_DEM = -1 OPEN(UNIT=37, + FILE=OLD_FILE, + STATUS='OLD', + FORM='FORMATTED', + IOSTAT=IOS, + READONLY) IF (IOS .EQ. 0) THEN READ(UNIT=37,FMT=100,IOSTAT=IOS) IN_STRING READ(IN_STRING(7:40),*,IOSTAT=IOS) DEM_NUM_COLS IF (IOS .EQ. 0) THEN READ(UNIT=37,FMT=100) IN_STRING READ(IN_STRING(7:40),*,IOSTAT=IOS) DEM_NUM_ROWS IF (IOS .EQ. 0) THEN READ(UNIT=37,FMT=100) IN_STRING READ(IN_STRING(11:40),*,IOSTAT=IOS) DEM_BASEX IF (IOS .EQ. 0) THEN READ(UNIT=37,FMT=100) IN_STRING READ(IN_STRING(11:40),*,IOSTAT=IOS) DEM_BASEY IF (IOS .EQ. 0) THEN READ(UNIT=37,FMT=100) IN_STRING READ(IN_STRING(10:40),*,IOSTAT=IOS) DEM_INC IF (IOS .EQ. 0) THEN READ(UNIT=37,FMT=100) IN_STRING READ(IN_STRING(14:40),*,IOSTAT=IOS) MISSING IF (IOS .EQ. 0) THEN DO DEM_ROW=DEM_NUM_ROWS,1,-1 READ(37,*,IOSTAT=IOS) (DEM_Z(DEM_COL,DEM_ROW), + DEM_COL=1, DEM_NUM_COLS) IF (IOS .EQ. 0) THEN GET_DEM = 1 ELSE WRITE(6,*) "Error: reading DEM data set." END IF END DO ELSE WRITE(6,*) "Error: reading missing data value." END IF ELSE WRITE(6,*) "Error: reading DEM increment value." END IF ELSE WRITE(6,*) "Error: reading Base Y value." END IF ELSE WRITE(6,*) "Error: reading Base X value." END IF ELSE WRITE(6,*) "Error: reading number of rows." END IF ELSE WRITE(6,*) "Error: reading number of columns." END IF ELSE WRITE(6,*) "Error: opening input ASCII grid file." END IF 100 FORMAT(A40) 101 FORMAT(A14,F7.0) 102 FORMAT(A14,F6.2) 103 FORMAT(A14,F8.0) 9999 CLOSE(UNIT=37) C C Now write out the data in FORTRAN binary format. C IF (GET_DEM .EQ. 1) THEN OPEN(UNIT=40, + STATUS='NEW', + FORM='UNFORMATTED', + IOSTAT=IOS, + FILE=NEW_FILE) IF (IOS .EQ. 0) THEN WRITE(UNIT=40) DEM_NUM_COLS WRITE(UNIT=40) DEM_NUM_ROWS WRITE(UNIT=40) DEM_BASEX WRITE(UNIT=40) DEM_BASEY WRITE(UNIT=40) DEM_INC WRITE(UNIT=40) MISSING WRITE(UNIT=40) ((DEM_Z(I,J),I=1,DEM_NUM_COLS), + J=1,DEM_NUM_ROWS) CLOSE(UNIT=40) END IF ELSE WRITE(6,*) 'Error - unable to write out data!' END IF END