Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Read Statement

JohnNichols
Valued Contributor III
364 Views
When I try to read this it does not get past the 07,  I want to miss up to the third comma and then grab the 3 doubles

2000,07/29/2016,10:10:14.349327,-0.0689359262076682,0.0031493396999162,1.00790136372755,,,

Is there a method in Fortran to inquire as to the list of files in a directory  and return say the CSV files

 

 

0 Kudos
3 Replies
mecej4
Honored Contributor III
364 Views

1. List-directed input considers '/' as end-of-record. Try

program jmnread
implicit none
character(132) :: iline = '2000,07/29/2016,10:10:14.349327,-0.0689359262076682,0.0031493396999162,1.00790136372755,,,'
double precision d(3)
integer :: p=0, ncom=0
!
do
   p=p+1
   if(iline(p:p) == ',')then       ! scan for commas
      ncom=ncom+1
      p=p+1
      if(ncom == 3)exit            ! 3 fields skipped
   endif
end do
read(iline(p:),*)d(1),d(2),d(3)    ! 
write(*,'(1p,3D15.4)')d
end program

2. See the documentation and example code for GETFILEINFOQQ:

    <Intel_Installation_Directory>/documentation_2016/en/compiler_f/common/core/index.htm  

0 Kudos
JohnNichols
Valued Contributor III
364 Views

Thanks -- worked a treat once I used '(A)' to read from the file

0 Kudos
JohnNichols
Valued Contributor III
364 Views
subroutine lineread(iline)
      implicit none
      character(160) :: iline
      double precision d(3)
      integer :: p=0, ncom=0, p1=0
!
      do p = 1,159
          if(iline(p:p) == ',')then       ! scan for commas
              ncom=ncom+1
              if(ncom == 3) then
                  p1 = p+1
                  exit            ! 3 fields skipped
              endif
          endif
      end do
      read(iline(p1:),*)d(1),d(2),d(3)
      write(*,'(1p,3D15.4)')d
      end subroutine

 

0 Kudos
Reply