#include "set_mark.h" #include "varext.h" fpos_t actpos=0; short int GetHyd4(hyd_header *hyd) { short int test, len, len_prev, i, maxw_a, maxw_b, max_a, max_b; pix_head_4 pixh; quarter quart_h; list_m_h *ptr; float pi=3.1415F; double volu, absv; fpos_t curr_pos; float HBL, HBR, HFL, HFR, HF, HB, H; float mid_a, mid_b; read_it: if (fgetpos(hyd_fil,&curr_pos) != 0) perror("gethyd01:"); if (fread(&len,2,1,hyd_fil)!=1){ if (feof) return (END_OF_FILE); else perror ("gethyd02:"); } if (len==(-1*size_mainh)){ main_h.indic=len; if (fread(&main_h.len_prev,size_mainh-2,1,hyd_fil)!=1){ fprintf(stderr," could not read main header ! \n"); perror("gethyd03:"); exit(0); } main_tim(); goto read_it; } else if (len==(-1*SIZE_QUART)){ quart_h.indic=len; if (fread(&quart_h.len_prev,SIZE_QUART-2,1,hyd_fil)!=1) perror("gethyd04:"); goto read_it; } if (len<0){ fprintf(stderr,"gethyd 05: len <0 ??? \n"); exit(0); } pixh.len=len; if (fread(&pixh.len_prev,size_pixh-2,1,hyd_fil)!=1) perror("gethyd05:"); if (lmh_start==NULL){ fprintf(stderr,"gethyd 01: no main header in file ?!? \n"); exit(0); } else if (lmh_start->next==NULL){ ptr=lmh_start; if (pixh.timline){ fprintf(stderr,"pixh.tim=%lu, ptr->line=%lu \n",pixh.tim,ptr->line); fprintf(stderr,"gethyd 02: no corresponding main header ? \n"); exit(0); } } else{ for (ptr=lmh_start;ptr->next!=NULL;ptr=ptr->next) if ((pixh.tim>=ptr->line)&&(pixh.tim<=(ptr->next)->line)) break; if(ptr->next!=NULL){ if((pixh.timline)||(pixh.tim>(ptr->next)->line)){ fprintf(stderr,"gethyd 03: no corresponding main header ? \n"); exit(0); } } else{ if(pixh.timline){ fprintf(stderr,"gethyd 04: no corresponding main header ? \n"); exit(0); } } } memcpy(&oeu,&ptr->m_h.line_frequ,OEU_PAR_SIZE); hyd->lin_day=pixh.tim; hyd->mh=&ptr->m_h; hyd->lines_a=pixh.up_lins; hyd->lines_b=hyd->lines_a+pixh.lo_up_lins; hyd->eq_diameter = (float)(pixh.eq_diam)/100.; hyd->n_area=0.f; hyd->type=pixh.len_prev/2048; hyd->min_a=pixh.min_up; hyd->min_b=pixh.min_lo; hyd->y_scale=(float)((pixh.y_scal)/10000.); hyd->x_scale_a=(float)((pixh.x_scale_up)/10000.); hyd->x_scale_b=(float)((pixh.x_scale_lo)/10000.); if (len > 0) decomp(hyd,pixh.len); hyd->f_pos=curr_pos; if (hyd->eq_diameter<=0.F) volu=0.001; else volu = pow((double)hyd->eq_diameter,3.)*pi/6.F; hyd->volume = (float)volu; if (fgetpos(hyd_fil,&actpos) != 0){ perror("gethyd06:"); exit(0); } maxw_a=0; max_a=0; for (i=0;ilines_a;i++){ if ( (pixA[1][i]-pixA[0][i]) > maxw_a ) maxw_a=pixA[1][i]-pixA[0][i]; if ( pixA[1][i] > max_a ) max_a=pixA[1][i]; } maxw_b=0; max_b=0; for (i=0;ilines_b;i++){ if ( (pixB[1][i]-pixB[0][i]) > maxw_b ) maxw_b=pixB[1][i]-pixB[0][i]; if ( pixB[1][i] > max_b ) max_b=pixB[1][i]; } hyd->max_a=max_a; hyd->max_b=max_b; hyd->width_a=maxw_a*hyd->x_scale_a; hyd->width_b=maxw_b*hyd->x_scale_b; mid_a=(hyd->min_a+hyd->max_a)/2.; mid_b=(hyd->min_b+hyd->max_b)/2.; HBL=ptr->m_h.HBL; HBR=ptr->m_h.HBR; HFR=ptr->m_h.HFR; HFL=HBL+HFR-HBR; HF=HFL+mid_a*(HFR-HFL)/(2.*ptr->m_h.mid_pix); HB=HBL+mid_a*(HBR-HBL)/(2.*ptr->m_h.mid_pix); H=HB+mid_b*(HF-HB)/(2.*ptr->m_h.mid_pix); if (pixh.diff_lins==0) hyd->velocity=100.F; else{ absv=0.5*fabs((double)pixh.diff_lins); hyd->velocity = (float)((ptr->m_h.line_frequ) * H/(1000.*absv)); } hyd->height_a=(hyd->lines_a)*hyd->y_scale; hyd->height_b=(hyd->lines_b)*hyd->y_scale; hyd->obl_a=hyd->height_a/hyd->width_a; hyd->obl_b=hyd->height_b/hyd->width_b; hyd->obl=(float)sqrt((double)(hyd->obl_a*hyd->obl_b)); hyd->succ = actpos; hyd->pred = curr_pos - pixh.len_prev%2048; hyd->f_pos= curr_pos; do{ if (fsetpos(hyd_fil,&hyd->succ)!=0){ if (feof) break; perror("gethyd08:"); exit(0); } if (fread(&test,2,1,hyd_fil)!=1){ if (feof) break; perror("gethyd09:"); exit(0); } if (test<0){ hyd->succ += abs(test); if (test==(-1*size_mainh)){ main_h.indic=test; if (fread(&main_h.len_prev,size_mainh-2,1,hyd_fil)!=1){ fprintf(stderr," could not read main header ! \n"); perror("gethyd10:"); exit(0); } main_tim(); } else if (test==(-1*SIZE_QUART)){ quart_h.indic=test; if (fread(&quart_h.len_prev,SIZE_QUART-2,1,hyd_fil)!=1) perror("gethyd11:"); } } } while (test<0); do{ if (fsetpos(hyd_fil,&hyd->pred)!=0){ if (feof) break; perror("gethyd12:"); exit(0); } if (fread(&test,2,1,hyd_fil)!=1){ if (feof) break; perror("gethyd13:"); exit(0); } if (test<0){ if (fread(&len_prev,2,1,hyd_fil)!=1){ if (feof) break; perror("gethyd14:"); exit(0); } hyd->pred -= len_prev%2048; } } while ((test<0)&&(hyd->pred!=0)); if (fsetpos(hyd_fil,&hyd->succ)!=0){ perror("gethyd15:"); exit(0); } return(0); }