PRO eis_rebuild_study_db


;replace call to astrolib
defsysv,'!DEBUG', 0
defsysv,'!TEXTUNIT', 0
defsysv,'!PRIV', 2
defsysv,'!TEXTOUT', EXIST = EXIST

status = eis_open_db(/STUDY)
items  = db_info('entries')
print,STRJOIN(['number of items = ',STRCOMPRESS(items[0])],/SINGLE)
st_array = REPLICATE({eis_study},items[0]+1)
;sc_array = REPLICATE(0,items[0]+1)

FOR i = 1, items[0]    DO BEGIN
;FOR i = 1, 9    DO BEGIN

    index   = STRCOMPRESS(i,/REMOVE_ALL)
    percent = STRCOMPRESS( (i/FLOAT(items[0]))*100. ,/REMOVE_ALL)
    print,STRJOIN(['Item: ',index,'  ',percent,'%  done.'],/SINGLE)
    st_array[i] = db_read_study_entry(i)


    FOR j = 0, st_array[i].nRasters - 1 DO BEGIN

        ra_id = st_array[i].studyRasters[j].ra_id
        ra    = db_read_raster_entry(ra_id)
        st_array[i].studyRasters[j].ra_duration = ra.duration
        st_array[i].studyRasters[j].ra_volume   = ra.volume

    ENDFOR

    st_array[i].duration = eis_study_duration(st_array[i])
    st_array[i].volume = eis_study_volume(  st_array[i])

ENDFOR

print,"time to re-build timeline DB?"
print,"Don't forget to modify the eis_study and eis_study2 dbd files'

stop
;
; OK, got all the time_component entries
;
CD    , '$HOME/planning_db/technical_db'
SPAWN , "rm eis_study_db.dbf  eis_study_db.dbh  eis_study_db.dbx"
SPAWN , "rm eis_study2_db.dbf eis_study2_db.dbh eis_study2_db.dbx"
dbcreate , 'eis_study_db'  , 1 , 1 , 500000 , /EXTERNAL
dbcreate , 'eis_study2_db' , 1 , 1 , 500000 , /EXTERNAL


FOR i = 1, items[0]   DO BEGIN

    index   = STRCOMPRESS(i,/REMOVE_ALL)
    percent = STRCOMPRESS( (i/FLOAT(items[0]))*100. ,/REMOVE_ALL)
    print,STRJOIN(['Item: ',index,'  ',percent,'%  done.'],/SINGLE)
    db_save_study_entry_create , st_array[i]

ENDFOR
stop

END
