00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <time.h>
00009 #include <math.h>
00010 #include <sys/time.h>
00011 #include "jsoc_main.h"
00012 #include "astro.h"
00013 #include "drms_dsdsapi.h"
00014
00015 #define PI (M_PI)
00016 #define RADSINDEG (PI/180)
00017
00018
00019
00020
00021 #define DIE(msg) {fflush(stdout); fprintf(stderr,"%s, status=%d\n", msg, status); return(status);}
00022
00023
00024 #define kRecSetIn "in"
00025 #define kSeriesOut "out"
00026 #define kSegIn "segin"
00027 #define kSegOut "segout"
00028 #define kNOTSPECIFIED "not specified"
00029
00030 #define RADSINDEG (PI/180)
00031 #define RAD2ARCSEC (648000. / M_PI)
00032
00033 char *module_name = "fdlos2radial";
00034
00035 ModuleArgs_t module_args[] =
00036 {
00037 {ARG_STRING, kRecSetIn, "", "Input data records."},
00038 {ARG_STRING, kSeriesOut, "", "Output data series."},
00039 {ARG_STRING, kSegIn, kNOTSPECIFIED, ""},
00040 {ARG_STRING, kSegOut, kNOTSPECIFIED, ""},
00041 {ARG_INT, "XSIZE", "4096", "", ""},
00042 {ARG_INT, "YSIZE", "4096", "", ""},
00043 {ARG_END}
00044 };
00045
00046 int DoIt(void)
00047 {
00048
00049 int status = DRMS_SUCCESS;
00050 int ds, nds;
00051 int xsize, ysize;
00052 char *inRecQuery, *outRecQuery;
00053 char tstr[64];
00054 int y,m,d;
00055 DRMS_RecordSet_t *inRD, *outRD;
00056
00057 inRecQuery = (char *)params_get_str(&cmdparams, kRecSetIn);
00058 outRecQuery = (char *)params_get_str(&cmdparams, kSeriesOut);
00059 xsize = cmdparams_get_int(&cmdparams, "XSIZE", &status);
00060 ysize = cmdparams_get_int(&cmdparams, "YSIZE", &status);
00061 inRD = drms_open_records(drms_env, inRecQuery, &status);
00062 if (status || inRD->n == 0)
00063 DIE("No input data found");
00064 nds = inRD->n;
00065
00066 outRD = drms_create_records(drms_env, nds, outRecQuery, DRMS_PERMANENT, &status);
00067 if (status)
00068 DIE("Output recordset not created");
00069
00070 for (ds = 0; ds < nds; ds++)
00071 {
00072 int xDim = xsize, yDim = ysize;
00073 double xDist = 0.0;
00074 double yDist = 0.0;
00075 double xDist2 = 0.0;
00076 double yDist2 = 0.0;
00077 double xDist2PlusyDist2 = 0.0;
00078 double dToDiskCenter = 0.0;
00079 int yOff = 0;
00080 int iData = 0;
00081 float radialCorrected = 0;
00082
00083 double sinrho = 0;
00084 double cosrho = 0;
00085 float dSun, rSun_ref, cdelt, asd;
00086 float rSun, xCenter, yCenter;
00087 float *bRadial;
00088 float *bLos;
00089 DRMS_Segment_t *inSeg = NULL;
00090 DRMS_Array_t *inArray;
00091 DRMS_Record_t *inRec;
00092
00093 inRec = inRD->records[ds];
00094
00095 dSun = drms_getkey_double(inRec, "DSUN_OBS", &status);
00096 rSun_ref = drms_getkey_double(inRec, "RSUN_REF", &status);
00097 if (status) rSun_ref = 6.96e8;
00098 cdelt = drms_getkey_float(inRec, "CDELT1", &status);
00099 asd = asin(rSun_ref/dSun);
00100 rSun = asin(rSun_ref / dSun) * RAD2ARCSEC / cdelt;
00101 xCenter = drms_getkey_float(inRec, "CRPIX1", &status) - 1.0;
00102
00103 yCenter = drms_getkey_float(inRec, "CRPIX2", &status) - 1.0;
00104
00105 bRadial = (float *) malloc(xDim * yDim * sizeof(float));
00106
00107 inSeg = drms_segment_lookupnum(inRec, 0);
00108 inArray = drms_segment_read(inSeg, DRMS_TYPE_FLOAT, &status);
00109 if (status)
00110 {
00111 printf("Bad data, skip! \n");
00112 continue;
00113 }
00114 bLos = (float *)inArray->data;
00115
00116 int jy = 0;
00117 for (jy = 0; jy < yDim; jy++)
00118 {
00119 int ix = 0;
00120 yDist = (double)jy - yCenter;
00121 yDist2 = yDist * yDist;
00122 yOff = jy * xDim;
00123
00124 for (ix = 0; ix < xDim; ix++)
00125 {
00126 iData = yOff + ix;
00127 xDist = (double)ix - xCenter;
00128 xDist2 = xDist * xDist;
00129 xDist2PlusyDist2 = xDist2 + yDist2;
00130 dToDiskCenter = sqrt(xDist2PlusyDist2);
00131 if (dToDiskCenter >= rSun)
00132 {
00133 bRadial[iData] = DRMS_MISSING_FLOAT;
00134 continue;
00135 }
00136
00137 if (isnan(bLos[iData]))
00138 {
00139 bRadial[iData] = DRMS_MISSING_FLOAT;
00140 continue;
00141 }
00142
00143 sinrho = dToDiskCenter / rSun;
00144 cosrho = sqrt(1 - sinrho * sinrho);
00145 if (cosrho > 0)
00146 {
00147 bRadial[iData] = (float)bLos[iData] / cosrho;
00148
00149 }
00150 else
00151 {
00152 bRadial[iData] = DRMS_MISSING_FLOAT;
00153 }
00154 }
00155 }
00156
00157 DRMS_Record_t *outRec;
00158 DRMS_Segment_t *outSeg;
00159 DRMS_Array_t *outArray;
00160 int outDims[2] = {xDim, yDim};
00161 outRec = outRD->records[ds];
00162
00163 drms_copykey(outRec, inRec, "T_REC");
00164 sprint_ut(tstr, CURRENT_SYSTEM_TIME);
00165 sscanf(tstr, "%d.%d.%d", &y, &m, &d);
00166 sprintf(tstr, "%04d-%02d-%02d", y, m, d);
00167 drms_setkey_string(outRec, "DATE", tstr);
00168
00169
00170 drms_copykey(outRec, inRec, "DATE__OBS");
00171 drms_copykey(outRec, inRec, "INSTRUME");
00172 drms_copykey(outRec, inRec, "CAMERA");
00173 drms_copykey(outRec, inRec, "HISTORY");
00174 drms_copykey(outRec, inRec, "COMMENT");
00175 drms_copykey(outRec, inRec, "BLD_VERS");
00176
00177 drms_copykey(outRec, inRec, "CRPIX1");
00178 drms_copykey(outRec, inRec, "CRPIX2");
00179 drms_copykey(outRec, inRec, "CRVAL1");
00180 drms_copykey(outRec, inRec, "CRVAL2");
00181 drms_copykey(outRec, inRec, "CDELT1");
00182 drms_copykey(outRec, inRec, "CDELT2");
00183 drms_copykey(outRec, inRec, "CADENCE");
00184
00185 drms_copykey(outRec, inRec, "CROTA2");
00186 drms_copykey(outRec, inRec, "CRDER1");
00187 drms_copykey(outRec, inRec, "CRDER2");
00188 drms_copykey(outRec, inRec, "CSYSER1");
00189 drms_copykey(outRec, inRec, "CSYSER2");
00190
00191 drms_copykey(outRec, inRec, "RSUN_OBS");
00192 drms_copykey(outRec, inRec, "DSUN_OBS");
00193 drms_copykey(outRec, inRec, "CRLN_OBS");
00194 drms_copykey(outRec, inRec, "CRLT_OBS");
00195 drms_copykey(outRec, inRec, "HGLN_OBS");
00196 drms_copykey(outRec, inRec, "CAR_ROT");
00197 drms_copykey(outRec, inRec, "OBS_VR");
00198 drms_copykey(outRec, inRec, "OBS_VW");
00199 drms_copykey(outRec, inRec, "OBS_VN");
00200
00201 drms_copykey(outRec, inRec, "T_OBS");
00202 drms_copykey(outRec, inRec, "QUALITY");
00203
00204 drms_copykey(outRec, inRec, "TOTVALS");
00205 drms_copykey(outRec, inRec, "DATAVALS");
00206 drms_copykey(outRec, inRec, "MISSVALS");
00207 drms_copykey(outRec, inRec, "CALVER64");
00208
00209
00210 outSeg = drms_segment_lookupnum(outRec, 0);
00211 outArray = drms_array_create(DRMS_TYPE_FLOAT, 2, outDims, bRadial, &status);
00212 status = drms_segment_write(outSeg, outArray, 0);
00213 if (status)
00214 {
00215 printf("problem writing file, skip! \n");
00216 continue;
00217 }
00218 drms_free_array(outArray);
00219 drms_free_array(inArray);
00220 }
00221
00222 drms_close_records(inRD, DRMS_FREE_RECORD);
00223 drms_close_records(outRD, DRMS_INSERT_RECORD);
00224 return 0;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240