Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Matrix Inversion API Client-Server Example to Fortran consume API

License

NotificationsYou must be signed in to change notification settings

ricardojacomini/api_wrapper.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Matrix Inversion API Client-Server ExampleThis repository demonstrates how to use a Fortran client to send a matrix to a Python Flask API for inversion. Since Fortran does not have native support for HTTP requests, a C wrapper is used to handle the HTTP communication.##Prerequisites-**Fortran Compiler**:`gfortran` (GNU Fortran)-**C Compiler**:`gcc` (GNU C Compiler)-**cURL Library**: Required for HTTP requests in the C wrapper.-**Python 3**: Required to run the Flask server.-**Flask**: Python web framework.-**NumPy**: Python library for numerical computations.##Setup###1. Clone the Repository```bashgit clone https://github.com/yourusername/matrix-api-client-server.gitcd matrix-api-client-server

2. Set Up the Python Environment

  1. Create a virtual environment and activate it:

    $ python3 -m venv venv$source venv/bin/activate
  2. Install the required Python packages:

    $ pip install flask numpy

3. Compile the C Wrapper

The C wrapper (api_wrapper.c) uses thelibcurl library to handle HTTP requests. Compile it as follows:

$ module load curl$ gcc -c api_wrapper.c -o api_wrapper.o -lcurl

4. Compile the Fortran Client

The Fortran client (client.f90) calls the C wrapper to send the matrix to the server. Compile it as follows:

$ module load curl$ gfortran -g client.f90 api_wrapper.o -o client -lcurl

5. Start the Flask Server

Run the Flask server (server.py) to handle incoming requests:

$ python server.py

The server will start onhttp://0.0.0.0:5000.

Usage

Running the Fortran Client

Once the server is running, execute the Fortran client:

$ ./client

The client will send a matrix to the server, receive the inverted matrix, and print both the original and inverted matrices.

Example Output

 Original matrix:  [[4.0, 7.0], [2.0, 6.0]] Server response: {"inverted_matrix": [[0.6, -0.7], [-0.2, 0.4]]}

Testing with cURL

You can also test the API directly usingcURL:

curl -v -X POST http://172.20.11.21:5000/invert-matrix -H"Content-Type: application/json" -d'{"matrix": [[4.0, 7.0], [2.0, 6.0]]}'

Service Setup (Optional)

To run the Flask server as a service, you can use the providedserver.service file. Follow these steps:

  1. Copy the service file to the systemd directory:

    $ sudo cp server.service /etc/systemd/server.service
  2. Reload the systemd daemon:

    $ sudo systemctl daemon-reload
  3. Start and enable the service:

    $ sudo systemctl start server.service$ sudo systemctlenable server.service

License

This project is licensed under the MIT License. See theLICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Acknowledgments

  • Flask for the web framework.
  • NumPy for matrix operations.
  • libcurl for HTTP requests in C.

About

Matrix Inversion API Client-Server Example to Fortran consume API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp