MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / open

Method open

SRC/handler/DataOutputFileHandler.cpp:68–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68int
69DataOutputFileHandler::open(char **dataDescription, int numData)
70{
71 if (fileName == 0) {
72 opserr << "DataOutputFileHandler::open() - no filename passed in constructor\n";
73 return -1;
74 }
75
76 if (dataDescription == 0) {
77 opserr << "DataOutputFileHandler::open() - no column description data passed\n";
78 return -1;
79 }
80
81 if (numData < 0) {
82 opserr << "DataOutputFileHandler::open() - numColumns (" << numData << ") < 0\n";
83 return -1;
84 } else
85 numColumns = numData;
86
87
88 if (theEchoMode == DATA_FILE) {
89 for (int i=0; i<numData; i++)
90 outputFile << dataDescription[i] << " ";
91 outputFile << endln;
92
93 } else if (theEchoMode == XML_FILE) {
94
95 // create a copy of the file name
96 int res = 0;
97 const char *name = outputFile.getFileName();
98 int fileNameLength = strlen(name);
99 char *xmlFileName = new char[fileNameLength + 5];
100
101 if (xmlFileName == 0) {
102 opserr << "DataOutputFileHandler::open - out of memory creating copy of string " << xmlFileName << endln;
103 return -1;
104 }
105
106 strcpy(xmlFileName, name);
107 if (fileNameLength > 4 && strcmp(".out", &name[fileNameLength-4]) == 0) {
108 xmlFileName[fileNameLength-4] = '\0';
109 }
110
111 strcat(xmlFileName,".xml");
112
113 FileStream xmlFile;
114 if (xmlFile.setFile(xmlFileName, OVERWRITE) == 0) {
115
116 // write the xml data
117 xmlFile << "<?xml version=\"1.0\"?>\n";
118 xmlFile << "<NumericalFileDataDescription>\n";
119 xmlFile << "\t<DataFile>\n";
120 xmlFile << "\t\t<DataFileName> " << name << "</DataFileName>\n";
121 xmlFile << "\t\t<NumberDataColumns> " << numData << "</NumberDataColumns>\n";
122 xmlFile << "\t</DataFile>\n";
123 for (int i=0; i<numData; i++) {
124 xmlFile << "\t<DataColumnDescription>\n";
125 xmlFile << "\t\t<ColumnLocation> " << i+1 << "</ColumnLocation>\n";

Callers

nothing calls this directly

Calls 3

getFileNameMethod · 0.45
setFileMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected