00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 void
00013 REAL2COM (IMAGE * in1,
00014 IMAGE * in2,
00015 short option,
00016
00017
00018 IMAGE ** out
00019
00020 )
00021 {
00022 register short i, j, k, n;
00023 char msg[SLEN];
00024
00025 if (TIMES)
00026 TIMING (T_REAL2COM);
00027 if (NAMES)
00028 {
00029 MESSAGE ('I', "");
00030 MESSAGE ('I', "REAL2COM");
00031 MESSAGE ('I', "");
00032 sprintf (msg, " First input image: %s", in1->text);
00033 MESSAGE ('I', msg);
00034 sprintf (msg, " Second input image: %s", in2->text);
00035 MESSAGE ('I', msg);
00036 if (option == REIMAG)
00037 {
00038 MESSAGE ('I', " Real and imaginary images are given");
00039 }
00040 else if (option == MAGPHA)
00041 {
00042 MESSAGE ('I', " Magnitude and phase images are given");
00043 }
00044 MESSAGE ('I', " ...............");
00045 }
00046
00047
00048 if (!CHECKIMG (in1))
00049 {
00050 MESSAGE ('E', " Can't identify first image.");
00051 goto the_end;
00052 }
00053 else if (!CHECKIMG (in2))
00054 {
00055 MESSAGE ('E', " Can't identify second image.");
00056 goto the_end;
00057 }
00058 else if (in1->nbnd != in2->nbnd)
00059 {
00060 MESSAGE ('E', " Number of bands must be identical in both images.");
00061 goto the_end;
00062 }
00063 else if (in1->nlin != in2->nlin)
00064 {
00065 MESSAGE ('E',
00066 " Number of lines/band must be identical in both images.");
00067 goto the_end;
00068 }
00069 else if (in1->npix != in2->npix)
00070 {
00071 MESSAGE ('E',
00072 " Number of pixels/line must be identical in both images.");
00073 goto the_end;
00074 }
00075 else if (option != REIMAG && option != MAGPHA)
00076 {
00077 MESSAGE ('E', " Option must be either REIMAG or MAGPHA.");
00078 goto the_end;
00079 }
00080
00081
00082 if (!CHECKIMG (*out))
00083 GETMEM (in1->nbnd, in1->nlin, 2 * in1->npix, out);
00084 if (!*out)
00085 goto the_end;
00086
00087 if (option == REIMAG)
00088 {
00089
00090 for (i = 0; i < in1->nbnd; i++)
00091 {
00092 for (j = 0; j < in1->nlin; j++)
00093 {
00094 for (k = 0, n = 0; k < in1->npix; k += 1, n += 2)
00095 {
00096 (*out)->data[i][j][n] = in1->data[i][j][k];
00097 (*out)->data[i][j][n + 1] = in2->data[i][j][k];
00098 }
00099 }
00100 }
00101 }
00102 else
00103 {
00104
00105 for (i = 0; i < in1->nbnd; i++)
00106 {
00107 for (j = 0; j < in1->nlin; j++)
00108 {
00109 for (k = 0, n = 0; k < in1->npix; k += 1, n += 2)
00110 {
00111 (*out)->data[i][j][n] =
00112 (PIXEL) (double) in1->data[i][j][k] *
00113 cos ((double) in2->data[i][j][k]);
00114 (*out)->data[i][j][n + 1] =
00115 (PIXEL) (double) in1->data[i][j][k] *
00116 sin ((double) in2->data[i][j][k]);
00117 }
00118 }
00119 }
00120 }
00121
00122 the_end:
00123 if (TIMES)
00124 TIMING (T_EXIT);
00125 }