00001 #include "mm5io.h" 00002 #include <stdio.h> 00003 #include <hdf5.h> 00004 00005 #include <F5/F5F.h> 00006 #include <F5/F5R.h> 00007 #include <F5/F5coordinates.h> 00008 /* -------------------------------------------------------------------------- */ 00009 /* DEFINITIONS */ 00010 /* -------------------------------------------------------------------------- */ 00011 #define BIG 0 00012 #define LITTLE 1 00013 #define BIG_HEADER 0 00014 #define SUB_HEADER 1 00015 00016 /* -------------------------------------------------------------------------- */ 00017 /* FUNCTION : check_endian */ 00018 /* DESCRIPTION : Checks if this machine is little/big endian */ 00019 /* IN DATA : none */ 00020 /* OUT DATA : none */ 00021 /* RETURN : BIG or LITTLE */ 00022 /* -------------------------------------------------------------------------- */ 00023 int check_endian(); 00024 00025 /* -------------------------------------------------------------------------- */ 00026 /* FUNCTION : swab4 */ 00027 /* DESCRIPTION : swaps 4 bytes values from/to little/big endian */ 00028 /* IN DATA : none */ 00029 /* OUT DATA : swapped value */ 00030 /* RETURN : none */ 00031 /* -------------------------------------------------------------------------- */ 00032 void swab4(void *value); 00033 00034 00035 /* -------------------------------------------------------------------------- */ 00036 /* FUNCTION : fort_read */ 00037 /* DESCRIPTION : Reads a record from a fortran unformatted file (big endian) */ 00038 /* IN DATA : pointer to result, size of data type, number of data type, 00039 pointer to file, machine order */ 00040 /* OUT DATA : record */ 00041 /* RETURN : record size on completion, -1 on error */ 00042 /* -------------------------------------------------------------------------- */ 00043 int fort_read(void* record, size_t size, size_t num, FILE* flnm, int machorder); 00044 00045 /* -------------------------------------------------------------------------- */ 00046 /* FUNCTION : fort_print */ 00047 /* DESCRIPTION : print a fortran format string */ 00048 /* IN DATA : pointer to the string, length of string */ 00049 /* OUT DATA : print to std */ 00050 /* RETURN : char printed on completion, -1 on error */ 00051 /* -------------------------------------------------------------------------- */ 00052 int fort_print(char* ptr, int num); 00053 00054 /* -------------------------------------------------------------------------- */ 00055 /* FUNCTION : process_header */ 00056 /* DESCRIPTION : change fortran format to c format */ 00057 /* IN DATA : pointer to the header, header type */ 00058 /* OUT DATA : pointer to processed header */ 00059 /* RETURN : nothing */ 00060 /* -------------------------------------------------------------------------- */ 00061 00062 void process_header(void* header, int type); 00063 00064 00065 /* -------------------------------------------------------------------------- */ 00066 /* FUNCTION : fort_read_field */ 00067 /* DESCRIPTION : read field data into memory */ 00068 /* IN DATA : pointer to file, No of dims, array of No of data in every dim */ 00069 /* OUT DATA : */ 00070 /* RETURN : pointer to filed start */ 00071 /* -------------------------------------------------------------------------- */ 00072 00073 int fort_read_field(FILE* input, float** field, int* ndim, int* end_index,int machorder); 00074 00075 00076 /* -------------------------------------------------------------------------- */ 00077 /* FUNCTION : time_char_double */ 00078 /* DESCRIPTION : converte char[24] time to double format */ 00079 /* IN DATA : the pointer to the start of char[24] */ 00080 /* OUT DATA : */ 00081 /* RETURN : float date */ 00082 /* -------------------------------------------------------------------------- */ 00083 00084 double time_char_double( char* ctime); 00085 00086 /* -------------------------------------------------------------------------- */ 00087 /* FUNCTION : prepare_vdata */ 00088 /* DESCRIPTION : convert scalar data to vector data file */ 00089 /* IN DATA : subh, vdata , field */ 00090 /* OUT DATA : */ 00091 /* RETURN : */ 00092 /* -------------------------------------------------------------------------- */ 00093 00094 void prepare_vdata(t_mm5v3_sub_header subh, F5_vec3f_t* vdata, float* field); 00095 00096 /* -------------------------------------------------------------------------- */ 00097 /* FUNCTION : convert_field_name */ 00098 /* DESCRIPTION : convert field name in MM5 to a string */ 00099 /* IN DATA : pointer to a mm5 field name */ 00100 /* OUT DATA : pointer to a string */ 00101 /* RETURN : -1 if error, 0 if success */ 00102 /* -------------------------------------------------------------------------- */ 00103 00104 int convert_field_name(char * str, char * fstr); 00105 00106 /* -------------------------------------------------------------------------- */ 00107 /* FUNCTION : convert_unit_name */ 00108 /* DESCRIPTION : convert unit name in MM5 to a string */ 00109 /* IN DATA : pointer to a mm5 field name */ 00110 /* OUT DATA : pointer to a string */ 00111 /* RETURN : -1 if error, 0 if success */ 00112 /* -------------------------------------------------------------------------- */ 00113 00114 int convert_unit_name(char * str, char * fstr); 00115 00116 /* -------------------------------------------------------------------------- */ 00117 /* FUNCTION : convert_spacing() */ 00118 /* DESCRIPTION : convert spacing from m to degree */ 00119 /* IN DATA : spacing */ 00120 /* OUT DATA : new spacing */ 00121 /* RETURN : -1 if error, 0 if success */ 00122 /* -------------------------------------------------------------------------- */ 00123 00124 int convert_spacing(F5_vec3_float_t* spacing); 00125 00126 00127