TF++, Miscellaneous classes and modules in C++:
hack_blitztogrepg.cc
Go to the documentation of this file.
1 
34 #define TF_HACK_BLITZTOGREPG_CC_VERSION \
35  "TF_HACK_BLITZTOGREPG_CC V1.0 "
36 
37 #include <fstream>
38 #include <tfxx/misc.h>
39 #include <tfxx/fortranio.h>
40 #include <tfxx/complexio.h>
41 #include <tfxx/blitzutil.h>
42 #include <tfxx/hack_blitztogrepg.h>
43 
44 namespace tfxx {
45 namespace hacks {
46 
48 void write_grepg_c(const blitz::Array<std::complex<float>, 2>& array,
49  const char* filename,
50  const double& dx=1., const double& dy=1.)
51 {
52  std::ofstream os(filename);
53  tfxx::ioswap::file_magic_write(os, "1234", true);
55  int nom=array.extent(blitz::firstDim);
56  int fom=array.lbound(blitz::firstDim);
57  int nslo=array.extent(blitz::secondDim);
58  int fslo=array.lbound(blitz::secondDim);
59  fos << nom << nslo;
60  fos.end_block();
61  for (int i=0; i<nom; i++)
62  { fos << float(3.14159265358979311*2.*(i+fom-1)*dx); }
63  for (int i=0; i<nslo; i++) { fos << float(1.e-3*(i+fslo-1)*dy); }
64  fos.end_block();
65  for (int i=0; i<nslo; i++)
66  {
67  for (int j=0; j<nom; j++)
68  {
69  fos << array(j+fom,i+fslo);
70  }
71  }
72  fos.end_block();
73 }
74 
75 /*----------------------------------------------------------------------*/
76 
78 void write_grepg_f(const blitz::Array<float, 2>& array,
79  const char* filename,
80  const double& dx=1., const double& dy=1.)
81 {
82  // create intermediate complex data
83  blitz::Array<std::complex<float>, 2> tmp(blitz::fortranArray);
84  tfxx::blitzutil::setToSameDomain(tmp, array.domain());
85  tmp=blitz::cast<std::complex<float> >(array);
86  write_grepg_c(tmp, filename, dx, dy);
87 }
88 
89 } // namespace hacks
90 } // namespace tfxx
91 
92 /* ----- END OF hack_blitztogrepg.cc ----- */
write FORTRAN binary data ,This class writes FORTRAN binary data. FORTRAN binary data is always writt...
Definition: fortranio.h:200
void end_block()
finish data block
Definition: fortranio.cc:155
void write_grepg_f(const blitz::Array< float, 2 > &array, const char *filename, const double &dx=1., const double &dy=1.)
create grepg file from float array
void setToSameDomain(blitz::Array< T, N > &array, const blitz::RectDomain< N > &domain, const blitz::GeneralArrayStorage< N > &storage=blitz::fortranArray)
create a second array spanning the same domain
Definition: blitzutil.h:90
void write_grepg_c(const blitz::Array< std::complex< float >, 2 > &array, const char *filename, const double &dx=1., const double &dy=1.)
create grepg file from complex array
void file_magic_write(std::ostream &os, const char *const cmagic, const bool &fortranmode=false)
Write magic number to file. ,.
Definition: ioswap.cc:135
Namespace containing all code of library libtfxx.