Thread: bug fix in readsac.m (missing fclose)

Started: 2011-02-15 00:05:59
Last activity: 2011-02-17 18:35:47
Topics: SAC Help
Warren Caldwell
2011-02-15 00:05:59
Hi all,

I believe I've found a bug (unbalanced fopen/fclose) in readsac.m.

When I read in a large number of sac files in Matlab using F=readsac(*
list-of-files-tens-**long*), Matlab hangs and crashes. I fixed it in
sac-101.2/utils/readsac.m by adding an fclose statement as follows:

Original (first line is line 243):
if ~ismember(B(7), 1:6) % non-native byte order
[comp, mxsize, endian] = computer;

Changed:
if ~ismember(B(7), 1:6) % non-native byte order
*fclose(fid);* % close original 'fid' since we are about to create a
new 'fid'
[comp, mxsize, endian] = computer;

Without this fclose, Matlab opens each file without closing the previous
one. I had to make the same change in sac-101.4/utils/readsac.m.


Cheers,
Warren

--
~~~~~~~~~~~~~~~~~~~~~~~~~
Warren Caldwell
Stanford Geophysics
pangea.stanford.edu/~warrenc

  • John Nabelek
    2011-02-15 21:44:40
    Hi

    I am trying to compile sac 101.4 in order to link some external programs against the current sac libraries.

    I have a problem with sac-101.4/src/coda/sac_code.c, which requires sac_header.h. This header file does not exist in my source distribution and thus sac_code.c does not compile, which in turn results in 'Undefined symbols: "_initialize_header"' error when I compile my codes.

    Is there someone who has the sac_header.h file and can you forward it to me?

    Thanks.

    -John

    • Brian Savage
      2011-02-17 18:35:47
      All,

      This problem below has been resolved following discussion between
      myself and John. The sac_code.c file is not compiled into the sac
      libraries or executable and should not be as it includes older and
      possibly buggy copies of SAC reading and writing routines. It is an
      older file that will be removed in the next version to avoid confusion.

      John, thank you.

      Brian

      On Feb 15, 2011, at 4:44 PM, Nabelek John wrote:

      Hi

      I am trying to compile sac 101.4 in order to link some external
      programs against the current sac libraries.

      I have a problem with sac-101.4/src/coda/sac_code.c, which requires
      sac_header.h. This header file does not exist in my source
      distribution and thus sac_code.c does not compile, which in turn
      results in 'Undefined symbols: "_initialize_header"' error when I
      compile my codes.

      Is there someone who has the sac_header.h file and can you forward
      it to me?

      Thanks.

      -John
      _______________________________________________
      sac-help mailing list
      sac-help<at>iris.washington.edu
      http://www.iris.washington.edu/mailman/listinfo/sac-help



  • Brian Savage
    2011-02-16 18:18:17
    Warren,

    Thank you for the fix. We will be including this in the upcoming
    101.5 version.

    Brian Savage
    savage<at>uri.edu

    On Feb 14, 2011, at 7:05 PM , Warren Caldwell wrote:

    Hi all,

    I believe I've found a bug (unbalanced fopen/fclose) in readsac.m.

    When I read in a large number of sac files in Matlab using
    F=readsac(list-of-files-tens-long), Matlab hangs and crashes. I
    fixed it in sac-101.2/utils/readsac.m by adding an fclose statement
    as follows:

    Original (first line is line 243):
    if ~ismember(B(7), 1:6) % non-native byte order
    [comp, mxsize, endian] = computer;

    Changed:
    if ~ismember(B(7), 1:6) % non-native byte order
    fclose(fid); % close original 'fid' since we are about to
    create a new 'fid'
    [comp, mxsize, endian] = computer;

    Without this fclose, Matlab opens each file without closing the
    previous one. I had to make the same change in sac-101.4/utils/
    readsac.m.


    Cheers,
    Warren

    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    Warren Caldwell
    Stanford Geophysics
    pangea.stanford.edu/~warrenc

    _______________________________________________
    sac-help mailing list
    sac-help<at>iris.washington.edu
    http://www.iris.washington.edu/mailman/listinfo/sac-help


10:25:27 v.b4412d20