PSI sics-cvs-psi-2008-10-02

This commit is contained in:
2008-10-02 00:00:00 +00:00
committed by Douglas Clowes
parent 6e926b813f
commit 4baffb9b7a
304 changed files with 77527 additions and 3612 deletions

View File

@@ -7,6 +7,7 @@
Mark Koennecke, October 2002
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "nxdataset.h"
@@ -19,6 +20,8 @@ static int getTypeSize(int typecode){
return 4;
break;
case NX_FLOAT64:
case NX_INT64:
case NX_UINT64:
return 8;
break;
case NX_INT16:
@@ -208,6 +211,10 @@ double getNXDatasetValueAt(pNXDS dataset, int address){
case NX_UINT32:
value = (double)dataset->u.iPtr[address];
break;
case NX_INT64:
case NX_UINT64:
value = (double)dataset->u.lPtr[address];
break;
case NX_INT16:
case NX_UINT16:
value = (double)dataset->u.sPtr[address];
@@ -224,10 +231,10 @@ char *getNXDatasetText(pNXDS dataset){
int length, status = 1;
if(dataset == NULL){
status = 0;
return strdup("NULL");
}
if(dataset->magic != MAGIC){
status = 0;
return strdup("NULL");
}
if(dataset->rank > 1){
status = 0;
@@ -236,6 +243,8 @@ char *getNXDatasetText(pNXDS dataset){
dataset->type == NX_FLOAT64 ||
dataset->type == NX_INT32 ||
dataset->type == NX_UINT32 ||
dataset->type == NX_INT64 ||
dataset->type == NX_UINT64 ||
dataset->type == NX_INT16 ||
dataset->type == NX_UINT16 ) {
status = 0;
@@ -284,6 +293,10 @@ int putNXDatasetValueAt(pNXDS dataset, int address, double value){
case NX_UINT32:
dataset->u.iPtr[address] = (int)value;
break;
case NX_INT64:
case NX_UINT64:
dataset->u.lPtr[address] = (int64_t)value;
break;
case NX_INT16:
case NX_UINT16:
dataset->u.sPtr[address] = (short int)value;
@@ -294,6 +307,140 @@ int putNXDatasetValueAt(pNXDS dataset, int address, double value){
}
return 1;
}
/*----------------------------------------------------------------------
This is working recursively through the dimensions. When at the last:
actual copying takes place.
-----------------------------------------------------------------------*/
static void copyCutData(pNXDS source, pNXDS target, int sourceDim[],
int targetDim[], int start[], int end[],
int dim){
int i, length;
double val;
targetDim[dim] = 0;
length = end[dim] - start[dim];
if(dim == source->rank -1){
for(i = 0; i < length; i++){
sourceDim[dim] = start[dim] + i;
val = getNXDatasetValue(source,sourceDim);
targetDim[dim] = i;
putNXDatasetValue(target, targetDim, val);
}
} else {
for(i = 0; i < length; i++){
sourceDim[dim] = start[dim] + i;
targetDim[dim] = i;
copyCutData(source,target, sourceDim, targetDim, start, end, dim+1);
}
}
}
/*-----------------------------------------------------------------------*/
pNXDS cutNXDataset(pNXDS source, int start[], int end[]){
pNXDS result = NULL;
int newDim[NX_MAXRANK], i;
int sourceDim[NX_MAXRANK], targetDim[NX_MAXRANK];
for(i = 0; i < source->rank; i++){
if(start[i] < 0 || end[i] > source->dim[i]){
fprintf(stderr,"ERROR: invalid boundaries specified for cutting");
return NULL;
}
newDim[i] = end[i] - start[i];
if(newDim[i] <= 0){
fprintf(stderr,"ERROR: invalid cut limits specified for cutting dataset");
return NULL;
}
}
result = createNXDataset(source->rank, source->type, newDim);
if(result == NULL){
fprintf(stderr,"ERROR: out of memory creating result dataset");
return NULL;
}
copyCutData(source, result, sourceDim, targetDim, start, end, 0);
return result;
}
/*----------------------------------------------------------------------
This recurses through all dimesnions, thereby skipping the summed one.
At the end of the rescusion the actual summing is performed.
----------------------------------------------------------------------*/
static void sumData(pNXDS source, pNXDS target, int sourceDim[],
int targetDim[], int targetDimCount, int dimNo,
int start, int end, int currentDim){
int i, length;
double val, sumVal;
/*
when we have recursed through all dimensions
we actually do the sums...
*/
if(currentDim == source->rank){
length = end - start;
sumVal = getNXDatasetValue(target, targetDim);
for(i = 0; i < length; i++){
sourceDim[dimNo] = start + i;
val = getNXDatasetValue(source,sourceDim);
sumVal += val;
}
putNXDatasetValue(target, targetDim, sumVal);
} else {
/*
jump over the summed dimension while recursing
through the dimensions
*/
if(currentDim == dimNo){
sumData(source,target,sourceDim,
targetDim,targetDimCount,
dimNo,start,end,currentDim+1);
} else {
/*
loop over all values of the non summed dimension
*/
for(i = 0; i < source->dim[currentDim]; i++){
/*
the problem here is that we have to jump over the summed
dimension here. This why we have to maintain a separate
dimension count for the target array. Jumping is done
above.
*/
targetDim[targetDimCount] = i;
targetDimCount++;
sourceDim[currentDim] = i;
sumData(source,target,sourceDim,targetDim,targetDimCount,
dimNo,start,end,currentDim+1);
targetDimCount--;
}
}
}
}
/*-----------------------------------------------------------------------*/
pNXDS sumNXDataset(pNXDS source, int dimNo, int start, int end){
int newDim[NX_MAXRANK], targetDim[NX_MAXRANK], sourceDim[NX_MAXRANK];
pNXDS result = NULL;
int i, count;
if(dimNo < 0 || dimNo > source->rank-1) {
fprintf(stderr,"ERROR: invalid dimension for summing requested");
return NULL;
}
/*
make result dataset with missing summed dimension
*/
for(i = 0, count = 0; i < source->rank; i++){
if(i != dimNo){
newDim[count] = source->dim[i];
count++;
}
}
result = createNXDataset(source->rank-1, source->type, newDim);
if(result == NULL){
fprintf(stderr,"ERROR: out of memory creating result dataset");
return NULL;
}
sumData(source,result,sourceDim,targetDim,0,
dimNo, start, end, 0);
return result;
}