How do I create modules written in c inside pythonista
This isn't possible.
There is the
ctypesmodule though, so if you want to call C functions, then you can do that with
ctypes. You can even call functions from Python's C API, if you really want to, but that isn't very useful in many cases.
For Fortran codes something here.
Obviously you must be online with your Pythonista.
As example of C code that you can edit in Pythonista and run using Pythonista and the remote server is the following:
from sage.misc.cython import compile_and_load C_code = """ def f(int n): return n*n """ module = compile_and_load(C_code) print(module.f(10))
As example of Fortran, the following:
FORTRAN_code = ''' C FILE: FIB1.F SUBROUTINE FIB(A,N) C C CALCULATE FIRST N FIBONACCI NUMBERS C INTEGER N REAL*8 A(N) DO I=1,N IF (I.EQ.1) THEN A(I) = 0.0D0 ELSEIF (I.EQ.2) THEN A(I) = 1.0D0 ELSE A(I) = A(I-1) + A(I-2) ENDIF ENDDO END ''' fortran(FORTRAN_code, globals()) import numpy a = numpy.array(range(10), dtype=float) fib(a, 10) print(a)
There is no reason to code in C or Fortran using Pythonista, but sometimes user wants to test some existing open source codes in these programming
@Matteo excuse my ignorance and my English, how do I install the sage package and where do I take the fortran function?
I have an iPhone. Thanks
@augusto Hi, you don't need to install SageMath in Pythonista, it is impossible. You can use a set of python scripts, that run well in Pythonista, in order to send to the remote server some C or Fortran codes/pieces of code to test them.
In short: with Pythonista you can do a lot of things (trust me, a lot), and a thing that you can do easly with Pythonista is to send some code to a remote python server (SageMathCell, please give credits to Andrey, the main maintainer, for this free service), wait for response and process the output, in order to use it in Pythonista, like a global variable that you can use as you want. You must be online to use the service.
Please follow the instructions in the corresponding thread here. Try by yourself, you must download the last version of sage_interface, extract it in any folder of Pythonista, see what is inside that folder to understand how to send some Fortran code and obtain the output as a printed string or number/array.
If you need more info, please ask in that thread.
Thank you @Matteo for your comments. What I did not understand was that their examples run on the sage side and not on the iOS device. Thanks a lot.
@augusto Yes, fortran codes run only by sage point of view, but you can use Pythonista to write fortran codes, test and use them when online, without using other ios apps that most likely are only able to send fortran code. Bye