!********************************************************************** ! ROUTINE: VCHIN.F90 ! PURPOSE: Objective is to write three records of characters ending ! with CRLF such that each record is a different length. Then read ! them as variable length ASCII records that could be up to 200 ! characters long. This program is Standard Fortran 90. ! ! PACKAGE: Examples ! CALLS: none ! AUTHOR: H. D. Knoble 26 February 1999. ! REVISIONS: !********************************************************************** ! ! ! Objective is to write three records of characters ending in CRLF ! (or LF) such that each record is a different length. Then read them ! variable length ASCII records that could be up to 200 characters ! long. This program is Standard Fortran 90. CHARACTER*200 REC ! Write 3 records, each one a different length. OPEN(UNIT=60,FILE='VCHIN.DAT') REC='1234567890' WRITE(60,1) REC(1:10) 1 FORMAT(A) REC='ABCDEFGHIJKLMNOP' WRITE(60,1) REC(1:16) REC='1A2B3C4D5E6F' WRITE(60,1) REC(1:12) CLOSE (UNIT=60) ! Read the records as variable length character strings. ! It is programmer's responsibility to figure how long ! each reacord actually is; that is, how much of REC ! after each READ represents each record as it was written. ! In this case, builtin Fortran 90 function LEN_TRIM can ! be used since no record ends with a blank. OPEN(UNIT=50,FILE='VCHIN.DAT',PAD='YES') DO I=1,3 READ(50,1,EOR=91,END=99,ADVANCE='NO') REC 91 LENREC=LEN_TRIM(REC) WRITE(*,*) 'Length=',LENREC,'->',REC(1:LENREC) END DO ! All Done 99 WRITE(*,*) 'VCHIN Done' CLOSE(UNIT=50) STOP END