# Stop reading SGY files

**URL:** <https://discourse.obspy.org/t/stop-reading-sgy-files/157>\
**Category:** Users Mailing List Archive\
**Tags:** archive\
**Created:** [December 5, 2012, 7:08pm UTC](https://discourse.obspy.org/t/stop-reading-sgy-files/157 "2012-12-05T19:08:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugo\_Samuel\_Sanchez](https://discourse.obspy.org/letter_avatar_proxy/v4/letter/h/b782af/32.png) [@Hugo\_Samuel\_Sanchez](https://discourse.obspy.org/u/Hugo_Samuel_Sanchez)\
**Post date:** [December 5, 2012, 7:08pm UTC](https://discourse.obspy.org/t/stop-reading-sgy-files/157/1 "2012-12-05T19:08:45Z")

</div>

Hi everyone!

I’m a begginer user of ObsPy. Maybe somebody could help me solving a problem of reading SEGY files.

I’m writing a fortran code able to read SEGY files. Right now I’ve already achieved to read and translate the 3200 bytes Textual Header, I also read and translated the 400 Binary Header (BIGENDIAN to LITTLEENDIAN), and I did the same to the first 240 Trace Header (trace number one) as well.

My problem comes while reading the values of the trace. My traces (according to the TraceHeader) have 1001 samples of 4 bytes each one, but the read stops at the sample 543.

My code:

do i=1,1001  
read(1,‘(A)’,advance=‘no’)valtraz  
float4=valtraz  
call SWAP\_f4(float4)  
write(11,\*) i, tsam, float4  
tsam=tsam+0.02  
enddo

The error says:

forrtl: severe (268): end of record during read, unit 1, file /home/hugo/Desktop/Cubos sismicos/Furbero\_PSTM\_TWT.sgy

I know that my record 1 (first line of file) is probably finished at that sample, but when I start reading the second record the supposed next samples 544-1001 don’t fit with the ones I got using ObsPy.

I run this same code using three different .sgy files, and the error is the same for all. Nevertheless, the read stops at differents samples of each file.

Could somebody help me understanding why my “I/0” instructions ends while reading de record? Why this ending-record-length is different for each .sgy file? Where could I see how ObsPy solved this?

Thanks a lot.  
Hugo.

---

<div class="post-metadata">

**Author:** ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)\
**Post date:** [December 5, 2012, 7:29pm UTC](https://discourse.obspy.org/t/stop-reading-sgy-files/157/2 "2012-12-05T19:29:40Z")

</div>

Hi Hugo,

just say 'st = read("Furbero\_PSTM\_TWT.sgy")' in Python. 😉

No, seriously, I am not sure this is the right place for your question,  
as this strictly speaking does not seem ObsPy related at all.

The source code doing that in ObsPy is here:  
[https://github.com/obspy/obspy/blob/master/obspy/segy/core.py#L114](https://github.com/obspy/obspy/blob/master/obspy/segy/core.py#L114)

best,  
Tobias

---

<div class="post-metadata">

**Author:** ![barsch](https://discourse.obspy.org/user_avatar/discourse.obspy.org/barsch/32/7_2.png) [@barsch](https://discourse.obspy.org/u/barsch)\
**Post date:** [December 5, 2012, 7:36pm UTC](https://discourse.obspy.org/t/stop-reading-sgy-files/157/3 "2012-12-05T19:36:17Z")

</div>

Hi Hugo,

you may also take a look into the sources of

(1) Convseis (FORTRAN), e.g.

ftp://www.orfeus-eu.org/pub/software/conversion/CONVSEIS/SOURCES/SEGY2ASC.FOR

(2) SEGY2ASC (C)

ftp://www.orfeus-eu.org/pub/software/conversion/SEGY2ASC/

Hope it helps,  
Robert

> Hi Hugo,
> 
> just say 'st = read("Furbero\_PSTM\_TWT.sgy")' in Python. 😉
> 
> No, seriously, I am not sure this is the right place for your  
> question, as this strictly speaking does not seem ObsPy related at  
> all.
> 
> The source code doing that in ObsPy is here:  
> [https://github.com/obspy/obspy/blob/master/obspy/segy/core.py#L114](https://github.com/obspy/obspy/blob/master/obspy/segy/core.py#L114)
> 
> best, Tobias
> 
> > Hi everyone!
> > 
> > I'm a begginer user of ObsPy. Maybe somebody could help me  
> > solving a problem of reading SEGY files.
> > 
> > I'm writing a fortran code able to read SEGY files. Right now  
> > I've already achieved to read and translate the 3200 bytes  
> > Textual Header, I also read and translated the 400 Binary Header  
> > (BIGENDIAN to LITTLEENDIAN), and I did the same to the first 240  
> > Trace Header (trace number one) as well.
> > 
> > My problem comes while reading the values of the trace. My  
> > traces (according to the TraceHeader) have 1001 samples of 4  
> > bytes each one, but the read stops at the sample 543.
> > 
> > My code:
> > 
> > do i=1,1001 read(1,'(A)',advance='no')valtraz float4=valtraz call  
> > SWAP\_f4(float4) write(11,\*) i, tsam, float4 tsam=tsam+0.02 enddo
> > 
> > The error says:
> > 
> > forrtl: severe (268): end of record during read, unit 1, file  
> > /home/hugo/Desktop/Cubos sismicos/Furbero\_PSTM\_TWT.sgy
> > 
> > I know that my record 1 (first line of file) is probably finished  
> > at that sample, but when I start reading the second record the  
> > supposed next samples 544-1001 don't fit with the ones I got  
> > using ObsPy.
> > 
> > I run this same code using three different .sgy files, and the  
> > error is the same for all. Nevertheless, the read stops at  
> > differents samples of each file.
> > 
> > Could somebody help me understanding why my "I/0" instructions  
> > ends while reading de record? Why this ending-record-length is  
> > different for each .sgy file? Where could I see how ObsPy solved  
> > this?
> > 
> > Thanks a lot. Hugo.
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ obspy-users  
> > mailing list obspy-users@lists.sevor.de  
> > [ObsPy Forum](http://lists.obspy.org/cgi-bin/mailman/listinfo/obspy-users)

- --  
Dr. Robert Barsch

EGU Office Munich  
Luisenstr. 37  
80333 Munich  
Germany

Phone: +49-89-21806549  
Fax: +49-89-218017855  
eMail: barsch@egu.eu

---

<div class="post-metadata">

**Author:** ![LionKrischer](https://discourse.obspy.org/user_avatar/discourse.obspy.org/lionkrischer/32/219_2.png) [@LionKrischer](https://discourse.obspy.org/u/LionKrischer)\
**Post date:** [December 5, 2012, 9:14pm UTC](https://discourse.obspy.org/t/stop-reading-sgy-files/157/4 "2012-12-05T21:14:18Z")

</div>

Hi Hugo,

it is also hard to tell what might go wrong without the file. From the way  
you describe the error I guess that you reach the end of the file so I would  
say your byte count got messed up somewhere along the line.

But why roll your own SEG-Y reader? Robert already pointed out some  
alternatives. Furthermore as far as I know Seismic Unix is also able to  
read SEG-Y files. It is written in C which you can call from Fortran with  
most compilers. It also has a very liberal license.

Good luck!

Lion
