/* ------------------------------------------------------------ */ /* GetBlock.c -- Get a ships-motion data block from the MCM. */ /* dam, May, 1999 */ /* ------------------------------------------------------------ */ #include #include #include #ifndef __NT__ #include #endif #include "CasperLib.h" #include "ShipsMotionFile.h" INT32 GetBlock (FILE *fp, DBASE_SHIPS_DATA* MotionData) { FLOAT64 x3rad,x4mps; FLOAT32 dtime, x1, x2, x3, x4, x5, x6, x7; INT32 Nread, ilat, ilon; size_t minlen = 70; char line[160]; struct tm t; if( fgets( line, 160, fp ) == NULL ) return( -1 ); if( strlen( line ) < minlen ) return( -2 ); Nread = sscanf(line, "%d/%d/%d,%d:%d:%d,%f,%f,%f,%f,%f,%f,%f,%f", &t.tm_mon, &t.tm_mday, &t.tm_year, &t.tm_hour, &t.tm_min, &t.tm_sec, &dtime,&x1,&x2,&x3,&x4,&x5,&x6,&x7); /* printf("line: %s",line); printf("data: %02d/%02d/%4d,%02d:%02d:%02d,%.0f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,%.4f,\n", t.tm_mon, t.tm_mday, t.tm_year, t.tm_hour, t.tm_min, t.tm_sec, dtime,x1,x2,x3,x4,x5,x6,x7); */ t.tm_year -= 1900; t.tm_mon -= 1; MotionData->TimeSeconds = (C_TIME_T)mktime( &t ); MotionData->TimeNSeconds = (C_TIME_T)0; ilat = (INT32)(x1 / 100.0); MotionData->Latitude = (FLOAT32)ilat + ((x1 - (FLOAT32)ilat * 100.0) / 60.0 ); ilon = (INT32)(x2 / 100.0); MotionData->Longitude = (FLOAT32)ilon + ((x2 - (FLOAT32)ilon * 100.0) / 60.0 ); x3rad = (FLOAT64)x3 * DEGRAD; x4mps = (FLOAT64)x4 * 0.5148; MotionData->N_Velocity = (FLOAT32)( cos( x3rad ) * x4mps); MotionData->E_Velocity = (FLOAT32)( sin( x3rad ) * x4mps); MotionData->Heading = x6; /* printf("conv: %.4f,%.4f,%.4f,%.4f,%.4f\n", MotionData->Latitude,MotionData->Longitude,MotionData->N_Velocity, MotionData->E_Velocity,MotionData->Heading); */ MotionData->MCM_CompMode = (BYTE)0; return (0); }