1 | //#include <netcdfcpp.h> |
---|
2 | #include <fstream.h> |
---|
3 | #include <fcntl.h> |
---|
4 | |
---|
5 | // void write_to_nc ( NcFile &nc, mat &X, std::string Xn, Array<std::string> A ) { |
---|
6 | // char tmpstr[200]; |
---|
7 | // int Len = X.rows(); |
---|
8 | // |
---|
9 | // sprintf ( tmpstr,"%s.length",Xn.c_str() ); |
---|
10 | // NcDim* lengt = nc.add_dim ( tmpstr, ( long ) Len ); |
---|
11 | // for ( int j=0; j<X.cols(); j++ ) { |
---|
12 | // if ( j<A.length() ) |
---|
13 | // sprintf ( tmpstr,"%s_%s",Xn.c_str(), ( A ( j ) ).c_str() ); |
---|
14 | // else |
---|
15 | // sprintf ( tmpstr,"%s_%d",Xn.c_str(),j ); |
---|
16 | // // Create variables and their attributes |
---|
17 | // NcVar* P = nc.add_var ( tmpstr, ncDouble, lengt ); |
---|
18 | // const double* Dp = X._data(); |
---|
19 | // P->put ( &Dp[j*Len],Len ); |
---|
20 | // } |
---|
21 | // } |
---|
22 | |
---|
23 | |
---|
24 | void dirfile_write (std::ofstream &form, std::string Dir, mat &X, std::string Xn, Array<std::string> A ) { |
---|
25 | char tmpstr[200]; |
---|
26 | char file[200]; |
---|
27 | const double* Dp=X._data(); |
---|
28 | int Len = X.rows(); |
---|
29 | |
---|
30 | for ( int j=0; j<X.cols(); j++ ) { |
---|
31 | if ( j<A.length() ) |
---|
32 | sprintf ( tmpstr,"%s_%s",Xn.c_str(), ( A ( j ) ).c_str() ); |
---|
33 | else |
---|
34 | sprintf ( tmpstr,"%s_%d",Xn.c_str(),j ); |
---|
35 | // save files == from kst-doc-datasource |
---|
36 | sprintf(file,"%s/%s",Dir.c_str(),tmpstr); |
---|
37 | |
---|
38 | int fp; |
---|
39 | fp = open(file, O_CREAT | O_WRONLY | O_TRUNC, 00644); |
---|
40 | write(fp,&Dp[j*Len],Len*sizeof(double)); |
---|
41 | close(fp); |
---|
42 | |
---|
43 | form << tmpstr << " RAW d 1" << endl; |
---|
44 | } |
---|
45 | } |
---|