{"id":28931666,"url":"https://github.com/beliavsky/calc","last_synced_at":"2026-02-11T04:02:19.758Z","repository":{"id":289706666,"uuid":"972151594","full_name":"Beliavsky/Calc","owner":"Beliavsky","description":"Interpreter in Fortran that can handle scalars and 1D arrays, with access to intrinsics and statistical functions and plotting with gnuplot","archived":false,"fork":false,"pushed_at":"2026-02-01T16:57:24.000Z","size":462,"stargazers_count":10,"open_issues_count":12,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-02-02T01:19:26.536Z","etag":null,"topics":["array","array-programming","array-programming-language","calculator","expression","expression-evaluator","expression-parser","fortran","gnuplot","interpreter","plot","statistics","time-series-analysis"],"latest_commit_sha":null,"homepage":"","language":"Fortran","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/Beliavsky.png","metadata":{"files":{"readme":"README.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-24T16:03:22.000Z","updated_at":"2026-02-01T16:57:27.000Z","dependencies_parsed_at":"2025-05-01T19:38:13.361Z","dependency_job_id":null,"html_url":"https://github.com/Beliavsky/Calc","commit_stats":null,"previous_names":["beliavsky/calc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Beliavsky/Calc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FCalc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FCalc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FCalc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FCalc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Beliavsky","download_url":"https://codeload.github.com/Beliavsky/Calc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beliavsky%2FCalc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29326822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["array","array-programming","array-programming-language","calculator","expression","expression-evaluator","expression-parser","fortran","gnuplot","interpreter","plot","statistics","time-series-analysis"],"created_at":"2025-06-22T16:07:36.728Z","updated_at":"2026-02-11T04:02:19.752Z","avatar_url":"https://github.com/Beliavsky.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Calc\n\nCalc is a Fortran-based interactive statistics interpreter with a session-to-Fortran transpiler.\n\n## What the interpreter supports\n\n- Scalars and 1D real arrays.\n- Array literals, slicing, arithmetic, reductions, and basic control flow.\n- Random simulation, fitting, and properties of many [probability distributions](distributions.md).\n- Time-series helpers including ACF/PACF and AR/MA/ARMA/ARFIMA utilities.\n- Robust summaries, common statistical tests, and AIC-based distribution scanning.\n- Plotting via gnuplot.\n\nSome interpreter code examples:\n\n```fortran\n! General\nrun(\"code.txt\")\ncalc code.txt\n\n! Scalars and arithmetic\nn = 10\nr = n / 2\nr^3\nconst m = 10^3\n\n! Vectors\ny = [1, 2, 3, 4, 5]\nv = 10 * arange(10)\nt = grid(11, 0.0, 0.1)\n\n! Element-wise operations\nz = n * y\nw = y + v(1:size(y))\nz ^ 2\n\n! Slicing\nv([2 4 6 8])\nv(3:9:2)\nreverse(v)\n\n! Random numbers and time series\nx = runif(10)                                ! 10 iid Uniform(0,1) draws\nx0 = runif()                                 ! one Uniform(0,1) draw\nrn = rnorm(5)                                ! 5 iid standard Normal draws\ntn = rnct(5, 8.0, 1.5)                       ! 5 iid noncentral t draws (df=8, ncp=1.5)\nmx = rmixnorm(5, [0.7,0.3], [0.0,2.0], [1.0,0.5]) ! 5 draws from a 2-component normal mixture\narsim(1000, [0.5, -0.4])                     ! simulate AR(2) series\nacf(x, 10)                                   ! sample ACF for lags 1..10\nacf(x, 10, plot=.true.)                      ! sample ACF and plot\npacf(x, 10)                                  ! sample PACF for lags 1..10\npacf(x, 10, plot=.true.)                     ! sample PACF and plot\nacfpacf(x, 10)                               ! print aligned ACF/PACF table\nacfpacf(x, 10, plot=.true.)                  ! table + joint ACF/PACF plot\nacfpacfar(x, 10)                             ! print ACF/PACF/AR-coefficient table\nacfpacfar(x, 10, plot=.true.)                ! table + joint ACF/PACF/AR plot\nfiacf(0.25, 10)                              ! theoretical ACF of ARFIMA(0,d,0)\narfimaacf([0.4], [0.2], 0.25, 10)            ! theoretical ACF of ARFIMA(1,d,1)\nfracdiff(x, 0.3)                             ! fractional differencing (1-L)^0.3 x\narfimafit(x, 1, 1)                           ! fit ARFIMA(1,d,1)\narfimasim(1000, 0.25, phi=[0.4], theta=[0.2]) ! simulate ARFIMA(1,d,1)\npolyroots([-6, -1, 1])                       ! roots of x^2 - x - 6 -\u003e packed as [Re1, Im1, Re2, Im2]\narmastab([0.6, 0.2], [0.3])                  ! [is_stationary, is_invertible, min_mod_ar, min_mod_ma]\narmastab(ma=[0.3])                           ! MA-only invertibility check\nadf_stat(x, 4)                               ! ADF t-statistic with 4 lagged differences\nadf(x, 4)                                    ! ADF report with p-value and critical values\nphillips_perron_stat(x, 8)                   ! PP tau-statistic with HAC bandwidth 8\nphillips_perron(x, 8)                        ! PP report with p-value and critical values\n\n! Stats\nsum(x)\nproduct(x)\nmean(x)\ntrimmean(x, 0.1)      ! 10% trimmed mean (drop lowest/highest 10%)\nwinsor_mean(x, 0.1)   ! 10% winsorized mean (cap tails at 10% quantiles)\nmad(x)                ! median absolute deviation (robust scale)\niqr(x)                ! interquartile range\niqr_scale(x)          ! robust sd estimate: IQR / 1.349\ngeomean(x)\nharmean(x)\nsd(x)\n[mean(x) sd(x) minval(x) maxval(x)]\nmssk(x)                             ! mean, sd, skew, kurtosis\nmssk_norm(0, 1)                     ! theoretical Normal moments [mean, sd, skew, kurtosis]\nmedian(x)\nrank(x)\nstdz(x)\n\n! Cumulative and differencing\ncumsum(y)\ncumprod(y)\ndiff(y)\n\n! Sorting and ordering\nsort(x)\np = indexx(y)                     ! permutation that sorts y\ny(p)                              ! y reordered by that permutation (same values as sort(y))\n\n! Head/tail\nhead(v)                            ! first 5 values (default)\nhead(v, 3)                         ! first 3 values\ntail(v)                            ! last 5 values (default)\ntail(v, 3)                         ! last 3 values\n\n! Comparisons\nx \u003e 0.5\nx \u003c= maxval(x)\ny == [1 2 3 4 5]\ny /= 3\ny \u003e= 4\n\n! Two-vector functions\ncor(x, y)                         ! Pearson correlation between x and y\ncor(x, y, method=spearman)        ! Spearman rank correlation\ncor(x, y, method=kendall)         ! Kendall tau-b correlation\ncor(x, y, method=[\"pearson\", \"spearman\", \"kendall\"]) ! all three pairwise in one call\ncov(x, y)                         ! sample covariance between x and y\ncor                               ! labeled correlation matrix for all same-length vectors in workspace\ncor(x, y, z)                      ! labeled correlation matrix for the listed vectors\ncor(x, y, z, method=kendall)      ! labeled matrix with Kendall method\ncor(x, y, z, method=[\"pearson\",\"kendall\"]) ! one labeled matrix per method\ndot(x, y)                         ! dot product of x and y\nmin(x, y)                         ! element-wise minimum of x and y\nmax(x, 0.5)                       ! element-wise maximum of x and scalar 0.5\nttest2(x, y)                      ! Welch two-sample t test -\u003e [t, df, p]\nks2_test(x, y)                    ! two-sample KS test -\u003e [D, p]\n\n! Workspace\n?vars                              ! list currently defined variables and their values\nread prices.csv                    ! read columns from prices.csv into workspace variables\nclear                              ! remove user-defined variables and user-defined functions\n\n! Control flow\nif (mean(x) \u003e 0.5) then\n  \"high\"\nelse\n  \"low\"\nend if\n\n! Do loop\ndo i=1,5\n  i, i^2\nend do\ndo i=1,5 i,i^2                     ! one-line do loop\n\ni = 0\ndo                                 ! potentially infinite loop; include an exit condition\n  i = i + 1\n  if (i \u003e 10) exit\nend do\n\n! For loop over collection\nfor z in [0.1, 0.2, 0.3]\n  z, sqrt(z)\nend for\nfor z in [0.1, 0.2, 0.3] z,sqrt(z) ! one-line for loop\n\n! User-defined functions (arguments are read-only / intent(in)-style)\nfunction center(a)\n  center = a - mean(a)\nend function\nxc = center(x)\n\nfunction xnorm(a, power=2)         ! default argument in user function\n  xnorm = sum(abs(a)^power)^(1/power)\nend function\nxnorm(x)                            ! uses power=2\nxnorm(x, 1)                         ! overrides default\nxnorm(x= x, power=1)                ! named arguments\n\n! User-defined subroutines (default argument intent is inout)\nsubroutine bump(a, b)\n  a = a + 1\n  b = 2*b\nend subroutine\ncall bump(x, y)\n\nsubroutine sum2(a, b, c)\n  intent(in) :: a, b\n  intent(out) :: c\n  c = a + b\nend subroutine\ncall sum2(2, 3, z)\n\nsubroutine shift_scale(y, shift=0, scale=1)\n  intent(in out) :: y\n  intent(in) :: shift, scale        ! defaults allowed for intent(in)\n  y = scale*y + shift\nend subroutine\ncall shift_scale(x)                 ! uses shift=0, scale=1\ncall shift_scale(x, 1.5, 0.5)       ! overrides defaults\ncall shift_scale(y=x, shift=1.5)    ! named arguments\n```\n\n`acf`/`pacf` return lags `1..n` and plotting is optional (`plot=.false.` by default). `acfpacf`/`acfpacfar` can also optionally plot.\n`adf`/`phillips_perron` print unit-root test reports; `adf_stat`/`phillips_perron_stat` return just the test statistic.\n`head`/`tail` accept an optional second argument for the number of elements to return.\nOne-line `do`/`for` loop bodies must be a single statement (you can still use `;` within that statement).\nDefaults in function/subroutine headers must be trailing. In subroutines, defaults are allowed only for arguments declared `intent(in)`.\nNamed arguments are supported in user-defined function and subroutine calls; positional arguments cannot appear after a named argument.\n\n## Regression and model fitting\n\n```text\n! Simple linear regression\nx = runif(200)\ny = 1.0 + 2.0*x + 0.2*rnorm(200)\nregress(x, y)                     ! with intercept by default\nregress(x, y, intcp=0)            ! no-intercept regression\nhuber_regress(y, x)               ! robust simple regression (Huber loss)\nhuber_regress(y, x, c=1.345)      ! robust threshold tuning\nbisquare_regress(y, x)            ! robust simple regression (Tukey bisquare)\nbisquare_regress(y, x, c=4.685)   ! robust threshold tuning\ndist_regress(normal, y, x)        ! Gaussian-error regression\ndist_regress(t, y, x)             ! Student-t regression, df estimated if omitted\ndist_regress(t, y, x, df=[4,6,8,12]) ! choose best df from candidate grid\n\n! Multiple regression\nz = x^2\nregress(y, x, z)                  ! multiple predictors via regress(...)\npoly1reg(y, x, 3)                 ! polynomial regression in one predictor up to degree 3\ndist_regress(normal, y, x, z)     ! Gaussian multiple regression\ndist_regress(t, y, x, z, df=8)    ! t-errors multiple regression with fixed df\n\n! No-predictor mode\ndist_regress(normal, y)           ! intercept-only normal model\ndist_regress(t, y)                ! intercept-only t model (df estimated)\ndist_regress(normal, y, intcp=0)  ! zero-mean normal model\ndist_regress(t, y, intcp=0, df=8) ! zero-mean t model with fixed df\n\n! AR/MA/ARMA fitting helpers\narfit(y, 1, 5)                    ! fit AR orders 1..5 and report fit metrics\nmafit(y, 1, 5)                    ! fit MA orders 1..5 and report fit metrics\narmafit(y, 1, 1)                  ! fit one ARMA(1,1) model\narsimfit(10^4, [0.6, 0.4])        ! simulate AR and fit default order=size(phi)\nmasimfit(10^4, [0.6, 0.4])        ! simulate MA and fit default order=size(theta)\narmasimfit(10^4, [0.6], [0.3])    ! simulate ARMA and fit default p=size(ar), q=size(ma)\narmafitgrid(y, 0, 3, 0, 3)        ! grid search over ARMA(p,q), p=0..3 and q=0..3\narmafitaic(y, 0, 5, 0, 5)         ! choose ARMA order by information criterion over p,q ranges\nfit_mixnorm(y, 2)                 ! fit a 2-component normal mixture [wgt, mean, sd]\nfit_mixnorm_aic(y, 1, 5, nstart=5, verbose=.true., plot=.true.) ! choose mixture size by AIC\n\n```\n\n`arfimafit(x, p, q)` prints a fit table including `npar` (number of estimated parameters), RMSE/AIC/BIC, and parameter estimates.\n`dist_regress` prints distribution, sample size, sigma, log-likelihood, AIC/BIC, and estimated coefficients. For `dist=t`, omitted `df` triggers df selection over an internal grid; supplying `df=[...]` uses that candidate set.\n\n## Resampling\n\n```text\nx = rnorm(100)\nresample(x)                       ! bootstrap sample, same size, with replacement\nresample(x, n=20)                 ! sample size 20\nresample(x, n=20, replace=0)      ! sample without replacement\n```\n\n## Distribution helpers\n\n- Most distributions expose `r*`/`d*`/`p*`/`q*` helpers plus `fit_*` and often `mssk_*`.\n\n```text\nx = rlnorm(5000, 0.0, 0.5)             ! r: random draws from Lognormal(meanlog, sdlog)\ndlnorm(x, 0.0, 0.5)                    ! d: lognormal density\nplnorm(x, 0.0, 0.5)                    ! p: lognormal CDF\nqlnorm(0.95, 0.0, 0.5)                 ! q: lognormal quantile\nskew_lnorm(0.5)                        ! theoretical skewness\nkurt_lnorm(0.5)                        ! theoretical excess kurtosis\nmssk_lnorm(0.0, 0.5)                   ! theoretical [mean, sd, skew, excess kurtosis]\nfit_lnorm(x)                           ! fit [meanlog, sdlog] from data\ndistaicscan(abs(x), 1)             ! fit compatible distributions and rank by AIC\n```\n\nSee [distributions.md](distributions.md) for interpreter-name to statistical-name mapping.\n\n## Data input modes\n\n```text\nread prices.csv                   ! REPL command: load named columns into workspace variables\nx = read(\"spy.csv\", 2)            ! function form: read numeric column 2 as a vector\nret = diff(log(read(\"spy.csv\", 2)))\n```\n\n## Robust stats and tests\n\n```text\nx = rnorm(300)\ny = rnorm(250)\n\ntrimmean(x)                        ! default 10% trimmed mean\ntrimmean(x, 0.2)                   ! 20% trimmed mean\nwinsor_mean(x, 0.1)                ! 10% winsorized mean\nhuber_mean(x)                      ! robust location (Huber M-estimator)\nhuber_mean(x, c=1.345)             ! scalar tuning constant\nhuber_mean(x, c=[1.0, 1.345, 2.0]) ! vector c -\u003e vector of estimates\nbisquare_mean(x)                   ! robust location (Tukey bisquare M-estimator)\nbisquare_mean(x, c=4.685)          ! scalar tuning constant\nbisquare_mean(x, c=[3.0, 4.685])   ! vector c -\u003e vector of estimates\nmad(x)                             ! median absolute deviation\niqr(x)                             ! interquartile range\niqr_scale(x)                       ! robust scale = IQR/1.349\n\njb_test(x)                         ! Jarque-Bera normality test -\u003e [JB, p]\nttest1(x, 0.0)                     ! one-sample t test -\u003e [t, df, p]\nttest2(x, y)                       ! Welch two-sample t test -\u003e [t, df, p]\nttest2(x, y, 1)                    ! pooled-variance two-sample t test\nks2_test(x, y)                     ! two-sample KS test -\u003e [D, p]\n\n! Kernel regression (1 predictor)\nxg = arange(300)/300\nyg = sin(6*xg) + 0.2*rnorm(300)\nyh = kernelreg(yg, xg)             ! Nadaraya-Watson estimate with default bandwidth\nyh = kernelreg(yg, xg, 0.06)       ! scalar bandwidth\nyh = kernelreg(yg, xg, [0.03,0.06,0.12]) ! vector bandwidth: plots one curve per bandwidth\nyh = kernelreg(yg, xg, 0.06, 1)    ! local linear fit (order=1)\nyh = kernelreg(yg, xg, 0.06, order=[0,1,2]) ! one bandwidth, multiple orders (plotted together)\nyh = kernelreg(yg, xg, [0.03,0.06], order=[0,1,2]) ! tensor product of bw and order curves\nyh = kernelreg(yg, xg, 0.06, points=.true.) ! overlay sample points on the fit plot\nyh = lowess(yg, xg)                         ! LOWESS with default span=0.3 and robust iterations\nyh = lowess(yg, xg, 0.2, it=1)              ! smaller span, one robust iteration\nyh = lowess(yg, xg, [0.15,0.3,0.5], plot=.true.) ! compare multiple spans on one plot\nyh = lowesscv(yg, xg)                       ! choose span by LOOCV over a default span grid\nyh = lowesscv(yg, xg, [0.1,0.2,0.3,0.4])    ! choose span by LOOCV over user grid\nyh = knnreg(yg, xg, 25)                     ! k-nearest-neighbors smoother (order=0 default)\nyh = knnreg(yg, xg, 25, order=1)            ! local linear fit on k-neighborhood\nyh = knnreg(yg, xg, [15,30,60], plot=.true.) ! compare multiple k values on one plot\nyh = knnregcv(yg, xg)                       ! choose k by LOOCV over a default k grid\nyh = knnregcv(yg, xg, [8,12,20,30], order=1) ! choose k by LOOCV over user k grid\n\n! Spline regression (plots fitted curve by default)\nyh = splinereg(yg, xg, 4)                    ! cubic spline with 4 interior knots\nyh = splinereg(yg, xg, 4, degree=1)          ! linear spline\nyh = splinereg(yg, xg, 4, degree=[1,2,3])    ! plots one fitted curve per degree\nyh = splinereg(yg, xg, 4, points=.true.)     ! overlay sample points on the fit plot\nyh = splinereg(yg, xg, 4, degree=3, plot=.false.) ! compute only (no plot)\n\n! Natural cubic spline regression (plots by default)\nyh = naturalspline(yg, xg)                   ! choose k by cross validation (plot title shows selected k)\nyh = naturalspline(yg, xg, 4)                ! natural cubic with 4 interior knots\nyh = naturalspline(yg, xg, [2,4,8])          ! plots one fitted curve per k\nyh = naturalspline(yg, xg, 4, points=.true.) ! overlay sample points on the fit plot\nyh = naturalspline(yg, xg, 4, plot=.false.)  ! compute only (no plot)\n\n! Plot output mode for whole session\nset plotout png                              ! save plots to PNG files\nset plotout pdf                              ! save plots to PDF files\nset plotout svg                              ! save plots to SVG files\nset plotout eps                              ! save plots to EPS files\nset plotout screen                           ! back to interactive windows\nset plotout                                  ! show current mode\n\n! Saved plots use title-based names, e.g. acf_0001.png, cpfit_0002.pdf\n\n! Changepoint simulation/fitting\nxcp = cpsim(400, [150,300])                  ! defaults: mu=0, sd=1, plot=.false.\nxcp = cpsim(400, [150,300], mu=[0,2,-1], sd=0.7, plot=.true.) ! plot data and true means\nxcp = cpsim(400, [150,300], verbose=.true.)  ! print true segment table (default verbose=.false.)\nfitcp = cpfit(xcp)                           ! defaults: mode=mean, max_cp=1, plot=.true.\nfitcp2 = cpfit(xcp, max_cp=3, minseg=20, plot=.false.)\nfitcp3 = cpfit(xcp, verbose=.false.)         ! suppress estimated segment table\nfitcp_sd = cpfit(xcp, mode=sd, max_cp=2, plot=.false.)   ! variance changepoints\nfitcp_both = cpfit(xcp, mode=both, max_cp=2, plot=.false.) ! mean+variance changepoints\nfitcp_best = cpfitaic(xcp, max_cp=5, criterion=aic, plot=.true.) ! choose best by AIC (default)\nfitcp_best2 = cpfitaic(xcp, max_cp=5, criterion=bic, plot=.false., plot_ic=.true.) ! IC-vs-max_cp plot\nfitcp_best3 = cpfitaic(xcp, max_cp=5, verbose=.true., plot=.false.) ! print per-model segment tables\n```\n\n## Sample session\n\n```text\n\u003e n = 10\n10.000000\n\n\u003e y = [1, 2, 3]\n[1.000000 2.000000 3.000000]\n\n\u003e z = n * y\n[10.000000 20.000000 30.000000]\n\n\u003e w = [10 20 30] + y\n[11.000000 22.000000 33.000000]\n\n\u003e z ^ 2\n[100.000000 400.000000 900.000000]\n\n\u003e x = runif(n)\n[.704414 .208529 .550907 .377847 .189410 .223593 .262786 .870069 .568524 .569907]\n\n\u003e sum(x)\n4.525986\n\n\u003e [sum(x) minval(x) maxval(x)]\n[4.525986 .189410 .870069]\n\n\u003e q\n```\n\nThe semicolon `;` can be used as a continuation separator and suppresses output when it appears at the end of the line. Iteration is supported with `*n` at the start of a line, meaning execute the rest of the line `n` times.\n\nExample (Newton iterations for `sqrt(3)`):\n\n```text\na = 3\nx = 1\n*5  x = (x + a/x)/2\n```\n\nTypical output:\n\n```text\n1.750000\n1.732143\n1.732051\n1.732051\n1.732051\n```\n\n## Build and run\n\n- Build interpreter:\n\n```bat\nmake\n```\n\n- Run interpreter executable:\n\n```bat\nfcalc.exe\n```\n\n- Run interpreter with plotting disabled:\n\n```bat\nfcalc.exe --noplot\n```\n\n## Transpiler (`transpile_session.py`)\n\nTranspiles a `.fi` session script to a standalone Fortran program.\n\n```bat\npython transpile_session.py code.fi -o tests.f90\nmake -f Makefile_tests\n```\n\n## Transpiler behavior (current)\n\n- Emits minimal `use ..., only:` imports.\n- Infers scalar/array/integer declarations and converts `const` assignments to `parameter` declarations.\n- Rewrites selected names to module procedures:\n  - `rnorm` -\u003e `random_normal`\n  - `sort` -\u003e `sorted`\n  - `stdz` -\u003e `standardize`\n  - `dot` -\u003e `dot_product`\n- Supports interpreter shorthand defaults for several distribution helpers by expanding omitted optional arguments (for compile-safe Fortran calls), e.g. `rexp(n)`, `rlnorm(n)`, `rlogis(n)`, `rgamma(n,a)`, and corresponding `mssk_*` calls.\n- Handles `read(\"file\", col)` in assignments by emitting `call read_vec(...)` and then applying any remaining expression.\n  - Example: `x = log(read(\"spy.csv\", 2))` transpiles to\n    - `call read_vec(\"spy.csv\", x, 2)`\n    - `x = log(x)`\n- Supports top-level `acf(..., plot=...)` / `pacf(..., plot=...)` by generating explicit plotting blocks in Fortran.\n- Rewrites `cor(...)` calls into compile-safe Fortran:\n  - pairwise `method=` shorthands (`pearson`/`spearman`/`kendall`) are normalized\n  - matrix-style `cor(x,y,z,...)` is lowered to labeled matrix-print helper calls\n- Supports `for ... in ...` / `end for` and one-line `for`/`do` loop forms.\n- Supports the newer analysis helpers used above (`poly1reg`, `distaicscan`, robust stats, and tests).\n- Rewrites legacy ARFIMA simulation call form when possible:\n  - `arfimasim(n, [phi], [theta], d)` -\u003e `arfimasim(n, d, phi=[phi], theta=[theta])`\n- Rewrites `iter=` to `niter=` where required by Fortran procedures (for relevant time-series helpers).\n- Rewrites integer order ranges to compile-safe forms for simulation-fit helpers:\n  - `arsimfit(..., arange(...))` / `masimfit(..., arange(...))` -\u003e `... irange(...)`\n  - `armasimfit(..., pvec=..., qvec=...)` order arguments are emitted as real vectors as required by the procedure interface.\n- Rewrites method-name shorthands to quoted strings where required (for example `method=burg` -\u003e `method=\"burg\"`).\n- Treats `run(\"...fi\")` in scripts as non-transpilable runtime control and comments it out in generated Fortran.\n\n## Batch transpile runner (`xpytr_all.py`)\n\nRuns `transpile_session.py` across many `.fi` scripts, compiles with `Makefile_tests`, and optionally runs interpreter scripts and generated executables.\n\n```bat\npython xpytr_all.py --include-re *simfit*.fi\n```\n\nCommon options:\n\n- `--include-re REGEX_OR_GLOB` include only matching files (supports regex, and glob-like patterns such as `*simfit*.fi`).\n- `--exclude-re REGEX_OR_GLOB` exclude matching files.\n- `--files \"a.fi b.fi\"` or `--files a.fi,b.fi` explicit file list.\n- `--limit N` process only first `N` selected files.\n- `--recent` process selected files from most recently modified to least recent.\n- `--run-script` run `fcalc` on each script before Fortran compile.\n- `--run-exe` run compiled `tests.exe`.\n- `--hide-output` suppress runtime stdout/stderr from interpreter/exe runs.\n- `--noplot` propagate `--noplot` to interpreter runs.\n- `--time` print timing DataFrame and summary stats.\n- `--fail-fast` stop on first failure.\n- `--resume` / `--restart` resume or reset checkpoint (`xpytr_all_state.json` by default).\n\nWhen failures occur, it writes `xpytr_all_errors.txt` containing, for each failed script:\n\n- original `.fi` script\n- transpiled `tests.f90` (when available)\n- tool/compiler/runtime output\n\n## Interpreter-only commands\n\nSome REPL/workspace commands are not mapped to standalone Fortran, e.g. `cor` (workspace correlation matrix mode), `?vars`, `clear`, `del ...`, and statement-form `read ...`.\n\n## Notes\n\n- Session logs and examples in this repository use `.fi` scripts.\n- `Makefile_tests` builds `tests.f90` together with project modules into `tests.exe`.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliavsky%2Fcalc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeliavsky%2Fcalc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeliavsky%2Fcalc/lists"}