Lemma is an Electromagnetics API
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

utSerialize.cpp 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 09/29/2014 01:31:26 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2014, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2014, Trevor Irons
  16. */
  17. #include "Lemma"
  18. using namespace Lemma;
  19. #ifdef HAVE_YAMLCPP
  20. #include "yaml-cpp/yaml.h"
  21. int main() {
  22. std::ofstream ofstr("output.yaml");
  23. //ofstr << "%YAML 1.2\n" << "---\n";
  24. //ofstr << "LEMMA_CLASSES:\n";
  25. // This works for individual classes or even groups of unrelated classes. But
  26. // How should references work? One option would be to hack YAML and allow for references
  27. // across 'Docs'. This is maybe undesireable, as then it's not valid YAML anymore.
  28. // OR we could have some other kind of IDENTIFIER that could be used and Connections could be
  29. // made AFTER the whole file is processed?
  30. // Alternative is each class is written to it's own file. And then implicit on the Serialize function, the file tags are written
  31. // into the YAML instead of the pointer. Alternatively, tags could do this too.
  32. // Or file could be saved as pointer.yaml
  33. // *
  34. // * Or a file contains all the subclasses it point to. So that it's self-enclosed. This is nice as it's quite
  35. // * flexible. The only downwside is possible repeat of classes. Basically if the API is careful though, only 1
  36. // * instance will need to be serialized.
  37. // *
  38. TEMTransmitter* Seq = TEMTransmitter::New();
  39. Seq->SetRepFrequency( 20, KHZ );
  40. VectorXr Times (18);
  41. VectorXr Amps (18);
  42. Times << 0.0, 0.03051, 0.10267, 0.19408, 0.19889, 0.21332, 0.74249, 1.3775, 1.83452, 2.52245, \
  43. 3.191132, 3.9031135, 4.0, 4.00484486, 4.123904, 4.200182, 4.20732, 4.212946;
  44. Amps << 0.0, 14.71872, 62.34372, 114.84372, 117.84372, 118.96872, 118.96872, 118.96872, 118.96872,\
  45. 118.59372, 119.34372, 120.0, 120.0, 117.94176, 47.60364, 0.8905848, 0.1203888, 0.0;
  46. Seq->SetWaveform(Times, Amps, MILLISEC);
  47. // OK dump to disk
  48. ofstr << *Seq ;
  49. ofstr.close();
  50. Seq->Delete();
  51. // OK now load
  52. std::ifstream ifstr("output.yaml");
  53. std::vector<YAML::Node> nodes = YAML::LoadAll(ifstr);
  54. TEMTransmitter* Seq2 = TEMTransmitter::DeSerialize( nodes[0] );
  55. std::cout << "Loaded\n" << *Seq2;
  56. Seq2->Delete();
  57. ifstr.close();
  58. //YAML::Node nodes = YAML::LoadFile("output.yaml");
  59. //std::cout << nodes[0] << std::endl;
  60. //std::cout << nodes[1] << std::endl;
  61. exit(EXIT_SUCCESS);
  62. }
  63. #else
  64. int main() {
  65. }
  66. #endif