static void win_max_min(float *max, float *min, Trace *c_trace, STI_TIME s_start, STI_TIME s_end) { int i_start,i_end; int i; float c_max=-99999999,c_min=99999999; float c_data; /* 1. find the indexes for the start and end of the window */ i_start=timeToIndex(c_trace,s_start); i_end=timeToIndex(c_trace,s_end); for(i=i_start;i<=i_end;i++) { c_data=c_trace->wave->data[i]; if (c_data>c_max) { c_max=c_data; } if (c_data<c_min) { c_min=c_data; } } *max=c_max; *min=c_min; return; }
static void DrawPmotion() { XPoint *points, *plot; Trace *trc=traces[cur_itrc]; Trace *trcV, *trcH; Triplet *trip= trc->trip; float ymax, ymin, xmax, xmin; float vs, hs; float *dataV, *dataH; int s_idxV, s_idxH, len; int i; switch(combo) { case 0: /* Z-X */ if(! (trcV = trip->trc[TRC_Z]) || ! (trcH = trip->trc[TRC_X])) return; break; case 1: /* Z-Y */ if(! (trcV = trip->trc[TRC_Z]) || ! (trcH = trip->trc[TRC_Y])) return; break; case 2: /* X-Y */ if(! (trcV = trip->trc[TRC_Y]) || ! (trcH = trip->trc[TRC_X])) return; break; } if (cur_reg!=NULL) { STI_TIME s_time,e_time; Trace *sel_trace=SReg_in_trace(cur_reg,trcV,trcH); sel_trace=trc; if (sel_trace==NULL) { fprintf(stderr,"problem finding region\n"); } s_time=indexToTime(sel_trace,cur_reg->left_index,1); e_time=indexToTime(sel_trace,cur_reg->right_index,1); win_max_min(&ymax,&ymin,trcV,s_time,e_time); win_max_min(&xmax,&xmin,trcH,s_time,e_time); s_idxV=timeToIndex(trcV, s_time); s_idxH=timeToIndex(trcH, s_time); len=cur_reg->right_index-cur_reg->left_index; } else { ymax= trcV->axis.ymax; ymin= trcV->axis.ymin; xmax= trcH->axis.ymax; xmin= trcH->axis.ymin; s_idxV= timeToIndex(trcV, trip->sovrlap); s_idxH= timeToIndex(trcH, trip->sovrlap); len= timeToIndex(trcV, trip->eovrlap)-s_idxV+1; } /* compute scale */ vs= (float)(pmwin_h-PMWIN_Y_OFF-MARGIN)/(ymax-ymin); hs= (float)(pmwin_w-PMWIN_X_OFF-MARGIN)/(xmax-xmin); dataV= trcV->wave->data; dataH= trcH->wave->data; /* plot & label Y-axis */ PlotYAxis(ymax, &ymin, &vs, trcV); /* plot X-axis */ PlotXAxis(xmax, &xmin, &hs, trcH); plot= points= (XPoint *)Malloc(sizeof(XPoint)*2000); for(i=0; i < len; i+= 2000) { int npts= ((len-i)>2000)? 2000:len-i; int j; points= plot; for(j=0; j < npts; j++) { points->x= (dataH[s_idxH+i+j]-xmin)*hs + PMWIN_X_OFF; points->y= pmwin_h-PMWIN_Y_OFF-(dataV[s_idxV+i+j]-ymin)*vs; points++; } XDrawLines(theDisp, pm_win, pm_gc, plot, npts, CoordModeOrigin); } XFlush(theDisp); free(plot); }
uint readVectorFromEnsight( latticeMesh* mesh, scalar*** field, char* fname ) { unsigned int status = 0; // Open file char name[200]; sprintf(name, "lattice.%s_%d", fname, timeToIndex(mesh->time.current)); MPI_File file; MPI_File_open( MPI_COMM_WORLD, name, MPI_MODE_RDONLY, MPI_INFO_NULL, &file ); // Allocate space *field = matrixDoubleAlloc(mesh->mesh.nPoints, 3, 0); float *auxField = (float*)malloc( mesh->mesh.nPoints * sizeof(float) ); // Set Offset MPI_Offset offset = 240*sizeof(char) + sizeof(int); uint i,j; for(i = 0 ; i < mesh->parallel.pid ; i++ ) { offset += 3*mesh->parallel.nodesPerPatch[i] * sizeof(float); offset += 160*sizeof(char) + sizeof(int); } MPI_File_seek(file, offset, MPI_SEEK_SET); // Read Array MPI_Status st; for( j = 0 ; j < 3 ; j++) { MPI_File_read(file, auxField, mesh->mesh.nPoints, MPI_FLOAT, &st); for( i = 0 ; i < mesh->mesh.nPoints ; i++ ) { field[0][i][j] = (scalar)auxField[i]; } MPI_Barrier(MPI_COMM_WORLD); } MPI_File_close(&file); free(auxField); if( (int)st._ucount/sizeof(float) == mesh->mesh.nPoints ) { status = 1; } return status; }