/[escript]/trunk/tools/escriptconvert/esdcreate.cpp
ViewVC logotype

Annotation of /trunk/tools/escriptconvert/esdcreate.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2548 - (hide annotations)
Mon Jul 20 06:20:06 2009 UTC (10 years, 4 months ago) by jfenwick
Original Path: trunk/tools/libescriptreader/src/esdcreate.cpp
File size: 4934 byte(s)
Updating copyright notices
1 caltinay 2183
2     /*******************************************************
3     *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 caltinay 2183 * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13    
14     #include <iostream>
15     #include <fstream>
16    
17     using namespace std;
18    
19     int main(int argc, char** argv)
20     {
21     string dsName;
22    
23     if (argc > 1) {
24     cerr << "esdcreate - escript datafile creator version 1.0" << endl;
25     cerr << "This program takes no arguments." << endl;
26     return -1;
27     }
28    
29     for (;;) {
30     cout << "Please enter a name for this dataset (e.g. simulation): ";
31     cin >> dsName;
32     dsName.append(".esd");
33     ifstream f;
34     f.open(dsName.c_str(), ifstream::in);
35     // File exists
36     if (f.good()) {
37     cout << "A file by the name " << dsName << " already exists! Overwrite? (y/n) ";
38     f.close();
39     char a = ' ';
40     while (a != 'y' && a != 'n')
41     cin >> a;
42     if (a == 'y')
43     break;
44    
45     } else
46     break;
47     }
48    
49     ofstream esdFile;
50     esdFile.open(dsName.c_str(), ifstream::out);
51     esdFile << "#escript datafile V1.0" << endl;
52    
53     int numTS = 0;
54     while (numTS <= 0) {
55     cout << "Number of timesteps: ";
56     cin >> numTS;
57     if (!cin.good()) {
58     cin.clear();
59     cin.ignore(100, '\n');
60     }
61     if (numTS <= 0)
62     cout << "Please enter a value > 0!" << endl;
63     }
64     esdFile << "T=" << numTS << endl;
65    
66     string meshName;
67     int numParts = 0;
68     for (;;) {
69     cout << "Filename of the mesh (without .nc): ";
70     cin >> meshName;
71     string fname = meshName;
72     fname.append(".nc");
73     ifstream f;
74     f.open(fname.c_str(), ifstream::in);
75     if (f.good()) {
76     f.close();
77     numParts = 1;
78     } else {
79     char partnum[10];
80     for (;; numParts++) {
81     snprintf(partnum, 10, ".%04d", numParts);
82     string pname = fname;
83     pname.append(partnum);
84     f.open(pname.c_str(), ifstream::in);
85     if (f.good())
86     f.close();
87     else
88     break;
89     }
90     }
91     if (numParts == 0)
92     cout << "The mesh was not found! Please try again." << endl;
93     else
94     break;
95     }
96     esdFile << "M=" << meshName << endl;
97     esdFile << "N=" << numParts << endl;
98    
99     cout << endl;
100     cout << "For each variable you would like to add please enter the filename" << endl;
101     cout << "of the variable (without .nc) followed by a colon and a name for" << endl;
102     cout << "the variable. For example: temp:temperature" << endl;
103     if (numTS > 1) {
104     cout << "Since you indicated that there are multiple timesteps, you have to put" << endl;
105     cout << "a format string at the right place of the filename which will be replaced" << endl;
106     cout << "by the actual timestep when loading the files." << endl;
107     cout << "Examples:" << endl;
108 caltinay 2525 cout << " temp.%d:temperature would be resolved to temp.0.nc, temp.1.nc etc." << endl;
109     cout << " temp.%04d:temperature would be resolved to temp.0000.nc, temp.0001.nc etc." << endl;
110 caltinay 2183 }
111     cout << endl;
112     cout << "When you are finished please enter: done" << endl;
113    
114     for (;;) {
115     string varString;
116     cout << "Filename and variable name: ";
117     cin >> varString;
118     if (varString == string("done"))
119     break;
120     if (varString.find(':') == varString.npos) {
121     cout << "Your input is invalid! Please enter filename:varname or done." << endl;
122     } else
123     esdFile << "V=" << varString << endl;
124     }
125    
126 caltinay 2525 if (numTS > 1) {
127     int tsIncrement = 0;
128     cout << endl;
129     cout << "Please supply the timestep increment to find your files." << endl;
130     cout << "For example, if your files are named temp.0, temp.10, temp.20, etc." << endl;
131     cout << "the increment is 10, whereas temp.0, temp.1, temp.2 have an increment of 1." << endl;
132     while (tsIncrement <= 0) {
133     cout << "Timestep increment for filenames: ";
134     cin >> tsIncrement;
135     if (!cin.good()) {
136     cin.clear();
137     cin.ignore(100, '\n');
138     }
139     if (tsIncrement <= 0)
140     cout << "Please enter a value > 0!" << endl;
141     }
142     esdFile << "DT=" << tsIncrement << endl;
143     }
144    
145 caltinay 2183 esdFile.close();
146    
147     cout << endl;
148     cout << "Your escript datafile has been written to " << dsName << "." << endl;
149     cout << "You can now open this file from within VisIt to visualise your data." << endl;
150    
151     return 0;
152     }
153    

  ViewVC Help
Powered by ViewVC 1.1.26