home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.parl.clemson.edu
/
2015-02-07.ftp.parl.clemson.edu.tar
/
ftp.parl.clemson.edu
/
pub
/
portedOneB.tar
/
OneB
/
RAConeb.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-07-19
|
42KB
|
1,448 lines
#include "RAConeb.h"
#include <unistd.h>
#include <../Ingest/platform.h>
#ifdef RAC_LINUX
#define SWABIT(x,y,z) do { if(x == y) memcpy(y,x,z); } while(0)
#else
#define SWABIT(x,y,z) swab(x,y,z)
#endif
char *c1Filename=0;
char *c2Filename=0;
char *c3Filename=0;
char *c4Filename=0;
char *c5Filename=0;
char *auxFilename=0;
char *syncFilename=0;
char *ephemFilename=0;
char *scanOpt="0";
char *bFilename=0;
cmdPair args[] =
{
"-iC1", &c1Filename,
"-iC2", &c2Filename,
"-iC3", &c3Filename,
"-iC4", &c4Filename,
"-iC5", &c5Filename,
"-iAUX", &auxFilename,
"-iSYNC", &syncFilename,
"-iEPHEM", &ephemFilename,
"-pMAXSCANS", &scanOpt,
"-ob", &bFilename,
0, 0
};
char satname[10][8]={"UNKNOWN","NOAA-11","NOAA-06","NOAA-14","NOAA-07",
"NOAA-12","NOAA-08","NOAA-09","NOAA-10","UNKNOWN"};
char typename[4][5]={"XXX", "LAC","GAC","HRPT"};
kep_t kepOrbEl;
/**** Main ****/
int main (int argc, char **argv)
{
int RC, i;
FILE *auxFile, *ephemFile, *syncFile;
int c1File, c2File, c3File, c4File, c5File, bFile;
ushort c1buf[2048], c2buf[2048], c3buf[2048], c4buf[2048], c5buf[2048];
ushort syncbuf[106], telemdata[103], auxBuf[97];
uchar tbmbuf[512], tbm44buf[50], buffer[13656], btemp[7400], timebuf[6], numbuf[2], locbuf[4];
uchar orbitbuf[7], telembuf[140];
short strhr, strmin, endhr, endmin;
double strsec, endsec;
uchar charbuf, longnumbuf[4];
char tmpchar[4], crap[64], daybuf[3], yrbuf[3];
unsigned int orbnum, orbnum2;
char satid[16], satnum[4];
ttOrbitTime startTime, endTime, scanTime;
int count = 0;
int ascend = 0;
short slixo;
int ilixo;
long lixo;
long tlong;
rct cartEl;
float gains[5], inters[5];
static double *Lats = NULL, *Lons = NULL;
static double *strLats = NULL, *strLons = NULL;
static double *endLats = NULL, *endLons = NULL;
struct stat st;
LDOUBLE zenith, zlat, zlon;
int scans, rc;
int MaxNumScans;
double two30, two22;
HRPTScan auxScan;
/* Parse Command Line */
RC = RACGetArgs(argc, argv, args);
if (RC != 0)
exit(RC);
two30 = pow(2.0, 30.0);
two22 = pow(2.0, 22.0);
MaxNumScans = atoi(scanOpt);
if (MaxNumScans == 0) MaxNumScans = 9999;
fprintf(stderr,"\nCommand Line Inputs:\n");
fprintf(stderr,"- Channel-1 : %s\n", c1Filename);
fprintf(stderr,"- Channel-2 : %s\n", c2Filename);
fprintf(stderr,"- Channel-3 : %s\n", c3Filename);
fprintf(stderr,"- Channel-4 : %s\n", c4Filename);
fprintf(stderr,"- Channel-5 : %s\n", c5Filename);
fprintf(stderr,"- Aux File : %s\n", auxFilename);
fprintf(stderr,"- Ephem File : %s\n", ephemFilename);
fprintf(stderr,"\nCommand Line Outputs:\n");
fprintf(stderr,"- 1B File : %s\n\n", bFilename);
c1File = open(c1Filename,O_RDONLY);
c2File = open(c2Filename,O_RDONLY);
c3File = open(c3Filename,O_RDONLY);
c4File = open(c4Filename,O_RDONLY);
c5File = open(c5Filename,O_RDONLY);
auxFile = fopen(auxFilename,"r");
syncFile = fopen(syncFilename,"r");
ephemFile = fopen(ephemFilename,"r");
bFile = creat(bFilename,0666);
if (c1File == -1 ||
c2File == -1 ||
c3File == -1 ||
c4File == -1 ||
c5File == -1 ||
auxFile == 0 ||
syncFile == 0 ||
ephemFile == 0 ||
bFile == -1 )
exit (1);
/* Get Satellite ID */
fseek(ephemFile, 0, SEEK_SET);
fscanf(ephemFile,"%s %s",&satid, &satnum);
fscanf(ephemFile, "%s %s %s %s", &crap, &crap, &crap, &crap);
sprintf(yrbuf,"%c%c", crap[0], crap[1]);
sprintf(daybuf,"%c%c%c", crap[2], crap[3], crap[4]);
scanTime.Year = startTime.Year = endTime.Year = 1900+atoi(yrbuf);
/* Get Scan Number */
stat(c1Filename,&st);
scans = st.st_size/4096;
/* Write TBM Header */
memset(tbmbuf,' ', 35);
write (bFile, tbmbuf, 30);
rc = fseek(auxFile, 0, SEEK_SET);
rc = fread(auxBuf, 2, 97, auxFile);
SWABIT(auxBuf,auxBuf,97*2);
memcpy(auxScan.ID, auxBuf, 97*2);
ReadScanTime(auxScan, &startTime);
decodeTime(startTime.Millisecond, &strhr, &strmin, &strsec);
orbnum = ReadLatLon(ephemFile, startTime, &strLats, &strLons);
rc = fseek(auxFile, 97L*2L*(scans-1), SEEK_SET);
rc = fread(auxBuf, 2, 97, auxFile);
SWABIT(auxBuf,auxBuf,97*2);
memcpy(auxScan.ID, auxBuf, 97*2);
ReadScanTime(auxScan, &endTime);
decodeTime(endTime.Millisecond, &endhr, &endmin, &endsec);
orbnum2 = ReadLatLon(ephemFile, endTime, &endLats, &endLons);
if (strLats[1024] > endLats[1024])
ascend = 1;
encodesat(tmpchar, atoi(satnum));
sprintf(tbm44buf,"NSS.HRPT.N%c.D%2d%3d.S%2d%2d.E%2d%2d.B%5d%2d.WI ",
tmpchar[0], startTime.Year%100, startTime.Day+1, strhr, strmin,
endhr, endmin, orbnum, orbnum2%100);
write(bFile,tbm44buf,44);
tbmbuf[0] = 'S';
write (bFile, tbmbuf, 1);
sprintf (tbmbuf,"%c%2d%c%2d%c%3d%c%3d",
(strLats[1023] >= 0)?'+':'-', abs((int)trunc(strLats[1023])),
(endLats[1023] >= 0)?'+':'-', abs((int)trunc(endLats[1023])),
(strLons[1023] >= 0)?'+':'-', abs((int)trunc(strLons[1023])),
(endLons[1023] >= 0)?'+':'-', abs((int)trunc(endLons[1023])));
write (bFile, tbmbuf, 14);
sprintf (tbmbuf,"%2d%2d%3d",strhr,strmin,(endhr*60+endmin)-(strhr*60+strmin));
write (bFile, tbmbuf, 7);
tbmbuf[0] = 'N';
write (bFile, tbmbuf, 1);
write (bFile, CHANNELS, 25);
/* Write Data Set Header Record (2) */
pack2number(numbuf, encodesat(tmpchar, atoi(satnum)));
charbuf = numbuf[1] | numbuf[0] << 4;
write (bFile, &charbuf, 1);
fprintf(stderr,"Satellite : %s(%c)\n", satname[(int)charbuf],tmpchar[0]);
if (!ascend)
fprintf(stderr,"Direction : Ascending\n");
else
fprintf(stderr,"Direction : Descending\n");
setPRTjunk(atoi(satnum));
/* Get Data Type */
pack2number(numbuf, 3);
charbuf = numbuf[0] | numbuf[1] << 4;
write (bFile, &charbuf, 1);
fprintf(stderr,"Data Type : HRPT\n");
/* Get Start Time */
packscantime(timebuf,(short)startTime.Year, (short)startTime.Day+1, startTime.Millisecond);
write (bFile, timebuf, 6);
fprintf(stderr,"Start Time : %0.2d.%0.2d %0.2d:%0.2d:%2.3f\n", startTime.Year, startTime.Day+1, strhr, strmin, strsec);
if (MaxNumScans == 9999) pack2number(numbuf, scans);
else pack2number(numbuf, MaxNumScans);
write (bFile, numbuf, 2);
/* Get End Time */
packscantime(timebuf,(short)endTime.Year, (short)endTime.Day+1, endTime.Millisecond);
write (bFile, timebuf, 6);
fprintf(stderr,"End Time : %0.2d.%0.2d %0.2d:%0.2d:%2.3f\n", endTime.Year, endTime.Day+1, endhr, endmin, endsec);
if (MaxNumScans == 9999) fprintf(stderr,"Number of Scans : %d\n", scans);
else fprintf(stderr,"Number of Scans : %d\n", MaxNumScans);
memset(btemp, 0, 7400);
sprintf(orbitbuf, "%.5d%.2d", orbnum, orbnum2%100);
write (bFile, orbitbuf, 7);
write (bFile, &btemp[0], 1);
write (bFile, btemp, 2);
write (bFile, btemp, 6);
write (bFile, btemp, 2);
write (bFile, &btemp[0], 1);
write (bFile, &btemp[0], 1);
write (bFile, &btemp[0], 1);
write (bFile, btemp, 3);
write (bFile, tbm44buf, 44);
pack2number(numbuf, kepOrbEl.T.Year % 100);
write (bFile, numbuf, 2);
pack2number(numbuf, kepOrbEl.T.Day);
write (bFile, numbuf, 2);
pack4number(longnumbuf, kepOrbEl.T.Millisecond);
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)kepOrbEl.A);
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(kepOrbEl.e * 100000000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(kepOrbEl.i * 100000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(kepOrbEl.w * 100000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(kepOrbEl.N * 100000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(kepOrbEl.m * 100000.0));
write (bFile, longnumbuf, 4);
cartEl = getCartesian(kepOrbEl);
pack4number(longnumbuf, (int)(cartEl.xp * 10000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(cartEl.yp * 10000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(cartEl.zp * 10000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(cartEl.xv * 1000000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(cartEl.yv * 1000000.0));
write (bFile, longnumbuf, 4);
pack4number(longnumbuf, (int)(cartEl.zv * 1000000.0));
write (bFile, longnumbuf, 4);
write (bFile, btemp, 7260);
write (bFile, btemp, 7400);
tlong = 0;
fseek (auxFile, 0, SEEK_SET);
do {
fread(auxBuf, 2, 97, auxFile);
SWABIT(auxBuf,auxBuf,97*2);
memcpy(auxScan.ID, auxBuf, 97*2);
rc = grabPRTlevels(auxScan.ID);
} while (rc != 0);
/* Write Data Records (2 per scan) */
while (read(c1File,c1buf, 4096) > 0) {
printf("------------------\n");
SWABIT(c1buf,c1buf,4096);
read(c2File,c2buf, 4096);
SWABIT(c2buf,c2buf,4096);
read(c3File,c3buf, 4096);
SWABIT(c3buf,c3buf,4096);
read(c4File,c4buf, 4096);
SWABIT(c4buf,c4buf,4096);
read(c5File,c5buf, 4096);
SWABIT(c5buf,c5buf,4096);
/* Scan Line Number*/
pack2number(numbuf, count+1);
write (bFile, numbuf, 2);
/* Time Code */
rc = fseek (auxFile, 97L*2L*count, SEEK_SET);
rc = fread (auxBuf, 2, 97, auxFile);
SWABIT(auxBuf,auxBuf,97*2);
memcpy(auxScan.ID, auxBuf, 97*2);
ReadScanTime(auxScan, &scanTime);
count++;
packscantime(timebuf,(short)scanTime.Year, (short)scanTime.Day+1, scanTime.Millisecond);
write (bFile, timebuf, 6);
/* Quality indicators */
if (ascend) {
if ((scanTime.Millisecond - tlong) != 167 && (scanTime.Millisecond - tlong) != 166)
if (count == 1)
btemp[0] = 0x02;
else {
printf ("(descend)Time error: %d at scan %d\n", scanTime.Millisecond-tlong, count);
btemp[0] = 0x02 | 0x40;
}
else
btemp[0] = 0x02;
}
else {
if ((scanTime.Millisecond - tlong) != 167 && (scanTime.Millisecond - tlong) != 166)
if (count == 1)
btemp[0] = 0x00;
else {
printf ("(ascend)Time error: %d at scan %d\n", scanTime.Millisecond-tlong, count);
btemp[0] = 0x00 | 0x40;
}
else
btemp[0] = 0x00;
}
btemp[1] = 0x00;
btemp[2] = 0x00;
btemp[3] = 0x00;
tlong = scanTime.Millisecond;
write (bFile, btemp, 4);
/* Calibration */
grabPRTgains(auxScan.ID, gains, inters);
for (i=0; i<5; i++) {
// printf("gains[%d] = %f, casting gains = %d\n", i, gains[i], (int)((double)gains[i] * two30));
pack4number(longnumbuf, (int)((double)gains[i] * two30));
write (bFile, longnumbuf, 4);
// printf("inters[%d] = %f, casting inters = %d\n", i, inters[i], (int)((double)inters[i] * two22));
pack4number(longnumbuf, (int)((double)inters[i] * two22));
write (bFile, longnumbuf, 4);
}
/* Meaningful za/el */
pack2number(numbuf, 51);
write (bFile, &numbuf[0], 1);
/* Solar Zenith Angles */
ReadLatLon(ephemFile, scanTime, &Lats, &Lons);
for (i=25; i<2048; i+=40) {
zlat = (LDOUBLE)Lats[i];
zlon = (LDOUBLE)Lons[i];
// printf("zlat = %Lf, zlon = %Lf\n", zlat, zlon);
SolarZenithAngle (btemp, scanTime.Year, scanTime.Day+1, scanTime.Millisecond, scanTime.UnixTime, zlat, zlon);
// printf("I'm going to write out : %i = %c\n", i, btemp[0]);
write (bFile, &btemp[0], 1);
}
/* Earth location */
for (i=25; i<2048; i+=40) {
packlocation (locbuf, Lats[i], Lons[i]);
write (bFile, locbuf, 4);
}
/* Telemetry */
rc = fread (syncbuf, 2, 106, syncFile);
SWABIT (syncbuf, syncbuf, 106*2);
memcpy (telemdata, syncbuf, 12);
memcpy (&telemdata[6], auxScan.ID, 194);
packtelem(telembuf, telemdata);
write (bFile, telembuf, 140);
/* Video Data */
packvideo(buffer, 1, c1buf, c2buf, c3buf, c4buf, c5buf);
write (bFile, buffer, 13656);
write (bFile, btemp, 20); /* Solar Zenith Angles decimals */
write (bFile, btemp, 2); /* Clock drift */
/* Spare */
memset(btemp, 0, 7400);
write (bFile, btemp, 674);
}
close (c1File);
close (c2File);
close (c3File);
close (c4File);
close (c5File);
close (bFile);
fclose (auxFile);
fclose (ephemFile);
exit(0);
}
int RACGetArgs(int argc, char **argv, cmdPair *args)
{
int i,j;
int ERROR=0;
for (i=1;i<argc;i+=1)
{
switch(*(argv[i]+0))
{
case('-'):
j=0;
while (args[j].Tag != 0)
{
if (strcmp(argv[i], args[j].Tag) == 0)
{
switch(*(args[j].Tag+1))
{
case('i'):
case('o'):
case('a'):
case('p'):
*args[j].Param = argv[i+1];
/* j += 1; */
break;
case('f'):
*args[j].Param = argv[i];
break;
}
}
j += 1;
}
break;
}
}
j = 0;
while (args[j].Tag != 0)
{
switch(*(args[j].Tag+1))
{
case('i'):
case('o'):
case('p'):
if (*args[j].Param == 0)
{
fprintf(stderr, "(%s)**ERROR** required argument '%s' not supplied\n", argv[0], args[j].Tag);
ERROR += 1;
}
break;
case('f'):
break;
}
j += 1;
}
return ERROR;
}
int ReadScanTime(HRPTScan aScan, ttOrbitTime *oTime)
{
int returnFlag=-1;
int rc;
returnFlag = ttGetHRPTScanTime(oTime, aScan.TimeCode);
return returnFlag;
}
unsigned int ReadLatLon(FILE *EphemFile, ttOrbitTime sTime, double **latList, double **lonList)
{
double *llLatList, *llLonList;
kep_t mean;
kep_t osc;
LDOUBLE DEL;
norad_t ephem;
static double *sig = NULL;
int i;
unsigned int orb;
fseek(EphemFile, 0, SEEK_SET);
ReadNorad(EphemFile, &ephem);
NoradToKep(&ephem, &mean);
brwlyd_initialize(mean);
if (*latList == 0)
*latList = malloc((2048+1024)*sizeof(double));
if (*lonList == 0)
*lonList = malloc((2048+1024)*sizeof(double));
if (sig == 0) {
sig = malloc((2048+1024)*sizeof(double));
for(i=0;i<2048;i+=1)
sig[i] = (55.4*2.0/2048.0) * (float) i-55.4;
}
kepOrbEl.A = mean.A;
kepOrbEl.e = mean.e;
kepOrbEl.i = mean.i * m_rToD;
kepOrbEl.N = mean.N * m_rToD;
kepOrbEl.w = mean.w * m_rToD;
kepOrbEl.m = mean.m * m_rToD;
kepOrbEl.T = mean.T;
/*
printf("A = %f, e = %f, i = %f, N = %f, w = %f, m = %f\n",
mean.A, mean.e, mean.i, mean.N, mean.w, mean.m);
printf("mean.T.Year = %d, mean.T.Day = %d, mean.T.fSecond = %f, mean.T.Second = %d\n",
mean.T.Year, mean.T.Day, mean.T.fSecond, mean.T.Second);
printf("mean.T.Milli = %d, mean.T.Millisecond = %d, mean.T.UnixTime - unknown.\n",
mean.T.Milli, mean.T.Millisecond);
*/
/*
ListKep(&mean);
printf(">>%f\n%f\n%f\n%f\n%f\n", mean.A, mean.e, mean.i, mean.N, mean.w, mean.m);
ttListOrbitTime(&mean.T);
*/
/*
printf("sTime.Year = %d, sTime.Day = %d, sTime.fSecond = %f\n",
sTime.Year, sTime.Day, sTime.fSecond);
*/
DEL = ttTimeDiff(&sTime, &mean.T);
/*
printf("DEL = %f\n", DEL);
*/
osc = brwlyd_osc(DEL);
/*
printf("osc.A = %f, osc.e = %f, osc.i = %f, osc.N = %f, osc.w = %f, osc.m = %f\n",
osc.A, osc.e, osc.i, osc.N, osc.w, osc.m);
*/
orb = osc.Orbit;
model_earthlocate(osc, 2048, sig, *latList, *lonList);
return orb;
}
int encodesat(char *let, int num)
{
int temp;
switch (num) {
case 6: temp = 2; let[0] = 'A'; break;
case 7: temp = 4; let[0] = 'C'; break;
case 8: temp = 6; let[0] = 'E'; break;
case 9: temp = 7; let[0] = 'F'; break;
case 10: temp = 8; let[0] = 'G'; break;
case 11: temp = 1; let[0] = 'H'; break;
case 12: temp = 5; let[0] = 'D'; break;
case 13: temp = 2; let[0] = 'I'; break;
case 14: temp = 3; let[0] = 'J'; break;
default: temp = 0; let[0] = '?'; break;
}
return temp;
}
rct getCartesian(kep_t kep)
{
LDOUBLE Ecc; // eccentric anomaly
LDOUBLE Esav; // save previous Ecc
LDOUBLE cosE,sinE,radius,xp0,xp1,xp2,xp3,F;
LDOUBLE cosGF,sinGF,cosN,sinN,cosi,sini;
rct rect;
Ecc = kep.m;
Esav= 0.0;
while (1) {
Ecc = kep.m + kep.e * sin (Ecc);
if (fabs(Ecc-Esav) < 1e-15) break;
Esav= Ecc;
}
cosE = cos (Ecc); sinE = sin (Ecc);
radius = kep.A * (1. - kep.e * cosE);
xp0 = sqrt (1. - kep.e * kep.e);
xp1 = sqrt (kep.A * ea_GM) / radius;
xp2 = xp0 * xp1;
xp3 = kep.e * sinE * xp1;
F = atan2 (sinE * xp0, cosE - kep.e);
cosGF = cos (kep.w + F);
sinGF = sin (kep.w + F);
cosN = cos (kep.N);
sinN = sin (kep.N);
cosi = cos (kep.i);
sini = sin (kep.i);
// position
rect.xp = (radius * (cosN * cosGF - sinN * cosi * sinGF)) / 1000.0;
rect.yp = (radius * (cosN * sinGF * cosi + sinN * cosGF)) / 1000.0;
rect.zp = (radius * (sini * sinGF)) / 1000.0;
// velocity
rect.xv = (xp3 * (cosN * cosGF - sinN * cosi * sinGF)
- xp2 * (sinN * cosGF * cosi + cosN * sinGF)) / 1000.0;
rect.yv = (xp3 * (cosN * sinGF * cosi + sinN * cosGF)
- xp2 * (sinN * sinGF - cosN * cosi * cosGF)) / 1000.0;
rect.zv = (xp3 * (sini * sinGF)
+ xp2 * (sini * cosGF)) / 1000.0;
return rect;
}
int decodeTime(long msec, short *hr, short *min, double *sec)
{
short temp1, temp2;
double tempgmt;
tempgmt = (double)(msec)/3600./1000.;
*hr=temp1=trunc(tempgmt);
*min=temp2=trunc((tempgmt-(double)(temp1))*60);
*sec = tempgmt*3600.0 - (double)(temp1)*3600.0 - (double)(temp2)*60.0;
return 0;
}
int pack2number (uchar *buffer, short scannum)
{
buffer[0] = (uchar)((scannum >> 8)&0x00ff);
buffer[1] = (uchar)(scannum&0x00ff);
return 0;
}
int pack4number (uchar *buffer, int scannum)
{
// printf("scannum = %d\n", scannum);
buffer[0] = (uchar)((scannum >> 24)&0x00ff);
buffer[1] = (uchar)((scannum >> 16)&0x00ff);
buffer[2] = (uchar)((scannum >> 8)&0x00ff);
buffer[3] = (uchar)(scannum&0x00ff);
// printf("buf0 = %d, buf1 = %d, buf2 = %d, buf3 = %d\n",
// buffer[0], buffer[1], buffer[2], buffer[3]);
return 0;
}
int packscantime(uchar *scanline,short scanyear,short scanday,long scangmt)
{
unsigned int msec;
double tempfl;
short tempsh, tempsh2;
uchar tempyr;
tempyr = scanyear - 1900;
msec = (unsigned int)scangmt;
scanline[0] = (uchar)((tempyr << 1)&0xfe) | (uchar)((scanday >> 8)&0x01);
scanline[1] = (uchar)(scanday&0x00ff);
scanline[2] = ((uchar)(msec >> 24)&0x000000ff)&0x07;
scanline[3] = (uchar)(msec >> 16)&0x000000ff;
scanline[4] = (uchar)(msec >> 8)&0x000000ff;
scanline[5] = (uchar)(msec)&0x000000ff;
return 0;
}
int packlocation(uchar *buffer, double aLat, double aLon)
{
short temp;
temp = (short)(aLat * 128.0);
buffer[0] = (uchar)((temp >> 8)&0x00ff);
buffer[1] = (uchar)(temp&0x00ff);
temp = (short)(aLon * 128.0);
buffer[2] = (uchar)((temp >> 8)&0x00ff);
buffer[3] = (uchar)(temp&0x00ff);
return 0;
}
int packtelem(uchar *buffer, ushort *telem)
{
int i, j;
int *tmpintPtr;
j = 0;
for (i=0; i < 34; i++) {
tmpintPtr = ((int *) &buffer[i*4]);
*tmpintPtr = (((((int)telem[j])<<20)&0x3ff00000) | ((((int)telem[j+1])<<10)&0x000ffc00) | ((((int)telem[j+2]))&0x000003ff));
j += 3;
#ifdef LINUX
swapint(tmpintPtr);
#endif LINUX
}
tmpintPtr = ((int *) &buffer[i*4]);
*tmpintPtr = (((((int)telem[j])<<20)&0x3ff00000) | ((((int)0)<<10)&0x000ffc00) | ((((int)0))&0x000003ff));
#ifdef LINUX
swapint(tmpintPtr);
#endif
return 0;
}
int packvideo(uchar *buffer,int datatype, ushort *ch1,ushort *ch2,ushort *ch3,ushort *ch4,ushort *ch5)
{
int i,j,tmpint;
int *tmpintPtr;
unsigned short decode_array[13661];
for(i=0;i<2048;i+=1)
{
decode_array[i*5] = ch1[i];
decode_array[i*5+1] = ch2[i];
decode_array[i*5+2] = ch3[i];
decode_array[i*5+3] = ch4[i];
decode_array[i*5+4] = ch5[i];
}
decode_array[i*5] = ch1[i];
decode_array[i*5+1] = ch2[i];
decode_array[i*5+2] = ch3[i];
decode_array[i*5+3] = ch4[i];
decode_array[i*5+4] = ch5[i];
j=0;
for (i=0;i<3414;i+=1)
{
tmpintPtr = ((int *) &buffer[i*4]);
*tmpintPtr = (((((int)decode_array[j])<<20)&0x3ff00000) | ((((int)decode_array[j+1])<<10)&0x000ffc00) | ((((int)decode_array[j+2]))&0x000003ff));
j += 3;
#ifdef LINUX
swapint(tmpintPtr);
#endif
}
return 0;
}
int setPRTjunk(int satellite)
{
if (satellite == 12)
{
PRTCoefficient[0][0] = 0.000000;
PRTCoefficient[0][1] = 0.000000;
PRTCoefficient[0][2] = 0.000000;
PRTCoefficient[0][3] = 0.000000;
PRTCoefficient[0][4] = 0.000000;
PRTWeight[0] = 0.000000;
PRTCoefficient[1][0] = 276.596985;
PRTCoefficient[1][1] = 0.051275;
PRTCoefficient[1][2] = 0.000001;
PRTCoefficient[1][3] = 0.000000;
PRTCoefficient[1][4] = 0.000000;
PRTWeight[1] = 0.250000;
PRTCoefficient[2][0] = 276.596985;
PRTCoefficient[2][1] = 0.051275;
PRTCoefficient[2][2] = 0.000001;
PRTCoefficient[2][3] = 0.000000;
PRTCoefficient[2][4] = 0.000000;
PRTWeight[2] = 0.250000;
PRTCoefficient[3][0] = 276.596985;
PRTCoefficient[3][1] = 0.051275;
PRTCoefficient[3][2] = 0.000001;
PRTCoefficient[3][3] = 0.000000;
PRTCoefficient[3][4] = 0.000000;
PRTWeight[3] = 0.250000;
PRTCoefficient[4][0] = 276.596985;
PRTCoefficient[4][1] = 0.051275;
PRTCoefficient[4][2] = 0.000001;
PRTCoefficient[4][3] = 0.000000;
PRTCoefficient[4][4] = 0.000000;
PRTWeight[4] = 0.250000;
RFuncWave[0] = 0.000000;
RFuncCenterWave[0] = 0.000000;
RFuncStep[0] = 0.000000;
RFuncCount[0] = 0.000000;
RFuncSum[0] = 0.000000;
RFuncWidth[0] = 0.000000;
SolarIrradiance[0] = 0.000000;
RFuncWave[1] = 0.000000;
RFuncCenterWave[1] = 0.000000;
RFuncStep[1] = 0.000000;
RFuncCount[1] = 0.000000;
RFuncSum[1] = 0.000000;
RFuncWidth[1] = 0.000000;
SolarIrradiance[1] = 0.000000;
RFuncWave[2] = 2439.023926;
RFuncCenterWave[2] = 2721.463867;
RFuncStep[2] = 9.414660;
RFuncCount[2] = 60.000000;
RFuncSum[2] = 1.042425;
RFuncWidth[2] = 0.000000;
SolarIrradiance[2] = 0.000000;
RFuncWave[3] = 847.457520;
RFuncCenterWave[3] = 931.583191;
RFuncStep[3] = 2.804190;
RFuncCount[3] = 60.000000;
RFuncSum[3] = 1.000085;
RFuncWidth[3] = 0.000000;
SolarIrradiance[3] = 0.000000;
RFuncWave[4] = 787.401367;
RFuncCenterWave[4] = 850.344055;
RFuncStep[4] = 2.098090;
RFuncCount[4] = 60.000000;
RFuncSum[4] = 0.992360;
RFuncWidth[4] = 0.000000;
SolarIrradiance[4] = 0.000000;
SpaceRad[2] = 0.000000;
SpaceRad[3] = 0.000000;
SpaceRad[4] = 0.000000;
AGIGain[0] = 0.104223;
AGIInter[0] = -4.449080;
AGIGain[1] = 0.101440;
AGIInter[1] = -3.399256;
RFunc[2][0] = 0.000044;
RFunc[2][1] = 0.000043;
RFunc[2][2] = 0.000056;
RFunc[2][3] = 0.000098;
RFunc[2][4] = 0.000189;
RFunc[2][5] = 0.000379;
RFunc[2][6] = 0.000757;
RFunc[2][7] = 0.001460;
RFunc[2][8] = 0.002308;
RFunc[2][9] = 0.002879;
RFunc[2][10] = 0.003148;
RFunc[2][11] = 0.003242;
RFunc[2][12] = 0.003271;
RFunc[2][13] = 0.003302;
RFunc[2][14] = 0.003357;
RFunc[2][15] = 0.003410;
RFunc[2][16] = 0.003427;
RFunc[2][17] = 0.003437;
RFunc[2][18] = 0.003466;
RFunc[2][19] = 0.003502;
RFunc[2][20] = 0.003518;
RFunc[2][21] = 0.003488;
RFunc[2][22] = 0.003430;
RFunc[2][23] = 0.003395;
RFunc[2][24] = 0.003397;
RFunc[2][25] = 0.003427;
RFunc[2][26] = 0.003477;
RFunc[2][27] = 0.003533;
RFunc[2][28] = 0.003548;
RFunc[2][29] = 0.003498;
RFunc[2][30] = 0.003495;
RFunc[2][31] = 0.003619;
RFunc[2][32] = 0.003470;
RFunc[2][33] = 0.003596;
RFunc[2][34] = 0.003442;
RFunc[2][35] = 0.003322;
RFunc[2][36] = 0.002956;
RFunc[2][37] = 0.002140;
RFunc[2][38] = 0.001237;
RFunc[2][39] = 0.000651;
RFunc[2][40] = 0.000356;
RFunc[2][41] = 0.000211;
RFunc[2][42] = 0.000141;
RFunc[2][43] = 0.000101;
RFunc[2][44] = 0.000074;
RFunc[2][45] = 0.000061;
RFunc[2][46] = 0.000057;
RFunc[2][47] = 0.000054;
RFunc[2][48] = 0.004781;
RFunc[2][49] = 0.000044;
RFunc[2][50] = 0.000045;
RFunc[2][51] = 0.000048;
RFunc[2][52] = 0.000049;
RFunc[2][53] = 0.000048;
RFunc[2][54] = 0.000048;
RFunc[2][55] = 0.000048;
RFunc[2][56] = 0.000048;
RFunc[2][57] = 0.000048;
RFunc[2][58] = 0.000048;
RFunc[2][59] = 0.000000;
RFunc[3][0] = 0.000235;
RFunc[3][1] = 0.000250;
RFunc[3][2] = 0.000249;
RFunc[3][3] = 0.000219;
RFunc[3][4] = 0.000209;
RFunc[3][5] = 0.000348;
RFunc[3][6] = 0.000760;
RFunc[3][7] = 0.001508;
RFunc[3][8] = 0.002627;
RFunc[3][9] = 0.004074;
RFunc[3][10] = 0.005591;
RFunc[3][11] = 0.006882;
RFunc[3][12] = 0.007820;
RFunc[3][13] = 0.008498;
RFunc[3][14] = 0.009021;
RFunc[3][15] = 0.009461;
RFunc[3][16] = 0.009867;
RFunc[3][17] = 0.010275;
RFunc[3][18] = 0.010653;
RFunc[3][19] = 0.010935;
RFunc[3][20] = 0.011072;
RFunc[3][21] = 0.011104;
RFunc[3][22] = 0.011095;
RFunc[3][23] = 0.011102;
RFunc[3][24] = 0.011148;
RFunc[3][25] = 0.011250;
RFunc[3][26] = 0.011415;
RFunc[3][27] = 0.011628;
RFunc[3][28] = 0.011867;
RFunc[3][29] = 0.012104;
RFunc[3][30] = 0.012293;
RFunc[3][31] = 0.012382;
RFunc[3][32] = 0.012336;
RFunc[3][33] = 0.012206;
RFunc[3][34] = 0.012071;
RFunc[3][35] = 0.011983;
RFunc[3][36] = 0.011819;
RFunc[3][37] = 0.011368;
RFunc[3][38] = 0.010435;
RFunc[3][39] = 0.009049;
RFunc[3][40] = 0.007414;
RFunc[3][41] = 0.005743;
RFunc[3][42] = 0.004198;
RFunc[3][43] = 0.002867;
RFunc[3][44] = 0.001830;
RFunc[3][45] = 0.001138;
RFunc[3][46] = 0.000730;
RFunc[3][47] = 0.000513;
RFunc[3][48] = 0.000397;
RFunc[3][49] = 0.000332;
RFunc[3][50] = 0.000300;
RFunc[3][51] = 0.000283;
RFunc[3][52] = 0.000266;
RFunc[3][53] = 0.000251;
RFunc[3][54] = 0.000239;
RFunc[3][55] = 0.000232;
RFunc[3][56] = 0.000230;
RFunc[3][57] = 0.000232;
RFunc[3][58] = 0.000235;
RFunc[3][59] = 0.000000;
RFunc[4][0] = 0.000343;
RFunc[4][1] = 0.000081;
RFunc[4][2] = 0.000075;
RFunc[4][3] = 0.000579;
RFunc[4][4] = 0.001763;
RFunc[4][5] = 0.003479;
RFunc[4][6] = 0.005505;
RFunc[4][7] = 0.007609;
RFunc[4][8] = 0.009513;
RFunc[4][9] = 0.010932;
RFunc[4][10] = 0.011658;
RFunc[4][11] = 0.011897;
RFunc[4][12] = 0.011984;
RFunc[4][13] = 0.012216;
RFunc[4][14] = 0.012624;
RFunc[4][15] = 0.013116;
RFunc[4][16] = 0.013603;
RFunc[4][17] = 0.014051;
RFunc[4][18] = 0.014467;
RFunc[4][19] = 0.014858;
RFunc[4][20] = 0.011520;
RFunc[4][21] = 0.015466;
RFunc[4][22] = 0.015585;
RFunc[4][23] = 0.015547;
RFunc[4][24] = 0.015433;
RFunc[4][25] = 0.015340;
RFunc[4][26] = 0.015351;
RFunc[4][27] = 0.015442;
RFunc[4][28] = 0.015531;
RFunc[4][29] = 0.015538;
RFunc[4][30] = 0.015451;
RFunc[4][31] = 0.015348;
RFunc[4][32] = 0.015313;
RFunc[4][33] = 0.015387;
RFunc[4][34] = 0.015383;
RFunc[4][35] = 0.015044;
RFunc[4][36] = 0.014117;
RFunc[4][37] = 0.012541;
RFunc[4][38] = 0.010500;
RFunc[4][39] = 0.008190;
RFunc[4][40] = 0.005812;
RFunc[4][41] = 0.003586;
RFunc[4][42] = 0.001743;
RFunc[4][43] = 0.000511;
RFunc[4][44] = 0.000000;
RFunc[4][45] = 0.000000;
RFunc[4][46] = 0.000121;
RFunc[4][47] = 0.000285;
RFunc[4][48] = 0.000326;
RFunc[4][49] = 0.000291;
RFunc[4][50] = 0.000231;
RFunc[4][51] = 0.000195;
RFunc[4][52] = 0.000189;
RFunc[4][53] = 0.000200;
RFunc[4][54] = 0.000217;
RFunc[4][55] = 0.000226;
RFunc[4][56] = 0.000228;
RFunc[4][57] = 0.000224;
RFunc[4][58] = 0.000218;
RFunc[4][59] = 0.000000;
}
else
if (satellite == 14)
{
PRTCoefficient[0][0] = 0.000000;
PRTCoefficient[0][1] = 0.000000;
PRTCoefficient[0][2] = 0.000000;
PRTCoefficient[0][3] = 0.000000;
PRTCoefficient[0][4] = 0.000000;
PRTWeight[0] = 0.000000;
PRTCoefficient[1][0] = 276.596985;
PRTCoefficient[1][1] = 0.051275;
PRTCoefficient[1][2] = 0.000001;
PRTCoefficient[1][3] = 0.000000;
PRTCoefficient[1][4] = 0.000000;
PRTWeight[1] = 0.250000;
PRTCoefficient[2][0] = 276.596985;
PRTCoefficient[2][1] = 0.051275;
PRTCoefficient[2][2] = 0.000001;
PRTCoefficient[2][3] = 0.000000;
PRTCoefficient[2][4] = 0.000000;
PRTWeight[2] = 0.250000;
PRTCoefficient[3][0] = 276.596985;
PRTCoefficient[3][1] = 0.051275;
PRTCoefficient[3][2] = 0.000001;
PRTCoefficient[3][3] = 0.000000;
PRTCoefficient[3][4] = 0.000000;
PRTWeight[3] = 0.250000;
PRTCoefficient[4][0] = 276.596985;
PRTCoefficient[4][1] = 0.051275;
PRTCoefficient[4][2] = 0.000001;
PRTCoefficient[4][3] = 0.000000;
PRTCoefficient[4][4] = 0.000000;
PRTWeight[4] = 0.250000;
RFuncWave[0] = 0.000000;
RFuncCenterWave[0] = 0.000000;
RFuncStep[0] = 0.000000;
RFuncCount[0] = 0.000000;
RFuncSum[0] = 0.000000;
RFuncWidth[0] = 0.136000;
SolarIrradiance[0] = 221.419998;
RFuncWave[1] = 0.000000;
RFuncCenterWave[1] = 0.000000;
RFuncStep[1] = 0.000000;
RFuncCount[1] = 0.000000;
RFuncSum[1] = 0.000000;
RFuncWidth[1] = 0.245000;
SolarIrradiance[1] = 252.289993;
RFuncWave[2] = 2439.023926;
RFuncCenterWave[2] = 2676.710449;
RFuncStep[2] = 7.922880;
RFuncCount[2] = 60.000000;
RFuncSum[2] = 1.000013;
RFuncWidth[2] = 0.000000;
SolarIrradiance[2] = 0.000000;
RFuncWave[3] = 854.700684;
RFuncCenterWave[3] = 935.079956;
RFuncStep[3] = 2.679310;
RFuncCount[3] = 60.000000;
RFuncSum[3] = 1.000042;
RFuncWidth[3] = 0.000000;
SolarIrradiance[3] = 0.000000;
RFuncWave[4] = 787.401367;
RFuncCenterWave[4] = 839.894775;
RFuncStep[4] = 1.749780;
RFuncCount[4] = 60.000000;
RFuncSum[4] = 1.000023;
RFuncWidth[4] = 0.000000;
SolarIrradiance[4] = 0.000000;
SpaceRad[2] = 0.006900;
SpaceRad[3] = -4.050000;
SpaceRad[4] = -2.290000;
AGIGain[0] = 0.108100;
AGIInter[0] = -3.864800;
AGIGain[1] = 0.109000;
AGIInter[1] = -3.674900;
RFunc[2][0] = 0.000046;
RFunc[2][1] = 0.000052;
RFunc[2][2] = 0.000061;
RFunc[2][3] = 0.000078;
RFunc[2][4] = 0.000116;
RFunc[2][5] = 0.000193;
RFunc[2][6] = 0.000329;
RFunc[2][7] = 0.000555;
RFunc[2][8] = 0.000918;
RFunc[2][9] = 0.001429;
RFunc[2][10] = 0.002041;
RFunc[2][11] = 0.002652;
RFunc[2][12] = 0.003088;
RFunc[2][13] = 0.003271;
RFunc[2][14] = 0.003303;
RFunc[2][15] = 0.003281;
RFunc[2][16] = 0.003269;
RFunc[2][17] = 0.003299;
RFunc[2][18] = 0.003348;
RFunc[2][19] = 0.003395;
RFunc[2][20] = 0.003445;
RFunc[2][21] = 0.003499;
RFunc[2][22] = 0.003529;
RFunc[2][23] = 0.003505;
RFunc[2][24] = 0.003463;
RFunc[2][25] = 0.003453;
RFunc[2][26] = 0.003467;
RFunc[2][27] = 0.003462;
RFunc[2][28] = 0.003431;
RFunc[2][29] = 0.003403;
RFunc[2][30] = 0.003394;
RFunc[2][31] = 0.003384;
RFunc[2][32] = 0.003358;
RFunc[2][33] = 0.003330;
RFunc[2][34] = 0.003315;
RFunc[2][35] = 0.003305;
RFunc[2][36] = 0.003278;
RFunc[2][37] = 0.003226;
RFunc[2][38] = 0.003166;
RFunc[2][39] = 0.003120;
RFunc[2][40] = 0.003133;
RFunc[2][41] = 0.003240;
RFunc[2][42] = 0.003358;
RFunc[2][43] = 0.003320;
RFunc[2][44] = 0.003032;
RFunc[2][45] = 0.002535;
RFunc[2][46] = 0.001894;
RFunc[2][47] = 0.001239;
RFunc[2][48] = 0.000729;
RFunc[2][49] = 0.000435;
RFunc[2][50] = 0.000286;
RFunc[2][51] = 0.000202;
RFunc[2][52] = 0.000149;
RFunc[2][53] = 0.000113;
RFunc[2][54] = 0.000085;
RFunc[2][55] = 0.000065;
RFunc[2][56] = 0.000053;
RFunc[2][57] = 0.000048;
RFunc[2][58] = 0.000046;
RFunc[2][59] = 0.000000;
RFunc[3][0] = 0.000230;
RFunc[3][1] = 0.000274;
RFunc[3][2] = 0.000343;
RFunc[3][3] = 0.000461;
RFunc[3][4] = 0.000645;
RFunc[3][5] = 0.000900;
RFunc[3][6] = 0.001228;
RFunc[3][7] = 0.001651;
RFunc[3][8] = 0.002214;
RFunc[3][9] = 0.002960;
RFunc[3][10] = 0.003882;
RFunc[3][11] = 0.004934;
RFunc[3][12] = 0.006068;
RFunc[3][13] = 0.007221;
RFunc[3][14] = 0.008315;
RFunc[3][15] = 0.009278;
RFunc[3][16] = 0.010070;
RFunc[3][17] = 0.010669;
RFunc[3][18] = 0.011054;
RFunc[3][19] = 0.011248;
RFunc[3][20] = 0.011288;
RFunc[3][21] = 0.011218;
RFunc[3][22] = 0.011087;
RFunc[3][23] = 0.010952;
RFunc[3][24] = 0.010867;
RFunc[3][25] = 0.010831;
RFunc[3][26] = 0.010802;
RFunc[3][27] = 0.010738;
RFunc[3][28] = 0.010648;
RFunc[3][29] = 0.010604;
RFunc[3][30] = 0.010683;
RFunc[3][31] = 0.010912;
RFunc[3][32] = 0.011206;
RFunc[3][33] = 0.011463;
RFunc[3][34] = 0.011600;
RFunc[3][35] = 0.011619;
RFunc[3][36] = 0.011555;
RFunc[3][37] = 0.011438;
RFunc[3][38] = 0.011251;
RFunc[3][39] = 0.010932;
RFunc[3][40] = 0.010417;
RFunc[3][41] = 0.009664;
RFunc[3][42] = 0.008684;
RFunc[3][43] = 0.007501;
RFunc[3][44] = 0.006143;
RFunc[3][45] = 0.004714;
RFunc[3][46] = 0.003372;
RFunc[3][47] = 0.002276;
RFunc[3][48] = 0.001530;
RFunc[3][49] = 0.001064;
RFunc[3][50] = 0.000780;
RFunc[3][51] = 0.000578;
RFunc[3][52] = 0.000407;
RFunc[3][53] = 0.000268;
RFunc[3][54] = 0.000167;
RFunc[3][55] = 0.000106;
RFunc[3][56] = 0.000079;
RFunc[3][57] = 0.000074;
RFunc[3][58] = 0.000081;
RFunc[3][59] = 0.000000;
RFunc[4][0] = 0.000106;
RFunc[4][1] = 0.000149;
RFunc[4][2] = 0.000260;
RFunc[4][3] = 0.000499;
RFunc[4][4] = 0.000917;
RFunc[4][5] = 0.001849;
RFunc[4][6] = 0.003915;
RFunc[4][7] = 0.006900;
RFunc[4][8] = 0.009963;
RFunc[4][9] = 0.012261;
RFunc[4][10] = 0.013237;
RFunc[4][11] = 0.013583;
RFunc[4][12] = 0.014026;
RFunc[4][13] = 0.014395;
RFunc[4][14] = 0.014533;
RFunc[4][15] = 0.014626;
RFunc[4][16] = 0.014784;
RFunc[4][17] = 0.014956;
RFunc[4][18] = 0.015077;
RFunc[4][19] = 0.015088;
RFunc[4][20] = 0.014993;
RFunc[4][21] = 0.014853;
RFunc[4][22] = 0.014730;
RFunc[4][23] = 0.014682;
RFunc[4][24] = 0.014698;
RFunc[4][25] = 0.014731;
RFunc[4][26] = 0.014731;
RFunc[4][27] = 0.014655;
RFunc[4][28] = 0.014508;
RFunc[4][29] = 0.014323;
RFunc[4][30] = 0.014132;
RFunc[4][31] = 0.013963;
RFunc[4][32] = 0.013806;
RFunc[4][33] = 0.013634;
RFunc[4][34] = 0.013416;
RFunc[4][35] = 0.013131;
RFunc[4][36] = 0.012838;
RFunc[4][37] = 0.012645;
RFunc[4][38] = 0.012663;
RFunc[4][39] = 0.012985;
RFunc[4][40] = 0.013384;
RFunc[4][41] = 0.013364;
RFunc[4][42] = 0.012859;
RFunc[4][43] = 0.012317;
RFunc[4][44] = 0.011981;
RFunc[4][45] = 0.011725;
RFunc[4][46] = 0.011199;
RFunc[4][47] = 0.009622;
RFunc[4][48] = 0.006625;
RFunc[4][49] = 0.003506;
RFunc[4][50] = 0.001657;
RFunc[4][51] = 0.000902;
RFunc[4][52] = 0.000530;
RFunc[4][53] = 0.000271;
RFunc[4][54] = 0.000126;
RFunc[4][55] = 0.000073;
RFunc[4][56] = 0.000057;
RFunc[4][57] = 0.000044;
RFunc[4][58] = 0.000030;
RFunc[4][59] = 0.000000;
}
else
{
return -1;
}
return 0;
}
int grabPRTlevels(unsigned short *aux)
{
static int PRTDecomIndex;
int j, PRTIndex;
if (PRTDecomIndex == 0)
PRTDecomIndex = -1;
if (PRTDecomIndex == -1)
if (aux[6+5]<10)
PRTDecomIndex = 0;
if (PRTDecomIndex >= 0)
{
PRTRead[0][PRTDecomIndex] = aux[6+5];
PRTRead[1][PRTDecomIndex] = aux[6+6];
PRTRead[2][PRTDecomIndex] = aux[6+7];
if (PRTDecomIndex == 4)
{
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
PRTTotal[0][PRTIndex] = PRTRead[0][PRTIndex];
PRTTotal[1][PRTIndex] = PRTRead[1][PRTIndex];
PRTTotal[2][PRTIndex] = PRTRead[2][PRTIndex];
}
PRTDecomIndex = -2;
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
PRTAverage[0][PRTIndex] = (float) PRTTotal[0][PRTIndex];
PRTAverage[1][PRTIndex] = (float) PRTTotal[1][PRTIndex];
PRTAverage[2][PRTIndex] = (float) PRTTotal[2][PRTIndex];
PRT[PRTIndex] = PRTAverage[1][PRTIndex];
PRT[PRTIndex] = ( PRTAverage[0][PRTIndex] +
PRTAverage[1][PRTIndex] +
PRTAverage[2][PRTIndex]) / 3;
}
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
PRTTemperature[PRTIndex] = 0.0;
for (j=0;j<5;j+=1)
{
PRTTemperature[PRTIndex] += PRTCoefficient[PRTIndex][j] * pow(PRT[PRTIndex], (float) j);
}
}
InternalTargetTemperature = 0.0;
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
InternalTargetTemperature += PRTWeight[PRTIndex] * PRTTemperature[PRTIndex];
}
PRTDecomIndex = 0;
return 0;
}
else
PRTDecomIndex += 1;
}
return -1;
}
int grabPRTgains(unsigned short *aux, float gain[5], float inter[5])
{
static int PRTDecomIndex;
int PRTIndex, SSDIndex, ITDIndex, RFuncIndex;
int i, j;
float Wave;
if (PRTDecomIndex == 0)
PRTDecomIndex = -1;
if (PRTDecomIndex < 0)
if (aux[6+5]<10)
PRTDecomIndex = 0;
if (PRTDecomIndex >= 0)
{
PRTRead[0][PRTDecomIndex] = aux[6+5];
PRTRead[1][PRTDecomIndex] = aux[6+6];
PRTRead[2][PRTDecomIndex] = aux[6+7];
if (PRTDecomIndex == 4)
{
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
PRTTotal[0][PRTIndex] = PRTRead[0][PRTIndex];
PRTTotal[1][PRTIndex] = PRTRead[1][PRTIndex];
PRTTotal[2][PRTIndex] = PRTRead[2][PRTIndex];
}
PRTDecomIndex = 0;
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
PRTAverage[0][PRTIndex] = (float) PRTTotal[0][PRTIndex];
PRTAverage[1][PRTIndex] = (float) PRTTotal[1][PRTIndex];
PRTAverage[2][PRTIndex] = (float) PRTTotal[2][PRTIndex];
PRT[PRTIndex] = PRTAverage[1][PRTIndex];
}
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
PRTTemperature[PRTIndex] = 0.0;
for (j=0;j<5;j+=1)
{
PRTTemperature[PRTIndex] += PRTCoefficient[PRTIndex][j] * pow(PRT[PRTIndex], (float) j);
}
}
InternalTargetTemperature = 0.0;
for (PRTIndex=0;PRTIndex<5;PRTIndex+=1)
{
InternalTargetTemperature += PRTWeight[PRTIndex] * PRTTemperature[PRTIndex];
}
}
else
PRTDecomIndex += 1;
}
for (ITDIndex=0;ITDIndex<10;ITDIndex+=1)
{
ITDTotal[ITDIndex][0] = 0;
ITDTotal[ITDIndex][1] = 0;
ITDTotal[ITDIndex][2] = aux[16+ITDIndex*3+0];
ITDTotal[ITDIndex][3] = aux[16+ITDIndex*3+1];
ITDTotal[ITDIndex][4] = aux[16+ITDIndex*3+2];
}
ITDCount = 1;
for (SSDIndex=0;SSDIndex<10;SSDIndex+=1)
{
SSDTotal[SSDIndex][0] = aux[46+SSDIndex*5+0];
SSDTotal[SSDIndex][1] = aux[46+SSDIndex*5+1];
SSDTotal[SSDIndex][2] = aux[46+SSDIndex*5+2];
SSDTotal[SSDIndex][3] = aux[46+SSDIndex*5+3];
SSDTotal[SSDIndex][4] = aux[46+SSDIndex*5+4];
}
SSDCount = 1;
for (RFuncIndex=2;RFuncIndex<5;RFuncIndex+=1)
{
RFuncRad[RFuncIndex] = 0.0;
Wave = RFuncWave[RFuncIndex];
for (i=0;i<RFuncCount[RFuncIndex];i+=1)
{
RFuncRad[RFuncIndex] += Planckf(Wave,
InternalTargetTemperature)*RFunc[RFuncIndex][i]*RFuncStep[RFuncIndex];
Wave += RFuncStep[RFuncIndex];
}
}
ITD[0] = 0.0;
ITD[1] = 0.0;
ITD[2] = 0.0;
ITD[3] = 0.0;
ITD[4] = 0.0;
for (ITDIndex=0;ITDIndex<10;ITDIndex+=1)
{
ITDAverage[ITDIndex][0] = 0.0;
ITDAverage[ITDIndex][1] = 0.0;
ITDAverage[ITDIndex][2] = (float) ITDTotal[ITDIndex][2] / (float) ITDCount;
ITDAverage[ITDIndex][3] = (float) ITDTotal[ITDIndex][3] / (float) ITDCount;
ITDAverage[ITDIndex][4] = (float) ITDTotal[ITDIndex][4] / (float) ITDCount;
ITD[0] += ITDAverage[ITDIndex][0];
ITD[1] += ITDAverage[ITDIndex][1];
ITD[2] += ITDAverage[ITDIndex][2];
ITD[3] += ITDAverage[ITDIndex][3];
ITD[4] += ITDAverage[ITDIndex][4];
}
ITD[0] /= 10.0;
ITD[1] /= 10.0;
ITD[2] /= 10.0;
ITD[3] /= 10.0;
ITD[4] /= 10.0;
SSD[0] = 0.;
SSD[1] = 0.;
SSD[2] = 0.;
SSD[3] = 0.;
SSD[4] = 0.;
for (SSDIndex=0;SSDIndex<10;SSDIndex+=1)
{
SSDAverage[SSDIndex][0] = (float) SSDTotal[SSDIndex][0] / (float) SSDCount;
SSDAverage[SSDIndex][1] = (float) SSDTotal[SSDIndex][1] / (float) SSDCount;
SSDAverage[SSDIndex][2] = (float) SSDTotal[SSDIndex][2] / (float) SSDCount;
SSDAverage[SSDIndex][3] = (float) SSDTotal[SSDIndex][3] / (float) SSDCount;
SSDAverage[SSDIndex][4] = (float) SSDTotal[SSDIndex][4] / (float) SSDCount;
SSD[0] += SSDAverage[SSDIndex][0];
SSD[1] += SSDAverage[SSDIndex][1];
SSD[2] += SSDAverage[SSDIndex][2];
SSD[3] += SSDAverage[SSDIndex][3];
SSD[4] += SSDAverage[SSDIndex][4];
}
SSD[0] /= 10.0;
SSD[1] /= 10.0;
SSD[2] /= 10.0;
SSD[3] /= 10.0;
SSD[4] /= 10.0;
for (i=0;i<2;i+=1)
{
gain[i] = AGIGain[i];
inter[i] = AGIInter[i];
}
for (i=2;i<5;i+=1)
{
if ((SSD[i]-ITD[i]) != 0)
{
gain[i] = (SpaceRad[i] - RFuncRad[i])/(SSD[i]-ITD[i]);
inter[i] = SpaceRad[i] - gain[i] * SSD[i];
}
else
{
gain[i] = -0.1;
inter[i] = 0.5;
}
}
return 0;
}
/*****************************************************************************
subroutine : swapint
input : *tmpint -> pointer to the integer to be swapped
output : *tmpint
description: swaps a 4-byte word to convert from a little endian to a big
endian format
*****************************************************************************/
void swapint(int *tmpint) {
unsigned short *ptr;
ptr=(unsigned short *) tmpint;
*ptr=(*ptr<<8)|((*ptr&0xff00)>>8);
ptr++;
*ptr=(*ptr<<8)|((*ptr&0xff00)>>8);
*tmpint=(*tmpint<<16)|((*tmpint&0xffff0000)>>16);
}