lfortran / lfortran

Official main repository for LFortran
https://lfortran.org/
Other
941 stars 151 forks source link

Support namelist #1999

Open certik opened 1 year ago

certik commented 1 year ago

https://github.com/certik/fastGPT/commit/11ead54d4943be4a1e189ce97b5f31c6a182dcb5

Shaikh-Ubaid commented 1 year ago

How do we support this? I guess we need a new data structure/node at the ASR Level.

certik commented 1 year ago

Yes, I need to think about it. This is very low priority, I think we'll just remove it from fastGPT. I initially thought I would set more variables this way, but it looks like we'll just set them at the command line if needed.

certik commented 1 year ago

Duplicate: https://github.com/lfortran/lfortran/issues/1851

certik commented 6 months ago

Let's figure out how to represent namelists at the ASR level. It would be good to design them in such a way as to allow (later) to represent any user-defined custom readers/writers for other formats like JSON, TOML, NPY, HDF5, GGUF, etc.

It looks like the read(u, input_fastGPT) line will read a structure format from the textual input file. One way is to transform it to something like _lfortran_namelist_read(u, "A", A, "B", B, etc.), and it would populate those variables if present in the input file. Similar to how we handle printing.

See also: https://github.com/j3-fortran/fortran_proposals/issues/331.

certik commented 6 months ago

One way that might work: read(u, input_fastGPT) where input_fastGPT is a namelist that contains arrays A, B and an integer i gets transformed into

_lfortran_namelist_context ctx;
_lfortran_namelist_read(u, &ctx);
_lfortran_namelist_read_array_f32(ctx, "A", size(A), A);
_lfortran_namelist_read_array_f64(ctx, "B", size(B), B);
_lfortran_namelist_read_i64(ctx, "i", i);

Let's check how other compilers do this.

certik commented 2 months ago

In the first implementation, let's do the following: