JuliaData / JuliaData/FortranFiles.jl

bug fix for skipping zero length record

Open
#7 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
41
Forks
12
PR merge metrics
No merged PRs in 30d

Description

Problem

One of my Fortran progame may write out a record of an empty array (for example, when no data point was found). When I try to read back the fortran file and skip this empty record using read(f) I got "attempting to read beyond record end" error. Reading the same file in Fortran has no problem.

Possible solution

In the src/withsubrecord.jl:

 49 function advance!( rec::RecordWithSubrecords )                                            
 50    #subreclen, sign = rdmarker(rec) # read trailing record marker                         
 51    #if subreclen != rec.subreclen                                                         
 52    #   fthrow("trailing subrecord marker doesn't match")                                  
 53    #end                                                                                   
 54    #**FIX HERE** advance to the next subrecord only when rec.more is true                                  
 55    if rec.more                                                                            
 56       subreclen, sign = rdmarker(rec) # read trailing record marker                       
 57       if subreclen != rec.subreclen                                                       
 58          fthrow("trailing subrecord marker doesn't match")                                
 59       end                                                                             
 60       subreclen, more = rdmarker(rec) # read next leading subrecord marker                
 61       rec.subleft = rec.subreclen = subreclen                                             
 62       rec.more = more                                                                     
 63    end                                                                                    
 64    nothing                                                                                
 65 end 

...

111 function Base.close( rec::RecordWithSubrecords )
112    if rec.writable
113       @assert rec.totleft == 0
114       @assert rec.subleft == 0
115       @assert !rec.more
116       wrmarker(rec, rec.subreclen, !rec.isfirst)
117    else
118       while rec.subleft > 0
119          skip(rec.io, rec.subleft)
120          rec.subleft = 0
121          advance!(rec)
122       end
123       @assert !rec.more
124       #**FIX HERE** read trailing record marker of the last subrecord
125       subreclen, sign = rdmarker(rec)
126       if subreclen != rec.subreclen
127          fthrow("trailing subrecord marker doesn't match")
128       end
129    end
130    nothing
131 end

Thank you!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/withsubrecord.jl with RecordWithSubrecords.advance! and Base.close, then reproduce reading a Fortran file containing an empty record with read(f). Trace how subrecord markers are consumed for zero-length records; done means the empty record can be skipped without reading beyond the record end and marker validation still succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.