Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAC files are not compatitble with "saclst" command or other C library #5

Open
nqdu opened this issue Apr 17, 2022 · 1 comment
Open

Comments

@nqdu
Copy link

nqdu commented Apr 17, 2022

Hi Liang,

I've created a SAC file by using your code. But when I use saclst to check some parameters, it raises an error:
sacio: Actual file size 19832 != expected file size: 39032 [npts: 4800]

I think the reason is that Fortran's character is not fully compatible with C's char *. In C, there should be an '\0' at the end of each char arrays to indicate its end.

To solve this problem, I think one way is to add a subroutine in the source file:

subroutine create_c_char(mychar)
  use iso_c_binding,only : c_null_char
  implicit none 
  character(len=*),intent(inout) :: mychar
  mychar = trim(mychar) // c_null_char
end subroutine

Before calling sacio_writesac/write_header, you could call this subroutine to convert all character arrays in sachead to C's char*. In addition, the length of each character array, like kstnm should have length 9 instead of 8.

Thanks!

@nqdu nqdu closed this as completed Apr 17, 2022
@wangliang1989
Copy link
Owner

@nqdu
why close?

@wangliang1989 wangliang1989 reopened this Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants