101 static void FatalError(s)
104 fprintf(stderr,
"%s\n",s); exit(1);
134 static void ParseVICARHeader(fd)
137 char Name[81],Value[1024];
142 Value[n] = fgetc( fd );
143 if ( Value[n] ==
' ' )
148 sscanf(Value,
"%80[^=]=%d",Name,&
LBLSIZE);
150 if (0 != strcmp(
"LBLSIZE",Name)) FatalError(
"This is not a VICAR file");
156 register char c =
' ';
160 while ( c ==
' ' && n <
LBLSIZE )
168 while ( c !=
'=' && c !=
'\0' && n <
LBLSIZE )
179 if (
'\0' == Name[0] || c ==
'\0')
183 Value[0] = fgetc( fd );
187 if (
'\'' == Value[0])
216 if (
VERBOSE) fprintf(stderr,
"[%s = %s]\n",Name,Value);
219 if (0 == strcmp(
"FORMAT" ,Name)) {strcpy(
FORMAT ,Value);
continue;}
220 if (0 == strcmp(
"TYPE" ,Name)) {strcpy(
TYPE ,Value);
continue;}
221 if (0 == strcmp(
"BUFSIZ" ,Name)) {
BUFSIZe = atoi(Value);
continue;}
222 if (0 == strcmp(
"DIM" ,Name)) {
DIM = atoi(Value);
continue;}
223 if (0 == strcmp(
"EOL" ,Name)) {
EOL = atoi(Value);
continue;}
224 if (0 == strcmp(
"RECSIZE",Name)) {
RECSIZE = atoi(Value);
continue;}
225 if (0 == strcmp(
"ORG" ,Name)) {strcpy(
ORG ,Value);
continue;}
226 if (0 == strcmp(
"NL" ,Name)) {
NL = atoi(Value);
continue;}
227 if (0 == strcmp(
"NS" ,Name)) {
NS = atoi(Value);
continue;}
228 if (0 == strcmp(
"NB" ,Name)) {
NB = atoi(Value);
continue;}
229 if (0 == strcmp(
"N1" ,Name)) {
N1 = atoi(Value);
continue;}
230 if (0 == strcmp(
"N2" ,Name)) {
N2 = atoi(Value);
continue;}
231 if (0 == strcmp(
"N3" ,Name)) {
N3 = atoi(Value);
continue;}
232 if (0 == strcmp(
"N4" ,Name)) {
N4 = atoi(Value);
continue;}
233 if (0 == strcmp(
"NBB" ,Name)) {
NBB = atoi(Value);
continue;}
234 if (0 == strcmp(
"NLB" ,Name)) {
NLB = atoi(Value);
continue;}
235 if (0 == strcmp(
"HOST" ,Name)) {strcpy(
HOST ,Value);
continue;}
236 if (0 == strcmp(
"INTFMT" ,Name)) {strcpy(
INTFMT ,Value);
continue;}
237 if (0 == strcmp(
"REALFMT",Name)) {strcpy(
REALFMT,Value);
continue;}
238 if (0 == strcmp(
"TASK" ,Name)) {strcpy(
TASK ,Value);
continue;}
239 if (0 == strcmp(
"USER" ,Name)) {strcpy(
USER ,Value);
continue;}
240 if (0 == strcmp(
"DAT_TIM",Name)) {strcpy(
DAT_TIM,Value);
continue;}
241 if (0 == strcmp(
"COMMENT",Name)) {strcpy(
COMMENT,Value);
continue;}
257 addVICARcomment( the_hdr, label, value )
266 comment = (
char *)malloc( 8 + strlen( label ) + strlen( value ) );
267 sprintf( comment,
"VICAR-%s=%s", label, value );
271 void SetUpRLEFile(the_hdr, xsize, ysize, zsize)
273 int xsize, ysize, zsize;
277 the_hdr
->xmax = xsize - 1;
279 the_hdr
->ymax = ysize - 1;
285 addVICARcomment( the_hdr,
"USER",
USER );
286 addVICARcomment( the_hdr,
"DAT_TIM",
DAT_TIM );
287 addVICARcomment( the_hdr,
"TASK",
TASK );
288 addVICARcomment( the_hdr,
"COMMENT",
COMMENT );
295 char *VICARFileName = NULL;
297 unsigned char *VICARImage;
298 char *outfname = NULL;
306 if (
scanargs( argc
, argv
, "% v%- o%-outfile!s infile%s\n(\
307 \tConvert VICAR format image to URT.\n\
308 \t-v\tVerbose -- print out VICAR header information.)",
309 &
VERBOSE, &oflag
, &outfname
, &VICARFileName
) == 0 )
311 rle_names( &the_hdr, cmd_name( argv ), outfname );
316 ParseVICARHeader(fd);
321 fprintf( stderr,
"%s: Can't handle NB (%d) != 1 in %s.\n",
325 if ( strcmp(
FORMAT,
"'BYTE'" ) != 0 )
327 fprintf( stderr,
"%s: Can't handle FORMAT (%s) != 'BYTE' in %s.\n",
333 VICARImage = (
unsigned char *)malloc(
NS *
NL );
338 SetUpRLEFile(&the_hdr,
NS,
NL,
NB);
344 nread = fread( VICARImage, 1,
NS*
NL, fd );
346 fprintf( stderr,
"%s: Short read from %s (%d bytes missing)\n",
348 for(y=(
NL-1);y>=0;y--)
351 rows[0] = VICARImage +
NS * y;
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
void main(int argc, char **argv)
int scanargs(int argc, char **argv, const char *format,...)
void rle_puteof(rle_hdr *the_hdr)
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
static char * RoutineName
void rle_put_setup(rle_hdr *the_hdr)
const char * rle_putcom(char *value, rle_hdr *the_hdr) const
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define RLE_CHECK_ALLOC(pgm, ptr, name)