work/mixpp/pmsm/iopom.h

00001 //#include <netcdfcpp.h>
00002 #include <fstream.h>
00003 #include <fcntl.h>
00004 
00005 // void write_to_nc ( NcFile &nc, mat &X, std::string Xn, Array<std::string> A ) {
00006 //      char tmpstr[200];
00007 //      int Len = X.rows();
00008 // 
00009 //      sprintf ( tmpstr,"%s.length",Xn.c_str() );
00010 //      NcDim* lengt = nc.add_dim ( tmpstr, ( long ) Len );
00011 //      for ( int j=0; j<X.cols(); j++ ) {
00012 //              if ( j<A.length() )
00013 //                      sprintf ( tmpstr,"%s_%s",Xn.c_str(), ( A ( j ) ).c_str() );
00014 //              else
00015 //                      sprintf ( tmpstr,"%s_%d",Xn.c_str(),j );
00016 //              // Create variables and their attributes
00017 //              NcVar* P = nc.add_var ( tmpstr, ncDouble, lengt );
00018 //              const double* Dp = X._data();
00019 //              P->put ( &Dp[j*Len],Len );
00020 //      }
00021 // }
00022 
00023 
00024 void dirfile_write (std::ofstream &form, std::string Dir, mat &X, std::string Xn, Array<std::string> A ) {
00025   char tmpstr[200];
00026   char file[200];
00027   const double* Dp=X._data();
00028   int Len = X.rows();
00029   
00030         for ( int j=0; j<X.cols(); j++ ) {
00031                 if ( j<A.length() )
00032                         sprintf ( tmpstr,"%s_%s",Xn.c_str(), ( A ( j ) ).c_str() );
00033                 else
00034                         sprintf ( tmpstr,"%s_%d",Xn.c_str(),j );
00035                 // save files == from kst-doc-datasource
00036                 sprintf(file,"%s/%s",Dir.c_str(),tmpstr);
00037                 
00038                 int fp;
00039                 fp = open(file, O_CREAT | O_WRONLY | O_TRUNC, 00644);
00040                 write(fp,&Dp[j*Len],Len*sizeof(double));
00041                 close(fp);
00042   
00043                 form << tmpstr << " RAW  d 1" << endl;
00044         }
00045 }

Generated on Fri Apr 18 11:15:15 2008 for mixpp by  doxygen 1.5.3