void Extractor::init(tokenlist &args) { // defaults xvflag=0; newdim[0]=41; newdim[1]=51; newdim[2]=27; newcube.voxsize[0]=3.75; newcube.voxsize[1]=3.75; newcube.voxsize[2]=5.00; newcube.origin[0]=21; newcube.origin[1]=31; newcube.origin[2]=10; original.ReadFile(args[0]); if (args.size()==1) newcube.SetFileName((string)"m"+original.GetFileName()); if (args.size()==2 || args.size()==3) { newcube.SetFileName(args[1]); if (args.size()==3) { xval=strtol(args[2]); xvflag=1; } } if (args.size()==11 || args.size()==12) { newcube.SetFileName(args[1]); newdim[0]=strtol(args[2]); newdim[1]=strtol(args[3]); newdim[2]=strtol(args[4]); newcube.voxsize[0]=strtod(args[5]); newcube.voxsize[1]=strtod(args[6]); newcube.voxsize[2]=strtod(args[7]); newcube.origin[0]=strtol(args[8]); newcube.origin[1]=strtol(args[9]); newcube.origin[2]=strtol(args[10]); if (args.size()==12) { xval=strtol(args[11]); xvflag=1; } } newcube.SetVolume(newdim[0],newdim[1],newdim[2],original.datatype); }
int receive_3d (char *fifo, char *path, int dimx, int dimy, int dimz, int datatype) { char fifo_from_idl [PATH_MAX]; char fifo_to_idl [PATH_MAX]; char line[200]; int i; strcpy (fifo_from_idl, fifo ); strcpy (fifo_to_idl, fifo ); strcat (fifo_from_idl, "-"); readfifopath = fifo_from_idl; return_path = fifo_to_idl; FILE *f = fopen (fifo_from_idl, "rb"); if (!f) complain(BADPATH); read_fifo = f; #ifdef DEBUG fprintf (stderr, "Entered receive_3d\n"); fflush (stderr); #endif //---------------------------------------------- // Check params // if (dimx <= 0 || dimy <= 0 || dimz <= 0) complain(ERROR_BADDIMS); if (datatype < 0) complain(ERROR_BADTYPE); //---------------------------------------------- // Get data type & size. // VB_datatype dt2; int datasize=0; switch (datatype) { case 1: dt2 = vb_byte; datasize=1; break; case 2: dt2 = vb_short; datasize=2; break; case 3: dt2 = vb_long; datasize=4; break; case 4: dt2 = vb_float; datasize=sizeof(float); break; case 5: dt2 = vb_double; datasize=sizeof(double); break; default: return ERROR_BADTYPE; } //---------------------------------------------- // Get the user-header info. // vector<string> user_header; if (0 > readline(f, line, 199)) complain(ERROR_EOF); int total_header_items = atoi(line); if (total_header_items < 0) complain(ERROR_BADHEADER); for (i=0; i < total_header_items; i++) { if (0 > readline(f, line, 199)) complain(ERROR_EOF); user_header.push_back (string(line)); } //---------------------------------------------- // Create the Cube object & put the data in it. // Cube *c = new Cube(dimx,dimy,dimz,dt2); if (!c) complain(ERROR_NOMEM); //---------------------------------------------- // Store the user header into the Cube object. // for (i=0; i < total_header_items; i++) { c->header.push_back (user_header[i]); } //---------------------------------------------- // Now we process specific user header data // that we know have equivalents in the Tes object. // for (i=0; i < total_header_items; i++) { const char *s = user_header[i].c_str(); char *s2 = s ? strchr(s, ':') : NULL; if (s2 && '*' == *s2) continue; #ifdef DEBUG fprintf(stderr, "putdata got user header line: %s\n", s); #endif if (!s2) s2 = s ? strchr (s, '=') : NULL; if (s2) { *s2++ = 0; if (!strcasecmp (s, "VoxSizes(xyz)")) { double x,y,z; if (3 == sscanf (s2, "%lg %lg %lg", &x,&y,&z)) { c->voxsize[0] = x; c->voxsize[1] = y; c->voxsize[2] = z; } else { WARNING("invalid voxsizes from user header."); } } else if (!strcasecmp (s, "Origin(xyz)")) { int x,y,z; if (3 == sscanf (s2, "%d %d %d", &x,&y,&z)) { c->origin[0] = x; c->origin[1] = y; c->origin[2] = z; } else { WARNING("invalid origin from user header."); } } else if (!strcasecmp (s, "Orientation")) { c->orient = s2; } else if (!strcasecmp (s, "Scale")) { // float f = atof(s2); // c->scalefactor = f ? f : 1.0; } else if (!strcasecmp (s, "ByteOrder")) { c->filebyteorder = atoi(s2)? ENDIAN_BIG : ENDIAN_LITTLE; } } } //---------------------------------------------- // Get the data // ulong chunk_size = dimx * dimy * dimz * datasize; unsigned char *chunk = (unsigned char*) malloc (chunk_size); if (!chunk) complain(ERROR_NOMEM); if (chunk_size != fread (chunk,1,chunk_size,f)) complain(ERROR_READFAIL); fclose (f); read_completed = true; c->data = chunk; //---------------------------------------------- // Write the Cube to a file. // c->SetFileName (path); #ifdef DEBUG fprintf(stderr, "Calling write cube to file %s\n", path); #endif c->WriteFile (); //---------------------------------------------- // Return the success code // f = fopen (fifo_to_idl, "wb"); if (!f) return 0; fprintf (f, "0\n"); fflush(f); fclose(f); delete c; return 0; }