libMesh
xdr_cxx.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 // C/C++ includes
20 #include <cstring>
21 #include <limits>
22 #include <iomanip>
23 #include <sstream>
24 #include <fstream>
25 
26 #include <unistd.h> // for getpid()
27 
28 // Local includes
29 #include "libmesh/xdr_cxx.h"
30 #include "libmesh/libmesh_logging.h"
31 #ifdef LIBMESH_HAVE_GZSTREAM
32 # include "libmesh/ignore_warnings.h" // shadowing in gzstream.h
33 # include "gzstream.h" // For reading/writing compressed streams
34 # include "libmesh/restore_warnings.h"
35 #endif
36 #include "libmesh/auto_ptr.h" // libmesh_make_unique
37 
38 // Anonymous namespace for implementation details.
39 namespace {
40 
41 // Nasty hacks for reading/writing zipped files
42 void bzip_file (const std::string & unzipped_name)
43 {
44 #ifdef LIBMESH_HAVE_BZIP
45  LOG_SCOPE("system(bzip2)", "XdrIO");
46 
47  std::string system_string = "bzip2 -f ";
48  system_string += unzipped_name;
49  if (std::system(system_string.c_str()))
50  libmesh_file_error(system_string);
51 #else
52  libmesh_error_msg("ERROR: need bzip2/bunzip2 to create " << unzipped_name << ".bz2");
53 #endif
54 }
55 
56 std::string unzip_file (const std::string & name)
57 {
58  std::ostringstream pid_suffix;
59  pid_suffix << '_' << getpid();
60 
61  std::string new_name = name;
62  if (name.size() - name.rfind(".bz2") == 4)
63  {
64 #ifdef LIBMESH_HAVE_BZIP
65  new_name.erase(new_name.end() - 4, new_name.end());
66  new_name += pid_suffix.str();
67  LOG_SCOPE("system(bunzip2)", "XdrIO");
68  std::string system_string = "bunzip2 -f -k -c ";
69  system_string += name + " > " + new_name;
70  if (std::system(system_string.c_str()))
71  libmesh_file_error(system_string);
72 #else
73  libmesh_error_msg("ERROR: need bzip2/bunzip2 to open .bz2 file " << name);
74 #endif
75  }
76  else if (name.size() - name.rfind(".xz") == 3)
77  {
78 #ifdef LIBMESH_HAVE_XZ
79  new_name.erase(new_name.end() - 3, new_name.end());
80  new_name += pid_suffix.str();
81  LOG_SCOPE("system(xz -d)", "XdrIO");
82  std::string system_string = "xz -f -d -k -c ";
83  system_string += name + " > " + new_name;
84  if (std::system(system_string.c_str()))
85  libmesh_file_error(system_string);
86 #else
87  libmesh_error_msg("ERROR: need xz to open .xz file " << name);
88 #endif
89  }
90  return new_name;
91 }
92 
93 void xzip_file (const std::string & unzipped_name)
94 {
95 #ifdef LIBMESH_HAVE_XZ
96  LOG_SCOPE("system(xz)", "XdrIO");
97 
98  std::string system_string = "xz -f ";
99  system_string += unzipped_name;
100  if (std::system(system_string.c_str()))
101  libmesh_file_error(system_string);
102 #else
103  libmesh_error_msg("ERROR: need xz to create " << unzipped_name << ".xz");
104 #endif
105 }
106 
107 
108 // remove an unzipped file
109 void remove_unzipped_file (const std::string & name)
110 {
111  std::ostringstream pid_suffix;
112  pid_suffix << '_' << getpid();
113 
114  // If we temporarily decompressed a file, remove the
115  // uncompressed version
116  if (name.size() - name.rfind(".bz2") == 4)
117  {
118  std::string new_name(name.begin(), name.end()-4);
119  new_name += pid_suffix.str();
120  std::remove(new_name.c_str());
121  }
122  if (name.size() - name.rfind(".xz") == 3)
123  {
124  std::string new_name(name.begin(), name.end()-3);
125  new_name += pid_suffix.str();
126  std::remove(new_name.c_str());
127  }
128 }
129 }
130 
131 namespace libMesh
132 {
133 
134 //-------------------------------------------------------------
135 // Xdr class implementation
136 Xdr::Xdr (const std::string & name,
137  const XdrMODE m) :
138  mode(m),
139  file_name(name),
140 #ifdef LIBMESH_HAVE_XDR
141  fp(nullptr),
142 #endif
143  in(),
144  out(),
145  comm_len(xdr_MAX_STRING_LENGTH),
146  gzipped_file(false),
147  bzipped_file(false),
148  xzipped_file(false)
149 {
150  this->open(name);
151 }
152 
153 
154 
156 {
157  this->close();
158 }
159 
160 
161 
162 void Xdr::open (const std::string & name)
163 {
164  file_name = name;
165 
166  if (name == "")
167  return;
168 
169  switch (mode)
170  {
171  case ENCODE:
172  case DECODE:
173  {
174 #ifdef LIBMESH_HAVE_XDR
175 
176  fp = fopen(name.c_str(), (mode == ENCODE) ? "w" : "r");
177  if (!fp)
178  libmesh_file_error(name.c_str());
179  xdrs = libmesh_make_unique<XDR>();
180  xdrstdio_create (xdrs.get(), fp, (mode == ENCODE) ? XDR_ENCODE : XDR_DECODE);
181 #else
182 
183  libmesh_error_msg("ERROR: Functionality is not available.\n" \
184  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
185  << "The XDR interface is not available in this installation");
186 
187 #endif
188  return;
189 
190  }
191 
192  case READ:
193  {
194  gzipped_file = (name.size() - name.rfind(".gz") == 3);
195  bzipped_file = (name.size() - name.rfind(".bz2") == 4);
196  xzipped_file = (name.size() - name.rfind(".xz") == 3);
197 
198  if (gzipped_file)
199  {
200 #ifdef LIBMESH_HAVE_GZSTREAM
201  igzstream * inf = new igzstream;
202  libmesh_assert(inf);
203  in.reset(inf);
204  inf->open(name.c_str(), std::ios::in);
205 #else
206  libmesh_error_msg("ERROR: need gzstream to handle .gz files!!!");
207 #endif
208  }
209  else
210  {
211  std::ifstream * inf = new std::ifstream;
212  libmesh_assert(inf);
213  in.reset(inf);
214 
215  std::string new_name = unzip_file(name);
216 
217  inf->open(new_name.c_str(), std::ios::in);
218  }
219 
220  libmesh_assert(in.get());
221 
222  if (!in->good())
223  libmesh_file_error(name);
224  return;
225  }
226 
227  case WRITE:
228  {
229  gzipped_file = (name.size() - name.rfind(".gz") == 3);
230  bzipped_file = (name.size() - name.rfind(".bz2") == 4);
231  xzipped_file = (name.size() - name.rfind(".xz") == 3);
232 
233  if (gzipped_file)
234  {
235 #ifdef LIBMESH_HAVE_GZSTREAM
236  ogzstream * outf = new ogzstream;
237  libmesh_assert(outf);
238  out.reset(outf);
239  outf->open(name.c_str(), std::ios::out);
240 #else
241  libmesh_error_msg("ERROR: need gzstream to handle .gz files!!!");
242 #endif
243  }
244  else
245  {
246  std::ofstream * outf = new std::ofstream;
247  libmesh_assert(outf);
248  out.reset(outf);
249 
250  std::string new_name = name;
251 
252  if (bzipped_file)
253  new_name.erase(new_name.end() - 4, new_name.end());
254 
255  if (xzipped_file)
256  new_name.erase(new_name.end() - 3, new_name.end());
257 
258  outf->open(new_name.c_str(), std::ios::out);
259  }
260 
261  libmesh_assert(out.get());
262  libmesh_assert (out->good());
263  return;
264  }
265 
266  default:
267  libmesh_error_msg("Invalid mode = " << mode);
268  }
269 }
270 
271 
272 
273 void Xdr::close ()
274 {
275  switch (mode)
276  {
277  case ENCODE:
278  case DECODE:
279  {
280 #ifdef LIBMESH_HAVE_XDR
281 
282  if (xdrs)
283  {
284  xdr_destroy (xdrs.get());
285  xdrs.reset();
286  }
287 
288  if (fp)
289  {
290  fflush(fp);
291  fclose(fp);
292  fp = nullptr;
293  }
294 #else
295 
296  libmesh_error_msg("ERROR: Functionality is not available.\n" \
297  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
298  << "The XDR interface is not available in this installation");
299 
300 #endif
301  file_name = "";
302  return;
303  }
304 
305  case READ:
306  {
307  if (in.get() != nullptr)
308  {
309  in.reset();
310 
311  if (bzipped_file || xzipped_file)
312  remove_unzipped_file(file_name);
313  }
314  file_name = "";
315  return;
316  }
317 
318  case WRITE:
319  {
320  if (out.get() != nullptr)
321  {
322  out.reset();
323 
324  if (bzipped_file)
325  bzip_file(std::string(file_name.begin(), file_name.end()-4));
326 
327  else if (xzipped_file)
328  xzip_file(std::string(file_name.begin(), file_name.end()-3));
329  }
330  file_name = "";
331  return;
332  }
333 
334  default:
335  libmesh_error_msg("Invalid mode = " << mode);
336  }
337 }
338 
339 
340 
341 bool Xdr::is_open() const
342 {
343  switch (mode)
344  {
345  case ENCODE:
346  case DECODE:
347  {
348 #ifdef LIBMESH_HAVE_XDR
349 
350  if (fp)
351  if (xdrs)
352  return true;
353 
354  return false;
355 
356 #else
357 
358  libmesh_error_msg("ERROR: Functionality is not available.\n" \
359  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
360  << "The XDR interface is not available in this installation");
361 
362  return false;
363 
364 #endif
365 
366  }
367 
368  case READ:
369  {
370  if (in.get() != nullptr)
371  return in->good();
372  return false;
373  }
374 
375  case WRITE:
376  {
377  if (out.get() != nullptr)
378  return out->good();
379  return false;
380  }
381 
382  default:
383  libmesh_error_msg("Invalid mode = " << mode);
384  }
385 
386  return false;
387 }
388 
389 
390 
392 {
393  switch (mode)
394  {
395  case ENCODE:
396  case DECODE:
397  {
398 #ifdef LIBMESH_HAVE_XDR
400 
401  // Are we already at eof?
402  if (feof(fp))
403  return true;
404 
405  // Or about to reach eof?
406  int next = fgetc(fp);
407  if (next == EOF)
408  {
409  // We should *only* be at EOF, not otherwise broken
410  libmesh_assert(feof(fp));
411  libmesh_assert(!ferror(fp));
412 
413  // Reset the EOF indicator
414  clearerr(fp);
415  libmesh_assert(!ferror(fp));
416 
417  // We saw EOF
418  return true;
419  }
420 
421  // We didn't see EOF; restore whatever we did see.
422  ungetc(next, fp);
423  break;
424 #else
425 
426  libmesh_error_msg("ERROR: Functionality is not available.\n" \
427  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
428  << "The XDR interface is not available in this installation");
429 
430  return false;
431 
432 #endif
433 
434  }
435  case READ:
436  {
437  libmesh_assert(in.get());
438 
439  // Are we already at eof?
440  if (in->eof())
441  return true;
442 
443  // Or about to reach eof?
444  int next = in->peek();
445  if (next == EOF)
446  {
447  // We should *only* be at EOF, not otherwise broken
448  libmesh_assert(in->eof());
449  libmesh_assert(!in->fail());
450 
451  // Reset the EOF indicator
452  in->clear();
453  libmesh_assert(in->good());
454 
455  // We saw EOF
456  return true;
457  }
458  break;
459  }
460  default:
461  libmesh_error();
462  }
463 
464  return false;
465 }
466 
467 
468 
469 #ifdef LIBMESH_HAVE_XDR
470 
471 // Anonymous namespace for Xdr::data helper functions
472 namespace
473 {
474 
475 template <typename T>
476 xdrproc_t xdr_translator();
477 
478 template <typename T>
479 bool xdr_translate(XDR * x, T & a)
480 {
481  return (xdr_translator<T>())(x, &a, 0);
482 }
483 
484 template <>
485 bool xdr_translate(XDR * x,
486  std::string & s)
487 {
488  char sptr[xdr_MAX_STRING_LENGTH+1];
489  std::copy(s.begin(), s.end(), sptr);
490  sptr[s.size()] = 0;
491  unsigned int length = xdr_MAX_STRING_LENGTH;
492 
493  // Get a pointer to the beginning of the buffer. We need to pass
494  // its address to the xdr API.
495  char * begin = sptr;
496  bool b = xdr_string(x, &begin, length);
497 
498  // This is necessary when reading, but inefficient when writing...
499  length = cast_int<unsigned int>(std::strlen(sptr));
500  s.resize(length);
501  std::copy(sptr, sptr+length, s.begin());
502 
503  return b;
504 }
505 
506 template <typename T>
507 bool xdr_translate(XDR * x, std::complex<T> & a)
508 {
509  T r = a.real(), i = a.imag();
510  bool b1 = xdr_translate(x, r);
511  bool b2 = xdr_translate(x, i);
512  a = std::complex<T>(r,i);
513  return (b1 && b2);
514 }
515 
516 template <typename T>
517 bool xdr_translate(XDR * x, std::vector<T> & a)
518 {
519  unsigned int length = cast_int<unsigned int>(a.size());
520  xdr_u_int(x, &length);
521  if (length > 0)
522  {
523  a.resize(length);
524  return xdr_vector(x, reinterpret_cast<char *>(a.data()), length, sizeof(T),
525  xdr_translator<T>());
526  }
527  else
528  return true;
529 }
530 
531 template <typename T>
532 bool xdr_translate(XDR * x, std::vector<std::complex<T>> & a)
533 {
534  unsigned int length = cast_int<unsigned int>(a.size());
535  bool b = xdr_u_int(x, &length);
536  a.resize(length);
537  for (auto & val : a)
538  if (!xdr_translate(x, val))
539  b = false;
540  return b;
541 }
542 
543 template <>
544 bool xdr_translate(XDR * x, std::vector<std::string> & s)
545 {
546  unsigned int length = cast_int<unsigned int>(s.size());
547  bool b = xdr_u_int(x, &length);
548  s.resize(length);
549  for (auto & val : s)
550  if (!xdr_translate(x, val))
551  b = false;
552  return b;
553 }
554 
555 template <>
556 xdrproc_t xdr_translator<int>()
557 {
558  // Don't let XDR truncate anything on systems where int is 64-bit;
559  // xdr_int is hard-coded to write 32 bits.
560  if (sizeof(int) <= 4)
561  return (xdrproc_t)(xdr_int);
562  else if (sizeof(int) == sizeof(long long))
563  return (xdrproc_t)(xdr_longlong_t);
564  else if (sizeof(int) == sizeof(long))
565  return (xdrproc_t)(xdr_long);
566  else
567  libmesh_error();
568 }
569 
570 template <>
571 xdrproc_t xdr_translator<unsigned int>()
572 {
573  // Don't let XDR truncate anything on systems where int is 64-bit;
574  // xdr_u_int is hard-coded to write 32 bits.
575  if (sizeof(unsigned int) <= 4)
576  return (xdrproc_t)(xdr_u_int);
577  else if (sizeof(unsigned int) == sizeof(unsigned long))
578  return (xdrproc_t)(xdr_u_long);
579  else if (sizeof(unsigned int) == sizeof(unsigned long long))
580  return (xdrproc_t)(xdr_u_longlong_t);
581  else
582  libmesh_error();
583 }
584 
585 template <>
586 xdrproc_t xdr_translator<long int>()
587 {
588  // Don't let XDR truncate anything on systems where long is 64-bit;
589  // xdr_long is hard-coded to write 32 bits.
590  if (sizeof(long int) <= 4)
591  return (xdrproc_t)(xdr_long);
592  else if (sizeof(long int) == sizeof(long long))
593  return (xdrproc_t)(xdr_longlong_t);
594  else
595  libmesh_error();
596 }
597 
598 template <>
599 xdrproc_t xdr_translator<unsigned long int>()
600 {
601  // Don't let XDR truncate anything on systems where long is 64-bit;
602  // xdr_u_long is hard-coded to write 32 bits. This bit us HARD.
603  if (sizeof(unsigned long int) <= 4)
604  return (xdrproc_t)(xdr_u_long);
605  else if (sizeof(unsigned long int) == sizeof(unsigned long long))
606  return (xdrproc_t)(xdr_u_longlong_t);
607  else
608  libmesh_error();
609 }
610 
611 // All the other XDR routines should be safe, unless
612 // 1. You're on a system with sizeof(short)==8 and you want to store
613 // n>2^32 in a short; this will never happen since we assume
614 // sizeof(short) may be as small as 2 bytes and we use at least int
615 // for anything larger.
616 // 2. You're on a system with sizeof(long long) > 8, and you want to
617 // store n>2^64 in one. Welcome, 22nd century programmers; sorry we
618 // couldn't accomodate you.
619 template <>
620 xdrproc_t xdr_translator<long long>() { return (xdrproc_t)(xdr_longlong_t); }
621 
622 template <>
623 xdrproc_t xdr_translator<unsigned long long>() { return (xdrproc_t)(xdr_u_longlong_t); }
624 
625 template <>
626 xdrproc_t xdr_translator<short int>() { return (xdrproc_t)(xdr_short); }
627 
628 template <>
629 xdrproc_t xdr_translator<unsigned short int>() { return (xdrproc_t)(xdr_u_short); }
630 
631 template <>
632 xdrproc_t xdr_translator<char>() { return (xdrproc_t)(xdr_char); }
633 
634 template <>
635 xdrproc_t xdr_translator<signed char>() { return (xdrproc_t)(xdr_char); }
636 
637 template <>
638 xdrproc_t xdr_translator<unsigned char>() { return (xdrproc_t)(xdr_u_char); }
639 
640 template <>
641 xdrproc_t xdr_translator<float>() { return (xdrproc_t)(xdr_float); }
642 
643 template <>
644 xdrproc_t xdr_translator<double>() { return (xdrproc_t)(xdr_double); }
645 
646 // FIXME - no XDR love for quadruple precision; not even for long double?
647 template <>
648 xdrproc_t xdr_translator<long double>() { return (xdrproc_t)(xdr_double); }
649 
650 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
651 template <>
652 xdrproc_t xdr_translator<Real>() { return (xdrproc_t)(xdr_double); }
653 #endif
654 
655 } // end anonymous namespace
656 
657 #endif
658 
659 template <typename T>
660 void Xdr::do_read(T & a)
661 {
662  *in >> a;
663  in->getline(comm, comm_len);
664 }
665 
666 template <typename T>
667 void Xdr::do_read(std::complex<T> & a)
668 {
669  T r, i;
670  *in >> r >> i;
671  a = std::complex<T>(r,i);
672  in->getline(comm, comm_len);
673 }
674 
675 template <>
676 void Xdr::do_read(std::string & a)
677 {
678  in->getline(comm, comm_len);
679 
680  a = "";
681 
682  for (unsigned int c=0, sl=std::strlen(comm); c!=sl; c++)
683  {
684  if (comm[c] == '\t')
685  break;
686  a.push_back(comm[c]);
687  }
688 }
689 
690 template <typename T>
691 void Xdr::do_read(std::vector<T> & a)
692 {
693  unsigned int length=0;
694  data(length, "# vector length");
695  a.resize(length);
696 
697  for (T & a_i : a)
698  {
699  libmesh_assert(in.get());
700  libmesh_assert (in->good());
701  *in >> a_i;
702  }
703  in->getline(comm, comm_len);
704 }
705 
706 template <typename T>
707 void Xdr::do_read(std::vector<std::complex<T>> & a)
708 {
709  unsigned int length=0;
710  data(length, "# vector length x 2 (complex)");
711  a.resize(length);
712 
713  for (std::complex<T> & a_i : a)
714  {
715  T r, im;
716  libmesh_assert(in.get());
717  libmesh_assert (in->good());
718  *in >> r >> im;
719  a_i = std::complex<T>(r,im);
720  }
721  in->getline(comm, comm_len);
722 }
723 
724 template <typename T>
725 void Xdr::do_write(T & a) { *out << a; }
726 
727 template <typename T>
728 void Xdr::do_write(std::complex<T> & a)
729 {
730  *out << a.real() << "\t " << a.imag();
731 }
732 
733 template <typename T>
734 void Xdr::do_write(std::vector<T> & a)
735 {
736  std::size_t length = a.size();
737  data(length, "# vector length");
738 
739  for (T & a_i : a)
740  {
741  libmesh_assert(out.get());
742  libmesh_assert (out->good());
743  this->do_write(a_i);
744  *out << "\t ";
745  }
746 }
747 
748 template <typename T>
749 void Xdr::do_write(std::vector<std::complex<T>> & a)
750 {
751  std::size_t length=a.size();
752  data(length, "# vector length x 2 (complex)");
753 
754  for (std::complex<T> & a_i : a)
755  {
756  libmesh_assert(out.get());
757  libmesh_assert (out->good());
758  this->do_write(a_i);
759  *out << "\t ";
760  }
761 }
762 
763 
764 
765 template <typename T>
766 void Xdr::data (T & a, const char * comment_in)
767 {
768  switch (mode)
769  {
770  case ENCODE:
771  case DECODE:
772  {
773 #ifdef LIBMESH_HAVE_XDR
774 
776 
777  xdr_translate(xdrs.get(), a);
778 
779 #else
780 
781  libmesh_error_msg("ERROR: Functionality is not available.\n" \
782  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
783  << "The XDR interface is not available in this installation");
784 
785 #endif
786  return;
787  }
788 
789  case READ:
790  {
791  libmesh_assert(in.get());
792  libmesh_assert (in->good());
793 
794  this->do_read(a);
795 
796  return;
797  }
798 
799  case WRITE:
800  {
801  libmesh_assert(out.get());
802  libmesh_assert (out->good());
803 
804  // We will use scientific notation sufficient to exactly
805  // represent our floating point precision in the following
806  // output. The desired precision and format will
807  // automatically determine the width.
808  *out << std::scientific
809  << std::setprecision(std::numeric_limits<T>::max_digits10);
810 
811  this->do_write(a);
812 
813  // If there's a comment provided, write a tab character and
814  // then the comment.
815  if (std::string(comment_in) != "")
816  *out << "\t " << comment_in;
817 
818  // Go to the next line.
819  *out << '\n';
820 
821  return;
822  }
823 
824  default:
825  libmesh_error_msg("Invalid mode = " << mode);
826  }
827 }
828 
829 
830 template <typename T>
831 void Xdr::data_stream (T * val, const unsigned int len, const unsigned int line_break)
832 {
833  switch (mode)
834  {
835  case ENCODE:
836  {
837 #ifdef LIBMESH_HAVE_XDR
838 
839  libmesh_assert (this->is_open());
840 
841  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
842 
843  xdr_vector(xdrs.get(),
844  (char *) val,
845  len,
846  size_of_type,
847  xdr_translator<T>());
848 #else
849  libmesh_error_msg("ERROR: Functionality is not available.\n" \
850  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
851  << "The XDR interface is not available in this installation");
852 
853 #endif
854  return;
855  }
856 
857  case DECODE:
858  {
859 #ifdef LIBMESH_HAVE_XDR
860 
861  libmesh_assert (this->is_open());
862 
863  unsigned int size_of_type = cast_int<unsigned int>(sizeof(T));
864 
865  if (len > 0)
866  xdr_vector(xdrs.get(),
867  (char *) val,
868  len,
869  size_of_type,
870  xdr_translator<T>());
871 #else
872  libmesh_error_msg("ERROR: Functionality is not available.\n" \
873  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
874  << "The XDR interface is not available in this installation");
875 
876 #endif
877  return;
878  }
879 
880  case READ:
881  {
882  libmesh_assert(in.get());
883  libmesh_assert (in->good());
884 
885  for (unsigned int i=0; i<len; i++)
886  {
887  libmesh_assert(in.get());
888  libmesh_assert (in->good());
889  *in >> val[i];
890  }
891 
892  return;
893  }
894 
895  case WRITE:
896  {
897  libmesh_assert(out.get());
898  libmesh_assert (out->good());
899 
900  // We will use scientific notation sufficient to exactly
901  // represent our floating point precision in the following
902  // output. The desired precision and format will
903  // automatically determine the width.
904  *out << std::scientific
905  << std::setprecision(std::numeric_limits<T>::max_digits10);
906 
907  if (line_break == libMesh::invalid_uint)
908  for (unsigned int i=0; i<len; i++)
909  {
910  libmesh_assert(out.get());
911  libmesh_assert (out->good());
912  *out << val[i] << " ";
913  }
914  else
915  {
916  const unsigned imax = std::min(line_break, len);
917  unsigned int cnt=0;
918  while (cnt < len)
919  {
920  for (unsigned int i=0; i<imax; i++)
921  {
922  libmesh_assert(out.get());
923  libmesh_assert (out->good());
924  *out << val[cnt++];
925 
926  // Write a space unless this is the last character on the current line.
927  if (i+1 != imax)
928  *out << " ";
929  }
930  libmesh_assert(out.get());
931  libmesh_assert (out->good());
932  *out << '\n';
933  }
934  }
935 
936  return;
937  }
938 
939  default:
940  libmesh_error_msg("Invalid mode = " << mode);
941  }
942 }
943 
944 
945 
946 template <>
947 void Xdr::data_stream (double * val, const unsigned int len, const unsigned int line_break)
948 {
949  switch (mode)
950  {
951  case ENCODE:
952  case DECODE:
953  {
954 #ifdef LIBMESH_HAVE_XDR
955 
956  libmesh_assert (this->is_open());
957 
958  if (len > 0)
959  xdr_vector(xdrs.get(),
960  (char *) val,
961  len,
962  sizeof(double),
963  (xdrproc_t) xdr_double);
964 
965 #else
966 
967  libmesh_error_msg("ERROR: Functionality is not available.\n" \
968  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
969  << "The XDR interface is not available in this installation");
970 
971 #endif
972  return;
973  }
974 
975  case READ:
976  {
977  libmesh_assert(in.get());
978  libmesh_assert (in->good());
979 
980  for (unsigned int i=0; i<len; i++)
981  {
982  libmesh_assert(in.get());
983  libmesh_assert (in->good());
984  *in >> val[i];
985  }
986 
987  return;
988  }
989 
990  case WRITE:
991  {
992  libmesh_assert(out.get());
993  libmesh_assert (out->good());
994 
995  // Save stream flags
996  std::ios_base::fmtflags out_flags = out->flags();
997 
998  // We will use scientific notation sufficient to exactly
999  // represent our floating point precision in the following
1000  // output. The desired precision and format will
1001  // automatically determine the width.
1002  *out << std::scientific
1003  << std::setprecision(std::numeric_limits<double>::max_digits10);
1004 
1005  if (line_break == libMesh::invalid_uint)
1006  for (unsigned int i=0; i<len; i++)
1007  {
1008  libmesh_assert(out.get());
1009  libmesh_assert (out->good());
1010  *out << val[i] << ' ';
1011  }
1012  else
1013  {
1014  const unsigned imax = std::min(line_break, len);
1015  unsigned int cnt=0;
1016  while (cnt < len)
1017  {
1018  for (unsigned int i=0; i<imax; i++)
1019  {
1020  libmesh_assert(out.get());
1021  libmesh_assert (out->good());
1022  *out << val[cnt++];
1023 
1024  // Write a space unless this is the last character on the current line.
1025  if (i+1 != imax)
1026  *out << " ";
1027  }
1028  libmesh_assert(out.get());
1029  libmesh_assert (out->good());
1030  *out << '\n';
1031  }
1032  }
1033 
1034  // Restore stream flags
1035  out->flags(out_flags);
1036 
1037  return;
1038  }
1039 
1040  default:
1041  libmesh_error_msg("Invalid mode = " << mode);
1042  }
1043 }
1044 
1045 
1046 template <>
1047 void Xdr::data_stream (float * val, const unsigned int len, const unsigned int line_break)
1048 {
1049  switch (mode)
1050  {
1051  case ENCODE:
1052  case DECODE:
1053  {
1054 #ifdef LIBMESH_HAVE_XDR
1055 
1056  libmesh_assert (this->is_open());
1057 
1058  if (len > 0)
1059  xdr_vector(xdrs.get(),
1060  (char *) val,
1061  len,
1062  sizeof(float),
1063  (xdrproc_t) xdr_float);
1064 
1065 #else
1066 
1067  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1068  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1069  << "The XDR interface is not available in this installation");
1070 
1071 #endif
1072  return;
1073  }
1074 
1075  case READ:
1076  {
1077  libmesh_assert(in.get());
1078  libmesh_assert (in->good());
1079 
1080  for (unsigned int i=0; i<len; i++)
1081  {
1082  libmesh_assert(in.get());
1083  libmesh_assert (in->good());
1084  *in >> val[i];
1085  }
1086 
1087  return;
1088  }
1089 
1090  case WRITE:
1091  {
1092  libmesh_assert(out.get());
1093  libmesh_assert (out->good());
1094 
1095  // Save stream flags
1096  std::ios_base::fmtflags out_flags = out->flags();
1097 
1098  // We will use scientific notation sufficient to exactly
1099  // represent our floating point precision in the following
1100  // output. The desired precision and format will
1101  // automatically determine the width.
1102  *out << std::scientific
1103  << std::setprecision(std::numeric_limits<float>::max_digits10);
1104 
1105  if (line_break == libMesh::invalid_uint)
1106  for (unsigned int i=0; i<len; i++)
1107  {
1108  libmesh_assert(out.get());
1109  libmesh_assert (out->good());
1110  *out << val[i] << ' ';
1111  }
1112  else
1113  {
1114  const unsigned imax = std::min(line_break, len);
1115  unsigned int cnt=0;
1116  while (cnt < len)
1117  {
1118  for (unsigned int i=0; i<imax; i++)
1119  {
1120  libmesh_assert(out.get());
1121  libmesh_assert (out->good());
1122  *out << val[cnt++];
1123 
1124  // Write a space unless this is the last character on the current line.
1125  if (i+1 != imax)
1126  *out << " ";
1127  }
1128  libmesh_assert(out.get());
1129  libmesh_assert (out->good());
1130  *out << '\n';
1131  }
1132  }
1133 
1134  // Restore stream flags
1135  out->flags(out_flags);
1136 
1137  return;
1138  }
1139 
1140  default:
1141  libmesh_error_msg("Invalid mode = " << mode);
1142  }
1143 }
1144 
1145 
1146 template <>
1147 void Xdr::data_stream (long double * val, const unsigned int len, const unsigned int line_break)
1148 {
1149  switch (mode)
1150  {
1151  case ENCODE:
1152  case DECODE:
1153  {
1154 #ifdef LIBMESH_HAVE_XDR
1155 
1156  libmesh_assert (this->is_open());
1157 
1158  // FIXME[JWP]: How to implement this for long double? Mac OS
1159  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1160  // Linux... for now, reading/writing XDR files with long
1161  // doubles drops back to double precision, but you can still
1162  // write long double ASCII files of course.
1163  // if (len > 0)
1164  // xdr_vector(xdrs.get(),
1165  // (char *) val,
1166  // len,
1167  // sizeof(double),
1168  // (xdrproc_t) xdr_quadruple);
1169 
1170  if (len > 0)
1171  {
1172  std::vector<double> io_buffer (len);
1173 
1174  // Fill io_buffer if we are writing.
1175  if (mode == ENCODE)
1176  for (unsigned int i=0, cnt=0; i<len; i++)
1177  io_buffer[cnt++] = double(val[i]);
1178 
1179  xdr_vector(xdrs.get(),
1180  reinterpret_cast<char *>(io_buffer.data()),
1181  len,
1182  sizeof(double),
1183  (xdrproc_t) xdr_double);
1184 
1185  // Fill val array if we are reading.
1186  if (mode == DECODE)
1187  for (unsigned int i=0, cnt=0; i<len; i++)
1188  {
1189  val[i] = io_buffer[cnt++];
1190  }
1191  }
1192 
1193 #else
1194 
1195  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1196  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1197  << "The XDR interface is not available in this installation");
1198 
1199 #endif
1200  return;
1201  }
1202 
1203  case READ:
1204  {
1205  libmesh_assert(in.get());
1206  libmesh_assert (in->good());
1207 
1208  for (unsigned int i=0; i<len; i++)
1209  {
1210  libmesh_assert(in.get());
1211  libmesh_assert (in->good());
1212  *in >> val[i];
1213  }
1214 
1215  return;
1216  }
1217 
1218  case WRITE:
1219  {
1220  libmesh_assert(out.get());
1221  libmesh_assert (out->good());
1222 
1223  // Save stream flags
1224  std::ios_base::fmtflags out_flags = out->flags();
1225 
1226  // We will use scientific notation sufficient to exactly
1227  // represent our floating point precision in the following
1228  // output. The desired precision and format will
1229  // automatically determine the width.
1230  *out << std::scientific
1231  << std::setprecision(std::numeric_limits<long double>::max_digits10);
1232 
1233  if (line_break == libMesh::invalid_uint)
1234  for (unsigned int i=0; i<len; i++)
1235  {
1236  libmesh_assert(out.get());
1237  libmesh_assert (out->good());
1238  *out << val[i] << ' ';
1239  }
1240  else
1241  {
1242  const unsigned imax = std::min(line_break, len);
1243  unsigned int cnt=0;
1244  while (cnt < len)
1245  {
1246  for (unsigned int i=0; i<imax; i++)
1247  {
1248  libmesh_assert(out.get());
1249  libmesh_assert (out->good());
1250  *out << val[cnt++];
1251 
1252  // Write a space unless this is the last character on the current line.
1253  if (i+1 != imax)
1254  *out << " ";
1255  }
1256  libmesh_assert(out.get());
1257  libmesh_assert (out->good());
1258  *out << '\n';
1259  }
1260  }
1261 
1262  // Restore stream flags
1263  out->flags(out_flags);
1264 
1265  return;
1266  }
1267 
1268  default:
1269  libmesh_error_msg("Invalid mode = " << mode);
1270  }
1271 }
1272 
1273 
1274 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
1275 template <>
1276 void Xdr::data_stream (Real * val, const unsigned int len, const unsigned int line_break)
1277 {
1278  switch (mode)
1279  {
1280  case ENCODE:
1281  case DECODE:
1282  {
1283 #ifdef LIBMESH_HAVE_XDR
1284 
1285  libmesh_assert (this->is_open());
1286 
1287  // FIXME[RHS]: This has the same "xdr_quadruple may not be
1288  // defined" problem as long double, and the problem may be
1289  // much worse since even _Quad/__float128 aren't standard
1290  // either.
1291  // if (len > 0)
1292  // xdr_vector(xdrs.get(),
1293  // (char *) val,
1294  // len,
1295  // sizeof(double),
1296  // (xdrproc_t) xdr_quadruple);
1297 
1298  if (len > 0)
1299  {
1300  std::vector<double> io_buffer (len);
1301 
1302  // Fill io_buffer if we are writing.
1303  if (mode == ENCODE)
1304  for (unsigned int i=0, cnt=0; i<len; i++)
1305  io_buffer[cnt++] = double(val[i]);
1306 
1307  xdr_vector(xdrs.get(),
1308  reinterpret_cast<char *>(io_buffer.data()),
1309  len,
1310  sizeof(double),
1311  (xdrproc_t) xdr_double);
1312 
1313  // Fill val array if we are reading.
1314  if (mode == DECODE)
1315  for (unsigned int i=0, cnt=0; i<len; i++)
1316  {
1317  val[i] = io_buffer[cnt++];
1318  }
1319  }
1320 
1321 #else
1322 
1323  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1324  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1325  << "The XDR interface is not available in this installation");
1326 
1327 #endif
1328  return;
1329  }
1330 
1331  case READ:
1332  {
1333  libmesh_assert(in.get());
1334  libmesh_assert (in->good());
1335 
1336  for (unsigned int i=0; i<len; i++)
1337  {
1338  libmesh_assert(in.get());
1339  libmesh_assert (in->good());
1340  *in >> val[i];
1341  }
1342 
1343  return;
1344  }
1345 
1346  case WRITE:
1347  {
1348  libmesh_assert(out.get());
1349  libmesh_assert (out->good());
1350 
1351  // Save stream flags
1352  std::ios_base::fmtflags out_flags = out->flags();
1353 
1354  // We will use scientific notation with a precision of 36
1355  // digits in the following output. The desired precision and
1356  // format will automatically determine the width.
1357  *out << std::scientific
1358  << std::setprecision(36);
1359 
1360  if (line_break == libMesh::invalid_uint)
1361  for (unsigned int i=0; i<len; i++)
1362  {
1363  libmesh_assert(out.get());
1364  libmesh_assert (out->good());
1365  *out << val[i] << ' ';
1366  }
1367  else
1368  {
1369  const unsigned imax = std::min(line_break, len);
1370  unsigned int cnt=0;
1371  while (cnt < len)
1372  {
1373  for (unsigned int i=0; i<imax; i++)
1374  {
1375  libmesh_assert(out.get());
1376  libmesh_assert (out->good());
1377  *out << val[cnt++];
1378 
1379  // Write a space unless this is the last character on the current line.
1380  if (i+1 != imax)
1381  *out << " ";
1382  }
1383  libmesh_assert(out.get());
1384  libmesh_assert (out->good());
1385  *out << '\n';
1386  }
1387  }
1388 
1389  // Restore stream flags
1390  out->flags(out_flags);
1391 
1392  return;
1393  }
1394 
1395  default:
1396  libmesh_error_msg("Invalid mode = " << mode);
1397  }
1398 }
1399 #endif // LIBMESH_DEFAULT_QUADRUPLE_PRECISION
1400 
1401 
1402 
1403 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
1404 template <>
1405 void Xdr::data_stream (std::complex<double> * val, const unsigned int len, const unsigned int line_break)
1406 {
1407  switch (mode)
1408  {
1409  case ENCODE:
1410  case DECODE:
1411  {
1412 #ifdef LIBMESH_HAVE_XDR
1413 
1414  libmesh_assert (this->is_open());
1415 
1416 
1417  if (len > 0)
1418  {
1419  std::vector<double> io_buffer (2*len);
1420 
1421  // Fill io_buffer if we are writing.
1422  if (mode == ENCODE)
1423  for (unsigned int i=0, cnt=0; i<len; i++)
1424  {
1425  io_buffer[cnt++] = val[i].real();
1426  io_buffer[cnt++] = val[i].imag();
1427  }
1428 
1429  xdr_vector(xdrs.get(),
1430  reinterpret_cast<char *>(io_buffer.data()),
1431  2*len,
1432  sizeof(double),
1433  (xdrproc_t) xdr_double);
1434 
1435  // Fill val array if we are reading.
1436  if (mode == DECODE)
1437  for (unsigned int i=0, cnt=0; i<len; i++)
1438  {
1439  double re = io_buffer[cnt++];
1440  double im = io_buffer[cnt++];
1441  val[i] = std::complex<double>(re,im);
1442  }
1443  }
1444 #else
1445 
1446  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1447  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1448  << "The XDR interface is not available in this installation");
1449 
1450 #endif
1451  return;
1452  }
1453 
1454  case READ:
1455  {
1456  libmesh_assert(in.get());
1457  libmesh_assert (in->good());
1458 
1459  for (unsigned int i=0; i<len; i++)
1460  {
1461  libmesh_assert(in.get());
1462  libmesh_assert (in->good());
1463  double re, im;
1464  *in >> re >> im;
1465  val[i] = std::complex<double>(re,im);
1466  }
1467 
1468  return;
1469  }
1470 
1471  case WRITE:
1472  {
1473  libmesh_assert(out.get());
1474  libmesh_assert (out->good());
1475 
1476  // Save stream flags
1477  std::ios_base::fmtflags out_flags = out->flags();
1478 
1479  // We will use scientific notation sufficient to exactly
1480  // represent our floating point precision in the following
1481  // output. The desired precision and format will
1482  // automatically determine the width.
1483  *out << std::scientific
1484  << std::setprecision(std::numeric_limits<double>::max_digits10);
1485 
1486  if (line_break == libMesh::invalid_uint)
1487  for (unsigned int i=0; i<len; i++)
1488  {
1489  libmesh_assert(out.get());
1490  libmesh_assert (out->good());
1491  *out << val[i].real() << ' ';
1492  *out << val[i].imag() << ' ';
1493  }
1494  else
1495  {
1496  const unsigned imax = std::min(line_break, len);
1497  unsigned int cnt=0;
1498  while (cnt < len)
1499  {
1500  for (unsigned int i=0; i<imax; i++)
1501  {
1502  libmesh_assert(out.get());
1503  libmesh_assert (out->good());
1504  *out << val[cnt].real() << ' ';
1505  *out << val[cnt].imag();
1506  cnt++;
1507 
1508  // Write a space unless this is the last character on the current line.
1509  if (i+1 != imax)
1510  *out << " ";
1511  }
1512  libmesh_assert(out.get());
1513  libmesh_assert (out->good());
1514  *out << '\n';
1515  }
1516  }
1517 
1518  // Restore stream flags
1519  out->flags(out_flags);
1520 
1521  return;
1522  }
1523 
1524  default:
1525  libmesh_error_msg("Invalid mode = " << mode);
1526  }
1527 }
1528 
1529 template <>
1530 void Xdr::data_stream (std::complex<long double> * val, const unsigned int len, const unsigned int line_break)
1531 {
1532  switch (mode)
1533  {
1534  case ENCODE:
1535  case DECODE:
1536  {
1537 #ifdef LIBMESH_HAVE_XDR
1538 
1539  libmesh_assert (this->is_open());
1540 
1541  // FIXME[JWP]: How to implement this for long double? Mac OS
1542  // X defines 'xdr_quadruple' but AFAICT, it does not exist for
1543  // Linux... for now, reading/writing XDR files with long
1544  // doubles drops back to double precision, but you can still
1545  // write long double ASCII files of course.
1546 
1547  if (len > 0)
1548  {
1549  std::vector<double> io_buffer (2*len);
1550 
1551  // Fill io_buffer if we are writing.
1552  if (mode == ENCODE)
1553  for (unsigned int i=0, cnt=0; i<len; i++)
1554  {
1555  io_buffer[cnt++] = val[i].real();
1556  io_buffer[cnt++] = val[i].imag();
1557  }
1558 
1559  xdr_vector(xdrs.get(),
1560  reinterpret_cast<char *>(io_buffer.data()),
1561  2*len,
1562  sizeof(double),
1563  (xdrproc_t) xdr_double);
1564 
1565  // Fill val array if we are reading.
1566  if (mode == DECODE)
1567  for (unsigned int i=0, cnt=0; i<len; i++)
1568  {
1569  double re = io_buffer[cnt++];
1570  double im = io_buffer[cnt++];
1571  val[i] = std::complex<long double>(re, im);
1572  }
1573  }
1574 #else
1575 
1576  libmesh_error_msg("ERROR: Functionality is not available.\n" \
1577  << "Make sure LIBMESH_HAVE_XDR is defined at build time\n" \
1578  << "The XDR interface is not available in this installation");
1579 
1580 #endif
1581  return;
1582  }
1583 
1584  case READ:
1585  {
1586  libmesh_assert(in.get());
1587  libmesh_assert (in->good());
1588 
1589  for (unsigned int i=0; i<len; i++)
1590  {
1591  libmesh_assert(in.get());
1592  libmesh_assert (in->good());
1593  long double re, im;
1594  *in >> re >> im;
1595  val[i] = std::complex<long double>(re,im);
1596  }
1597 
1598  return;
1599  }
1600 
1601  case WRITE:
1602  {
1603  libmesh_assert(out.get());
1604  libmesh_assert (out->good());
1605 
1606 
1607  // Save stream flags
1608  std::ios_base::fmtflags out_flags = out->flags();
1609 
1610  // We will use scientific notation with a precision of
1611  // 'max_digits10' digits in the following output. The desired
1612  // precision and format will automatically determine the
1613  // width. Note: digit10 is the number of digits (in decimal
1614  // base) that can be represented without change. Equivalent
1615  // to FLT_DIG, DBL_DIG or LDBL_DIG for floating types.
1616  *out << std::scientific
1617  << std::setprecision(std::numeric_limits<long double>::max_digits10);
1618 
1619  if (line_break == libMesh::invalid_uint)
1620  for (unsigned int i=0; i<len; i++)
1621  {
1622  libmesh_assert(out.get());
1623  libmesh_assert (out->good());
1624  *out << val[i].real() << ' ' << val[i].imag() << ' ';
1625  }
1626  else
1627  {
1628  const unsigned imax = std::min(line_break, len);
1629  unsigned int cnt=0;
1630  while (cnt < len)
1631  {
1632  for (unsigned int i=0; i<imax; i++)
1633  {
1634  libmesh_assert(out.get());
1635  libmesh_assert (out->good());
1636  *out << val[cnt].real() << ' ' << val[cnt].imag();
1637  cnt++;
1638 
1639  // Write a space unless this is the last character on the current line.
1640  if (i+1 != imax)
1641  *out << " ";
1642  }
1643  libmesh_assert(out.get());
1644  libmesh_assert (out->good());
1645  *out << '\n';
1646  }
1647  }
1648 
1649  // Restore stream flags
1650  out->flags(out_flags);
1651 
1652  return;
1653  }
1654 
1655  default:
1656  libmesh_error_msg("Invalid mode = " << mode);
1657  }
1658 }
1659 #endif // # LIBMESH_USE_COMPLEX_NUMBERS
1660 
1661 void Xdr::comment (std::string & comment_in)
1662 {
1663  switch (mode)
1664  {
1665  case ENCODE:
1666  case DECODE:
1667  {
1668  return;
1669  }
1670 
1671  case READ:
1672  {
1673  libmesh_assert(in.get());
1674  libmesh_assert (in->good());
1675  in->getline(comm, comm_len);
1676  return;
1677  }
1678 
1679  case WRITE:
1680  {
1681  libmesh_assert(out.get());
1682  libmesh_assert (out->good());
1683  *out << "\t " << comment_in << '\n';
1684  return;
1685  }
1686 
1687  default:
1688  libmesh_error_msg("Invalid mode = " << mode);
1689  }
1690 }
1691 
1692 
1693 #undef xdr_REAL
1694 
1695 
1696 //
1697 template void Xdr::data<int> (int &, const char *);
1698 template void Xdr::data<unsigned int> (unsigned int &, const char *);
1699 template void Xdr::data<unsigned short int> (unsigned short int &, const char *);
1700 template void Xdr::data<short int> (short int &, const char *);
1701 template void Xdr::data<unsigned long int> (unsigned long int &, const char *);
1702 template void Xdr::data<unsigned long long> (unsigned long long &, const char *);
1703 template void Xdr::data<long int> (long int &, const char *);
1704 template void Xdr::data<long long> (long long &, const char *);
1705 template void Xdr::data<char> (char &, const char *);
1706 template void Xdr::data<signed char> (signed char &, const char *);
1707 template void Xdr::data<unsigned char> (unsigned char &, const char *);
1708 template void Xdr::data<float> (float &, const char *);
1709 template void Xdr::data<double> (double &, const char *);
1710 template void Xdr::data<long double> (long double &, const char *);
1711 template void Xdr::data<std::complex<float>> (std::complex<float> &, const char *);
1712 template void Xdr::data<std::complex<double>> (std::complex<double> &, const char *);
1713 template void Xdr::data<std::complex<long double>> (std::complex<long double> &, const char *);
1714 template void Xdr::data<std::string> (std::string &, const char *);
1715 template void Xdr::data<std::vector<int>> (std::vector<int> &, const char *);
1716 template void Xdr::data<std::vector<unsigned int>> (std::vector<unsigned int> &, const char *);
1717 template void Xdr::data<std::vector<short int>> (std::vector<short int> &, const char *);
1718 template void Xdr::data<std::vector<unsigned short int>> (std::vector<unsigned short int> &, const char *);
1719 template void Xdr::data<std::vector<long int>> (std::vector<long int> &, const char *);
1720 template void Xdr::data<std::vector<long long>> (std::vector<long long> &, const char *);
1721 template void Xdr::data<std::vector<unsigned long int>> (std::vector<unsigned long int> &, const char *);
1722 template void Xdr::data<std::vector<unsigned long long>> (std::vector<unsigned long long> &, const char *);
1723 template void Xdr::data<std::vector<char>> (std::vector<char> &, const char *);
1724 template void Xdr::data<std::vector<signed char>> (std::vector<signed char> &, const char *);
1725 template void Xdr::data<std::vector<unsigned char>> (std::vector<unsigned char> &, const char *);
1726 template void Xdr::data<std::vector<float>> (std::vector<float> &, const char *);
1727 template void Xdr::data<std::vector<double>> (std::vector<double> &, const char *);
1728 template void Xdr::data<std::vector<long double>> (std::vector<long double> &, const char *);
1729 template void Xdr::data<std::vector<std::complex<float>>> (std::vector<std::complex<float>> &, const char *);
1730 template void Xdr::data<std::vector<std::complex<double>>> (std::vector<std::complex<double>> &, const char *);
1731 template void Xdr::data<std::vector<std::complex<long double>>> (std::vector<std::complex<long double>> &, const char *);
1732 template void Xdr::data<std::vector<std::string>> (std::vector<std::string> &, const char *);
1733 template void Xdr::data_stream<unsigned char> (unsigned char * val, const unsigned int len, const unsigned int line_break);
1734 template void Xdr::data_stream<short int> (short int * val, const unsigned int len, const unsigned int line_break);
1735 template void Xdr::data_stream<int> (int * val, const unsigned int len, const unsigned int line_break);
1736 template void Xdr::data_stream<long long> (long long * val, const unsigned int len, const unsigned int line_break);
1737 template void Xdr::data_stream<unsigned short int> (unsigned short int * val, const unsigned int len, const unsigned int line_break);
1738 template void Xdr::data_stream<unsigned int> (unsigned int * val, const unsigned int len, const unsigned int line_break);
1739 template void Xdr::data_stream<unsigned long int> (unsigned long int * val, const unsigned int len, const unsigned int line_break);
1740 template void Xdr::data_stream<unsigned long long> (unsigned long long * val, const unsigned int len, const unsigned int line_break);
1741 
1742 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
1743 template void Xdr::data<Real> (Real &, const char *);
1744 template void Xdr::data<std::complex<Real>> (std::complex<Real> &, const char *);
1745 template void Xdr::data<std::vector<Real>> (std::vector<Real> &, const char *);
1746 template void Xdr::data<std::vector<std::complex<Real>>> (std::vector<std::complex<Real>> &, const char *);
1747 #endif
1748 
1749 } // namespace libMesh
libMesh::MeshTools::Subdivision::next
static const unsigned int next[3]
A lookup table for the increment modulo 3 operation, for iterating through the three nodes per elemen...
Definition: mesh_subdivision_support.h:102
libMesh::invalid_uint
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:249
libMesh::Xdr::gzipped_file
bool gzipped_file
Are we reading/writing zipped files?
Definition: xdr_cxx.h:241
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Xdr::is_eof
bool is_eof()
Definition: xdr_cxx.C:391
libMesh::Xdr::file_name
std::string file_name
The file name.
Definition: xdr_cxx.h:205
libMesh::Xdr::comm_len
const int comm_len
A buffer to put comment strings into.
Definition: xdr_cxx.h:235
libMesh::WRITE
Definition: enum_xdr_mode.h:40
libMesh::Xdr::Xdr
Xdr(const std::string &name="", const XdrMODE m=UNKNOWN)
Constructor.
Definition: xdr_cxx.C:136
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::Xdr::do_write
void do_write(T &a)
Helper method for writing different data types.
Definition: xdr_cxx.C:725
libMesh::Xdr::data
void data(T &a, const char *comment="")
Inputs or outputs a single value.
Definition: xdr_cxx.C:766
libMesh::XdrMODE
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:35
libMesh::DECODE
Definition: enum_xdr_mode.h:39
libMesh::Xdr::mode
const XdrMODE mode
The mode used for accessing the file.
Definition: xdr_cxx.h:200
libMesh::Xdr::do_read
void do_read(T &a)
Helper method for reading different data types.
Definition: xdr_cxx.C:660
libMesh::READ
Definition: enum_xdr_mode.h:41
libMesh::Xdr::open
void open(const std::string &name)
Opens the file.
Definition: xdr_cxx.C:162
libMesh::Xdr::data_stream
void data_stream(T *val, const unsigned int len, const unsigned int line_break=libMesh::invalid_uint)
Inputs or outputs a raw data stream.
Definition: xdr_cxx.C:831
xdr_MAX_STRING_LENGTH
const unsigned int xdr_MAX_STRING_LENGTH
Definition: xdr_cxx.h:43
libMesh::ENCODE
Definition: enum_xdr_mode.h:38
libMesh::Xdr::close
void close()
Closes the file if it is open.
Definition: xdr_cxx.C:273
libMesh::Xdr::xzipped_file
bool xzipped_file
Definition: xdr_cxx.h:241
libMesh::Xdr::is_open
bool is_open() const
Definition: xdr_cxx.C:341
libMesh::Xdr::out
std::unique_ptr< std::ostream > out
The output file stream.
Definition: xdr_cxx.h:230
libMesh::Xdr::fp
FILE * fp
File pointer.
Definition: xdr_cxx.h:218
libMesh::Xdr::bzipped_file
bool bzipped_file
Definition: xdr_cxx.h:241
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::Xdr::in
std::unique_ptr< std::istream > in
The input file stream.
Definition: xdr_cxx.h:225
libMesh::Xdr::xdrs
std::unique_ptr< XDR > xdrs
Pointer to the standard XDR struct.
Definition: xdr_cxx.h:213
libMesh::out
OStreamProxy out
libMesh::Xdr::comment
void comment(std::string &)
Writes or reads (ignores) a comment line.
Definition: xdr_cxx.C:1661
libMesh::Xdr::~Xdr
~Xdr()
Destructor.
Definition: xdr_cxx.C:155
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libMesh::Xdr::comm
char comm[xdr_MAX_STRING_LENGTH]
Definition: xdr_cxx.h:236