/* $Id$ */ /*****************************************************************************/ /* Name: tmireader.c - Read TMI data in HDF-EOS format */ /* */ /* Usage: tmireader filename [N] */ /* filename - Name of TMI 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 */ /*****************************************************************************/ #include #include #include #include #include #include "SDP_Utilities.h" /* Size of one track of data */ #define XTRACK 104 /* Static data */ static double Time; /* Time value */ static float Latitude[XTRACK]; /* Latitude values */ static float Longitude[XTRACK]; /* Longitude values */ static short SunAngle[XTRACK]; /* Sun angle */ static short SurfaceType[XTRACK]; /* Surface type */ static short SeaSurfaceTemp[XTRACK]; /* Sea surface temperature */ static short TMIWindSpeed[XTRACK]; /* All chan. wind speed */ static short OneWindSpeed[XTRACK]; /* 19-37GHz chan. wind speed */ static short ColWaterVapor[XTRACK]; /* Columnar water vapor */ static short ColCloudWater[XTRACK]; /* Columnar cloud water */ static short OneRainRate[XTRACK]; /* 19-37GHz rain rate */ static short TwoRainRate[XTRACK]; /* 11GHz rain rate */ static char QualityFlag; /* Quality flag */ static char AdjacentRain[XTRACK]; /* Adjacent rain flag */ static char WindQCFlag[XTRACK]; /* 19-37GHz wind QC flag */ /* Local functions */ static int readTMI (char *name, int n); static void writeTMI (int n); /*---------------------------------------------------------------------------*/ /* Name: main - Main program for TMI reader */ /* */ /* Usage: main (int argc, char *argv[]); */ /* argc - Count of arguments */ /* argv - Array of arguments */ /* */ /* Description: */ /* Parse the command-line arguments and pass them to the reader. */ /* */ /* Notes: */ /* None. */ /* */ /* Revision history: */ /* 99-02-10 BEB Written */ /*---------------------------------------------------------------------------*/ void main (int argc, char *argv[]) { int n; /* Desired scan number */ /* Check the calling sequence */ if (argc < 2 || argc > 3) { printf ("Usage is tmireader filename [N]\n"); exit (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"); exit (1); } } else { n = 1; } /* Call the reader */ if (readTMI (argv[1], n) != 0) exit (1); /* Display the results */ writeTMI (n); exit (0); } /*---------------------------------------------------------------------------*/ /* Name: readTMI - Read one scan line of TMI data */ /* */ /* Usage: int result = readTMI (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 readTMI (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 */ 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); } if (SWreadfield (swid, "Sun angle", start, NULL, edge, SunAngle) != 0) { printf ("Error reading 'Sun angle' values\n"); return (-1); } if (SWreadfield (swid, "Surface type", start, NULL, edge, SurfaceType) != 0) { printf ("Error reading 'Surface type' values\n"); return (-1); } if (SWreadfield (swid, "Sea surface temperature", start, NULL, edge, SeaSurfaceTemp) != 0) { printf ("Error reading 'Sea surface temperature' values\n"); return (-1); } if (SWreadfield (swid, "All channels 10m wind speed", start, NULL, edge, TMIWindSpeed) != 0) { printf ("Error reading 'All channels 10m wind speed' values\n"); return (-1); } if (SWreadfield (swid, "19-37GHz 10m wind speed", start, NULL, edge, OneWindSpeed) != 0) { printf ("Error reading '19-37GHz 10m wind speed' values\n"); return (-1); } if (SWreadfield (swid, "Columnar water vapor", start, NULL, edge, ColWaterVapor) != 0) { printf ("Error reading 'Columnar water vapor' values\n"); return (-1); } if (SWreadfield (swid, "Columnar cloud water", start, NULL, edge, ColCloudWater) != 0) { printf ("Error reading 'Columnar cloud water' values\n"); return (-1); } if (SWreadfield (swid, "19-37GHz rain rate", start, NULL, edge, OneRainRate) != 0) { printf ("Error reading '19-37GHz rain rate' values\n"); return (-1); } if (SWreadfield (swid, "11GHz rain rate", start, NULL, edge, TwoRainRate) != 0) { printf ("Error reading '11GHz rain rate' values\n"); return (-1); } if (SWreadfield (swid, "Quality flag", start, NULL, edge, &QualityFlag) != 0) { printf ("Error reading 'Quality flag' values\n"); return (-1); } if (SWreadfield (swid, "Adjacent rain flag", start, NULL, edge, AdjacentRain) != 0) { printf ("Error reading 'Adjacent rain flag' values\n"); return (-1); } if (SWreadfield (swid, "19-37GHz wind QC flag", start, NULL, edge, WindQCFlag) != 0) { printf ("Error reading '19-37GHz wind QC flag' values\n"); return (-1); } /* All OK */ (void) SWdetach (swid); (void) SWclose (fid); return (0); } /*---------------------------------------------------------------------------*/ /* Name: writeTMI - Output data from globals */ /* */ /* Usage: writeTMI (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 writeTMI (int n) { char utc[28]; /* Time stamp */ int i; /* 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); /* If the quality flag is non-zero, the entire scan is invalid */ if (QualityFlag != 0x00) { printf ("The quality flag indicates this entire scan is invalid.\n"); return; } /* Header */ printf (" Sea TMI 19-37 Water " "Cloud Rain 11GHz\n"); printf (" Lat. Lon. SA ARF WQC Sfc Temp Wind Wind Vapor " "Water Rate Rain\n"); printf ("--- ------- -------- -- --- --- ----- ----- ----- ----- ----- " "----- ----- -----\n"); /* Loop through the data */ for (i = 0; i < XTRACK; i++) { printf ("%3d", i + 1); printf ("%8.3f", Latitude[i]); printf ("%9.3f", Longitude[i]); if (SunAngle[i] == 31) printf (" "); else printf ("%3d", SunAngle[i]); printf (" %c", (AdjacentRain[i] != 0x00) ? 'Y' : ' '); printf (" %s", (WindQCFlag[i] != 0x00) ? "BAD" : " "); switch (SurfaceType[i]) { case 0: printf (" Ocean"); break; case 1: printf (" Coast"); break; case 2: printf (" Land "); break; default: printf ("? "); break; } if (SeaSurfaceTemp[i] == -32768) printf (" -----"); else printf ("%6.2f", ((float) SeaSurfaceTemp[i]) / 100.0); if (TMIWindSpeed[i] == -32768) printf (" -----"); else printf ("%6.2f", ((float) TMIWindSpeed[i]) / 100.0); if (WindQCFlag[i] != 0x00) printf (" -----"); else if (OneWindSpeed[i] == -32768) printf (" -----"); else printf ("%6.2f", ((float) OneWindSpeed[i]) / 100.0); if (ColWaterVapor[i] == -32768) printf (" -----"); else printf ("%6.2f", ((float) ColWaterVapor[i]) / 100.0); if (ColCloudWater[i] == -32768) printf (" -----"); else printf ("%6.2f", ((float) ColCloudWater[i]) / 100.0); if (OneRainRate[i] == -32768) printf (" -----"); else printf ("%6.2f", ((float) OneRainRate[i]) / 100.0); if (TwoRainRate[i] == -32768) printf (" -----"); else printf ("%6.2f", ((float) TwoRainRate[i]) / 100.0); printf ("\n"); } }