/* currhdr.c cl /AL currhdr.c getfile */ #include #include #include "nomouse.h" #define NUMDAT 50 #define NUMCOM 10 #define MAX_NUM 1000 #define S_SIZE 40 #define F_SIZE 20 #define T_SIZE 15 int Mouse=0; struct file_id { char name[S_SIZE]; long size; unsigned date,time; }; extern struct file_id GF_File[MAX_NUM]; extern int GF_Order[MAX_NUM]; char GF_String[MAX_NUM][S_SIZE]; unsigned char Bit[8]={1,2,4,8,16,32,64,128}; struct time { int da,mo,yr,hr,min,sec; }; struct info { int order; char name[20]; char units[20]; char codes[20]; float depth; char inst[20]; float min,max; }; struct header { char id[38]; struct time start_time,stop_time; long cycles,num_days; char expt[32]; char date_created[32]; struct time time_create; float water_depth; /* meters */ float mag_var; /* degrees */ float lat,lon; /* degrees */ float sampling_interval; /* seconds */ struct info Data[NUMDAT]; char comment[NUMCOM][80]; int num_var; int order[NUMDAT]; char dummy[28]; /* 1 -- Temp 2 -- Conductivity 3 -- Salinity 4 -- Led_Trans1 5 -- Attenuation 6 -- U 7 -- V 8 -- U.2 9 -- V.2 10 -- VDir 11 -- VSpd 12 -- Rotor_Speed 13 -- Rotor_Count 14 -- Vane 15 -- Bearing 16 -- Compass 17 -- Pressure-I 18 -- Pressure-B 19 -- PSDev 20 -- TransOn 21 -- TransOff 22 -- Neph 23 -- NephOff 24 -- Int-Rotor1 25 -- Int-Rotor2 26 -- R1-R2 27 -- Burst-NUV 28 -- BRotor/Rotor 29 -- Ext_Coef 30 -- Sigma_T 31 -- FR-Temp 32 -- trans2 33 -- Temp-Diff 34 -- Err 35 -- Rel_Sea_Level 36 -- Attenuation2 37 -- Wave_period 38 -- Wave_height 39 -- Wave_dir 40 -- Dew_point */ }Hdr; struct data_type { int num_name; char *name[8]; }DType[NUMDAT]= { { 1,"Time"}, { 6,"Temp","temperature","Temp-LP","Temp-Q","Air_Temp","Air"}, { 2,"Conductivity","Conduct-Q"}, { 2,"Salinity","Salinity-Q"}, { 4,"Led_Trans","Led_Trans-Q","Trans1","TransOn-A"}, { 5,"Attenuation","Trans1-ATT","LG(TN)","LN(TR)","LTN"}, { 7,"U","U.1","U.1-Q","East","East-Q","East_Comp","EastQ"}, { 7,"V","V.1","V.1-Q","North","North-Q","North_Comp","NorthQ"}, { 4,"U.2","U.2-Q","Ustrss","Ustress"}, { 4,"V.2","V.2-Q","Vstrss","Vstress"}, { 7,"VDir","VDir.1","VDir.1-Q","VDir-Q","Wind_direc","Direction", "Direction-Q"}, { 8,"VSpd","VSpd.1","VSpd.1-Q","VSpd-Q","Speed","Speed-Q","Wind_Speed", "Stress"}, { 8,"Rotor_Speed","burst_speed","Rotor","Rotor-Q","Max_speed", "N.wind.spd","Raw","Rotor1-Q"}, { 1,"Rotor_Count"}, { 1,"Vane"}, { 1,"Bearing"}, { 2,"Compass","Compass-Q"}, { 8,"Pressure-I","IPressure-Q","Pressure","Press-LP","Press", "Atmos_press", "baro_press","Sea_lev_pres"}, { 3,"Pressure-B","Atmos_pres","Pressure-Q"}, { 1,"PSDev"}, { 3,"TransOn","TransOn-Q","TransOn-N"}, { 3,"TransOff","TransOff-Q","TransOff-A"}, { 2,"NephOn","NephOn-Q"}, { 2,"NephOff","NephOff-Q"}, { 8,"Int-Rotor1","IRotor1-Q","Int_Rotor1","Int_Rotor1-Q","Int_Rotor", "Int._Rotor","Int._RotorQ","Int_RotorQ"}, { 7,"Int-Rotor2","IRotor2-Q","Int_Rotor2","Int_Rotor2-Q","Rotor2-Q", "Mean_BRotor","R2-Q"}, { 1,"R1-R2"}, { 2,"Burst-NUV","Burst_NUV"}, { 3,"BRotor/Rotor","BRot/RotorQ","BR/Rotor-Q"}, { 1,"Ext_Coef"}, { 2,"SigmaT","Density"}, { 6,"FRTemp","FR_Temp","FR-Temp","Sea_Surf_tem","water_temp","Sea"}, { 1,"Trans2"}, { 2,"Temp-Diff","Temp_Diff"}, { 2,"Err","Steadiness"}, { 2,"Rel_Sea_Leve","Tidal_Elev"}, { 1,"Trans2-ATT"}, { 1,"Wave_period"}, { 1,"Wave_height"}, { 1,"Wave_dir"}, { 1,"Dew_point"}, { 1,"Bpres-Ipres"}, { 1,"Rotorsdev"}, { 1,"VDir.2"}, { 1,"Vspd.2"}, { 0," "}, { 0," "}, { 0," "}, { 0," "}, { 0," "} }; struct hdr_hdr { float maxlat,minlat,maxlon,minlon; float maxwd,minwd,maxid,minid,maxih,minih; long freq[33]; long mintime,maxtime; long numfiles; }Hhdr; struct short_hdr { char name[12]; float lat,lon; /* degrees */ float w_depth,i_depth,i_height; /* meters */ float ob_freq; /* obs/hr */ long start,stop; /* 85012 = 1985, j-day 12 */ unsigned char parm[10]; }Shdr; int day_tab[2][13]= { { 0,31,28,31,30,31,30,31,31,30,31,30,31}, { 0,31,29,31,30,31,30,31,31,30,31,30,31}, }; main() { int i,j,k; char ans; do { printf(" 1 -- scan headers\n"); printf(" 2 -- check 'current.hdr' header\n"); printf(" 3 -- check 'current.hdr' entries\n"); printf("\n x -- exit program\n\n"); ans=getch(); if(ans=='1') scan_hdrs(); if(ans=='2') print_hhdr(); if(ans=='3') print_shdr(); }while(ans!='x'); } /*********************************************************************** ** ** ** ** ************************************************************************/ int print_hhdr() { int i,j,k; FILE *fpin; fpin=fopen("current.hdr","rb"); fread((char *)&Hhdr,sizeof(struct hdr_hdr),1,fpin); printf("# of file = %ld\n",Hhdr.numfiles); printf("Lat = %10.4f to %10.4f\n",Hhdr.minlat,Hhdr.maxlat); printf("Lon = %10.4f to %10.4f\n",Hhdr.minlon,Hhdr.maxlon); printf("water depth = %6.1f to %6.1f\n",Hhdr.minwd,Hhdr.maxwd); printf("inst. depth = %6.1f to %6.1f\n",Hhdr.minid,Hhdr.maxid); printf("inst. height = %6.1f to %6.1f\n",Hhdr.minih,Hhdr.maxih); printf("time = %ld to %ld\n",Hhdr.mintime,Hhdr.maxtime); printf("Freq. Number\n"); for(i=0;i<33;i++) if(Hhdr.freq[i]>0) printf(" %2d %5ld\n",i,Hhdr.freq[i]); fclose(fpin); } /*********************************************************************** ** ** ** ** ************************************************************************/ int print_shdr() { int i,j,k; FILE *fpin; unsigned char uval; int num=0; fpin=fopen("current.hdr","rb"); fread((char *)&Hhdr,sizeof(struct hdr_hdr),1,fpin); printf("# of file = %ld\n",Hhdr.numfiles); printf("Lat = %10.4f to %10.4f\n",Hhdr.minlat,Hhdr.maxlat); printf("Lon = %10.4f to %10.4f\n",Hhdr.minlon,Hhdr.maxlon); printf("water depth = %6.1f to %6.1f\n",Hhdr.minwd,Hhdr.maxwd); printf("inst. depth = %6.1f to %6.1f\n",Hhdr.minid,Hhdr.maxid); printf("inst. height = %6.1f to %6.1f\n",Hhdr.minih,Hhdr.maxih); printf("time = %ld to %ld\n",Hhdr.mintime,Hhdr.maxtime); printf("Freq. Number\n"); for(i=0;i<33;i++) if(Hhdr.freq[i]>0) printf(" %2d %5ld\n",i,Hhdr.freq[i]); while(fread((char *)&Shdr,sizeof(struct short_hdr),1,fpin)>0) { printf("%4d ",++num); for(i=0;i-0.0001&&Shdr.lat<0.0001)||Shdr.lat<-90.0||Shdr.lat>90.0|| (Shdr.lon>-0.0001&&Shdr.lon<0.0001)|| Shdr.lon<-180.0||Shdr.lon>180.0) { good=0; fprintf(fperr,"Dropped '%s' for lat/lon\n",Shdr.name); } for(k=0;kHhdr.maxlat) Hhdr.maxlat=Shdr.lat; if(Shdr.latHhdr.maxlon) Hhdr.maxlon=Shdr.lon; if(Shdr.lonHhdr.maxwd) Hhdr.maxwd=Shdr.w_depth; if(Shdr.w_depthHhdr.maxid) Hhdr.maxid=Shdr.i_depth; if(Shdr.i_depthHhdr.maxih) Hhdr.maxih=Shdr.i_height; if(Shdr.i_heightHhdr.maxtime) Hhdr.maxtime=Shdr.stop; } printf(" %9.4f %10.4f",Shdr.lat,Shdr.lon); printf(" %7.1f %7.1f %7.1f", Shdr.w_depth,Shdr.i_depth,Shdr.i_height); printf(" %2.0f",Shdr.ob_freq); printf("\n %5ld %5ld\n",Shdr.start,Shdr.stop); printf("%2d%2d%2d %2d%2d%2d", Hdr.start_time.yr,Hdr.start_time.mo,Hdr.start_time.da, Hdr.stop_time.yr,Hdr.stop_time.mo,Hdr.stop_time.da); printf("\n"); for(k=0;k0) { if(getch()==27) { rewind(fpout); fwrite((char *)&Hhdr,sizeof(struct hdr_hdr),1,fpout); fclose(fpout); exit(0); } } } rewind(fpout); fwrite((char *)&Hhdr,sizeof(struct hdr_hdr),1,fpout); fclose(fpout); } /******************************************************************** ** ** ** ********************************************************************* */ int day_of_year(year,month,day) int year,month,day; { int i,leap; if(month<1||month>12)return(-1); /* invalid month */ leap=year%4==0&&year%100!=0||year%400==0; if(day<1||day>day_tab[leap][month])return(-2); /* invalid day */ for(i=1;i