Skip to content

Instantly share code, notes, and snippets.

@certik
Last active February 14, 2021 19:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save certik/9744747 to your computer and use it in GitHub Desktop.
Save certik/9744747 to your computer and use it in GitHub Desktop.
Fortran / C interoperability for logical

Compile using either of:

./compile_gnu

and you should get the result:

           3 T F
true -> false
           3 F T
false -> true
Done.

Now compile using Intel:

./compile_intel

and you get the result:

           3 T F
true -> true
           3 F T
false -> true
Done.

Which is incorrect. Enable -fpscomp logical in compile_intel, recompile, then you get:

           3 T F
true -> false
           3 F T
false -> true
Done.
module a
use iso_c_binding, only: c_int, c_bool
implicit none
private
public foo
contains
subroutine foo(n, relat, relat_out) bind(c, name="foo")
integer(c_int), intent(in), value :: n
logical(c_bool), intent(in), value :: relat
logical(c_bool), intent(out) :: relat_out
relat_out = .not. relat
print *, n, relat, relat_out
end subroutine
end module
gcc -o m.o -c m.c
gfortran -o a.o -c a.f90
gcc m.o a.o -lgfortran
icc -o m.o -c m.c
#ifort -fpscomp nologicals -o a.o -c a.f90
ifort -o a.o -c a.f90
icc m.o a.o -lifcore
pgcc -o m.o -c m.c
pgf90 -o a.o -c a.f90
pgcc m.o a.o -pgf90libs
#include <stdio.h>
#include <stdbool.h>
void foo(int n, bool relat, bool *relat_out);
int main()
{
bool relat_out;
foo(3, true, &relat_out);
printf("true -> %s\n", relat_out ? "true" : "false");
foo(3, false, &relat_out);
printf("false -> %s\n", relat_out ? "true" : "false");
printf("Done.\n");
return 0;
}
@kunalbali
Copy link

Hello
I need some help in fortran programming. As i am new in fortran so i am not getting how to merge two file or all i can say how to compile 2 file. As i am student of atmospheric science stream so i need to merge some satellite data. I have 10 files (Lat Lon Vales in each files). I want to make it one and also want to do average of each lat , lon values.

Hope you got my problem

Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment