From a80f90c40f40f3410d9f2564303e11920d866a18 Mon Sep 17 00:00:00 2001 From: Xu Li Date: Wed, 23 Apr 2014 13:44:28 -0400 Subject: [PATCH] update support of load function 1. the built-in load will mark the data variable to unknown size; 2. for the back end, it needs a user-defined subroutine to preprocess the data file to get the shape of the data, and then use the result to allocate data variable. Migrated from Sable/mclab@de40a26ddab7be28c6896ecf6916f95fff226b6e --- .../FortranCodeASTGenerator.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/languages/Natlab/src/natlab/backends/Fortran/codegen_readable/FortranCodeASTGenerator.java b/languages/Natlab/src/natlab/backends/Fortran/codegen_readable/FortranCodeASTGenerator.java index ec956c8..713357d 100644 --- a/languages/Natlab/src/natlab/backends/Fortran/codegen_readable/FortranCodeASTGenerator.java +++ b/languages/Natlab/src/natlab/backends/Fortran/codegen_readable/FortranCodeASTGenerator.java @@ -374,6 +374,25 @@ else if (rhsString.substring(0, rhsString.indexOf("(")).equals("load")) { String fileName = rhsString.substring(rhsString.indexOf("(") + 1, rhsString.indexOf(")")).replace("'", ""); sb.append("OPEN(UNIT = 1, FILE = \"" + fileName + "\");\n"); String varName = fileName.split("\\.")[0]; + // TODO adding some preprocessing function to get the shape of the file. + sb.append(getMoreIndent(0) + "CALL file_analyze('" + fileName + "', " + varName + "_r, " + varName + "_c);\n"); + sb.append(getMoreIndent(0) + "ALLOCATE(" + varName + "(" + varName + "_r, " + varName + "_c));\n"); + fotranTemporaries.put(varName + "_r", new BasicMatrixValue( + null, + PrimitiveClassReference.INT32, + new ShapeFactory>().getScalarShape(), + null, + new isComplexInfoFactory>() + .newisComplexInfoFromStr("REAL") + )); + fotranTemporaries.put(varName + "_c", new BasicMatrixValue( + null, + PrimitiveClassReference.INT32, + new ShapeFactory>().getScalarShape(), + null, + new isComplexInfoFactory>() + .newisComplexInfoFromStr("REAL") + )); sb.append(getMoreIndent(0) + "DO row_" + varName + " = 1, SIZE(" + varName + ", 1)\n"); sb.append(getMoreIndent(1) + "READ(1, *) " + varName + "(row_" + varName + ", :);\n"); sb.append(getMoreIndent(0) + "END DO\n");