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

Function textToBinary

DEVELOPER/core/BinaryFileStream.cpp:687–764  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

685}
686
687int
688textToBinary(const char *inputFilename, const char *outputFilename)
689{
690 //
691 // open the files
692 //
693
694 ifstream input(inputFilename, ios::in);
695 ofstream output(outputFilename, ios::out | ios::binary);
696 if (input.bad()) {
697 std::cerr << "WARNING - BinaryFileStream - binaryToText()";
698 std::cerr << " - could not open file " << inputFilename << std::endl;
699 output.close();
700 return -1;
701 }
702 if (output.bad()) {
703 std::cerr << "WARNING - BinaryFileStream - binaryToText()";
704 std::cerr << " - could not open file " << outputFilename << std::endl;
705 output.close();
706 return -1;
707 }
708
709 //
710 // until done
711 // read input consisting doubles till \n and write to output file
712 //
713
714 char data[100];
715 char *dataNext;
716 double d;
717
718 while ( !input.eof()) {
719 string inputLine;
720 getline(input, inputLine);
721 const char *c = inputLine.data();
722 const char *cNext = c;
723
724 int loc = 0;
725 int endLoc = int(inputLine.length());
726 int numNumbers = 0;
727
728 while (loc < endLoc) {
729
730 int dataCount = 0;
731
732
733 while ((loc < endLoc) &&
734 (*cNext != ' ') &&
735 (*cNext != '\n')) {
736 data[dataCount++] = cNext[0];
737 cNext++;
738 loc++;
739 }
740
741 if (dataCount != 0) {
742 data[dataCount] = '\n';
743 d = strtod(&data[0], &dataNext);
744 output.write((char *)&d, 8);

Callers

nothing calls this directly

Calls 4

lengthMethod · 0.80
closeMethod · 0.45
dataMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected