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

Function textToBinary

SRC/handler/BinaryFileStream.cpp:688–765  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

OPS_convertTextToBinaryFunction · 0.50
convertTextToBinaryFunction · 0.50

Calls 4

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

Tested by

no test coverage detected