📄 get_stn_hdr.c
字号:
/*===========================================================================*//* DMC Interim out | get_stn_hdr | SEED Headers *//*===========================================================================*//* Name: get_stn_hdr Purpose:concatenate all SEED station id (type 50) and station comment (type 51) blockettes preparatory to building a SEED station control header Usage: int get_stn_hdr (); char *stnname; struct input_time start; struct input_time end; char *bottom; char *top; int error; error = get_stn_hdr (stnname, start, end, &bottom, &top); Input: stnname = string containing station call letters, e.g. "ANMO" start = start time of desired time window end = end time of desired time window Output: bottom = pointer to start of station header for station top = pointer to end of station header for station (used by get_chnl_hdr as a starting point) error = error value; FALSE if no error, nonzero otherwise. It contains values of MESSAGE, WARNING, ERROR, or FATAL (see constants.h) Externals:Debug - environment varible to set debug response level Lrecl - logical record length (globals.h) Messages:No station comments found for station; no action taken Warnings:none Errors: No station info available for station; return null ptrs Fatals: Unable to malloc, realloc sufficient space; quit immediately Called by: Calls to:build_stn_path - construct path to station files load_data - fetch blockettes from blockette files patch_field - update a data entry in a blockette error_handler - handle error conditions Algorithm: allocate 1 logical record's worth of space for header (fatal if this fails); construct base path to station information; open the station id (type 50) file for reading (error if this fails) and concatenate this information into the station control header; open the station comment file for reading (message if this fails) and concatenate this information into the station control header. If more space is needed for either type 50 or type 51 data, allocate more (fatal if this fails). Notes: This uses pointers-to-pointers to pass the alterred values of "stn_hdr" and "top" back to the caller; all work is performed internally using a local pointer "localptr", and the mapping of addresses for "stn_hdr" and "top" is done at the very end. This routine assumes that relevant information resides in files called something/B050 and something/B051. Problems:ASSUMES *bottom points to an 050 blockette after load_data Debug: level D_MIN - print out start and finish notices level D_MED - show files opened and closed, memory allocation level D_MAX - show contents of read files References:none Language:C, more or less ANSI standard, under Sun OS 3.5 Revisions: 02/25/89 Dennis O'Neill original version 05/03/89 Kevin MacKenzie changed return value to "error" as count available from top-bottom added B051 counter and patch of B050 data to include the B051 count. 06/22/89 mw fix patch code; shorten maxlen arg. *bottom may not stay fixed across load_data calls. 11/02/93 cl added some code to make version 2.3*/#include "output.h"extern char *get_net_code();/* ------------------------------------------------------------------------ */int get_stn_hdr (stnname, start, end, bottom, top)char *stnname; /* station/network name */struct input_time start; /* volume start time */struct input_time end; /* volume end time */char **bottom; /* ptr to start of stn hdr */char **top; /* ptr inside stn hdr */{ int error; /* return error status */ char stnpath[PATHLENGTH+1]; /* path to station info */ char infilename[PATHLENGTH+1]; /* name of input file */ FILE *infile; /* input file ptr */ char message[MSGLENGTH+1]; /* message buffer */ char c; /* input stream char */ int i; /* general use integer */ int count050; /* count of B050s copied */ int count051; /* count of B051s copied */ char *p050; /* ptr to start of first B050 */ char stn[6]; char net[3]; if (Debug >= D_MIN) fprintf (D_OUT, "[get_stn_hdr] Started.\n"); error = FALSE; strncpy(stn, stnname, 5); stn[5] = '\0'; strncpy(net, &stnname[5], 2); net[2] = '\0'; /*=====================================*//*=================| construct station header files path |=================*/ /*=====================================*/ if (error = build_stn_path (trim_str(stn), net, Header_path, stnpath)) { error_handler (ERROR, "[get_stn_hdr] Bad station pathname.\n"); *bottom = NULL; *top = NULL; error = ERROR; return (error); } /*=====================================*//*=================| load station id (type 50) info |=================*/ /*=====================================*/ /* construct file name */ sprintf (infilename, "%s/B050", stnpath); /* open file for reading, load info into memory */ if (error = load_data (infilename, start, end, bottom, top, &count050, stnname /* only used here */)) { sprintf (message, "[get_stn_hdr] No station info available for station %s.\n", stnname); error_handler (ERROR, message); *bottom = NULL; *top = NULL; error = ERROR; return (error); } if (count050 == 0) return(STN_NOT_FOUND_WARNING); /*=====================================*//*=================| load station comment (type 51) info |=================*/ /*=====================================*/ /* construct file name */ sprintf (infilename, "%s/B051", stnpath); /* open file for reading, load info into memory */ error = load_data (infilename, start, end, bottom, top, &count051); if (Debug >= D_MED) fprintf (D_OUT, "[get_stn_hdr] Found %d valid B051s.\n",count051); if (error && (Debug >= D_MIN)) { sprintf (message, "[get_stn_hdr] No station comments available for %s\n", stnname); error_handler (MESSAGE, message); error = MESSAGE; } /*=====================================*//*=================| update station header comment count |=================*/ /*=====================================*//* * note that we patch the first blockette 50 read (there could be more than * one for the required time window in addition to possible updates) with * the correct count of station comment (blockettes 051s) whether zero or * otherwise. this is not explicitly correct as the effective dates for a * given comment may more appropriately overlap one of the other blockette * 050s. we assume the count fields in the other blockette 050s are set to * zero. */ p050 = *bottom; error = patch_field (p050, 0, 44, 0, count051, "%3.3d"); /*=====================================*//*=================| clean up |=================*/ /*=====================================*/ if (Debug >= D_MIN) fprintf (D_OUT, "[get_stn_hdr] Completed.\n"); return (error);}/* -------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -