home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GRIPS 2: Government Rast…rocessing Software & Data
/
GRIPS_2.cdr
/
dos
/
imdisp
/
source
/
imdisp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-08
|
58KB
|
1,943 lines
/*************************************************************/
/* Copyright (C) 1989, California Institute of Technology */
/* U. S. Government Sponsorship under NASA Contract */
/* NAS7-918 is acknowledged. */
/*************************************************************/
/*** Program: IMDISP
Interactive Image Display Program
***/
/* * * * INCLUDE files * * * */
#include <conio.h>
#include <ctype.h>
#include <direct.h>
#include <dos.h>
#include <io.h>
#include <malloc.h>
#include <process.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "imdef.h"
#include "dispio.h"
#include "disputil.h"
#include "display.h"
#include "fileio.h"
#include "fileutil.h"
#include "help.h"
#include "imageio.h"
#include "imagutil.h"
#include "labutil.h"
#include "plot.h"
#include "refresh.h"
#include "swap.h"
#include "browse.h"
#include "palette.h"
/* * * * External functions * * * */
/* * * * Function declarations * * * */
int BadStatus (char status[]);
int DoRefresh (void);
int SetValues (void);
int DoHistogram (void);
int DoPalette (void);
int DoPlot (void);
int DoStretch (void);
int DoCursor (void);
int DoProfile (void);
int StartUp (int argc, char **argv);
int DoSave (void);
int DoBatch (void);
int DoLabel (void);
int DoMenu (void);
int DoPosText (void);
int DoOverlay (void);
int DoSerial (void);
int DoPrint (void);
int ctrl_c (void);
long min3arr( long *, int);
long max3arr( long *, int);
int LoadPalette( char *);
/* * * * Global Variables * * * */
struct Color CT[256];
char CommandString[80];
int nl, ns, bitsperpix;
int DNlow, DNhigh;
int OpenFileFlag;
int nld, nsd, sl, ss;
int nldd, nsdd, sldd, ssdd;
int subsample, zoom;
int centerline, centersamp;
int lastsl, lastss;
FILE *BatchFile;
long Histogram; /* Location of histogram in file */
long Palette; /* Location of palette in file */
char PaletteFileName[64];
int Color_Hist;
int Microsoft;
int TurnCursorOff; /* Set cursor funct. on */
int BatchFlag; /* To control batch file on input cmd line */
int flowthru;
int IntoMem;
int abort_disp ;
int ByteSwap = FALSE;
char memmsg[] = "Insufficient memory.";
char dirMask[30] = "*.*"; /* select all files */
char BrowseName[40] = "C:\\BROWSE.CMD"; /* default browse file name */
char MenuName[40] = "MENU.MNU"; /* default menu name */
FILE *SelectFile;
int SelectFlag; /* To control interactive selection of files */
char ImageFileName[80];
char SelectName[40] = "C:\\IMDISP.SEL"; /* default select file name */
/******************** Start of main program ***********************/
main (int argc, char *argv[])
{
union REGS inregs, outregs;
struct SREGS segregs;
unsigned int cur_dseg_var;
char execute[80];
int command, len, i, j, k, flag;
char status[128], temp[136];
char DosCommand[72];
char *result, *comspec, *imbrowse, SwapName[40];
int swap_return, sys_return;
unsigned char exec_return;
signal(SIGINT,ctrl_c);
/* ReduceDefaultData(); */
StartUp (argc, argv);
strcpy( SwapName, "C:\\IMDISWAP.FIL");
do
{
if (flowthru)
{
flowthru = 0;
}
else if (BatchFlag)
{
if (abort_disp == 1)
result = NULL;
else
result = fgets( CommandString, 127, BatchFile);
if (result == NULL)
{
fclose (BatchFile);
BatchFlag = 0;
if (SelectFlag)
{
fclose (SelectFile);
SelectFlag = 0;
}
strcpy (CommandString, "DONE");
}
if (strnicmp (CommandString, "SEL", 3) == 0)
{
SelectFile = fopen (SelectName, "w");
if (SelectFile == NULL)
{
TextLine = 14; TextSample = 1;
WriteText ("Error in opening Select file");
}
else
SelectFlag = 1;
}
if (strnicmp (CommandString, "PAU", 3) == 0)
{
GetKeywordInteger(CommandString, "PAU",0, &i, &flag);
if (flag < 1)
GetKeywordInteger(CommandString, "pau",0, &i, &flag);
if (flag==1) for (j=0; j<i*13; j++)
{
for (k=0; k<32000; k++);
}
else
{
StatusLine(0,"Pausing - Type any key to continue...");
while(!kbhit); getch();
}
}
if (strnicmp(CommandString,"BAT",3) == 0 || abort_disp == 1)
{
fclose(BatchFile);
BatchFlag = 0;
if (SelectFlag)
{
fclose(SelectFile);
SelectFlag = 0;
}
abort_disp=0;
}
/* write the batch command line */
if (CommandString[strlen(CommandString)-1] == 0x0a)
CommandString[strlen(CommandString)-1] = '\0';
StatusLine(2,CommandString);
for (i=0;i<5000;i++); /* delay a bit */
}
else if (OneScreen)
{
abort_disp = 0;
StatusLine(2,"Command: ");
AcceptText (CommandString);
strcpy (temp, "Command: ");
strcat (temp, CommandString);
strcat (temp, " ");
LengthText (temp, TextHeight, &len);
EraseText (TextLine, TextSample, TextHeight, len, 0);
}
else
{
abort_disp = 0;
printf ("%s", "Command: ");
gets (CommandString);
}
strupr (CommandString);
command = GetCommand (CommandString,
"FIL DIS ERA SET HIS PAL STR CUR PRO REF HEL EXI QUI DON BAT SAV CD DIR TYP SYS > MEN LAB TEX OVE BRO PLO SER PRI NEG");
/* if you add more than 29 commands you must fix getcommand in PARAM.C */
switch (command)
{
case 1 : GetFile(); break;
case 2 : DisplayImage(); break;
case 3 : ClearDisplay(0); break;
case 4 : SetValues(); break;
case 5 : DoHistogram(); break;
case 6 : DoPalette(); break;
case 7 : DoStretch(); break;
case 8 : DoCursor(); break;
case 9 : DoProfile(); break;
case 10 : DoRefresh(); break;
case 11 : GiveHelp(); break;
case 12 : /* exit command */ break;
case 13 : /* quit command */ break;
case 14 : /* done/null command*/break;
case 15 : DoBatch(); break;
case 16 : DoSave(); break;
case 17 :
GetKeywordString (CommandString,"CD",".",temp, &flag);
result = temp; /* change to char pointer */
segregs.ds = FP_SEG(result);
inregs.h.ah = 0x3B;
inregs.x.dx = (unsigned)temp;
intdosx(&inregs,&outregs,&segregs);
break;
case 18 :
case 19 :
case 20 :
case 21 :
DisplayOff();
if (OpenFileFlag)
{
CloseImage (0, status);
if (BadStatus (status)) return;
OpenFileFlag = 0;
}
/* if (RefreshLines > 0) */
while (RefreshLines > 0)
FreeRefresh( "sys cmd" );
comspec = getenv("COMSPEC");
if ((imbrowse = getenv("IMBROWSE")) != NULL)
{
strcpy(SwapName, imbrowse);
strcat(SwapName, "IMDISWAP.FIL");
}
if (command == 18 || command == 19)
{
strcpy(execute, "/C ");
strcat(execute,CommandString);
}
else
{
printf("Type \'exit\' to return to IMDISP.\n");
strcpy(execute,"");
}
swap_return = swap(comspec, execute, &exec_return, SwapName);
if (swap_return == SWAP_NO_SAVE)
{
printf( "Not much memory to work with...\n");
sys_return = system( execute );
if (sys_return != -1)
swap_return = SWAP_OK;
}
if (command == 18 || command == 19)
{
printf("Type any key to continue:");
while(!kbhit); getch();
}
DisplayOn();
WritePalette (DefaultPalette);
switch (swap_return)
{
case SWAP_OK:
StatusLine(0,"Successful, executed program returned.");
break;
case SWAP_NO_SHRINK:
StatusLine(0,"Unable to shrink DOS memory block.");
break;
case SWAP_NO_SAVE:
StatusLine(0,"Unable to save program to memory or disk.");
break;
case SWAP_NO_EXEC:
StatusLine(0,"DOS EXEC call failed. Error is: ");
switch (exec_return)
{
case BAD_FUNC:
StatusLine (1,"Bad function.");
break;
case FILE_NOT_FOUND:
StatusLine (1,"Program file not found.");
break;
case ACCESS_DENIED:
StatusLine (1,"Access to program file denied.");
break;
case NO_MEMORY:
StatusLine (1,"Insufficient memory to run program.");
break;
case BAD_ENVIRON:
StatusLine (1,"Bad environment.");
break;
case BAD_FORMAT:
StatusLine (1,"Bad format.");
break;
default:
StatusLine (1,"Unexpected error code.");
break;
}
}
break;
case 22: DoMenu(); break;
case 23: DoLabel(); break;
case 24: DoPosText(); break;
case 25: DoOverlay(); break;
case 26: DoBrowse(); break;
case 27: DoPlot(); break;
case 28: DoSerial(); break;
case 29: DoPrint(); break;
case 30: DoNegative(); break;
default : /* otherwise sound beep */
{
/* check for drive change command */
if (strlen(CommandString) == 2 && CommandString[1] == ':')
bdos(14,(int)CommandString[0]-'A',0);
else if ((strncmp(CommandString,"PAU",3) != 0) &&
(strncmp(CommandString,"SEL",3) != 0))
{
StatusLine(2,"INVALID! ");
printf("\a");
for (i=0;i<5000;i++);
}
}
}
} while ((command != 12) && (command != 13));
if (OpenFileFlag)
{
CloseImage (0, status);
BadStatus (status);
}
DisplayOff();
}
int BadStatus (char * status)
/* Prints out error message if there is one.
Returns true if error.
*/
{
if (strlen(status) > 0)
{
StatusLine(0,status);
return (1);
}
else
return (0);
}
int DoRefresh(void)
/* DoRefresh performs the refresh command.
The whole display screen, or as much as there is in memory,
is redisplayed.
*/
{
int line;
unsigned char *buffer;
while ((buffer = malloc(dispns)) == NULL)
FreeRefresh("refr cmd");
for (line = 1; line <= RefreshLines; line++)
{
GetRefresh (buffer, line, 1, dispns);
DisplayLine (buffer, line, 1, dispns);
}
free (buffer);
}
int SetValues(void)
/* SetValues performs the set command.
The DN range parameters are gotten and printed out.
*/
{
int newns;
int swapflag, loflag, hiflag, refflag, dispflag, nsflag, broflag;
char dispstr[128];
GetKeywordInteger (CommandString, "LO", DNlow , &DNlow, &loflag);
if (loflag < 0)
GetKeywordInteger (CommandString, "DNL", DNlow , &DNlow, &loflag);
GetKeywordInteger (CommandString, "HI", DNhigh , &DNhigh, &hiflag);
if (hiflag < 0)
GetKeywordInteger (CommandString, "DNH", DNhigh , &DNhigh, &hiflag);
GetKeywordInteger (CommandString, "REF", RefreshLines, &RefreshLines, &refflag);
GetKeywordInteger (CommandString, "NS", IMCB[0].ns , &newns, &nsflag);
if (nsflag > 0)
{
IMCB[0].ns = newns;
IMCB[0].reclen = newns;
}
GetKeywordString (CommandString, "SWA", "","", &swapflag);
if (swapflag == 0) ByteSwap = FALSE;
GetKeywordString (CommandString, "UNSWA", "","", &swapflag);
if (swapflag == 0) ByteSwap = TRUE;
GetKeywordString (CommandString, "BRO", "C:\\BROWSE.CMD" , BrowseName, &broflag);
GetKeywordString (CommandString, "SEL", "C:\\BROWSE.SEL" , SelectName, &broflag);
GetKeywordString (CommandString, "DIS", "vga", dispstr, &dispflag);
if (dispflag > 0)
{
DisplayOff();
if (stricmp(dispstr, "cga" ) == 0)
DisplayDevice = CGA;
else if (stricmp(dispstr, "ega480" ) == 0)
DisplayDevice = EGA480;
else if (stricmp(dispstr, "ega" ) == 0)
DisplayDevice = EGA350;
else if (stricmp(dispstr, "pga" ) == 0)
DisplayDevice = PGA;
else if (stricmp(dispstr, "vga320" ) == 0)
DisplayDevice = VGA200;
else if (stricmp(dispstr, "vga" ) == 0)
DisplayDevice = VGA480;
else if (stricmp(dispstr, "orchid1024") == 0)
DisplayDevice = ORCHID768;
else if (stricmp(dispstr, "orchid800") == 0)
DisplayDevice = ORCHID600;
else if (stricmp(dispstr, "orchid" ) == 0)
DisplayDevice = ORCHID480;
else if (stricmp(dispstr, "evga640" ) == 0)
DisplayDevice = EVGA640;
else if (stricmp(dispstr, "evga512" ) == 0)
DisplayDevice = EVGA512;
else if (stricmp(dispstr, "evga800" ) == 0)
DisplayDevice = EVGA800;
else if (stricmp(dispstr, "bios" ) == 0)
DisplayDevice = BIOS;
else if (stricmp(dispstr, "ati640" ) == 0)
DisplayDevice = ATI640;
else if (stricmp(dispstr, "ati800" ) == 0)
DisplayDevice = ATI800;
else if (stricmp(dispstr, "ati1024" ) == 0)
DisplayDevice = ATI1024;
else if (stricmp(dispstr, "paradise" ) == 0)
DisplayDevice = PARADISE;
DisplayOn();
WritePalette (DefaultPalette);
}
if (DNlow > 32767) DNlow = 32767;
if (DNhigh < DNlow+2) DNhigh = DNlow + 2;
if (loflag > 0 || hiflag > 0)
{
sprintf (dispstr, "DN low : %5d DN high : %5d ", DNlow, DNhigh);
StatusLine(2,dispstr);
}
}
int DoHistogram(void)
/* DoHistogram performs the histogram command.
First the parameter are scanned. Then the image is read
in and the histogram calculated. Finally DisplayHistogram
is called to plot it on the screen. Different pieces of code
are used for different pixel formats.
*/
{
int hnld, hnsd, hsl, hss;
int hnldd, hnsdd;
int hsubsample;
int line, samp, i, j;
int DN, scale, flag, VoyFlag, VikFlag;
long int histbuf[256];
char status[128], dispstr[80], ch;
unsigned char *buffer, *tempbuf;
int *intbuf;
if (OpenFileFlag == 0)
{
StatusLine(0,"Use the \'FILE fname\' command to select image first");
return;
}
if (bitsperpix == 32)
{
/* added by AEE: 01/17/90 */
StatusLine(0,"No histogram for 32 bits per pixel");
return;
}
DrawBox (dispnl-45, 1, 46, dispns, 0);
for (DN = 0; DN <= 255; DN++)
histbuf[DN] = 0;
GetKeywordSubcommand (CommandString, "COL", &flag);
if (flag >= 0) Color_Hist= 1;
else Color_Hist = 0;
GetKeywordSubcommand (CommandString, "CEN", &flag);
if (flag == 0)
{
hsl = lastsl;
hss = lastss;
hnld = nld;
hnsd = nsd;
if (hnld+hsl-1 > nl)
hnld = nl-hsl+1;
if (hnsd+hss-1 > ns)
hnsd = ns-hss+1;
hnldd = zoom*hnld / subsample;
hnsdd = zoom*hnsd / subsample;
if (hnldd+sldd-1 > dispnl)
hnldd = dispnl-sldd+1;
if (hnsdd+ssdd-1 > dispns)
hnsdd = dispns-ssdd+1;
hnld = subsample*hnldd / zoom;
hnsd = subsample*hnsdd / zoom;
hnldd = hnldd/zoom;
hnsdd = hnsdd/zoom;
hsubsample = subsample;
}
else
{
GetKeywordInteger (CommandString, "NL", nl, &hnld, &flag);
GetKeywordInteger (CommandString, "NS", ns, &hnsd, &flag);
GetKeywordInteger (CommandString, "SL", 1, &hsl, &flag);
GetKeywordInteger (CommandString, "SS", 1, &hss, &flag);
GetKeywordInteger (CommandString, "SUB", 1, &hsubsample, &flag);
GetKeywordString (CommandString, "VOY", " ",status,&VoyFlag);
GetKeywordString (CommandString, "VIK", " ",status,&VikFlag);
if (hnld+hsl-1 > nl)
hnld = nl-hsl+1;
if (hnsd+hss-1 > ns)
hnsd = ns-hss+1;
hnldd = hnld / hsubsample;
hnsdd = hnsd / hsubsample;
}
if ((bitsperpix == 16) || (bitsperpix == 32)) /* 16 bit images */
{
while ((intbuf = (int *)malloc(2*hnsd)) == NULL)
FreeRefresh("intbuf 16");
scale = max( 1, ((DNhigh - DNlow) / 255) );
line = hsl;
for (i = 0; i < hnldd; i++)
{
ReadLine (0, intbuf, line, hss, hnsd, status);
if (BadStatus(status))
free(intbuf);
samp = 0;
for (j = 0; j < hnsdd; j++)
{
DN = intbuf[samp];
if (DN >= DNhigh)
DN = DNhigh;
else if (DN <= DNlow)
DN = DNlow;
DN = ((long)DN-DNlow) / scale;
DN = min( DN, 255);
DN = max( DN, 0);
(histbuf[DN])++;
samp += hsubsample;
}
line += hsubsample;
/*
keyboard abort added
*/
if (kbhit()) /* abort disp if keypressed mdm 2/19/88*/
{
if ((ch = getch()) == 0) ch = 0x80 | getch();
if (ch != 17) /* don't abort if cntl q */
{
j=hnldd;
abort_disp = 1;
}
}
}
if (abort_disp != 1)
DisplayHistogram (histbuf, 256, DNlow, DNlow+256*scale);
free(intbuf);
}
else if (bitsperpix == 8) /* 8 bit images */
{
while ((buffer = malloc(hnsd)) == NULL)
FreeRefresh("intbuf 8");
if ((hss==1 && hnsd==800 && hsl==1 && hnld == 800 && hsubsample == 1
&& VoyFlag == 0) ||
(hss==1 && hnsd==1204 && hsl==1 && hnld == 1056 && hsubsample == 1
&& VikFlag == 0) ||
(hss==1 && hsl == 1 && hnld == nl && hnsd == ns && hsubsample == 1
&& Histogram > 0L ))
/* read histogram from file*/
{
/* location of vgr histo */
if (VoyFlag == 0)
Histogram = 671496L + (Microsoft*2048);
/* location of vik histo */
if (VikFlag == 0)
Histogram = 1337472L + (Microsoft*2048);
lseek(FCB[0].handle,Histogram,SEEK_SET);
read(FCB[0].handle,(char *)histbuf,1024);
}
else
{
line = hsl;
for (i = 0; i < hnldd; i++)
{
ReadLine (0, buffer, line, hss, hnsd, status);
if (BadStatus(status))
free (buffer);
samp = 0;
for (j = 0; j < hnsdd; j++)
{
(histbuf[buffer[samp]])++;
samp += hsubsample;
}
line += hsubsample;
/*
keyboard abort added
*/
if (kbhit()) /* abort disp if keypressed mdm 2/19/88*/
{
if ((ch = getch()) == 0) ch = 0x80 | getch();
if (ch != 17) /* don't abort if cntl q */
{
j=hnldd;
abort_disp = 1;
}
}
}
}
if (abort_disp != 1)
DisplayHistogram (histbuf, 256, 0, 255);
free (buffer);
}
else /* 4 bit and 1 bit images */
{
while ((buffer = malloc(hnsd)) == NULL)
FreeRefresh("buf 4");
while ((tempbuf = malloc(hnsd)) == NULL)
FreeRefresh("temp buf");
line = hsl;
for (i = 0; i < hnldd; i++)
{
ReadLine (0, tempbuf, line, hss, hnsd, status);
if (BadStatus(status))
{
free (buffer);
free (tempbuf);
}
ConvertLine (tempbuf, buffer, bitsperpix, 8, hnsd, status);
samp = 0;
for (j = 0; j < hnsdd; j++)
{
(histbuf[buffer[samp]])++;
samp += hsubsample;
}
line += hsubsample;
}
DisplayHistogram (histbuf, 16, 0, 15);
free (buffer);
free (tempbuf);
}
}
int DoPalette(void)
/*** DoPalette performs the palette command.
***/
{
int pseudo, flag, numdiddle, diddleflag;
int i, color, saveflag, loadflag, showflag, eraseflag;
char savename[64], loadname[64];
FILE *unit;
GetKeywordInteger (CommandString, "PS", 0, &pseudo, &flag);
GetKeywordInteger (CommandString, "EDI", numDN, &numdiddle, &diddleflag);
if (diddleflag < 0)
GetKeywordInteger (CommandString, "DID", numDN, &numdiddle, &diddleflag);
GetKeywordString (CommandString, "SAV", "IMDISP.PAL", savename, &saveflag);
GetKeywordString (CommandString, "LOA", "IMDISP.PAL", loadname, &loadflag);
GetKeywordSubcommand (CommandString, "DIS", &showflag);
GetKeywordSubcommand (CommandString, "ERA", &eraseflag);
if (saveflag >= 0)
{
if ( (unit = fopen (savename, "w")) == NULL )
return;
ReadPalette (CT);
fprintf (unit, "CCSD3ZF0000100000001NJPL3IF0PDS200000001 = SFDU_LABEL\012");
fprintf (unit, "RECORD_TYPE = STREAM\012");
fprintf (unit, "FILE_RECORDS = %3d\012", 13+numDN);
fprintf (unit, "OBJECT = TABLE\012");
fprintf (unit, " TABLE_ROWS = %3d\012", numDN);
fprintf (unit, " ROW_COLUMNS = 4\012");
fprintf (unit, " COLUMN_NAME = (COLOR_NUMBER,\012");
fprintf (unit, " RED_VALUE,\012");
fprintf (unit, " GREEN_VALUE,\012");
fprintf (unit, " BLUE_VALUE)\012");
fprintf (unit, " COLUMN_TYPE = (INTEGER,INTEGER,INTEGER,INTEGER)\012");
fprintf (unit, "END_OBJECT\012");
fprintf (unit, "END\012");
for (i = 0; i < numDN; i++)
fprintf (unit, "%4d,%4d,%4d,%4d\012", i, CT[i].r, CT[i].g, CT[i].b);
fclose (unit);
}
else if (loadflag >= 0)
{
LoadPalette(loadname);
}
else if (diddleflag >= 0)
{
DiddlePalette (numdiddle);
}
else if (showflag >= 0)
{
ShowPalette (numdiddle);
}
else if (eraseflag >= 0)
{
ErasePalette (numdiddle);
}
else if (flag < 0) /* pal command with no args loads default */
WritePalette(DefaultPalette);
else
{
switch (pseudo)
{
case 0 :
for (i = 0; i < numDN; i++)
{
color = (16*i)/numDN;
if (color > 15) color = 15;
CT[i].r = PScolor[color][0];
CT[i].g = PScolor[color][1];
CT[i].b = PScolor[color][2];
}
WritePalette (CT);
break;
case 1 :
if (DisplayDevice == ATI1024)
{
for (i = 0; i < 256; i++)
{
CT[i].r = i;
CT[i].g = i;
CT[i].b = i;
}
WritePalette (CT);
}
else
Stretch (0, numDN-1);
break;
case 2 :
for (i = 0; i < numDN; i++)
{
color = (16*i)/numDN;
if (color > 15) color = 15;
CT[i].r = Scolor[color][0];
CT[i].g = Scolor[color][1];
CT[i].b = Scolor[color][2];
}
WritePalette (CT);
break;
case 3 :
for (i = 0; i < 256; i++)
{
CT[i].r = Redorange[i][0];
CT[i].g = Redorange[i][1];
CT[i].b = Redorange[i][2];
}
if (numDN == 16)
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
WritePalette (CT);
break;
case 4 :
for (i = 0; i < 256; i++)
{
CT[i].r = Prism[i][0];
CT[i].g = Prism[i][1];
CT[i].b = Prism[i][2];
}
if (numDN == 16)
{
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
/* special fix to display text */
CT[15].r=255; CT[15].g=255; CT[15].b=255;
}
WritePalette (CT);
break;
case 5 :
for (i = 0; i < 256; i++)
{
CT[i].r = Topo[i][0];
CT[i].g = Topo[i][1];
CT[i].b = Topo[i][2];
}
if (numDN == 16)
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
WritePalette (CT);
break;
case 6 :
for (i = 0; i < 256; i++)
{
CT[i].r = Contour[i][0];
CT[i].g = Contour[i][1];
CT[i].b = Contour[i][2];
}
if (numDN == 16)
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
WritePalette (CT);
break;
case 7 :
for (i = 0; i < 256; i++)
{
CT[i].r = BGRY[i][0];
CT[i].g = BGRY[i][1];
CT[i].b = BGRY[i][2];
}
if (numDN == 16)
{
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
/* special fix to display text */
CT[15].r=255; CT[15].g=255; CT[15].b=255;
}
WritePalette (CT);
break;
case 8 :
for (i = 0; i < 256; i++)
{
CT[i].r = Glasses1[i][0];
CT[i].g = Glasses1[i][1];
CT[i].b = Glasses1[i][2];
}
if (numDN == 16)
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
WritePalette (CT);
break;
case 9 :
for (i = 0; i < 256; i++)
{
CT[i].r = Glasses2[i][0];
CT[i].g = Glasses2[i][1];
CT[i].b = Glasses2[i][2];
}
if (numDN == 16)
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
WritePalette (CT);
break;
}
}
}
int LoadPalette(char * palettefile)
/* LoadPalette reads in the color palette from the given palette filename
(palettefile). This code originally resided in the DoPalette routine,
but was moved into its own routine to accomodate detached palette
processing -- Ron Baalke -- 07/27/90 */
{
int i, n, r, g, b, result;
unsigned char color[256];
char filedata[133];
FILE *unit;
if (Palette != 0L)
{
lseek(FCB[0].handle, Palette, SEEK_SET);
read(FCB[0].handle, color, 256);
for (i=0;i<256;i++)
CT[i].r = color[i];
read(FCB[0].handle, color, 256);
for (i=0;i<256;i++)
CT[i].g = color[i];
read(FCB[0].handle, color, 256);
for (i=0;i<256;i++)
CT[i].b = color[i];
WritePalette (CT);
Palette = 0L; /* reset value to zero */
return(0);
}
if ((unit = fopen (palettefile, "r")) == NULL)
{
StatusLine(0,"Palette file not found.");
return;
}
fgets(filedata,132,unit);
/*
if (strnicmp(filedata,"CCSD",4) == 0 || strnicmp(filedata,"NJPL",4) == 0)
{
*/
do
{
fgets(filedata,132,unit);
if (strnicmp(filedata,"END",3) == 0 &&
(strlen(filedata) <= 5 || filedata[3] == ' '))
break;
} while (!feof(unit));
fgets (filedata, 132, unit);
/*
}
*/
/* zero out palette but make highest value white */
for (i=0;i<255;i++)
CT[i].r = CT[i].g = CT[i].b = 0;
if (numDN == 256)
CT[255].r = CT[255].g = CT[255].b = 255;
else
CT[15].r = CT[15].g = CT[15].b = 255;
i = 0;
do
{
result = sscanf(filedata, "%d %d %d %d", &n,&r,&g,&b);
if (result == 1) /* try comma separated value */
result = sscanf(filedata, "%d,%d,%d,%d", &n,&r,&g,&b);
if (result == 3) /* no index value on line */
{CT[i].r = n; CT[i].g = r; CT[i].b = g;}
else if (result == 4 && (n >= 0 && n <= 256))
{
if (i==n-1) n = i; /* patch to handle old palettes */
/* with values from 1 to 256 */
CT[n].r = r; CT[n].g = g; CT[n].b = b;}
else
{
StatusLine (0,"Invalid Palette file format.");
fclose(unit); return;
}
i++;
fgets (filedata, 132, unit);
} while (! feof(unit) && i < 256);
if (numDN == 16 && i > 15)
for (i=0;i<16;i++)
{
CT[i].r = CT[i*16+8].r;
CT[i].g = CT[i*16+8].g;
CT[i].b = CT[i*16+8].b;
}
WritePalette (CT);
fclose (unit);
}
int DoPlot()
/*
DoPlot performs the plot command. First the parameters are scanned.
Then the image is read in and plotted. Ordered pairs are plotted by
Plotpair, other data by Plot32.
*/
{
int wordbits=16, longbits=32;
int line, i, k, zoom, color, symbolflag;
int lineflag, ovlflag, zoomflag, minflag, maxflag;
char status[128], Symbol[2], PlotOvly;
long miny=0x7FFFFFFF, maxy=0x80000000;
long minx=0x7FFFFFFF, maxx=0x80000000;
long *buf32, *xbuf, *ybuf;
unsigned char *buffer;
int *intbuf;
GetKeywordSubcommand (CommandString, "OVE", &ovlflag);
if (ovlflag == 1)
{
/* OVErlay specified, don't clear the screen */
PlotOvly = 'Y';
}
else
{
ClearDisplay(0);
PlotOvly = 'N';
}
GetKeywordSubcommand (CommandString, "ZOO", &zoomflag);
if (zoomflag == 1)
zoom = 1;
else
/* ZOOm not specified, don't ask to zoom plot */
zoom = 0;
GetKeywordInteger (CommandString, "LIN", 1, &line, &lineflag);
if (line > nl || line < 1)
line = 1;
GetKeywordInteger (CommandString, "COL", numDN-1, &color, &lineflag);
GetKeywordLong (CommandString, "MIN", miny, &miny, &minflag);
GetKeywordLong (CommandString, "MAX", maxy, &maxy, &maxflag);
GetKeywordString (CommandString, "SYM", "", Symbol, &symbolflag);
if (PDSused == 1 && switched == 1 && ns == 1 && nl > 1)
{
/*PDS label used */
i = nl;
nl = ns;
ns = i;
}
/* Allocate enough memory for the 32-bit buffers */
while ((buf32 = (long *)malloc(4*ns)) == NULL)
{
RefreshLines -= 1;
free (RefreshBuf[RefreshLines]);
if (RefreshLines == 0)
{
DisplayOff();
printf("Not enough memory to run program");
exit(1);
}
}
if ( (ns == 2 || ns == 3) && bitsperpix == 32)
{
while ((xbuf = (long *)malloc(4*nl)) == NULL)
{
RefreshLines -= 1;
free (RefreshBuf[RefreshLines]);
if (RefreshLines == 0)
{
DisplayOff();
printf("Not enough memory to run program");
free(buf32);
exit(1);
}
}
while ((ybuf = (long *)malloc(4*nl)) == NULL)
{
RefreshLines -= 1;
free (RefreshBuf[RefreshLines]);
if (RefreshLines == 0)
{
DisplayOff();
printf("Not enough memory to run program");
free(xbuf);
free(buf32);
exit(1);
}
}
/* 32 bit samples, ordered pairs */
k = 0;
for (i = 0; i < nl; i++)
{
ReadLine (0, buf32, line, 1, ns, status);
if (BadStatus(status))
{
free(ybuf);
free(xbuf);
free(buf32);
return;
}
xbuf[i] = buf32[0];
ybuf[i] = buf32[1];
line++;
k++;
}
for (i=0; i<nl; i++)
{
if (xbuf[i] < minx)
minx = xbuf[i];
if (xbuf[i] > maxx)
maxx = xbuf[i];
}
if (minflag < 1)
{
miny = min3arr( ybuf, nl);
miny = miny + miny/10;
}
if (maxflag < 1)
{
maxy = max3arr( ybuf, nl);
maxy = maxy + maxy/10;
}
Plotpair( xbuf, ybuf, minx, maxx, miny, maxy, k, Symbol, color, zoom);
TextLine = TextHeight + 5; TextSample = 1;
free(ybuf);
free(xbuf);
free(buf32);
return;
}
if (ns != 2) /* images (not pairs) */
{
if (bitsperpix == 8) /* 8 bit images */
{
while ((buffer = malloc(ns)) == NULL)
{
RefreshLines -= 1;
free (RefreshBuf[RefreshLines]);
if (RefreshLines == 0)
{
DisplayOff();
printf("Not enough memory to run program");
exit(1);
}
}
ReadLine( 0, buffer, line, 1, ns, status);
if (BadStatus(status))
{
free (buffer);
free (buf32);
return;
}
ConvertLine( buffer, buf32, bitsperpix, longbits, ns, status);
free (buffer);
}
else if (bitsperpix == 16) /* 16 bit images */
{
while ((intbuf = malloc(2*ns)) == NULL)
{
RefreshLines -= 1;
free (RefreshBuf[RefreshLines]);
if (RefreshLines == 0)
{
DisplayOff();
printf("Not enough memory to run program");
exit(1);
}
}
ReadLine( 0, intbuf, line, 1, ns, status);
if (BadStatus(status))
{
free (intbuf);
free (buf32);
return;
}
ConvertLine( intbuf, buf32, bitsperpix, longbits, ns, status);
free (intbuf);
}
else if (bitsperpix == 32) /* 32 bit images */
{
ReadLine (0, buf32, line, 1, ns, status);
if (BadStatus(status))
{
free(buf32);
return;
}
}
if (minflag < 1)
{
miny = min3arr( buf32, ns);
miny = miny + miny/10;
}
if (maxflag < 1)
{
maxy = max3arr( buf32, ns);
maxy = maxy + maxy/10;
}
Plot32( buf32, miny, maxy, ns, Symbol, color, zoom);
TextLine = TextHeight + 5; TextSample = 1;
free(buf32);
return;
}
}
long min3arr( long * buf, int nvals)
/*
Finds the third smallest value in a 32-bit integer array
*/
{
long min1 = 0x7fffffff, min2 = 0x7fffffff, min3 = 0x7fffffff;
int i;
for ( i=0; i<nvals; i++)
{
if (buf[i] < min1)
{
min3 = min2;
min2 = min1;
min1 = buf[i];
}
else if (buf[i] < min2)
{
min3 = min2;
min2 = buf[i];
}
else if (buf[i] < min3)
{
min3 = buf[i];
}
}
if (nvals > 2)
return(min3);
else
return(min1);
}
long max3arr( long * buf, int nvals)
/*
Finds the third largest value in a 32-bit integer array
*/
{
long max1 = 0x80000000, max2 = 0x80000000, max3 = 0x80000000;
int i;
for ( i=0; i<nvals; i++)
{
if (buf[i] > max1)
{
max3 = max2;
max2 = max1;
max1 = buf[i];
}
else if (buf[i] > max2)
{
max3 = max2;
max2 = buf[i];
}
else if (buf[i] > max3)
{
max3 = buf[i];
}
}
if (nvals > 2)
return(max3);
else
return(max1);
}
int DoStretch(void)
/* DoStretch performs the stretch command.
*/
{
int DNlow, DNhigh, flag;
GetKeywordInteger (CommandString, "LO", 0, &DNlow, &flag);
if (flag < 0)
GetKeywordInteger (CommandString, "DNL", 0 , &DNlow, &flag);
GetKeywordInteger (CommandString, "HI", numDN-1, &DNhigh, &flag);
if (flag < 0)
GetKeywordInteger (CommandString, "DNH", numDN-1 , &DNhigh, &flag);
Stretch (DNlow, DNhigh);
}
int DoCursor(void)
/* DoCursor performs the cursor command.
After cursor mode the image line and sample are calculated and displayed.
*/
{
int line, samp, i, len;
char dispstr[64];
StatusLine(1,"Arrow keys move; +,- changes cursor increment; '.' to exit.");
MoveCursor(&line,&samp);
centerline = subsample*(line-sldd) / zoom + sl;
centersamp = subsample*(samp-ssdd) / zoom + ss;
sprintf (dispstr, "Line : %5d Sample : %5d", centerline, centersamp);
StatusLine(1,dispstr);
}
int DoProfile(void)
/* DoProfile performs the profile command.
*/
{
DrawBox (dispnl-45, 1, 46, dispns, 0);
Profile();
}
int StartUp (int argc, char **argv)
/* StartUp sets up some things for the main program.
The display is turned on, variables initialized, and the
welcome message is printed or the file opened instead.
*/
{
int i;
char *dot_ptr, *batchname;
char f_extension[4];
char temp[40];
InitDisplay();
OpenFileFlag = 0;
nl = 0; ns = 0; sl = 1; ss = 1; sldd = 1; ssdd = 1;
subsample = 1; zoom = 1;
centerline = -1; centersamp = -1; lastsl = 1; lastss = 1;
DNlow = 0; DNhigh = 255;
if ((batchname = getenv("IMBROWSE")) != NULL)
{
strcpy(BrowseName, batchname);
strcat(BrowseName, "BROWSE.CMD");
strcpy(SelectName, batchname);
strcat(SelectName, "IMDISP.SEL");
}
if (argc > 1)
{
if((dot_ptr = strpbrk(argv[1],".")) == NULL)
{
StatusLine(0,"Illegal command line entry");
}
dot_ptr++; /* Move ptr to the extension of the command file */
strncpy(f_extension, dot_ptr, 3); /* Get copy of extension */
f_extension[3] = '\0';
if (!strcmp(strupr(f_extension),"MNU"))
{
strcpy (CommandString, "MENU ");
strcat (CommandString, argv[1]);
DoMenu();
}
else if (!strcmp(strupr(f_extension),"CMD"))
{
strcpy (CommandString, "BATCH ");
strcat (CommandString, argv[1]);
DoBatch();
}
else
{
/* default will make the filename an image */
strcpy (CommandString, "FILE ");
strcat (CommandString, argv[1]);
GetFile();
}
}
else
{
Font (0);
DrawText ("Welcome to the Planetary Data System",
30, 0, BigChars, 0, numDN-1);
DrawText ("Image Display Program Version v5.6",
56, 0, TextHeight, 0, numDN-1);
DrawText ("Copyright (C) 1989, 1990",
80, 35, SmallChars, 0, numDN-1);
DrawText ("California Institute of Technology",
98, 35, SmallChars, 0, numDN-1);
DrawText ("Sponsorship under NASA Contract",
116, 35, SmallChars, 0, numDN-1);
DrawText ("NAS7-918 is acknowledged.",
134, 35, SmallChars, 0, numDN-1);
DrawText ("Use HELP SET to see display options.",
150, 35, SmallChars, 0, numDN-1);
sprintf( temp, "Allocated %d lines in REFRESH buffer.", RefreshLines);
DrawText (temp,
166, 35, SmallChars, 0, numDN-1);
}
if (argc == 1) StatusLine(1,"Type HELP for help");
}
int DoSave(void)
/* should ask for nl,ns if there is no open image file */
{
/* DoSave saves the current display to a disk file */
char filename[128], status[128], dispstr[128];
unsigned char *linebuf,*outbuf;
int i,j,k,flag;
int ssl,sss,snl,sns,sbitsperpix;
int DN;
int defnl, defns;
int dispbits = 1;
if (OpenFileFlag == 0)
{
StatusLine(0,"Use the \'FILE fname\' command to select image");
return;
}
if (numDN == 16) dispbits = 4;
if (numDN == 256) dispbits = 8;
defnl = (dispnl > nl) ? nl : dispnl; /* default nl and ns */
defns = (dispns > ns) ? ns : dispns;
GetKeywordInteger (CommandString, "SL", 1, &ssl, &flag);
GetKeywordInteger (CommandString, "SS", 1, &sss, &flag);
GetKeywordInteger (CommandString, "NL", defnl-ssl+1, &snl, &flag);
GetKeywordInteger (CommandString, "NS", defns-sss+1, &sns, &flag);
GetKeywordInteger (CommandString, "BP", dispbits, &sbitsperpix, &flag);
GetKeywordString (CommandString, "SAV", " ", filename, &flag);
/* make sure parameters don't get interpreted as a filemask. */
if (strcmp(filename,"SL") == 0 || strcmp(filename,"SS") == 0 ||
strcmp(filename,"NL") == 0 || strcmp(filename,"NS") == 0 ||
strcmp(filename,"BP") == 0)
{
BadStatus ("Must give name of image file, (eg. SAVE image.img)");
return;
}
OpenImage (filename, 1, "write", &snl, &sns, &sbitsperpix, status);
if (BadStatus (status))
return;
while ((linebuf = malloc(sns*2)) == NULL)
FreeRefresh("linebuf save");
while ((outbuf = malloc(sns*2)) == NULL)
FreeRefresh("outbuf save");
j = 1;
for (i = ssl;i < ssl+snl; i++)
{
/* check here for going off screen */
for (k=sss;k < sns+sss; k++)
{
ReadPixel(i,k,&DN);
linebuf[k-sss] = DN;
}
if (sbitsperpix != 8)
{
ConvertLine(linebuf,outbuf,8,sbitsperpix,sns,status);
WriteLine(1,outbuf,j,1,sns,status);
}
else
WriteLine(1,linebuf,j,1,sns,status);
j++;
}
free(linebuf);
free(outbuf);
CloseImage(1,status);
}
int DoBatch(void)
{
char BatchName[32];
int flag = 0;
char buffer[81];
GetKeywordString (CommandString, "BAT", "BATCH.CMD", BatchName, &flag);
/* ClearDisplay(0); */
BatchFile = fopen(BatchName,"r");
if (BatchFile == NULL)
StatusLine(0,"File not found.");
else
{
/* check for SFDU labels */
BatchFlag = 1;
fgets(buffer, 80, BatchFile);
if (strnicmp(buffer,"CCSD",4) == 0 ||
strnicmp(buffer,"NJPL",4) == 0)
do
{
fgets(buffer,80,BatchFile);
if (strnicmp(buffer,"END",3) == 0 &&
(strlen(buffer) <= 5 || buffer[3] == ' '))
break;
} while (!feof(BatchFile));
else
fseek(BatchFile, 0L, SEEK_SET);
}
}
int DoLabel(void)
{
FILE *labels;
int i;
char buffer[81];
int line_count=0;
int ch;
int done;
if (OpenFileFlag == 0)
{
StatusLine(0,"Use the \'FILE fname\' command to select image");
return;
}
ReadPalette(CT);
DisplayOff();
for (i=0; i<24; i++)
printf("\n");
if (LabelFileName[0] != NULL)
labels = fopen(LabelFileName,"r");
else
{
lseek( FCB[0].handle, 0L, SEEK_SET);
labels = fdopen(FCB[0].handle,"r");
}
done = FALSE;
while (!done)
{
fgets(buffer,81,labels);
printf("%s",buffer);
line_count++;
if (line_count == 22)
{
printf("\n<< Hit Q to quit, or any other key to continue... >>\n");
ch = getch();
if ((ch == 81) || (ch == 113)) done = TRUE;
printf("\n");
line_count=0;
}
if (feof(labels) || (strnicmp(buffer,"END",3) == 0 &&
(strlen(buffer) <= 5 || buffer[3] == ' ')))
{
done = TRUE;
printf( "\n<< Press any key to return to command line >>\n" );
getch();
}
}
if (LabelFileName[0] != NULL)
fclose(labels);
if (!done)
{
printf( "\n<< Press any key to return to command line >>\n" );
getch();
}
DisplayOn();
WritePalette(DefaultPalette);
}
int DoMenu(void)
{
FILE *MenuFile;
char temp[40], string[81], writebuf[81], choice[10], *fileopt[50];
int flag = 0, done = 0, index = 0, toplist = 1, lowlist = PAGELEN;
int charcnt=81, i, numchoice;
GetKeywordString(CommandString, "MEN", "MENU.MNU",temp, &flag);
if (flag == 1)
strcpy(MenuName, temp);
if ((MenuFile = fopen(MenuName,"r"))==NULL)
{
StatusLine(0,"File not found.");
return;
}
fseek(MenuFile, 0L, SEEK_SET);
do
{
fgets(string, charcnt, MenuFile);
if (strnicmp(string,"CCSD",4) == 0 ||
strnicmp(string,"NJPL",4) == 0)
{
do
{
fgets(string,charcnt,MenuFile);
if (strnicmp(string,"END",3) == 0 &&
(strlen(string) <= 5 || string[3] == ' ')) break;
} while (!feof(MenuFile));
fgets(string,charcnt,MenuFile);
}
for (i = 1; i < 81; i++)
if (string[i] == '\n')
string[i] = '\0';
index += 1;
while ((fileopt[index] = malloc(strlen(string)+1))==NULL)
FreeRefresh("fileopt");
strcpy(fileopt[index],string);
} while (!feof(MenuFile));
fclose(MenuFile);
index--; /* Take off the END from the menu list */
while( !done )
{
ClearDisplay(0);
TextLine = TextHeight + 5; TextSample = 10;
WriteText("Menu Selection");
if (index < PAGELEN)
lowlist = index;
for (i = toplist; i <= lowlist; i++)
{
sprintf( writebuf, "%d) %s", i, fileopt[i]);
WriteText(writebuf);
}
WriteText("Choose: <#>, N(ext page), P(revious page), Q(uit)");
TypeText("Option>> ");
/*TextLine-=15;*/ TextSample = 90;
AcceptText(choice);
switch(choice[0])
{
case 'N':
case 'n':
toplist = ((toplist + PAGELEN) > index) ? index : toplist + PAGELEN;
lowlist = ((toplist + PAGELEN) > index) ? index : toplist + PAGELEN;
break;
case 'P':
case 'p':
toplist = ((toplist - PAGELEN) < 1) ? 1 : toplist - PAGELEN;
lowlist = ((toplist + PAGELEN) > index) ? index : toplist + PAGELEN-1;
break;
case 'Q':
case 'q':
ClearDisplay(0);
done = 1;
break;
default:
if (isdigit(choice[0]))
{
numchoice= atoi(choice);
if (numchoice > 0 && numchoice <= index)
{
if ((strnicmp(fileopt[numchoice]+
strlen(fileopt[numchoice])-4,".pal",4))== 0)
strcpy(CommandString,"PAL LOAD ");
else if ((strnicmp(fileopt[numchoice]+
strlen(fileopt[numchoice])-4,".cmd",4))== 0)
strcpy(CommandString,"BATCH ");
else
strcpy(CommandString,"FILE ");
strcat( CommandString, fileopt[numchoice]);
flowthru = 1;
done = 1;
ClearDisplay(0);
}
else
WriteText("Invalid input!!!!");
}
break;
}
}
for (i = 1; i <= index+1; i++)
free(fileopt[i]);
}
int DoPosText(void)
{
char string[81], dispstr[64], *lquotptr, *fquotptr;
int flag = 0;
int line = 0, samp = 0;
GetKeywordInteger (CommandString, "LIN", 0, &line, &flag);
GetKeywordInteger (CommandString, "SAM", 0, &samp, &flag);
GetKeywordString(CommandString, "TEX", "", string, &flag);
if (!flag)
{
StatusLine(2,"Please enter text:");
AcceptText(string);
strcpy(dispstr,"Please enter text:");
strcat(dispstr,string);
LengthText (dispstr, TextHeight, &line);
EraseText (TextLine, TextSample, TextHeight, line, 0);
DoRefresh();
}
else
{
fquotptr = strpbrk(CommandString,"\'\"");
lquotptr = strrchr(CommandString,'\'');
if (lquotptr == NULL)
{
lquotptr = strrchr(CommandString,'\"');
CommandString[strlen(CommandString)] = NULL;
}
else
strcpy(lquotptr,"\0");
strcpy(string,++fquotptr);
}
if (line == 0 || samp == 0)
{
StatusLine(1,"Arrow keys move; +,- changes cursor increment; '.' to exit.");
MoveCursor(&line,&samp);
}
TextLine = line - (TextHeight + 0); TextSample = samp;
IntoMem = 0;
TypeText(string);
TextSample = samp;
/*
IntoMem = 1;
TypeText(string);
DoRefresh();
*/
}
int DoOverlay(void)
{
int dn, grids, i, j, x, y, flag, start, incr, defdn, offset = 0;
char label[20];
float delta, mlat, mlon, hold;
if (zoom != 1 || subsample != 1)
{
StatusLine(0,"Can't overlay zoomed or subsampled images.");
return;
}
if ((strncmp(Object,"^CLOUD_IMAGE",12) == 0) ||
(strncmp(Object,"^MOSAIC_IMAGE",13) == 0))
{
maxlat = 55.0;
maxlon = 140.0;
delta = 5.0;
start = 1;
incr = 71;
defdn = numDN-1;
}
else
{
delta = 1.0;
start = 7;
incr = 100;
defdn = 0;
}
if (maxlat == 0.0 && minlat == 0.0 && maxlon == 0.0 && minlon == 0.0)
{
GetKeywordReal (CommandString, "MAXLAT", 0.0, &maxlat, &flag);
GetKeywordReal (CommandString, "MAXLON", 0.0, &maxlon, &flag);
}
if (maxlon < 0.0)
maxlon *= -1.0; /* convert to west lon */
if (minlon < 0.0)
minlon *= -1.0;
if (minlon > maxlon)
{
hold = maxlon;
maxlon = minlon;
minlon = hold;
}
GetKeywordString (CommandString, "LEG", "",label,&flag);
if (flag >= 0)
{
j = 120;
hold = -1.0;
TextLine = j+8; TextSample = 540;
sprintf( label, "%4.1f", hold);
WriteText(label);
hold += .5;
DrawLine( j, 590-5, j++, 610, 35/(256/numDN));
for (i=38;i<255;i+=3)
{
if (i==74 || i==116 || i == 158 || i == 200 || i == 242)
{
offset = 5;
TextLine = j+8; TextSample = 540;
sprintf(label,"%4.1f",hold);
WriteText(label);
hold += .5;
}
DrawLine( j, 590-offset, j++, 610, i/(256/numDN));
DrawLine( j, 590, j++, 610, i/(256/numDN));
offset = 0;
}
DrawLine( j, 590, j++, 610, 255/(256/numDN));
TextLine = j+20; TextSample = 520;
strcpy(label,"Pigment");
WriteText(label);
TextLine = j+40; TextSample = 520;
strcpy(label,"Concentratn");
WriteText(label);
TextLine = j+60; TextSample = 520;
strcpy(label,"LOG(mg/m-3)");
WriteText(label);
}
GetKeywordInteger (CommandString, "DN", 0, &dn, &flag);
if (flag <=0)
dn = defdn;
mlat = maxlat; mlon = maxlon;
x = min(ns,dispns); y = min(nl-sl+1,dispnl);
if (sl > 1)
{
if (sl < start)
offset = 1-sl;
else
{
i = sl/incr+1;
offset += i * incr - sl + 1;
mlat -= (float)i * delta;
}
}
for (i=start;i<ns;i+=incr) /* draw x axis */
{
DrawLine(1,i,y,i,dn);
TextLine = start+offset+38; TextSample = i+1;
sprintf(label,"%4.0f",mlon);
WriteText(label);
mlon -= delta;
}
for (i=start+offset;i<y;i+=incr) /* draw y axis */
{
DrawLine(i,1,i,x,dn);
TextLine = i+15; TextSample = 8;
sprintf(label,"%4.0f",mlat);
WriteText(label);
mlat -= delta;
}
}
int DoSerial(void)
{
TextLine = dispnl; TextSample = 1;
WriteText ("Not implemented yet.");
}
int DoPrint(void)
{
TextLine = dispnl; TextSample = 1;
WriteText ("Not implemented yet.");
}
int ctrl_c(void) /* interrupt routine. */
{
DisplayOff();
puts("\nUser Aborted\n");
exit(2);
return(1);
}