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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26