read (str,*) iv vs. read (str,'(i5)') iv

read (str,*) iv vs. read (str,'(i5)') iv

Will A. below do the same as B. but better (because not restricted to 1-5 characters) ?

A. READ(cv,*) iv

B. where fw (passed variable) equals field width:
if (fw.eq.1) then
read(cv,'(i1)') iv
elseif (fw.eq.2) then
read(cv,'(i2)') iv
elseif (fw.eq.3) then
read(cv,'(i3)') iv
elseif (fw.eq.4) then
read(cv,'(i4)') iv
elseif (fw.eq.5) then
read(cv,'(i5)') iv
endif

Thanks,
Keith

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Not quite - using * will allow input such as 2.45 or T and convert it to integer.

You don't need the complicated IF tests. Just use a format of '(BN,I5)')

Steve

Steve - Intel Developer Support

Thanks, Steve. BN works great.

Keith Richardson

Leave a Comment

Please sign in to add a comment. Not a member? Join today