Silverfrost Forums

Welcome to our forums

Where is error?

7 Jun 2016 7:44 #17560

Do i have to stop programming? Damn, i can not find the error for hours. The data is gotten by scanning large database, it has produced a lot of errors due to that, but i seems found all of them. I spotted the error making smallest snippet from the data. Some error is still there

        real*4 EZ0(100)
        character*1 aaaa


        OPEN (UNIT=3,FILE='data',STATUS='OLD')

	READ (3,*,ERR=1003,END=1000) IZNatmd
	READ (3,'(A)') AAAA
	READ(3,*,ERR=1004,END=1000) (EZ0(i),i=1,IZNatmd)

	close(3)
	goto 1000

1003    print*, 'Error reading data 1 '
	goto 1000
1004    print*, 'Error reading data 2'

1000	end


The file called 'data' is here:

10
!...IONIZATION  POTENTIALS (ALL DATA IN FORMAT = *)
6.815E0,1.447E1,2.349E1,3.632E1,4.9l4E1,9.266E1,1.187E2,1.30lE2,1.595E2,1.797E2,
7 Jun 2016 7:54 #17562
   real*4 EZ0(100) 
   character*1 aaaa 
   integer*4 IZNatmd ,i

    OPEN (UNIT=3,FILE='data',STATUS='OLD') 

    READ (3,*,ERR=1003,END=1000) IZNatmd 
    READ (3,'(A)') AAAA 
    READ(3,*,ERR=1004,END=1000) (EZ0(i),i=1,IZNatmd) 

    close(3) 
    goto 1000 

 1003    print*, 'Error reading data 1 ' 
    goto 1000 
 1004    print*, 'Error reading data 2' 
         write (*,*) (EZ0(i),i=1,IZNatmd) 

 1000   end 

Dan,

Try this as it shows the error is in the 4th number. You typed '9L' instead of '91' in the 5th number : 4.9l4E1

7 Jun 2016 11:27 #17569

If the 'large database' file is suspected to contain more such errors, it would be helpful in spotting the bad input line to keep track of the number of lines read from the data file and, when the ERR=... clause is triggered, print that line number.

In addition, you could also print out the offending line of data to facilitate further manual inspection and correction. Here is your program, modified to do these additional checks:

        Program XDRR
        real*4 EZ0(100),EZi
        character*1 aaaa
        character*132 line      
        OPEN (UNIT=3,FILE='data',STATUS='OLD') 

        READ (3,*,ERR=1003,END=1000) IZNatmd 
        READ (3,'(A)') AAAA 
        READ(3,'(A)',END=1000) line
        READ(line,*,ERR=1004)(EZ0(i),i=1,IZNatmd) 

        close(3) 
        goto 1000 

1003    print*, 'Error reading data 1 ' 
        goto 1000 
1004    print*, 'Error reading data 2' 
        print*, 'Line containing error: ',trim(line)
        k=1
        l=len_trim(line)
        do i=1,IZNatmd
           read(line(k:),*,ERR=1010)Ezi
           do while(line(k:k).ne.',')
              k=k+1
              if(k.gt.l)then
                 write(*,*)'Input line exhausted after reading ',
     1               i-1,' items'
                 exit
              end if
           end do
           if(k.gt.l)exit
		   k=k+1           !skip ','
        end do   
 1010 write(*,'(A,I1,2x,A)')'Data item causing error is #',
     1                      i,' contents: ',trim(line(k:))
1000   end 

The modified program outputs:

 Error reading data 2
 Line containing error: 6.815E0,1.447E1,2.349E1,3.632E1,4.9l4E1,9.266E1,1.187E2,1.30lE2,1.595E2,1.797E2,
Data item causing error is #5   contents:  4.9l4E1,9.266E1,1.187E2,1.30lE2,1.595E2,1.797E2,
7 Jun 2016 5:58 #17575

Ufff, thanks John and Mecej4. And looks like not one but two such errors are here...Do not remember when last time I confused l and 1...

Mecej4. Lately I do things like you have demonstrated, but a bit differently. But this was older code touching which was as dangerous as touching old landmine. Will use your method too, thanks, still have a lot of data to load.

Or may be someone has good quality database of ionization potentials of all ion stages of all atomic elements of periodic table? Mine old one has errors in every second number

7 Jun 2016 6:49 #17577

Dan,

You can spot the offending 'l' (l.c. L) characters more easily if you make an 'upper case' copy of your data file and compare the two versions with a file difference utility such as Windiff or Kdiff3

6.815E0,1.447E1,2.349E1,3.632E1,4.9[u:b8e4b7f0ed]l[/u:b8e4b7f0ed]4E1,9.266E1,1.187E2,1.30[u:b8e4b7f0ed]l[/u:b8e4b7f0ed]E2,1.595E2,1.797E2 6.815E0,1.447E1,2.349E1,3.632E1,4.9[u:b8e4b7f0ed]L[/u:b8e4b7f0ed]4E1,9.266E1,1.187E2,1.30[u:b8e4b7f0ed]L[/u:b8e4b7f0ed]E2,1.595E2,1.797E2

A variable-width font in your browser or a text-editor will show the second line to be a bit longer than the first, alerting you to the presence of the 'l' or a similar character with different widths for lower and upper case.

Even though these lower case ELL-s may have seemed troublesome, the reality is that there are data errors that are more harmful and harder to catch. Consider this: neither John nor I needed to know anything about ionization to spot the problem -- the compiler and the RTL did that, and John spotted the exact location for you. Take that number: 4.914E1. Is it correct? What are the rules for deciding? Suppose that the physics of the problem imposes a threshold value of 4.974E1, and that the '7' was typed in as '1' by mistake. How will you ever catch this error?

In general, gross errors tend to be spotted soon. The tough-to-catch errors are those that give reasonable-looking but incorrect results. Such errors can remain unfixed for decades.

7 Jun 2016 11:40 #17578

Dan,

A different approach: I have written a text file scanner that counts all characters (0:255) in the file. I actually wrote it to test stream I/O and also find dos vs unix file formats. Effectively, this reports all numeric and non numeric characters. It would be very easy to also create a report that lists all non-numeric characters in the file, or those lines only, by replacing all numeric characters with a blank. It would be a quick data verifier, that would work for text files. I might see if I can patch a 'non-numeric' report up.

John

9 Jun 2016 12:06 #17608

Dan,

This is a link to the scan program that can report all non-numeric characters.
It provides statistics of what characters are used in the file, which can be good to understand the type of data in the file or testing for DOS or UNIX format text files. It also gives an example of using FTN95's stream I/O, opening with form = 'UNFORMATTED', access = 'TRANSPARENT',

https://www.dropbox.com/s/trk4k3acmj4gz9e/scan_file.f95?dl=0

To compile use : ftn95 scan_file /link To report all non-numeric characters use : scan_file text_file_name /numeric /stats

I hope it can provide some ideas and let me know if there are any major errors in the program.

John

Please login to reply.