ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / applications / utilities / postProcessing / graphics / ensightFoamReader / USERD_set_filenames.H
blob11c8c15b9f05f78b1e806f34ae13784f060e9811
1 //======================================================================
2 //  Setting filenames
3 //======================================================================
4 int USERD_set_filenames
6     char filename_1[],
7     char filename_2[],
8     char the_path[],
9     int swapbytes
12 #ifdef ENSIGHTDEBUG
13     Info<< "Entering: USERD_set_filenames" << endl << flush;
14 #endif
16     char tmp[100];
18     label lRoot = strlen(the_path);
19     label lCase = strlen(filename_1);
21     bool cleared = false;
23     while (!cleared)
24     {
25         lRoot = strlen(the_path);
26         lCase = strlen(filename_1);
28         // remove the last '/' from rootDir
29         if (the_path[lRoot-1] == '/')
30         {
31             the_path[lRoot-1] = (char)NULL;
32         }
33         else
34         {
35             cleared = true;
36         }
37     }
39     rootDir = the_path;
41     // the path is pre-pended to filename_1
42     // 1 is the 'Geometry' : 2 the 'Result' which is null here
43     // since two_field is FALSE
44     for (label i=0; i<lCase-lRoot;i++)
45     {
46         tmp[i] = filename_1[i+1+lRoot];
47     }
48     caseDir = tmp;
50     if (!isDir(rootDir/caseDir))
51     {
52        Info<< rootDir/caseDir << " is not a valid directory."
53            << endl;
54        return Z_ERR;
55     }
57     // construct the global pointers to the database and mesh
59     delete meshPtr;
60     delete runTimePtr;
62     runTimePtr = new Time
63     (
64         Time::controlDictName,
65         rootDir,
66         caseDir
67     );
69     Time& runTime = *runTimePtr;
71     meshPtr = new fvMesh
72     (
73         IOobject
74         (
75             fvMesh::defaultRegion,
76             runTime.timeName(),
77             runTime
78         )
79     );
81     // set the available number of time-steps
82     timeDirs = Foam::Time::findTimes(rootDir/caseDir);
84     Num_time_steps = timeDirs.size() - 1;
86     nPatches = meshPtr->boundaryMesh().size();
88     // set the number of fields and store their names
89     // a valid field must exist for all time-steps
90     runTime.setTime(timeDirs.last(), timeDirs.size()-1);
91     IOobjectList objects(*meshPtr, runTime.timeName());
93     fieldNames = objects.names();
95     // because of the spray being a 'field' ...
96     // get the availabe number of variables and
97     // check for type (scalar/vector/tensor)
99     label nVar = 0;
100     wordList scalars = objects.names(scalarName);
102     forAll(fieldNames, n)
103     {
104         bool isitScalar = false;
105         forAll(scalars,i)
106         {
107             if (fieldNames[n] == scalars[i])
108             {
109                 isitScalar = true;
110                 var2field[nVar++] = n;
111             }
112         }
113         isScalar[n] = isitScalar;
114     }
116     wordList vectors = objects.names(vectorName);
118     forAll(fieldNames, n)
119     {
120         bool isitVector = false;
121         forAll(vectors,i)
122         {
123             if (fieldNames[n] == vectors[i])
124             {
125                 isitVector = true;
126                 var2field[nVar++] = n;
127             }
128         }
129         isVector[n] = isitVector;
130     }
132     wordList tensors = objects.names(tensorName);
134     forAll(fieldNames, n)
135     {
136         bool isitTensor = false;
137         forAll(tensors,i)
138         {
139             if (fieldNames[n] == tensors[i])
140             {
141                 isitTensor = true;
142                 var2field[nVar++] = n;
143             }
144         }
145         isTensor[n] = isitTensor;
146     }
148     bool lagrangianNamesFound = false;
149     label n = 0;
150     while (!lagrangianNamesFound && n < Num_time_steps)
151     {
152         runTime.setTime(timeDirs[n+1], n+1);
154         Cloud<passiveParticle> lagrangian(*meshPtr);
156         n++;
157         if (lagrangian.size())
158         {
159             lagrangianNamesFound = true;
160         }
161     }
163     IOobject sprayHeader
164     (
165         "positions",
166         runTime.timeName(),
167         cloud::prefix,
168         runTime,
169         IOobject::NO_READ,
170         IOobject::NO_WRITE,
171         false
172     );
174     if (sprayHeader.headerOk())
175     {
176         Info<< "[Found lagrangian]" << endl;
178         delete sprayPtr;
180         sprayPtr = new Cloud<passiveParticle>(*meshPtr);
182         IOobjectList objects(*meshPtr, runTime.timeName(), cloud::prefix);
184         lagrangianScalarNames =
185             (const wordList&)objects.names(sprayScalarFieldName);
186         lagrangianVectorNames =
187             (const wordList&)objects.names(sprayVectorFieldName);
189         isSpray[fieldNames.size()] = true;
191         nSprayVariables += lagrangianScalarNames.size();
192         nSprayVariables += lagrangianVectorNames.size();
194         Num_unstructured_parts++;
195     }
197     Current_time_step = Num_time_steps;
198     runTime.setTime(timeDirs[Current_time_step], Current_time_step);
200     Num_variables = nVar + nSprayVariables;
201     Numparts_available =
202         Num_unstructured_parts + Num_structured_parts + nPatches;
204 #ifdef ENSIGHTDEBUG
205     Info<< "Leaving: USERD_set_filenames" << endl << flush;
206 #endif
208     return Z_OK;