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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (22 months, 2 weeks ago) by uqaeller
File size: 5191 byte(s)
Updated the copyright header.


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

  ViewVC Help
Powered by ViewVC 1.1.26