pumppasob.blogg.se

Simply fortran graphics examples
Simply fortran graphics examples








In Fortran: SUBROUTINE EXAMPLE1(STR1, DATA, STR2, INFO) CHARACTER*(*)STR1, STR2 DOUBLE PRECISIONDATA, INFO Example: Calling a Fortran Routine Using a Fortran Interface RoutineĬalling Fortran is similar to calling C, with the significant difference that Fortran expects all arguments to be passed by reference. This extra parameter is added to the end of the Fortran routine call in the C function, but does not explicitly appear in the Fortran routine.įor example, in C: char * str1= 'IDL' char * str2= 'ITT' int len1= 3 int len2= 3 double data, info /* Call a Fortran sub-routine named example1 */ example1_(str1, data, str2, info, len1, len2) When passing C null-terminated character strings into a Fortran routine, the C function should also pass in the string length. The returned value is contained in the variable sum. In this example, example.so is the name of the sharable image file, sum_array is the name of the entry point, and X and N_ELEMENTS(X) are passed to the called routine as parameters. X = FINDGEN(10) A floating result SUM = 0.0 S = CALL_EXTERNAL( 'example.so', $ 'sum_array', X, N_ELEMENTS(X), sum) To call the example program from within IDL: Make an array. This directory also contains a makefile, which builds this example on UNIX platforms. For more information on compiling and linking on your platform, see the README file contained in the external/call_external/Fortran subdirectory of the IDL distribution. This example is compiled and linked in a manner similar to that used in the C example above.

simply fortran graphics examples

c SUBROUTINE sumarray1(array, n, sum) INTEGER* 4 n REAL* 4 array(n), sum sum= 0.0 DO i= 1,n sum = sum + array(i) PRINT *, sum, array(i) ENDDO RETURN END

simply fortran graphics examples

The following are the contents of example_c2f.c and example.f: #include void sum_array(int argc, void *argv) Ĭ This subroutine is called by SUM_ARRAY and has no IDL-specific code. In these examples, the object name of the Fortran subroutine will be sum_array1_ to match the output of the Fortran compiler. The example.f file contains the Fortran routine that actually sums the array. The example_c2f.c file contains the C interface routine, which would be compiled as illustrated above.

#Simply fortran graphics examples code

The following code segments illustrate this. If C passes a pointer (an address) by value, Fortran will interpret it correctly as the address of an argument. Fortran expects all arguments to be passed by reference it expects all arguments to be addresses. The arguments f, n, and s are pointers that are being passed by value. This issue is discussed in By-Value and By-Reference Arguments.Ī C interface routine can easily extract the addresses of the arguments from the argv array and pass them to the actual routine which will compute the sum.

simply fortran graphics examples

This means that the address of the argument is passed rather than the argument itself. Example: Calling a Fortran Routine Using a C Interface RoutineĬalling Fortran is similar to calling C, with the significant difference that Fortran code expects all arguments to be passed by reference and not by value (the C default).








Simply fortran graphics examples