source: issm/trunk-jpl/src/c/Container/Results.cpp@ 10989

Last change on this file since 10989 was 10989, checked in by Mathieu Morlighem, 13 years ago

Fixed many bugs in OutputResult for results_as_patches = 0

File size: 4.1 KB
Line 
1/*
2 * \file Results.c
3 * \brief: implementation of the Results class, derived from DataSet class
4 */
5
6/*Headers: {{{1*/
7#ifdef HAVE_CONFIG_H
8 #include <config.h>
9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
13#include <vector>
14#include <functional>
15#include <algorithm>
16#include <iostream>
17
18#include "./DataSet.h"
19#include "../shared/shared.h"
20#include "../include/include.h"
21#include "../EnumDefinitions/EnumDefinitions.h"
22
23using namespace std;
24/*}}}*/
25
26/*Object constructors and destructor*/
27/*FUNCTION Results::Results(){{{1*/
28Results::Results(){
29 enum_type=ResultsEnum;
30 return;
31}
32/*}}}*/
33/*FUNCTION Results::~Results(){{{1*/
34Results::~Results(){
35 return;
36}
37/*}}}*/
38
39/*Object management*/
40/*FUNCTION Results::SpawnTriaResults{{{1*/
41Results* Results::SpawnTriaResults(int* indices){
42
43 /*Intermediary*/
44 vector<Object*>::iterator object;
45 ElementResult* resultin=NULL;
46 ElementResult* resultout=NULL;
47
48 /*Output*/
49 Results* newresults=new Results();
50
51 /*Go through results and call Spawn function*/
52 for ( object=objects.begin() ; object < objects.end(); object++ ){
53
54 /*Create new result*/
55 resultin=(ElementResult*)(*object);
56 resultout=resultin->SpawnTriaElementResult(indices);
57
58 /*Add result to new results*/
59 newresults->AddObject((Object*)resultout);
60 }
61
62 /*Assign output pointer*/
63 return newresults;
64}
65/*}}}*/
66/*FUNCTION Results::Write{{{1*/
67#ifdef _SERIAL_
68void Results::Write(mxArray** pdataref){
69
70 int i,j;
71 int count;
72
73 /*output: */
74 mxArray* dataref=NULL;
75 mxArray* processeddataref=NULL;
76 mwSize nfields;
77 mwSize maxfields;
78 mwSize nsteps;
79 mwSize step;
80 const char **fnames = NULL;
81 int *enums = NULL;
82 int baseenum;
83 mwSize onebyone[2] = {1,1};
84 mwSize ndim = 2;
85
86 /*How many time steps do we have? : */
87 nsteps=0;
88 for(i=0;i<this->Size();i++){
89 ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
90 step=result->GetStep();
91 if(step>nsteps)nsteps=step;
92 }
93 onebyone[0]=nsteps;
94
95 /*How many field names do we have. First, figure out how many result types we have: */
96 maxfields=(mwSize)this->Size();
97 enums=(int*)xmalloc(maxfields*sizeof(int));
98 for(i=0;i<maxfields;i++){
99 ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
100 enums[i]=result->InstanceEnum();
101 }
102 /*Now, make result types unique: */
103 for(i=0;i<maxfields;i++){
104 if(enums[i]>=0){//if <0, it means this enum was found to replicate another one previously
105 baseenum=enums[i];
106 /*is the baseenum repeated later on?:*/
107 for(j=i+1;j<maxfields;j++){
108 if (enums[j]==baseenum)enums[j]=-1;
109 }
110 }
111 else continue;
112 }
113
114 /*Now, go through enums, and whatever is not null is a non repeated field name: */
115 nfields=0;
116 for(i=0;i<maxfields;i++)if(enums[i]>0)nfields++;
117
118 /*Add 2 fields for time and step: */
119 nfields=nfields+2;
120
121 /*Fill the names of the structure field: */
122 fnames=(const char**)xmalloc(nfields*sizeof(char*));
123 count=0;
124 for(i=0;i<maxfields;i++){
125 if (enums[i]>0){
126 fnames[count]=EnumToStringx(enums[i]);
127 count++;
128 }
129 }
130 /*don't forget the extra fields "time" and "step":*/
131 fnames[nfields-2]="time";
132 fnames[nfields-1]="step";
133
134 /*Initialize structure: */
135 dataref=mxCreateStructArray( ndim,onebyone,nfields,fnames);
136
137 /*Fill each field: */
138 for(i=0;i<this->Size();i++){ //do not include the last one used for time
139 ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
140 result->SetMatlabField(dataref);
141 }
142
143 /*Now, process the patch in the dataref structure, by calling MatlabProcessPatch.m
144 *on the current dataref structure: */
145 mexCallMATLAB(1,&processeddataref,1,&dataref, "MatlabProcessPatch");
146
147 /*Assign output pointers:*/
148 *pdataref=processeddataref;
149}
150#else
151void Results::Write(Parameters* parameters){
152
153 int i;
154 FILE *fid = NULL;
155 bool io_gather=true;
156
157 /*Recover file descriptor: */
158 parameters->FindParam(&fid,OutputFilePointerEnum);
159 parameters->FindParam(&io_gather,SettingsIoGatherEnum);
160
161 for(i=0;i<this->Size();i++){
162 ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
163
164 /*write result to disk: */
165 result->WriteData(fid,io_gather);
166 }
167
168}
169#endif
170/*}}}*/
Note: See TracBrowser for help on using the repository browser.