{"id":18466604,"url":"https://github.com/mankoff/gdb_fortran_tools","last_synced_at":"2025-04-08T08:32:18.816Z","repository":{"id":248217093,"uuid":"824192700","full_name":"mankoff/gdb_fortran_tools","owner":"mankoff","description":"Tools to help debug Fortran code with gdb - plotting, saving, and Numpy functions.","archived":false,"fork":false,"pushed_at":"2025-03-11T18:54:11.000Z","size":159,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T09:48:40.690Z","etag":null,"topics":["debug","debugger","debugging","fortran","gdb","numpy","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mankoff.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-04T14:51:21.000Z","updated_at":"2025-03-20T22:07:28.000Z","dependencies_parsed_at":"2024-07-13T07:22:21.996Z","dependency_job_id":"f2909d49-7a48-4ae1-b5cc-40e7f4487624","html_url":"https://github.com/mankoff/gdb_fortran_tools","commit_stats":null,"previous_names":["mankoff/gdb_fortran_tools"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mankoff%2Fgdb_fortran_tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mankoff%2Fgdb_fortran_tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mankoff%2Fgdb_fortran_tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mankoff%2Fgdb_fortran_tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mankoff","download_url":"https://codeload.github.com/mankoff/gdb_fortran_tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247804708,"owners_count":20999028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debug","debugger","debugging","fortran","gdb","numpy","python"],"created_at":"2024-11-06T09:16:55.583Z","updated_at":"2025-04-08T08:32:18.810Z","avatar_url":"https://github.com/mankoff.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n* gdb_fortran_tools\n\n* Table of contents                               :toc_3:noexport:\n:PROPERTIES:\n:CUSTOM_ID: toc\n:END:\n- [[#gdb_fortran_tools][gdb_fortran_tools]]\n- [[#introduction][Introduction]]\n- [[#installation][Installation]]\n- [[#usage-example][Usage example]]\n- [[#commands][Commands]]\n- [[#supported-types][Supported types]]\n- [[#warnings][Warnings]]\n  - [[#array-indexing][Array indexing]]\n  - [[#allocatable-arrays][Allocatable arrays]]\n- [[#additional-hints][Additional hints]]\n- [[#requirements][Requirements]]\n- [[#acknowledgements][Acknowledgements]]\n\n* Introduction\n:PROPERTIES:\n:CUSTOM_ID: intro\n:END:\n\nSupport more advanced =gdb= debugging of Fortran code\n+ [X] Generic access to many basic numpy array operators: sum, min, max, log10, etc.\n+ [X] Access to custom complex on-liners\n+ [X] Graphics: plot, imshow, scatter\n+ [X] Save data: pickle, CSV\n\n* Installation\n:PROPERTIES:\n:CUSTOM_ID: install\n:END:\n\nYou need a Python environment with =matplotlib=, =numpy=, and =gdb=.\n\nInstall this software with:\n\n#+BEGIN_SRC bash :exports both :results verbatim\ngit clone https://github.com/mankoff/gdb_fortran_tools\n#+END_SRC\n\nSet an environment variable to that location (perhaps in your =.bashrc= or other init script).\n\n#+BEGIN_SRC bash :exports both :results verbatim\nexport GFT_DIR=/path/to/gdb_fortran_tools\n#+END_SRC\n\nEdit your =~/.gdbinit= file to load =gdb_fortran_tools=\n\n#+BEGIN_SRC python\npython\nimport os\nimport sys\nif 'GFT_DIR' not in os.environ:\n   print(f'WARNING: environmental var GFT_DIR not found')\nelse:\n   sys.path.insert(0, os.path.expanduser(os.environ['GFT_DIR']))\n   try:\n      import gdb_fortran_tools\n   except:\n      print(\"WARNING: Could not import gdb_fortran_tools\")\nend\n#+END_SRC\n\n* Usage example\n:PROPERTIES:\n:CUSTOM_ID: example\n:END:\n\nWith the following code in =example.F90=\n\n#+BEGIN_SRC f90 :exports both :tangle example.F90\nprogram main\n  real, allocatable, DIMENSION(:) :: x, y\n  real, allocatable, DIMENSION(:,:) :: xy\n  INTEGER :: im, jm, i,j\n\n  im = 4\n  jm = 5\n  \n  allocate(x(im))\n  allocate(y(jm))\n  allocate(xy(im,jm))\n\n  do i=1,im\n     x(i) = i+3\n     do j=1,jm\n        y(j) = j+5\n        xy(i,j) = x(i)*y(j)\n     end do\n  end do\n  \n  print *, x\n  print *, y\n  print *, xy\nend program main\n#+END_SRC\n\nCompile it for debugging with\n\n#+BEGIN_SRC bash :exports both :results verbatim\ngfortran -g example.F90\n#+END_SRC\n\nRun gdb:\n\n#+BEGIN_SRC bash :exports both :results verbatim\ngdb ./a.out\nbreak 23\nrun\n\n# traditional GDB commands\np x\nptype x\n\n# Simple numpy accessors\nnp sum x\nnp max y\nnp log10 xy\n\n# Plots\nplot x\nimshow xy\nimshow xy x y\nimshow0 xy x y\nlogshow xy\nlogshow xy x y\nplot xy\nplot x y(2:5)\nscatter x y(2:5)\n\n# arbitrary Python commands\npycmd xy print(_)\npycmd xy np.min(_[np.where(_ != 0)])\npycmd xy [item for item in _.flatten() if (item % 2) == 0]\n\n# save to CSV\nsavecsv xy.csv xy\n#+END_SRC\n\n* Commands\n\n+ Graphical\n  + imshow :: Display 2D array using =matplotlib.pyplot.imshow=\n  + imshow0 :: Same as =imshow= but set 0 to NaN (colorbar scaling)\n  + logshow :: Same as =imshow= but display =np.log10()= of data\n  + scatter :: Display scatter plot of two vectors\n  + plot3d :: Display 3D plot of 2D array\n  + scatter3d :: Display 3D scatter plot\n  + hist :: Display histogram of vector\n  + fft :: Display FFT of vector\n+ Numerical\n  + np \u003cfunction\u003e \u003cvariable\u003e :: Call =np.function(variable)= for any numpy function\n  + pycmd \u003cvariable\u003e \u003cstatements(_)\u003e :: Run any sequence of valid one-line Python =statements= on variable. Within =statement=, access variable via =_= (underscore)\n+ I/O\n  + savecsv \u003cfile.csv\u003e \u003cvariable\u003e :: Save =variable= to =file.csv=\n  + savepy \u003cfilename\u003e \u003cvariable\u003e :: Save =variable= to =filename= in Python pickle format\n  + save \u003cfile\u003e \u003cvariable\u003e :: Save =variable= to =file= using numpy =tofile= function\n\n* Supported types\n\n#+BEGIN_SRC f90 :exports both\nreal*{4,8}, dimension(:), dimension(:,:), dimension(:,:,:)\ninteger*{4,8}, dimension(:), dimension(:,:), dimension(:,:,:)\nlogical\n#+END_SRC\n\n* Warnings\n:PROPERTIES:\n:CUSTOM_ID: warn\n:END:\n\n** Array indexing\n\n+ Fortran uses 1-based array indexing\n+ Python uses 0-based array indexing\n\n** Allocatable arrays\nNote: If gdb reports\n\n#+BEGIN_EXAMPLE\n(gdb) ptype foo\ntype = real(kind=8), allocatable (72,0:47)\n#+END_EXAMPLE\n\nThen you need to use the syntax =imshow foo(:,:)=\n\n* Additional hints\n\nYou can create custom =gdb= commands that build on commands provided here. For example to find the range of an array, add this to your =~/.gdbinit=\n\n#+BEGIN_SRC bash :exports both :results verbatim\ndefine mm\n    np min $arg0\n    np max $arg0\nend            \ndocument mm\n    print min and max of an array or vector. Uses gdb_fortran_tools.\nend\t\n#+END_SRC\n\n* Requirements\n:PROPERTIES:\n:CUSTOM_ID: req\n:END:\n\n- GDB \u003e= 7.0\n- Python 3\n  - NumPy\n  - Matplotlib\n  - gdb (the Python package)\n\n\n* Acknowledgements\n:PROPERTIES:\n:CUSTOM_ID: ack\n:END:\n\nThanks to [[https://github.com/X-Neon][X-Neon]] and [[https://github.com/X-Neon/gdbplotlib][gdbplotlib]].\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmankoff%2Fgdb_fortran_tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmankoff%2Fgdb_fortran_tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmankoff%2Fgdb_fortran_tools/lists"}