Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Functions | Variables
vcrtorle.c File Reference
#include <assert.h>
#include <stdio.h>
#include "rle.h"
Include dependency graph for vcrtorle.c:

Go to the source code of this file.

Functions

static void FatalError (char *s)
 
static void ParseVICARHeader (FILE *fd)
 
void addVICARcomment (rle_hdr *the_hdr, char *label, char *value)
 
void SetUpRLEFile (rle_hdr *the_hdr, int xsize, int ysize, int zsize)
 
int main (int argc, argv)
 

Variables

static char rcs_id [] = "$Header:$"
 
static int VERBOSE = 0
 
static char * RoutineName
 
static long int VICARpos
 
static int LBLSIZE
 
static char FORMAT [80]
 
static char TYPE [80]
 
static int BUFSIZe
 
static int DIM
 
static int EOL
 
static int RECSIZE
 
static char ORG [80]
 
static int NL
 
static int NS
 
static int NB
 
static int N1
 
static int N2
 
static int N3
 
static int N4
 
static int NBB
 
static int NLB
 
static char HOST [80]
 
static char INTFMT [80]
 
static char REALFMT [80]
 
static char TASK [80]
 
static char USER [80]
 
static char DAT_TIM [80]
 
static char COMMENT [80]
 

Function Documentation

void addVICARcomment ( rle_hdr the_hdr,
char *  label,
char *  value 
)

Definition at line 257 of file vcrtorle.c.

260 {
261  char *comment;
262 
263  if ( *value == 0 )
264  return;
265  /* 8 = length of "VICAR" + "=" + nul byte. */
266  comment = (char *)malloc( 8 + strlen( label ) + strlen( value ) );
267  sprintf( comment, "VICAR-%s=%s", label, value );
268  rle_putcom( comment, the_hdr );
269 }
const char * rle_putcom(const char *value, rle_hdr *the_hdr)
void * malloc()
const char * value
Definition: rleClock.c:574
static void FatalError ( char *  s)
static

Definition at line 101 of file vcrtorle.c.

103  {
104  fprintf(stderr,"%s\n",s); exit(1);
105  }
_urt_stack * s
Definition: rleClock.c:919
int main ( int  argc,
argv   
)

Definition at line 291 of file vcrtorle.c.

294 {
295  char *VICARFileName = NULL;
296  FILE *fd;
297  unsigned char *VICARImage;
298  char *outfname = NULL;
299  int oflag = 0;
300  int x,y,z;
301  long int nread;
303  rle_pixel **rows;
304 
305  the_hdr = *rle_hdr_init( (rle_hdr *)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 )
310  exit( 1 );
311  rle_names( &the_hdr, cmd_name( argv ), outfname );
312  rle_addhist( argv, NULL, &the_hdr );
313 
314  fd = rle_open_f(the_hdr.cmd,VICARFileName,"r");
315 
316  ParseVICARHeader(fd);
317 
318  /* Check for what we know how to handle. */
319  if ( NB != 1 )
320  {
321  fprintf( stderr, "%s: Can't handle NB (%d) != 1 in %s.\n",
322  the_hdr.cmd, NB, the_hdr.file_name );
323  exit( 1 );
324  }
325  if ( strcmp( FORMAT, "'BYTE'" ) != 0 )
326  {
327  fprintf( stderr, "%s: Can't handle FORMAT (%s) != 'BYTE' in %s.\n",
328  the_hdr.cmd, FORMAT, the_hdr.file_name );
329  exit( 1 );
330  }
331 
332  /* !!! Will have to be modified when we handle NB>1. !!! */
333  VICARImage = (unsigned char *)malloc( NS * NL );
334  RLE_CHECK_ALLOC(the_hdr.cmd, VICARImage, "image");
335 
336  the_hdr.rle_file = rle_open_f( the_hdr.cmd, outfname, "w" );
337 
338  SetUpRLEFile(&the_hdr, NS, NL, NB);
339  rle_put_setup( &the_hdr );
340 
341  rows = (rle_pixel **)malloc( NB * sizeof(rle_pixel *) );
342 
343  /* !!! Will have to be modified when we handle NB>1. !!! */
344  nread = fread( VICARImage, 1, NS*NL, fd );
345  if ( nread < NS*NL )
346  fprintf( stderr, "%s: Short read from %s (%d bytes missing)\n",
347  the_hdr.cmd, the_hdr.file_name, NS*NL - nread );
348  for(y=(NL-1);y>=0;y--) /* flip in y */
349  {
350  /* !!! Loop somehow if NB > 1. !!! */
351  rows[0] = VICARImage + NS * y;
352 
353  rle_putrow( rows, NS, &the_hdr );
354  }
355  rle_puteof( &the_hdr );
356  exit(0);
357 }
rle_hdr the_hdr
Definition: aliastorle.c:100
static int NB
Definition: vcrtorle.c:119
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static char FORMAT[80]
Definition: vcrtorle.c:110
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
static int NL
Definition: vcrtorle.c:117
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
static int y
Definition: getami.c:691
static int NS
Definition: vcrtorle.c:118
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
Definition: rle.h:96
void SetUpRLEFile(rle_hdr *the_hdr, int xsize, int ysize, int zsize)
Definition: vcrtorle.c:271
static int x
Definition: getami.c:691
static int VERBOSE
Definition: vcrtorle.c:96
rle_pixel ** rows
Definition: rletopaint.c:57
FILE * fd
Definition: getfb.h:18
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
const char * file_name
Definition: rle.h:134
int oflag
Definition: painttorle.c:45
static void ParseVICARHeader(FILE *fd)
Definition: vcrtorle.c:134
FILE * rle_file
Definition: rle.h:114
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
static void ParseVICARHeader ( FILE *  fd)
static

Definition at line 134 of file vcrtorle.c.

136 {
137  char Name[81],Value[1024];
138  int n;
139 
140  for ( n = 0; ; n++ )
141  {
142  Value[n] = fgetc( fd );
143  if ( Value[n] == ' ' )
144  break;
145  }
146  Value[n++] = 0;
147 
148  sscanf(Value,"%80[^=]=%d",Name,&LBLSIZE);
149  if (VERBOSE) fprintf(stderr,"[%s = %d]\n",Name,LBLSIZE);
150  if (0 != strcmp("LBLSIZE",Name)) FatalError("This is not a VICAR file");
151 
152  /* There must be a better way to read the header. This is gross. */
153  while(n < LBLSIZE)
154  {
155  register char *cp;
156  register char c = ' ';
157  int done;
158 
159  /* Skip spaces. */
160  while ( c == ' ' && n < LBLSIZE )
161  {
162  c = fgetc( fd );
163  n++;
164  }
165 
166  /* Get Name. */
167  cp = &Name[0];
168  while ( c != '=' && c != '\0' && n < LBLSIZE )
169  {
170  *cp++ = c;
171  c = fgetc( fd );
172  n++;
173  }
174  *cp = 0;
175 
176  if ( n >= LBLSIZE )
177  break;
178 
179  if ('\0' == Name[0] || c == '\0')
180  break;
181 
182  /* At this point, c is '='. Get the next character. */
183  Value[0] = fgetc( fd );
184  n++;
185 
186  cp = &Value[1];
187  if ('\'' == Value[0])
188  for(;n < LBLSIZE;cp++)
189  {
190  *cp = fgetc( fd );
191  n++;
192  if ('\'' == *cp)
193  {
194  *++cp = '\0';
195  break;
196  }
197  }
198  else
199  for(;n < LBLSIZE;cp++)
200  {
201  *cp = fgetc(fd);
202  n++;
203  if (' ' == *cp)
204  {
205  *cp = '\0';
206  done = 0;
207  break;
208  }
209  if ('\0' == *cp)
210  {
211  done = -1;
212  break;
213  }
214  }
215 
216  if (VERBOSE) fprintf(stderr,"[%s = %s]\n",Name,Value);
217  Value[80] = '\0'; /* for our own protection... */
218 
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;}
242  if (done) break;
243  }
244 
245  /* Skip the rest of the label. */
246  while ( n < LBLSIZE )
247  {
248  (void)fgetc( fd );
249  n++;
250  }
251 
252  VICARpos = n;
253 }
static int DIM
Definition: vcrtorle.c:113
static int NB
Definition: vcrtorle.c:119
static char HOST[80]
Definition: vcrtorle.c:126
static char FORMAT[80]
Definition: vcrtorle.c:110
static void FatalError(char *s)
Definition: vcrtorle.c:101
static char DAT_TIM[80]
Definition: vcrtorle.c:131
static char ORG[80]
Definition: vcrtorle.c:116
static int N2
Definition: vcrtorle.c:121
static int BUFSIZe
Definition: vcrtorle.c:112
static int NL
Definition: vcrtorle.c:117
static int EOL
Definition: vcrtorle.c:114
static int N3
Definition: vcrtorle.c:122
static int NS
Definition: vcrtorle.c:118
static int RECSIZE
Definition: vcrtorle.c:115
static int NLB
Definition: vcrtorle.c:125
static int VERBOSE
Definition: vcrtorle.c:96
static char USER[80]
Definition: vcrtorle.c:130
static char INTFMT[80]
Definition: vcrtorle.c:127
done()
Definition: getcx3d.c:270
FILE * fd
Definition: getfb.h:18
static long int VICARpos
Definition: vcrtorle.c:99
static char REALFMT[80]
Definition: vcrtorle.c:128
static int LBLSIZE
Definition: vcrtorle.c:109
static int N4
Definition: vcrtorle.c:123
static int N1
Definition: vcrtorle.c:120
static char TASK[80]
Definition: vcrtorle.c:129
static int NBB
Definition: vcrtorle.c:124
static char COMMENT[80]
Definition: vcrtorle.c:132
static char TYPE[80]
Definition: vcrtorle.c:111
void SetUpRLEFile ( rle_hdr the_hdr,
int  xsize,
int  ysize,
int  zsize 
)

Definition at line 271 of file vcrtorle.c.

274 {
275 
276  the_hdr->xmin = 0;
277  the_hdr->xmax = xsize - 1;
278  the_hdr->ymin = 0;
279  the_hdr->ymax = ysize - 1;
280 
281  /* 1=B&W, 3=RGB? */
282  the_hdr->ncolors = zsize;
283 
284  /* Carry over info from VICAR file as comments. */
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 );
289 }
int xmin
Definition: rle.h:100
static char DAT_TIM[80]
Definition: vcrtorle.c:131
int xsize
Definition: read98721.c:58
int ymin
Definition: rle.h:100
int xmax
Definition: rle.h:100
static char USER[80]
Definition: vcrtorle.c:130
int ymax
Definition: rle.h:100
int ysize
Definition: read98721.c:59
static char TASK[80]
Definition: vcrtorle.c:129
static char COMMENT[80]
Definition: vcrtorle.c:132
void addVICARcomment(rle_hdr *the_hdr, char *label, char *value)
Definition: vcrtorle.c:257
int ncolors
Definition: rle.h:100

Variable Documentation

int BUFSIZe
static

Definition at line 112 of file vcrtorle.c.

char COMMENT[80]
static

Definition at line 132 of file vcrtorle.c.

char DAT_TIM[80]
static

Definition at line 131 of file vcrtorle.c.

int DIM
static

Definition at line 113 of file vcrtorle.c.

int EOL
static

Definition at line 114 of file vcrtorle.c.

char FORMAT[80]
static

Definition at line 110 of file vcrtorle.c.

char HOST[80]
static

Definition at line 126 of file vcrtorle.c.

char INTFMT[80]
static

Definition at line 127 of file vcrtorle.c.

int LBLSIZE
static

Definition at line 109 of file vcrtorle.c.

int N1
static

Definition at line 120 of file vcrtorle.c.

int N2
static

Definition at line 121 of file vcrtorle.c.

int N3
static

Definition at line 122 of file vcrtorle.c.

int N4
static

Definition at line 123 of file vcrtorle.c.

int NB
static

Definition at line 119 of file vcrtorle.c.

int NBB
static

Definition at line 124 of file vcrtorle.c.

int NL
static

Definition at line 117 of file vcrtorle.c.

int NLB
static

Definition at line 125 of file vcrtorle.c.

int NS
static

Definition at line 118 of file vcrtorle.c.

char ORG[80]
static

Definition at line 116 of file vcrtorle.c.

char rcs_id[] = "$Header:$"
static

Definition at line 85 of file vcrtorle.c.

char REALFMT[80]
static

Definition at line 128 of file vcrtorle.c.

int RECSIZE
static

Definition at line 115 of file vcrtorle.c.

char* RoutineName
static

Definition at line 97 of file vcrtorle.c.

char TASK[80]
static

Definition at line 129 of file vcrtorle.c.

char TYPE[80]
static

Definition at line 111 of file vcrtorle.c.

char USER[80]
static

Definition at line 130 of file vcrtorle.c.

int VERBOSE = 0
static

Definition at line 96 of file vcrtorle.c.

long int VICARpos
static

Definition at line 99 of file vcrtorle.c.