; ; ; Procedure to allow df.pro to add events to the database, very specific to ; df.pro. See cme_db_add.pro for more general approach. ; data must be an array of structures as defined by df.pro ; fit is another structure containing the computed values returned by ; df_fit.pro. See df_fit.pro for the definition of the structure. ; PRO df_dbadd, data, fit numtags=N_TAGS(fit) ;determine whether we have the 1st order structure ;or the 2nd order structure. ;===Open the database ; db_id=NCDF_OPEN('/bail/d/tdarnell/database/cme_meas_db.nc',/WRITE) ; ;===Get the variable id's, what a pain. ; event_id= NCDF_VARID(db_id,'EVENT') num_meas_id= NCDF_VARID(db_id,'NUM_MEAS') quality_id= NCDF_VARID(db_id,'QUALITY') utc_id= NCDF_VARID(db_id,'UTC') radius_id= NCDF_VARID(db_id,'RADIUS') error_id= NCDF_VARID(db_id,'ERROR') theta_id= NCDF_VARID(db_id,'THETA') width_id= NCDF_VARID(db_id,'WIDTH') mass_id= NCDF_VARID(db_id,'MASS') feature_id= NCDF_VARID(db_id,'FEATURE') inst_id= NCDF_VARID(db_id,'INSTRUMENT') start_id= NCDF_VARID(db_id,'START_TIME') height_id= NCDF_VARID(db_id,'START_HEIGHT') accel_id= NCDF_VARID(db_id,'ACCEL') finalv_id= NCDF_VARID(db_id,'FINAL_V') ; ;===Get dimensions ; NCDF_DIMINQ,db_id,NCDF_DIMID(db_id,'index'),ind_str,index NCDF_DIMINQ,db_id,NCDF_DIMID(db_id,'measurements'),meas_str,measurements NCDF_DIMINQ,db_id,NCDF_DIMID(db_id,'utc_str_len'),utc_str,utc_str_len NCDF_DIMINQ,db_id,NCDF_DIMID(db_id,'feat_str_len'),feat_str,feat_str_len NCDF_DIMINQ,db_id,NCDF_DIMID(db_id,'inst_str_len'),inst_str,inst_str_len NCDF_DIMINQ,db_id,NCDF_DIMID(db_id,'event_str_len'),event_str,event_str_len NCDF_DIMINQ,db_id,NCDF_DIMID(db_id,'num_features'),num_str,num_features ; ;===Make UTC format string ; time_arr=data[WHERE(data.time_str NE '')].time_str date_arr=data[WHERE(data.date_str NE '')].date_str tmp_arr=date_arr+'T'+time_arr+'.000Z' utc_arr=anytim2utc(tmp_arr,/mdy) utc_arr=utc2str(utc_arr) ; ;===Construct event identifier yydxxx and check to see if it exists ; utc_str=utc_arr(0) print,utc_str utc=str2utc(utc_str) doy=utc2doy(utc) doy=STRING(doy,FORMAT='(I3.3)') year=anytim2cal(utc,/date,form=7) year=STRMID(year,0,2) ident=year+'d'+doy NCDF_VARGET,db_id,event_id,event_arr,OFFSET=[0,0],COUNT=[8,index] event_arr=STRING(event_arr) asterisk=WHERE(event_arr EQ '*') IF (asterisk NE -1) THEN index=asterisk(0) + 1 ;Place index marker at spot ;of previous deletion if it ;exists. print,index test=db_chk(ident) IF (test(0) EQ -1) THEN BEGIN NCDF_VARPUT,db_id,event_id,ident,OFFSET=[0,index] ENDIF ELSE BEGIN ;NCDF_VARGET,db_id,event_id,event_arr,OFFSET=[0,0],COUNT=[8,index] ;event_arr=STRING(event_arr) sz=SIZE(test) ind=LINDGEN(sz(1)) letters=['a','b','c','d','e','f','g','h'] prompt_arr=[ $ 'There are events on this day in the database.', $ 'There are currently'+STRCOMPRESS(STRING(sz(1)))+' events on this day.', $ event_arr(test), $ 'Do you wish to add this measurement to this day?', $ 'Answering ''Yes'' will append an '''+letters[sz(1)]+''' to the identifier',$ 'Answering ''No'' will overwrite'] ans=DIALOG_MESSAGE(prompt_arr,/QUESTION,/CANCEL) IF (ans EQ 'Cancel') THEN RETURN IF (ans EQ 'Yes') THEN BEGIN event_arr(test)=STRMID(event_arr(test),0,6) new_ident=event_arr(test)+letters(ind) event_arr(test)=new_ident event_arr=BYTE(event_arr) NCDF_VARPUT,db_id,event_id,event_arr,OFFSET=[0,0] ident=ident+letters[sz(1)] NCDF_VARPUT,db_id,event_id,ident,OFFSET=[0,index] ENDIF IF (ans EQ 'No') THEN BEGIN index=test(0) ENDIF ENDELSE ; ;===Fill measurement array with measurements from data structure ; num_meas=SIZE(WHERE(data.radius GT 0.0)) num_meas=num_meas(1) NCDF_VARPUT,db_id,num_meas_id,num_meas,OFFSET=index ;---Fill Instrument array inst_arr=data[WHERE(data.dataset NE '')].dataset NCDF_VARPUT,db_id,inst_id,inst_arr,OFFSET=[0,0,index] ;---Fill Time Strings NCDF_VARPUT,db_id,utc_id,utc_arr,OFFSET=[0,0,index] ;---Fill Radius array rad_arr=data[WHERE(data.radius GT 0.0)].radius NCDF_VARPUT,db_id,radius_id,rad_arr,OFFSET=[0,index] ;---Fill Theta array theta_arr=data[WHERE(data.theta GT 0.0)].theta NCDF_VARPUT,db_id,theta_id,theta_arr,OFFSET=[0,index] ;---Fill error array error_arr=data[WHERE(data.error GT 0.0)].error NCDF_VARPUT,db_id,error_id,error_arr,OFFSET=[0,index] ;---Fill feature array feat_arr=data[WHERE(data.feature NE '')].feature NCDF_VARPUT,db_id,feature_id,feat_arr,OFFSET=[0,0,index] ;=== Now fill the computed values from the fit. IF (numtags EQ 6) THEN BEGIN ;1st order strucure ;start times NCDF_VARPUT,db_id,start_id,fit.loop_start,OFFSET=[0,0,index] NCDF_VARPUT,db_id,start_id,fit.cav_start,OFFSET=[0,1,index] NCDF_VARPUT,db_id,start_id,fit.core_start,OFFSET=[0,2,index] ;velocities NCDF_VARPUT,db_id,finalv_id,fit.loop_v,OFFSET=[0,index] NCDF_VARPUT,db_id,finalv_id,fit.cav_v,OFFSET=[1,index] NCDF_VARPUT,db_id,finalv_id,fit.core_v,OFFSET=[2,index] ENDIF IF (numtags EQ 12) THEN BEGIN ;2nd order structure ;start times NCDF_VARPUT,db_id,start_id,fit.loop_start,OFFSET=[0,0,index] NCDF_VARPUT,db_id,start_id,fit.cav_start,OFFSET=[0,1,index] NCDF_VARPUT,db_id,start_id,fit.core_start,OFFSET=[0,2,index] ;velocities NCDF_VARPUT,db_id,finalv_id,fit.loop_v,OFFSET=[0,index] NCDF_VARPUT,db_id,finalv_id,fit.cav_v,OFFSET=[1,index] NCDF_VARPUT,db_id,finalv_id,fit.core_v,OFFSET=[2,index] ;start heights NCDF_VARPUT,db_id,height_id,fit.loop_h,OFFSET=[0,index] NCDF_VARPUT,db_id,height_id,fit.cav_h,OFFSET=[1,index] NCDF_VARPUT,db_id,height_id,fit.core_h,OFFSET=[2,index] ;accelerations NCDF_VARPUT,db_id,accel_id,fit.loop_accel,OFFSET=[0,index] NCDF_VARPUT,db_id,accel_id,fit.cav_accel,OFFSET=[1,index] NCDF_VARPUT,db_id,accel_id,fit.core_accel,OFFSET=[2,index] ENDIF ; ;===Close the database ; NCDF_CLOSE,db_id END