[3938] | 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
|
---|
[9320] | 8 | #include <config.h>
|
---|
[3938] | 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 |
|
---|
| 23 | using namespace std;
|
---|
| 24 | /*}}}*/
|
---|
| 25 |
|
---|
| 26 | /*Object constructors and destructor*/
|
---|
| 27 | /*FUNCTION Results::Results(){{{1*/
|
---|
| 28 | Results::Results(){
|
---|
[10522] | 29 | enum_type=ResultsEnum;
|
---|
[3938] | 30 | return;
|
---|
| 31 | }
|
---|
| 32 | /*}}}*/
|
---|
| 33 | /*FUNCTION Results::~Results(){{{1*/
|
---|
| 34 | Results::~Results(){
|
---|
| 35 | return;
|
---|
| 36 | }
|
---|
| 37 | /*}}}*/
|
---|
| 38 |
|
---|
[4037] | 39 | /*Object management*/
|
---|
| 40 | /*FUNCTION Results::SpawnTriaResults{{{1*/
|
---|
| 41 | Results* Results::SpawnTriaResults(int* indices){
|
---|
[3938] | 42 |
|
---|
[4037] | 43 | /*Intermediary*/
|
---|
[3938] | 44 | vector<Object*>::iterator object;
|
---|
[4053] | 45 | ElementResult* resultin=NULL;
|
---|
| 46 | ElementResult* resultout=NULL;
|
---|
[3938] | 47 |
|
---|
[4037] | 48 | /*Output*/
|
---|
| 49 | Results* newresults=new Results();
|
---|
[3938] | 50 |
|
---|
[4037] | 51 | /*Go through results and call Spawn function*/
|
---|
[3938] | 52 | for ( object=objects.begin() ; object < objects.end(); object++ ){
|
---|
| 53 |
|
---|
[4037] | 54 | /*Create new result*/
|
---|
[4053] | 55 | resultin=(ElementResult*)(*object);
|
---|
| 56 | resultout=resultin->SpawnTriaElementResult(indices);
|
---|
[3938] | 57 |
|
---|
[4037] | 58 | /*Add result to new results*/
|
---|
[4042] | 59 | newresults->AddObject((Object*)resultout);
|
---|
[4037] | 60 | }
|
---|
[3938] | 61 |
|
---|
[4037] | 62 | /*Assign output pointer*/
|
---|
| 63 | return newresults;
|
---|
[3938] | 64 | }
|
---|
| 65 | /*}}}*/
|
---|
[6372] | 66 | /*FUNCTION Results::Write{{{1*/
|
---|
[11853] | 67 | #ifdef _SERIAL_
|
---|
[6372] | 68 | void 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);
|
---|
[9883] | 100 | enums[i]=result->InstanceEnum();
|
---|
[6372] | 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){
|
---|
[8224] | 126 | fnames[count]=EnumToStringx(enums[i]);
|
---|
[6372] | 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: */
|
---|
[10989] | 138 | for(i=0;i<this->Size();i++){ //do not include the last one used for time
|
---|
[6372] | 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
|
---|
| 151 | void Results::Write(Parameters* parameters){
|
---|
| 152 |
|
---|
| 153 | int i;
|
---|
| 154 | FILE *fid = NULL;
|
---|
[6389] | 155 | bool io_gather=true;
|
---|
[6372] | 156 |
|
---|
| 157 | /*Recover file descriptor: */
|
---|
| 158 | parameters->FindParam(&fid,OutputFilePointerEnum);
|
---|
[9622] | 159 | parameters->FindParam(&io_gather,SettingsIoGatherEnum);
|
---|
[6372] | 160 |
|
---|
| 161 | for(i=0;i<this->Size();i++){
|
---|
| 162 | ExternalResult* result=(ExternalResult*)this->GetObjectByOffset(i);
|
---|
| 163 |
|
---|
| 164 | /*write result to disk: */
|
---|
[6389] | 165 | result->WriteData(fid,io_gather);
|
---|
[6372] | 166 | }
|
---|
| 167 |
|
---|
| 168 | }
|
---|
| 169 | #endif
|
---|
| 170 | /*}}}*/
|
---|