#ident "@(#) read_idf.c 1.17 05/08/19 SwRI" #include /* for stderr */ #include /* for memcpy */ #include "old_local_defs.h" #include "old_vidf_str.h" #include "vidf_local.h" #include "vidf_codes.h" #include "SDDAS_types.h" /***************************************************************************** * * * READ_OLD_IDF SUBROUTINE * * * * DESCRIPTION * * This routine is called to retrieve information from the VIDF definition* * file for the data set specified. The information is either retrieved * * from the VIDF definition file on disk (slow method) or from the memory * * that was allocated to hold the VIDF data (fast method). If an error * * condition was encountered when setting up the fast method, conditions * * are reset to indicate slow access if the user wishes to ignore the error * * code returned. * * * * INPUT VARIABLES * * SDDAS_CHAR *var output value(s) associated with selected * * field * * SDDAS_SHORT quan specified field in VIDF file * * SDDAS_SHORT num the table or constant definition from * * which the required field is to be retrieved* * SDDAS_SHORT len if the selected field is an array, this is * * the number of elements to be returned * * SDDAS_LONG start if the selected field is an array, this is * * the starting position in the array * * * * USAGE * * x = read_idf (&var, quan, num, start, len) * * * * NECESSARY SUBPROGRAMS * * read_idf_disk () access the VIDF information from the file * * located on disk * * read_idf_memory () access the VIDF information from the memory* * that was allocated to hold the data * * * * EXTERNAL VARIABLES * * * * INTERNAL VARIABLES * * SDDAS_LONG ret_val the value returned by the called routine * * * * SUBSYSTEM * * Display Level * * * ****************************************************************************/ SDDAS_LONG ReadOldVIDF (vidf_info *VIDF_INFO, int fdi, SDDAS_CHAR *var, SDDAS_SHORT quan, SDDAS_SHORT num, SDDAS_LONG start, SDDAS_SHORT len) { SDDAS_LONG ret_val = ALL_OKAY; float version = 2.1; /* this is the last version of the old VIDF */ int i; SDDAS_SHORT num_sensors = 0; char num_cals = 0; SDDAS_CHAR *cptr = (SDDAS_CHAR *) var; SDDAS_LONG *lptr = (SDDAS_LONG *) var; SDDAS_SHORT pa_apps, sarr[5000]; /* All the fields are completely unsupported by the old VIDF */ switch (quan) { case _PHI_METHOD : *var = 0; break; /* compute phi */ case _NANO_DEFINED : *var = 0; break; /* no nsec correction */ case _DATA_LAT_UNITS : *var = -6; break; /* microseconds */ case _SWP_RESET_UNITS : *var = -6; break; /* microseconds */ case _SEN_RESET_UNITS : *var = -6; break; /* microseconds */ case _PMI_DEFINED : *var = 0; break; /* no PMI info. */ case _PMI_FORMAT : *(SDDAS_SHORT *) var = 1; break; case _NUM_PMI_ANGLES : *(SDDAS_SHORT *) var = 0; break; case _PMI_PROJECT : *var = '\0'; break; case _PMI_MISSION : *var = '\0'; break; case _PMI_EXPER : *var = '\0'; break; case _PMI_INST : *var = '\0'; break; case _PMI_VINST : *var = '\0'; break; case _PMI_SENSORS : *var = 0; break; case _PMI_ROTATION_AXIS : *var = 0; break; case _PMI_APPS : *(SDDAS_SHORT *) var = 0; break; case _PMI_TBLS : *var = 0; break; case _PMI_OPS : *(SDDAS_LONG *) var = 0; break; case _CP_DEFINED : *var = 0; break; /* no Celestial Position info.*/ case _CP_FORMAT : *(SDDAS_SHORT *) var = 1; break; case _CP_PROJECT : *var = '\0'; break; case _CP_MISSION : *var = '\0'; break; case _CP_EXPER : *var = '\0'; break; case _CP_INST : *var = '\0'; break; case _CP_VINST : *var = '\0'; break; case _CP_DECLINATION_SENSOR : *(SDDAS_SHORT *) var = 0; break; case _CP_DECLINATION_APPS : *(SDDAS_SHORT *) var = 0; break; case _CP_DECLINATION_TBLS : *var = 0; break; case _CP_DECLINATION_OPS : *(SDDAS_LONG *) var = 0; break; case _CP_RT_ASCENSION_SENSOR : *(SDDAS_SHORT *) var = 0; break; case _CP_RT_ASCENSION_APPS : *(SDDAS_SHORT *) var = 0; break; case _CP_RT_ASCENSION_TBLS : *var = 0; break; case _CP_RT_ASCENSION_OPS : *(SDDAS_LONG *) var = 0; break; case _ORBITING_BODY : *(SDDAS_SHORT *) var = 0; break; case _REF_SEN_DELAY : *(SDDAS_FLOAT *) var = 0.0; break; /* 0 */ case _REF_SEN_DELAY_UNIT : *(SDDAS_SHORT *) var = 1; break; /* seconds*/ case _POT_SRC_DEFINED : *var = 0; break; /* no Moments info. */ case _POT_SRC_FORMAT : *(SDDAS_SHORT *) var = 1; break; case _POT_SRC_PROJECT : *var = '\0'; break; case _POT_SRC_MISSION : *var = '\0'; break; case _POT_SRC_EXPER : *var = '\0'; break; case _POT_SRC_INST : *var = '\0'; break; case _POT_SRC_VINST : *var = '\0'; break; case _POT_SRC_SENSOR : *(SDDAS_SHORT *) var = 0; break; case _POT_SRC_APPS : *(SDDAS_SHORT *) var = 0; break; case _POT_SRC_TBLS : *var = 0; break; case _POT_SRC_OPS : *(SDDAS_LONG *) var = 0; break; case _POT_CONSTANT_VAL : *(SDDAS_FLOAT *) var = 0.0; break; /* 0 */ case _MAX_PACKING : *(SDDAS_SHORT *) var = 1; break; /* 1 scalar per sensor set - no packing */ case _START_SPIN_DEFINED : *var = 0; break; /* no Start of Spin info. */ case _START_SPIN_PROJECT : *var = '\0'; break; case _START_SPIN_MISSION : *var = '\0'; break; case _START_SPIN_EXPER : *var = '\0'; break; case _START_SPIN_INST : *var = '\0'; break; case _START_SPIN_VINST : *var = '\0'; break; case _START_SPIN_SENSOR : *(SDDAS_SHORT *) var = 0; break; case _START_SPIN_MSEC_ADJ : *(SDDAS_LONG *) var = 0; break; case _START_SPIN_NSEC_ADJ : *(SDDAS_LONG *) var = 0; break; case _COORD_SYSTEM_DEFINED : *var = 0; break; /* no Coordinate System info. */ case _COORD_SYSTEM : *cptr = '\0'; break; case _BKGD_DEFINED : *var = 0; break; /* no Background info. */ case _BKGD_FORMAT : *(SDDAS_SHORT *) var = 1; break; case _BKGD_PROJECT : *var = '\0'; break; case _BKGD_MISSION : *var = '\0'; break; case _BKGD_EXPER : *var = '\0'; break; case _BKGD_INST : *var = '\0'; break; case _BKGD_VINST : *var = '\0'; break; case _BKGD_SENSORS : *var = 0; break; case _BKGD_APPS : *var = 0; break; case _BKGD_TBLS : *var = 0; break; case _BKGD_OPS : *(SDDAS_LONG *) var = 0; break; /* This field can return multiple values. */ case _CAL_SCOPE : if (fdi != 0) { fprintf (stderr, "read_idf_disk no longer supported!!!\n"); ret_val = VIDF_READ_IDF_DISK; } else ret_val = read_idf_memory (VIDF_INFO, &num_cals, _CAL_SETS, 0, 0, -1); /* Since not defined for the old VIDF format, set the same for all cal sets. */ i = 0; while ((ret_val == 1) && (i < num_cals)) { cptr[i] = 0; /* default back to when each sensor defines the cal set */ i++; } break; /* This field can return multiple values. */ case _CAL_D_TYPE: if (fdi != 0) { fprintf (stderr, "read_idf_disk no longer supported!!!\n"); ret_val = VIDF_READ_IDF_DISK; } else ret_val = read_idf_memory (VIDF_INFO, &num_cals, _CAL_SETS, 0, 0, -1); /* Since not defined for old VIDF format, and data conversion was */ /* hard-coded to zero, set the same for all cal sets. */ i = 0; while ((ret_val == 1) && (i < num_cals)) { cptr[i] = 0; /* default to hard-coded d_type value of 0 */ i++; } break; case _SPIN_TIME_OFF : if (fdi != 0) { fprintf (stderr, "read_idf_disk no longer supported!!!\n"); ret_val = VIDF_READ_IDF_DISK; } else ret_val = read_idf_memory (VIDF_INFO, (SDDAS_CHAR *) &num_sensors, _SEN, 0, 0, 1); /* Since not defined for the old VIDF format, set to zero for all sensors. */ i = 0; while ((ret_val == 1) && (i < num_sensors)) { lptr[i] = 0; i++; } break; case _HEADER_FORMAT : *var = 1; break; /* original header definition */ /* Unlike other fields, tensor information is totally non-related */ /* to the old VIDF definition, so set to invalid value for rank, */ /* empty list for lengths, empty list for dimension names and */ /* no range for dimension. */ case _TENSOR_RANK : *(SDDAS_SHORT *) var = 0; break; case _TENSOR_LENGTHS : *(SDDAS_LONG *) var = 0; break; /* case _TENSOR_IDS : *(SDDAS_SHORT *) var = 0; break; */ case _TENSOR_DNAMES : *cptr = '\0'; break; case _TENSOR_MIN_VALS : *(SDDAS_FLOAT *) var = 0.0; break; /* 0 */ case _TENSOR_MAX_VALS : *(SDDAS_FLOAT *) var = 0.0; break; /* 0 */ /* The version is hard coded */ case _VERSION : memcpy (var, &version, sizeof (float)); break; /* In order to support advanced buffers, tbl_opers need to change to SDDAS_LONGS */ /* BUT to be backwards compatible, binary files need to be written as SDDAS_SHORTS */ /* so need to read as shorts and return as longs. */ case _PA_OPS : if (fdi != 0) { fprintf (stderr, "read_idf_disk no longer supported!!!\n"); ret_val = VIDF_READ_IDF_DISK; } else { /* Get the tbl_opers, which are written as SDDAS_SHORTS in */ /* binary format */ ret_val = read_idf_memory (VIDF_INFO, (SDDAS_CHAR *) sarr, quan, num, start, len); if (ret_val == 1) { /* User wanted all tbl_operators for pitch angle conversion? */ if (len == -1) ret_val = read_idf_memory (VIDF_INFO, (SDDAS_CHAR *) &pa_apps, _PA_APPS, 0, 0, -1); /* User wanted a subset of tbl_operators for pitch angle conversion. */ else pa_apps = len; } } /* Return as SDDAS_LONG to calling module. */ i = 0; while ((ret_val == 1) && (i < pa_apps)) { lptr[i] = sarr[i]; i++; } break; /* Otherwise it is supported */ default : /****************************************************************/ /* Read the VIDF information from the disk or from memory? */ /****************************************************************/ if (fdi != 0) { fprintf (stderr, "read_idf_disk no longer supported!!!\n"); ret_val = VIDF_READ_IDF_DISK; /* ret_val = read_idf_disk (VIDF_INFO, fdi, var, quan, num, start, len); */ } else ret_val = read_idf_memory (VIDF_INFO, var, quan, num, start, len); } /* switch */ return (ret_val); }