/* This procedure opens and reads ACE MAG field averages data from a level 1 HDF file. Data records are read into a structure. This procedure was modified from its original source to be called from a Fortran main routine and pass back the data set contents as a structure array. Original source: MAG_AVGVEC_RD.C - ACE Science Center Modifications: port to VMS platform - Sandy Kramer, NASA/GSFC 12/11/98 */ #include #include #include "mag_avgvec.h" #include "df.h" #include "mfhdf.h" int rd_magavgvec(name, avgvecdat, avgveccnt) char *name; struct MagAvgVec *avgvecdat; int *avgveccnt; { int32 hdf_fp, sd_id; struct MagAvgVec testdata; int ii,jj,retval; int32 numrec; printf("ACE MAG field averages read routine\n"); printf("File name is <%s>\n", name); if (name[0] == ' ') { printf("Usage: rd_hdf hdf_file\n"); return(1); } /* testdata=malloc(sizeof(struct MagAvgVec)); */ /* open hdf input file */ if ((hdf_fp=Hopen(name, DFACC_RDONLY, 0))==FAIL) { fprintf(stderr, "Hopen: could not open hdf file\n"); return(-1); } printf("File successfully opened.\n"); Vstart(hdf_fp); if ((sd_id=SDstart(name, DFACC_RDONLY))==FAIL) { fprintf(stderr, "SDstart: could not open hdf file\n"); return(-1); } if( init_rd_mag_avgvec(hdf_fp, sd_id, "r") <=0) { fprintf(stderr,"No mag vector data\n"); } ii=0; while((retval= read_mag_avgvec(&testdata,ii))!=-1) { avgvecdat[ii] = testdata; /* printf("%10u %10u ", testdata->sctime_readout,testdata->sctime_collection); printf("%10.4f %10.4f %10.4f %10.4f\n", testdata->b_inertial[0], testdata->b_inertial[1], testdata->b_inertial[2],testdata->b_sigma); */ ii++; } *avgveccnt = ii; /* all done, close HDF file */ close_rd_mag_avgvec(); Vend(hdf_fp); if (SDend(sd_id)==FAIL) { fprintf(stderr, "SDend: could not close hdf file\n"); return(-1); } if (Hclose(hdf_fp)==FAIL) { fprintf(stderr, "Hclose: could not close hdf file\n"); return(-1); } return(0); }