H�/***********************************************************************@�*_Title ADDLAB - Combine VICAR label and PDS label/edr data file�*�H�*_Descr ADDLAB combines the VICAR label and the PDS label/edr data filesK�* that were created for CDROM into the original NIMS edr file format �I�* of 1024 byte records. ADDLAB is used solely to create a file for�A�* the VICAR/NIMS software systems which reqire a VICAR formatted��* file.��*�H�* ADDLAB has two command-line arguments - the first parameter mustE�* contain the name of the PDS/EDR labeled file. Specify the complete�D�* pathname, including the directory specification. The program willC�* determine the name of the VICAR label file. The second parameter��* is the output file.��*�A�* The commands to compile, link and run this program on a DEC VAX�*�* and a SUN UNIX workstation are below.�*��* VAX:�* cc addlab�* link addlab�F�* To run a C program with command-line arguments on a VAX the:�* program must be installed as a foreign command::�* eg: addf=="$disk:[directory]addlab.exe" �* To run:/�* eg: addf pdsfile outfile ��*��*��* SUN UNIX:�;�* cc -o addlab.exe addlab.c will compile and link��* the program.;�* addlab pdsfile outfile will run the program.��*�I�*_Hist Nov 18 1992 Tracie Stoewe, PDS Imaging Node, USGS, Flagstaff Az��*��*_End�I�************************************************************************/��#include <stdio.h>�#include <stdlib.h>��#include <string.h>������#define IREC_LEN1 1024�#define IREC_LEN2 512��#define OREC_LEN 1024��#define VIC "VIC"��#define vic "vic"����int vicname();���main(argc, argv) � int argc;� char *argv[];�{�8� static char vicfile[81]; /* Name of VICAR label file */0� static char pdsfile[81]; /* Name of PDS file */H� static char outfile[81]; /* Name of out file(VICAR label + PDS file) */� char ibuf[OREC_LEN];��� � int ierr;��� FILE *fpi1;� FILE *fpi2;� FILE *fpo;���� if (argc != 3)�� {G� printf("You must specify the PDS image filename in 1st argument\n");�@� printf("You must specify output filename in 2nd argument\n");� exit;� }� �K�/**************************************************************************�<�* The VICAR label file is constructed from the PDS filenameL�***************************************************************************/� strcpy(pdsfile,argv[1]);�� strcpy(outfile,argv[2]);�!� ierr = vicname(vicfile,pdsfile);�� if (ierr != 0) exit;���L�/***************************************************************************�* Open input filesM�****************************************************************************/�,� if ( (fpi1 = fopen(vicfile,"rb")) == NULL )� {E� printf(" *** ERROR *** Can't open VICAR label file %s\n",vicfile);�� exit;� }��,� if ( (fpi2 = fopen(pdsfile,"rb")) == NULL )� {C� printf(" *** ERROR *** Can't open PDS image file %s\n",pdsfile);�� exit;� }��K�/**************************************************************************�D�* Open output file ( VICAR label + PDS edr file including PDS labelsL�***************************************************************************/�# ifdef vax�<� fpo = fopen(outfile,"wb","rfm=fix","fop=cbt","mrs=1024");�# else� fpo = fopen(outfile,"wb");��# endif�� �� if (fpo == NULL)�� {F� printf(" *** ERROR *** Can't open outpuf image file %s\n",outfile);� exit;� }��J�/*************************************************************************%�* Read VICAR label and write to ouput�K�**************************************************************************/�!� fread(ibuf, IREC_LEN1, 1, fpi1);� � fwrite(ibuf, OREC_LEN, 1, fpo);� fclose(fpi1);��J�/*************************************************************************M�* Read PDS labels and image and write to output- input has 512 byte records,��* output has 1024 byte records�K�/*************************************************************************/���� while (!feof(fpi2)) �� {"� fread(ibuf,IREC_LEN2, 1, fpi2);*� fread(ibuf+IREC_LEN2,IREC_LEN2,1,fpi2);3� if (!feof(fpi2)) fwrite(ibuf, OREC_LEN, 1, fpo);�� }��� fclose(fpi2); � fclose(fpo);����}����int vicname(vicfile, pdsfile)�� char *vicfile;�� char *pdsfile;�L�/***************************************************************************F�* vicname creates the VICAR label filename from the PDS edr filename �* which is input�M�/***************************************************************************/��{� � char *i;���� strcpy(vicfile, pdsfile);� i = strstr(vicfile, "EDR");,� if (i == NULL) i = strstr(vicfile, "edr");� if (i == NULL) goto err;�!� if (*i == 'E') strncpy(i,VIC,3);�!� if (*i == 'e') strncpy(i,vic,3);�� �� �� i = strrchr(vicfile,']');1� if (i == NULL) i = strrchr(vicfile,'/');�2� if (i == NULL) i = strrchr(vicfile,'\\');1� if (i == NULL) i = strrchr(vicfile,':');�� if (i == NULL) goto err;�)� if ( (toupper(*(++i))) != 'E') goto err;�� *i = (*i == 'E')?'V':'v';�� � return 0;��>� err: printf("*** ERROR *** Can not build VICAR file name\n");5� printf("from the PDS file name: %s\n",pdsfile);�9� printf("You must include the full directory name");�� return -1;�}�