1

I built an R-package with several Fortran subroutines back in 2012. Up to 2019 (or a bit earlier) I had no problem updating and running the package under an R session. The Fortran source has a lot of write and format. Prior to 2019, the output of these commands showed up nicely on the screen (RStudio or Rconsole), but after that the same commands break R (and RStudio) with R (3.6.3), clang (12.0.0) and gfortran (11.2.0) on macOS Catalina

> res=olsml65(model,x,y,10) [1] 0 Into Fortran code  
nst =            2  
leng =         1114   
*** caught segfault *** 
address 0x0, cause 'memory not mapped'
Traceback:  1: olsml65(model, x, y, 10) 
Possible actions: 
1: abort (with core dump, if enabled) 
2: normal R exit 
3: exit R without saving workspace 
4: exit R saving workspace

If I use print instead of write and no format at all, the package runs smoothly.

Here is one line that breaks R:

    write(6,999) j
999   format(' * (Process) terms of submodel',i2,' under regression *')

I could get rid of all writes but I wonder if there is a workaround.

francescalus
  • 30,576
  • 16
  • 61
  • 96
Ed Mendes
  • 267
  • 1
  • 3
  • 9
  • 1
    How exactly does it break? Does `print 999,j` break it? Does `write (*,*) j` break it? Does `write(6,*) j` break it? Does `write(*,999) j` break it? Does Is unit `6` opened anywhere? – Vladimir F Героям слава Nov 18 '21 at 14:15
  • print 999, write(6,999) and write(*,999) break it. Format seems to be the problem. Unit 6 opens the display in R console or RStudio. Example: > res=olsml65(model,x,y,10) [1] 0 Into Fortran code nst = 2 leng = 1114 – Ed Mendes Nov 18 '21 at 14:57
  • 1
    And what about `write (*,*) ' * (Process) terms of submodel',j,' under regression *')'`? What exactly happens? Does it crash? Is there any error message? Which gfortran do you use? Does R does with its own gfortran? Which OS? – Vladimir F Героям слава Nov 18 '21 at 14:59
  • It works just fine. No error msg, nothing. Only the output on the screen: * terms of submodel 2 under regression * 1114 – Ed Mendes Nov 18 '21 at 15:05
  • So I do not understand the problem. What should happen instead? – Vladimir F Героям слава Nov 18 '21 at 15:35
  • I don't use write(6,*) but write with a format for a nice display of the results. Format breaks R. Can an external C function do the job? – Ed Mendes Nov 18 '21 at 15:40
  • Bot **how** does it break R? What should happen instead? Please also add the compiler and OS versions into your question. – Vladimir F Героям слава Nov 18 '21 at 15:52
  • R (3.6.3), clang (12.0.0) and gfortran (11.2.0) on macOS Catalina. It breaks R when it reaches write(6,239) nst, leng 239 format(' * terms of submodel',i3,' under regression *',i4) Here is what I see on an R session: > res=olsml65(model,x,y,10) [1] 0 Into Fortran code nst = 2 leng = 1114 *** caught segfault *** address 0x0, cause 'memory not mapped' Traceback: 1: olsml65(model, x, y, 10) Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace – Ed Mendes Nov 18 '21 at 16:25
  • Are there any other versions of *libgfortran* anywhere on your computer? Please check the formatting inside the edited question. The error messages and other important information really belong there. – Vladimir F Героям слава Nov 18 '21 at 16:57
  • Yes, there are quite a few versions of the library. – Ed Mendes Nov 18 '21 at 19:18
  • It is very likely some kind of clash between these versions. – Vladimir F Героям слава Nov 18 '21 at 19:26
  • Thanks. Would you know how to remove them safely? – Ed Mendes Nov 18 '21 at 20:19
  • No. I would try to find which one (if any at all) works better using https://stackoverflow.com/a/8515047/721644 – Vladimir F Героям слава Nov 18 '21 at 20:31
  • Thanks. Somehow I don't think that will be the problem. If I am not mistaken, I think I heard that there is an issue with fortran-write. – Ed Mendes Nov 18 '21 at 21:57
  • Many thanks. One last question. clang (mac) is called to link the libraries. Unfortunately, clang is using an old library (-L option). How can I change that? Sorry but it has been a long time since I work with that. – Ed Mendes Nov 19 '21 at 12:07
  • @VladimirF Thank you ever so much! I managed to remember how to change the settings (not in a clear but it worked). You were completely right. The problem was a mixed-up library. – Ed Mendes Nov 19 '21 at 13:29

0 Answers0