00001 
00002 #include <fstream.h>
00003 #include <fcntl.h>
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
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                 
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 }