Skip to content

Commit

Permalink
update support of load function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Xu Li committed Apr 23, 2014
1 parent 9f5e2c3 commit a80f90c
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AggrValue<BasicMatrixValue>>().getScalarShape(),
null,
new isComplexInfoFactory<AggrValue<BasicMatrixValue>>()
.newisComplexInfoFromStr("REAL")
));
fotranTemporaries.put(varName + "_c", new BasicMatrixValue(
null,
PrimitiveClassReference.INT32,
new ShapeFactory<AggrValue<BasicMatrixValue>>().getScalarShape(),
null,
new isComplexInfoFactory<AggrValue<BasicMatrixValue>>()
.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");
Expand Down

0 comments on commit a80f90c

Please sign in to comment.