Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner

Read function doesn't read the file properly

Good morning. I wrote the following code:

       do ii=1,nnodi

      

        read (spostamenti,*), servline(1,:)     ! Leggo la stringa e l'associo all'ii-esima riga della matrice lista nodi      

 

        do i=1,int_nod_ut

 

       if (servline(1,1)>=nod_ut_in(i,1) .and. 

     &    servline(1,1)<=nod_ut_fin(i,1)) then  

         jj=jj+1;

         spost_nodi(jj,:)=servline(1,2:5)

         idx_spost_nodi(jj,:)=servline(1,1);   

        end if

 

      enddo

 

      end do

 

 

      ii=0 

      jj=0              ! Inizializzo l'indice del ciclo

                                 

       

        do ii=1,nnodi

      read (veloc,*), servline(1,:)        ! Leggo la stringa e l'associo all'ii-esima riga della matrice lista nodi     

      do i=1,int_nod_ut

      if (servline(1,1)>=nod_ut_in(i,1) .and.

     &    servline(1,1)<=nod_ut_fin(i,1)) then  

         jj=jj+1;

         veloc_nodi(jj,:)=servline(1,2:4)

         idx_veloc_nodi(jj,:)=servline(1,1);   

      end if

      enddo

      end do

 

The files " spostamenti" and "veloc" are very similar. I can import the first file properly, in the second case read function reads the first line, then skip the second line, then it reads the third, skip the fourth and so on. Probably is something very stupid, but I can't understand what is wrong in this procedure.

0 Kudos
2 Replies
Highlighted
Beginner

The problem is in the read

The problem is in the read function, because writing this:

   do ii=1,nnodi

        read (veloc,*), servline(1,:)       

        write(*,*),  servline(1,:)  

    end do

It's simple to understand that read function skips a line each time.

0 Kudos
Highlighted
Black Belt

What are the types of the

What are the types of the variables spostamenti and veloc? Are they of type CHARACTER or of type INTEGER?

You will need to show the source code and the data files in more detail, if you wish to obtain advice regarding what your code is doing. Without knowing what the data files contain, and without knowing the types and shapes of the variables in the I/O lists, it is almost impossible to tell what is happening.

0 Kudos