Hi,
I am dealing with a Fortran code that reads numeric data from a file that is generated from another software. The data looks like this:
The headings are stripped off and handled separately and the numeric data is read into an array using this routine:
SUBROUTINE ReadR4Ary ( UnIn, Fil, Ary, AryLen, AryName, AryDescr, ErrStat, ErrMsg, UnEc )
! This routine reads a AryLen values into a 4-byte real array separated by white space
! (possibly on the same line of the input file).
! Argument declarations:
INTEGER, INTENT(IN) :: AryLen ! Length of the array.
INTEGER, INTENT(IN) :: UnIn ! I/O unit for input file.
INTEGER, INTENT(IN),OPTIONAL :: UnEc ! I/O unit for echo file. If present and > 0, write to UnEc
INTEGER, INTENT(OUT) :: ErrStat ! Error status
CHARACTER(*), INTENT(OUT) :: ErrMsg ! Error message
REAL(SiKi), INTENT(INOUT) :: Ary(AryLen) ! Real array being read.
CHARACTER(*), INTENT(IN) :: Fil ! Name of the input file.
CHARACTER(*), INTENT(IN) :: AryDescr ! Text string describing the variable.
CHARACTER(*), INTENT(IN) :: AryName ! Text string containing the variable name.
! Local declarations:
INTEGER :: Ind ! Index into the real array. Assumed to be one digit.
INTEGER :: IOS ! I/O status returned from the read statement.
READ (UnIn,*,IOSTAT=IOS) ( Ary(Ind), Ind=1,AryLen )
CALL CheckIOS ( IOS, Fil, TRIM( AryName ), NumType, ErrStat, ErrMsg )
IF (ErrStat >= AbortErrLev) RETURN
DO Ind=1,AryLen
CALL CheckRealVar( Ary(Ind), AryName, ErrStat, ErrMsg)
IF (ErrStat >= AbortErrLev) RETURN
END DO
IF ( PRESENT(UnEc) ) THEN
IF ( UnEc > 0 ) THEN
WRITE( UnEc, Ec_ReAryFrmt ) TRIM( AryName ), AryDescr, Ary(1:MIN(AryLen,NWTC_MaxAryLen))
END IF
END IF
RETURN
END SUBROUTINE ReadR4Ary
The READ statement loads the data into the array “Ary”. If the READ is successful - IOS = 0 and if not successful the IOS would be some integer number.
The next line CALL CheckIOS checks about this and returns errror if IOS is not 0,
Now in the new version of the software, there are NUL characters introduced in the output file.
Now the line in the above code:
READ (UnIn,*,IOSTAT=IOS) ( Ary(Ind), Ind=1,AryLen )
Sets IOS to some integer value (because the read failed) and thereby throws error.
My question is
- Is there a way to remove the NUL values in the file even before sending the file to this routine, so that I need not modify this routine ?
- If that’s not feasible how can I modify this code to be able to accommodate NUL values ?
Link to the new output file with NUL values
Thank you,
Ashok