| 1 |
/* |
| 2 |
* This subroutine performs the calls to the PBOB c routines |
| 3 |
* |
| 4 |
*/ |
| 5 |
#include <stdlib.h> |
| 6 |
#include <assert.h> |
| 7 |
#include <string.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <sph_types.h> |
| 10 |
#include <pbob.h> |
| 11 |
#include <particle.h> |
| 12 |
|
| 13 |
extern PBOB *ReadPBOB(char *file_name); |
| 14 |
extern PARTICLE *ReadParticle(char *file_name,int time_slice,int start_indx,int N); |
| 15 |
|
| 16 |
void set_blocklabel(int *icol, char *name); |
| 17 |
void read_pbob_data_fromc(int icol, int istep, int np, double temparr[np],int itype[np], char *tag); |
| 18 |
void read_pbob_header(char *filename, |
| 19 |
int *npart, |
| 20 |
int *ncol, |
| 21 |
int *nsteps, |
| 22 |
int *ndim, |
| 23 |
int *ndimV, |
| 24 |
double *time, |
| 25 |
int *ierr) |
| 26 |
{ |
| 27 |
*npart = 0; |
| 28 |
*ierr = 0; |
| 29 |
*ncol = 0; |
| 30 |
*nsteps = 0; |
| 31 |
*time = 0.; |
| 32 |
*npart = 0; |
| 33 |
*ndim = 2; |
| 34 |
*ndimV = 2; |
| 35 |
*ncol = 15; /* hard wired */ |
| 36 |
PBOB *pbob = NULL; |
| 37 |
if ((pbob=ReadPBOB(filename))==NULL) { |
| 38 |
*ierr = 1; |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
/*printf(" cluster_size = %i \n",pbob->cluster_size); |
| 43 |
printf(" length_units = %s \n",pbob->length_units); |
| 44 |
printf(" mass_units = %s \n",pbob->mass_units); |
| 45 |
printf(" time_units = %s \n",pbob->time_units); |
| 46 |
printf(" energy_units = %s \n",pbob->internal_energy_units); |
| 47 |
*/ |
| 48 |
printf(" short title = %s \n",pbob->short_title); |
| 49 |
printf(" total_particles = %llu \n",pbob->total_particles); |
| 50 |
printf(" nn_k = %i \n",pbob->nn_k); |
| 51 |
printf(" time slices = %i \n",pbob->number_of_time_slices); |
| 52 |
/* |
| 53 |
printf(" offset = %i \n",pbob->first_particle_byte_offset); |
| 54 |
printf(" length = %i \n",pbob->particle_length_bytes); |
| 55 |
*/ |
| 56 |
printf(" endian = %s \n",pbob->endian_str); |
| 57 |
printf(" version = %s \n",pbob->pbob_version); |
| 58 |
*nsteps = pbob->number_of_time_slices; |
| 59 |
*npart = pbob->total_particles; |
| 60 |
*time = pbob->time; |
| 61 |
/* |
| 62 |
printf(" ascii_header: \n"); |
| 63 |
printf("%s\n",pbob.ascii_header); |
| 64 |
*/ |
| 65 |
} |
| 66 |
|
| 67 |
void read_pbob_data(char *filename, |
| 68 |
int npart, |
| 69 |
int time_slice, |
| 70 |
double *timeval, |
| 71 |
int *ierr) |
| 72 |
{ |
| 73 |
|
| 74 |
PARTICLE *particle = NULL; |
| 75 |
*ierr = 0; |
| 76 |
int start_indx = 0; |
| 77 |
int N = npart; |
| 78 |
int i; |
| 79 |
*timeval = -1.; |
| 80 |
/*printf(" time_slice = %i\n",time_slice);*/ |
| 81 |
if ((particle=ReadParticle(filename,time_slice,start_indx,N))==NULL) |
| 82 |
{ |
| 83 |
*ierr = 2; |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
int species[npart]; |
| 88 |
for (i=0;i<N;i++) { |
| 89 |
switch(particle[i].species) |
| 90 |
{ |
| 91 |
case 2048: |
| 92 |
species[i] = 3; |
| 93 |
break; |
| 94 |
case 1024: |
| 95 |
species[i] = 2; |
| 96 |
break; |
| 97 |
default: |
| 98 |
species[i] = 1; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/* |
| 103 |
printf("i = %7i x = %20.10f index = %i species = %i node=%i\n",i,(float)particle[i].x,(int)particle[i].index,(int)particle[i].species,(int)particle[i].start_node); |
| 104 |
*/ |
| 105 |
*timeval = particle[0].time; |
| 106 |
double *temp = 0; |
| 107 |
temp = malloc(npart*sizeof(double)); |
| 108 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].x; } |
| 109 |
read_pbob_data_fromc(1,time_slice,N,temp,species,"x"); |
| 110 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].z; } |
| 111 |
read_pbob_data_fromc(2,time_slice,N,temp,species,"z"); |
| 112 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].y; } |
| 113 |
read_pbob_data_fromc(3,time_slice,N,temp,species,"y"); |
| 114 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].vx; } |
| 115 |
read_pbob_data_fromc(4,time_slice,N,temp,species,"vx"); |
| 116 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].vz; } |
| 117 |
read_pbob_data_fromc(5,time_slice,N,temp,species,"vz"); |
| 118 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].vy; } |
| 119 |
read_pbob_data_fromc(6,time_slice,N,temp,species,"vy"); |
| 120 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].ax; } |
| 121 |
read_pbob_data_fromc(7,time_slice,N,temp,species,"ax"); |
| 122 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].az; } |
| 123 |
read_pbob_data_fromc(8,time_slice,N,temp,species,"az"); |
| 124 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].ay; } |
| 125 |
read_pbob_data_fromc(9,time_slice,N,temp,species,"ay"); |
| 126 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].U; } |
| 127 |
read_pbob_data_fromc(10,time_slice,N,temp,species,"U"); |
| 128 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].dUdt; } |
| 129 |
read_pbob_data_fromc(11,time_slice,N,temp,species,"dUdt"); |
| 130 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].h; } |
| 131 |
read_pbob_data_fromc(12,time_slice,N,temp,species,"h"); |
| 132 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].rho; } |
| 133 |
read_pbob_data_fromc(13,time_slice,N,temp,species,"rho"); |
| 134 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].p; } |
| 135 |
read_pbob_data_fromc(14,time_slice,N,temp,species,"p"); |
| 136 |
for (i=0;i<N;i++) { temp[i] = (double) particle[i].m; } |
| 137 |
read_pbob_data_fromc(15,time_slice,N,temp,species,"m"); |
| 138 |
free(temp); |
| 139 |
|
| 140 |
return; |
| 141 |
} |
| 142 |
|