/* $Id$ */ /*****************************************************************************/ /* Name: amsuareader.c - Read AMSU-A data in HDF-EOS format */ /* */ /* Usage: amsuareader filename [N] */ /* filename - Name of AMSU-A data file */ /* N - Scan line to read, 1-#scans in file */ /* */ /* Description: */ /* Read the Nth scan line from the given file, or the first if "N" is */ /* not specified. This file contains the following routines: */ /* */ /* main - Main program */ /* */ /* Notes: */ /* Makes a lot of assumptions about the file's format. */ /* */ /* Revision history: */ /* 99-02-10 BEB Written */ /* 00-08-07 BEB Updated to new format */ /*****************************************************************************/ #include #include #include #include #include #include "SDP_Utilities.h" #define XTRACK 30 /* Cross-track dimension */ #define NDATAS 15 /* Number of data fields */ /* Static data */ static float64 Time; /* Time value */ static float32 Latitude[XTRACK]; /* Latitude values */ static float32 Longitude[XTRACK]; /* Longitude values */ static float32 Data[NDATAS][XTRACK]; /* Data values */ /* Data field names */ static char *Datanames[NDATAS] = { "23800.37 MHz", "31400.42 MHz", "50299.91 MHz", "52799.39 MHz", "53595.41 +- 115 MHz", "54399.53 MHz", "54940.64 MHz", "55498.70 MHz", "57290.33 MHz", "57290.33 +- 217 MHz", "57290.33 +- 322.2 +- 48 MHz", "57290.33 +- 322.2 +- 22 MHz", "57290.33 +- 322.2 +- 10 MHz", "57290.33 +- 322.2 +- 4.5 MHz", "88997.00 MHz" }; /* Local functions */ static int readAMSUA(char *name, int n); static void writeAMSUA(int n); /*---------------------------------------------------------------------------*/ /* Name: main - Main program for AMSU-A reader */ /* */ /* Usage: int result = main(int argc, char *argv[]); */ /* argc - Count of arguments */ /* argv - Array of arguments */ /* result - Exit status */ /* */ /* Description: */ /* Parse the command-line arguments and pass them to the reader. */ /* */ /* Notes: */ /* None. */ /* */ /* Revision history: */ /* 99-02-10 BEB Written */ /*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { int n; /* Desired scan number */ /* Check the calling sequence */ if (argc < 2 || argc > 3) { printf("Usage is amsuareader filename [N]\n"); return (0); } /* Get the scan number, if any */ if (argc == 3) { if (sscanf(argv[2], "%d", &n) != 1 || n < 1) { printf("Scan number is invalid\n"); return (1); } } else { n = 1; } /* Call the reader */ if (readAMSUA(argv[1], n) != 0) return (1); /* Display the results */ writeAMSUA(n); return (0); } /*---------------------------------------------------------------------------*/ /* Name: readAMSUA - Read one scan line of AMSU-A data */ /* */ /* Usage: int result = readAMSUA(char *name, int n); */ /* name - Name of file to read */ /* n - Number of scan line */ /* result - Non-zero on errors */ /* */ /* Description: */ /* Read scan line "n" (1-#scans) from "name" and store it into the */ /* global variables. */ /* */ /* Notes: */ /* None. */ /* */ /* Revision history: */ /* 99-02-10 BEB Written */ /*---------------------------------------------------------------------------*/ static int readAMSUA(char *name, int n) { int32 fid; /* File identifier */ int32 swid; /* Swath identifier */ int32 size; /* Size of things */ int32 start[2]; /* Start index array */ int32 edge[2]; /* Edge count array */ int f; /* Loop counter */ char swname[64]; /* Swath name */ /* Open the file */ if ((fid = SWopen(name, DFACC_READ)) == -1) { printf("Unable to open '%s' for reading", name); return (-1); } /* Retrieve the name of the swath within the file */ if (SWinqswath(name, swname, &size) != 1) { printf("Wrong number of swath objects in '%s'\n", name); return (-1); } /* Attach to the swath */ if ((swid = SWattach(fid, swname)) == -1) { printf("Unable to attach to '%s'\n", swname); return (-1); } /* See how many scan lines in this file */ if ((size = SWdiminfo(swid, "Track")) == -1) { printf("Unable to determine the value of 'Track'\n"); return (-1); } /* Check the user's value */ if (n > size) { printf("Sorry, there are only %d scans in this file\n", size); return (-1); } /* Read in the data */ start[0] = n - 1; edge[0] = 1; start[1] = 0; edge[1] = XTRACK; if (SWreadfield(swid, "Time", start, NULL, edge, &Time) != 0) { printf("Error reading 'Time' value\n"); return (-1); } if (SWreadfield(swid, "Latitude", start, NULL, edge, Latitude) != 0) { printf("Error reading 'Latitude' values\n"); return (-1); } if (SWreadfield(swid, "Longitude", start, NULL, edge, Longitude) != 0) { printf("Error reading 'Longitude' values\n"); return (-1); } for (f = 0; f < NDATAS; f++) { if (SWreadfield(swid, Datanames[f], start, NULL, edge, Data[f]) != 0) { printf("Error reading '%s' values\n", Datanames[f]); return (-1); } } /* All OK */ (void) SWdetach(swid); (void) SWclose(fid); return (0); } /*---------------------------------------------------------------------------*/ /* Name: writeAMSUA - Output data from globals */ /* */ /* Usage: writeAMSUA(int n); */ /* n - Scan number */ /* */ /* Description: */ /* Display the data assembled in the global variables. */ /* */ /* Notes: */ /* None. */ /* */ /* Revision history: */ /* 99-02-10 BEB Written */ /*---------------------------------------------------------------------------*/ static void writeAMSUA(int n) { char utc[28]; /* Time stamp */ int i; /* Local index */ int f; /* Local index */ /* Convert the TAI value to UTC */ (void) SDP_TD_TAItoUTC((float64) Time, utc); /* Write out the first line */ printf("Scan %d at %s\n\n", n, utc); /* Header */ printf(" Field 1 Field 2 Field 3 Field 4 Field 5\n"); printf(" Field 6 Field 7 Field 8 Field 9 Field 10\n"); printf(" Lat. Lon. Field 11 Field 12 Field 13 Field 14 Field 15\n"); printf("-- ------ ------- -------- -------- -------- -------- --------\n"); /* Loop through the data */ for (i = 0; i < XTRACK; i++) { printf("%2d", i + 1); printf("%7.2f", Latitude[i]); printf("%8.2f", Longitude[i]); for (f = 0; f < NDATAS; f++) { if (f > 0 && f % 5 == 0) printf("\n "); printf("%9.2f", Data[i][f]); } printf("\n"); } }