00001
00002
00003
00004 #include <jsoc_main.h>
00005 #include <cmdparams.h>
00006 #include <drms.h>
00007 #include <drms_names.h>
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 #include <HMIparam.h>
00012 #include "drms_defs.h"
00013 #include "drms_fitsrw.h"
00014 #include "fstats.h"
00015 #include <ctype.h>
00016 #include <sys/types.h>
00017 #include <sys/time.h>
00018 #include <sys/stat.h>
00019 #include <unistd.h>
00020 #include <printk.h>
00021 #include "/home/jsoc/cvs/Development/JSOC/proj/libs/astro/astro.h"
00022 #include <fresize.h>
00023 #include <gapfill.h>
00024 #include "/home/jsoc/cvs/Development/JSOC/proj/lev0/apps/imgdecode.h"
00025 #include "/home/jsoc/cvs/Development/JSOC/proj/lev0/apps/lev0lev1.h"
00026 #include "/home/jsoc/cvs/Development/JSOC/proj/lev0/apps/limb_fit.h"
00027
00028 char *module_name = "ingest_Aimee";
00029
00030
00031 ModuleArgs_t module_args[] =
00032 {
00033 {ARG_STRING,"fits", "","FITS file to be ingested into the series"},
00034 {ARG_STRING,"out","","Output series"},
00035 {ARG_STRING,"inRec", "","input query"},
00036 {ARG_STRING, "dpath","/home/jsoc/cvs/Development/JSOC","path of development code"},
00037 {ARG_END}
00038 };
00039
00040 #include "/home/jsoc/cvs/Development/JSOC/proj/lev0/apps/limb_fit_function.c"
00041
00042
00043
00044 int heightformation(int FID, double OBSVR, float *CDELT1, float *RSUN, float *CRPIX1, float *CRPIX2, float CROTA2)
00045 {
00046 int wl=0;
00047 int status=0;
00048 float correction=0.0,correction2=0.0;
00049
00050 wl = (FID/10)%20;
00051
00052 if( (wl >= 0) && (wl < 20) )
00053 {
00054 correction = 0.445*exp(-(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.25)*(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.25)/7.1);
00055 correction2 = 0.39*(-2.0*(wl-10.- (float)OBSVR/(0.690/6173.*3.e8/20.)-0.35)/6.15)*exp(-(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.35)*(wl-10.-(float)OBSVR/(0.690/6173.*3.e8/20.)-0.35)/6.15);
00056 printf("A CDELT1= %f CROTA2= %f OBS_VR= %f RSUN= %f correction= %f \n",*CDELT1,CROTA2,OBSVR,*RSUN,correction);
00057 *CDELT1 = *CDELT1*(*RSUN)/((*RSUN)-correction);
00058 printf("B CDELT1= %f CROTA2= %f OBS_VR= %f \n",*CDELT1,CROTA2,OBSVR);
00059 *RSUN = *RSUN-correction;
00060 *CRPIX1 = *CRPIX1-cos(M_PI-CROTA2*M_PI/180.)*correction2;
00061 *CRPIX2 = *CRPIX2-sin(M_PI-CROTA2*M_PI/180.)*correction2;
00062 }
00063 else status=1;
00064
00065 return status;
00066
00067 }
00068
00069 int DoIt(void) {
00070
00071 int status = 0;
00072 int nRecs;
00073 DRMS_Type_t type = DRMS_TYPE_FLOAT;
00074 float RSUN_LF=0.0, X0_LF=0.0, Y0_LF=0.0;
00075 double tempRSUN=0.0, tempX0=0.0, tempY0=0.0;
00076 int FID;
00077 double OBSVR;
00078 float CROTA2,CDELT1;
00079
00080 const char *infile=cmdparams_get_str(&cmdparams, "fits", NULL);
00081 const char *dsout =cmdparams_get_str(&cmdparams, "out", NULL);
00082 const char *inRecQuery=cmdparams_get_str(&cmdparams, "inRec", NULL);
00083 const char *dpath = cmdparams_get_str(&cmdparams,"dpath",NULL);
00084
00085
00086 drms_series_exists(drms_env, dsout, &status);
00087 if(status != DRMS_SUCCESS)
00088 {
00089 printf("Output series %s doesn't exist\n",dsout);
00090 exit(EXIT_FAILURE);
00091 }
00092 if(status == DRMS_SUCCESS)
00093 {
00094 printf("Output series %s exists.\n",dsout);
00095 }
00096
00097
00098 DRMS_Array_t *image;
00099 image=drms_fitsrw_read(drms_env,infile,0,NULL,&status);
00100
00101
00102
00103 DRMS_RecordSet_t *data = drms_open_records(drms_env,inRecQuery,&status);
00104 if (status == DRMS_SUCCESS && data != NULL && data->n > 0)
00105 {
00106 nRecs = data->n;
00107 printf("Number of level 1 records satisfying the request= %d \n",nRecs);
00108 }
00109 else
00110 {
00111 printf("Input level 1 series %s doesn't exist\n",inRecQuery);
00112 exit(EXIT_FAILURE);
00113 }
00114
00115
00116 DRMS_RecordSet_t *dataout = NULL;
00117 DRMS_Record_t *recout = NULL;
00118 DRMS_Segment_t *segout = NULL;
00119 dataout = drms_create_records(drms_env,1,dsout,DRMS_PERMANENT,&status);
00120 if (status != DRMS_SUCCESS)
00121 {
00122 printf("Could not create a record for the lookup tables\n");
00123 exit(EXIT_FAILURE);
00124 }
00125 recout = dataout->records[0];
00126
00127
00128 DRMS_Segment_t *segin1 = NULL;
00129 DRMS_Array_t *arrin1 = NULL;
00130 segin1 = drms_segment_lookupnum(data->records[0],1);
00131 arrin1 = drms_segment_read(segin1,type,&status);
00132
00133
00134 FID = drms_getkey_int(data->records[0],"FID",&status);
00135 CROTA2 = drms_getkey_float(data->records[0],"CROTA2",&status);
00136 CDELT1 = drms_getkey_float(data->records[0],"CDELT1",&status);
00137 OBSVR = drms_getkey_double(data->records[0],"OBS_VR",&status);
00138 printf("CDELT1= %f CROTA2= %f OBS_VR= %f \n",CDELT1,CROTA2,OBSVR);
00139 status = limb_fit(data->records[0],image->data,&tempRSUN,&tempX0,&tempY0,4096,4096,0);
00140 RSUN_LF=(double)tempRSUN;
00141 X0_LF=(double)tempX0;
00142 Y0_LF=(double)tempY0;
00143 printf("X0_LF= %f Y0_LF= %f RSUN_LF= %f FID= %d \n",X0_LF,Y0_LF,RSUN_LF,FID);
00144
00145 status = heightformation(FID,OBSVR,&CDELT1,&RSUN_LF,&X0_LF,&Y0_LF,-CROTA2);
00146 printf("CDELT1= %f \n",CDELT1);
00147
00148 drms_copykeys(dataout->records[0],data->records[0],0,kDRMS_KeyClass_Explicit);
00149 status = drms_setkey_float(dataout->records[0],"CRPIX1",X0_LF+1);
00150 status = drms_setkey_float(dataout->records[0],"CRPIX2",Y0_LF+1);
00151 status = drms_setkey_float(dataout->records[0],"R_SUN",RSUN_LF);
00152 status = drms_setkey_float(dataout->records[0],"CDELT1",CDELT1);
00153
00154
00155 printf("Writing a record on the DRMS\n");
00156 segout = drms_segment_lookupnum(recout, 0);
00157 image->bzero = segout->bzero; image->bscale = segout->bscale; image->israw = 0;
00158 drms_segment_write(segout,image,0);
00159
00160 printf("Writing a record on the DRMS\n");
00161 segout = drms_segment_lookupnum(recout, 1);
00162 image->bzero = segout->bzero; image->bscale = segout->bscale; image->israw = 0;
00163 drms_segment_write(segout,arrin1,0);
00164
00165
00166 drms_close_records(dataout, DRMS_INSERT_RECORD);
00167
00168 return(0);
00169
00170 }