Document title: VAX VMS program 60S2ASC.FOR to convert flat files to ASCII for NDADS ISEE1 and ISEE2 60-second magnetometer flat-file datatype MAG_4S_FF Project: ISEE1 and ISEE2 NDADS Datatype: MAG_1M_FF Super-EID: SOFTWARE There may be other documents also identified by this super-EID. NDADS filename: 60S2ASC.FOR TRF entry: b46643.txt in NSSDC's controlled digital document library, Mar. 1998. Document text follows: ---------------------- C * ------------------------------------------------------------------------- * C * * C * 60s2asc.for - Program to read UCLA-IGPP flat files containing ISEE 60- * C * second magnetic field averages and write an ascii text file * C * of the data. * C * * C * This program reads files containing 60-second magnetic field* C * averages and Multi-Coordinate Ephemeris (MCE) data of the * C * International Sun-Earth Explorers (ISEE) 1 and 2 spacecraft * C * of the United States National Aeronautics and Space * C * Adminstration (NASA). This program writes both the meta * C * data portion of the 60-second flat file and the binary data * C * portion of the flat file as ASCII text to a user specified * C * output file. * C * * C * A flat file is made up of a pair of files: an ASCII file * C * containing meta data with the file type extension ".ffh" * C * (for flat file header); and a data file containing binary * C * values with the file type extension ".ffd" (for flat file * C * data). * C * * C * This program assumes that the input flat files are from a * C * DEC VAX_VMS based WORM so no conversion of floating-point * C * values is required. * C * * C * At the end of this code there is a list that includes the * C * name of each data column in a 60-second flat file along with* C * a brief description of each data item. * C * * C * Copyright (c) 1975-94 Regents of the University of California. * C * All Rights Reserved. * C * * C * Redistribution and use in source and binary forms are permitted * C * provided that the above copyright notice and this paragraph are * C * duplicated in all such forms and that any documentation, advertising * C * materials, and other materials related to such distribution and use * C * acknowledge that the software was developed by the University of * C * California, Los Angeles. The name of the University may not be used * C * to endorse or promote products derived from this software without * C * specific prior written permission. THIS SOFTWARE IS PROVIDED "AS IS" * C * AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT * C * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * C * FOR A PARTICULAR PURPOSE. * C * * C * For information about this software please contact: * C * * C * Principal Investigator: * C * Christopher Russell * C * UCLA - Institute of Geophysics and Planetary Physics * C * 6871 Slichter Hall * C * Los Angeles, Ca. 90024-1567 * C * INTERNET e-mail: ctrussell@igpp.ucla.edu * C * NSI/DECnet e-mail: BRUNET::CTRUSSELL * C * Telephone: (310) 825-3188 * C * * C * Programmer: * C * Harry Herbert * C * UCLA - Institute of Geophysics and Planetary Physics * C * 5833 Slichter Hall * C * Los Angeles, Ca. 90024-1567 * C * INTERNET e-mail: hherbert@igpp.ucla.edu * C * NSI/DECnet e-mail: BRUNET::HARRY * C * Telephone: (310) 825-9030 * C * * C * ------------------------------------------------------------------------- * c FORTRAN 77 requires that if the program statement exists that the first c character of the program name be alphabetic (A - Z). Since the line is c only used for internal reference, it is commented out here. The operating c system compilers and linkers have no problem with this program name. c program 60s2asc c "fname" - the name of the input flat file c "aname" - the name of the output ASCII file c "trimlen" - an integer function that returns the length of a string with c trailing blanks removed c "fflen" - the character length of the input file name contained in "fname" character*64 fname, aname integer trimlen, fflen c Print out introductory information about the program. write(*,'(a)') > ' Program: 60s2asc ', > ' ', > ' ''60s2asc'' reads UCLA-IGPP flat files containing 60- ', > ' second ISEE magnetic field averages and ephemeris data and ', > ' writes both the meta data and binary data files as ASCII ', > ' text to a user specified file. ', > ' ', > ' A UCLA-IGPP flat file is made up of two files: a file', > ' with the type extension ''.ffh'' (for flat file header) has', > ' ASCII meta data; and a file with the type extension ''.ffd''', > ' (for flat file data) has binary data values. ', > ' ' write(*,'(a)') > ' The naming convention for the 60-second data files are', > ' ''60s#XXXX.ffh'' and ''60s#XXXX.ffd'' where # is the ISEE ', > ' spacecraft number, either 1 or 2, and XXXX is the four ', > ' digit orbit number, with leading zeroes as needed. For ', > ' example, ''60s10001'' has data for ISEE-1, orbit 1. ', > ' ', > ' The 60-second flat files read by this program are ', > ' about 1.35 Mbytes each. The ASCII version of the same data', > ' made by this program is about 4.5 Mbytes. ', > ' ' c Get the name of the name of the 60-second input flat file from the user. write (*,*) 'Enter the name of the 60-second input flat file:' read (*,'(a)',iostat=ierr) fname if(ierr.ne.0) then write(*,*) 'Error',ierr,' getting name of input flat file' stop endif c Get the name of the output ASCII file from the user. write (*,*) 'Enter the name of the output ASCII file:' read (*,'(a)',iostat=ierr) aname if(ierr.ne.0) then write(*,*) 'Error',ierr,' getting name of output ASCII file' stop endif c Open the ASCII output file. open (10,file=aname,access='sequential',iostat=ierr,status='new') if(ierr.ne.0) then write(*,*) 'Error',ierr,' opening file ',aname stop endif c Get the length of the input flat file name. fflen = trimlen(fname) c Check to see if the user included the file type extension. If so, c ignore it by reducing the length parameter value. if(fname(fflen-3:fflen-1).eq.'.ff') fflen = fflen - 4 c Build the name of the ASCII header portion of the flat file pair. write(fname,'(a)') fname(1:fflen)//'.ffh' fflen = trimlen(fname) c Write out the meta data for the 60-second data file. call ffheader(fname(1:fflen)) c Build the name of the binary data portion of the flat file pair. write(fname(fflen:fflen),'(a)') 'd' c Write out the data in the 60-second data file. call ffdata(fname(1:fflen)) c Close the ASCII output file. 10 close(10) c Finish up. stop end c ----------------------------------------------------------------------------- c This routine reads the ASCII header portion of the flat file pair, c which contains meta data for the ISEE 60-second averaged magnetometer c data file. It then writes the information to an ASCII text file. subroutine ffheader(fname) character*(*) fname character*72 string c Open the ASCII header portion of the flat file pair. open (20,file=fname,access='direct',iostat=ierr,status='old', > form='formatted',recordtype='fixed',organization='sequential', > readonly) if(ierr.ne.0) then write(*,*) 'Error',ierr,' opening file ',fname stop endif c Read then write the file attribute portion of the header file. do irec = 1, 6 read (20,fmt='(a)',rec=irec,iostat=ierr) string if(ierr.eq.0) then write(10,*) string else go to 10 endif end do c Read and modify the data column descriptor header line then write it out. read (20,fmt='(a)',rec=7,iostat=ierr) string if(ierr.eq.0) then string(51:72) = 'FORMAT' write(10,*) string else go to 10 endif c Read and modify the data column descriptor lines then write them out. irec = 8 do while (string.ne.'ABSTRACT') read (20,fmt='(a)',rec=irec,iostat=ierr) string if(ierr.eq.0) then if(string.ne.'ABSTRACT') then if(string(1:3).eq.'001') then string(15:50) = 'YR DOY MON DY HR MN SC MS' string(51:72) = 'I3.2,I4.3,5I3.2,I4.3' else string(51:72) = 'G13.5' endif endif write(10,*) string irec = irec + 1 else go to 10 endif end do c Read then write the abstract portion of the header file. do while (string.ne.'END') read (20,fmt='(a)',rec=irec,iostat=ierr) string if(ierr.eq.0) then write(10,*) string irec = irec + 1 else go to 10 endif end do c Close the ASCII header portion of the flat file pair. 10 close(20) c Define the flag values which are written out below as part of the meta data. iflag = 0 flag = 1.0e34 c Finish the meta data documentation by providing the FORTRAN format c statement used to write the data and a sample "record" of the flag c values for each data item. write(10,*) 'FORTRAN FORMAT:' write(10,*) '(I3.2,I4,3,5I3.2,I4.3,/,16(6G13.5,/))' write(10,*) 'MISSING DATA FLAGS:' write(10,'(I3.2,I4.3,5I3.2,I4.3,/,16(6G13.5,/))') > (iflag,i=1,8), (flag,i=1,96) write(10,*) 'DATA:' c Finish up. return end c ----------------------------------------------------------------------------- c This routine reads the binary data portion of the flat file pair, c which contains the ISEE 60-second averaged magnetometer data file. c It then writes the data to the same ASCII text file as the meta data. subroutine ffdata(fname) character*(*) fname real*4 record(98) real*8 time integer itime(8) equivalence (time,record(1)) c Open the binary data portion of the flat file pair. open (30,file=fname,access='direct',iostat=ierr,status='old', > form='unformatted',recordtype='fixed',organization='sequential', > readonly) if(ierr.ne.0) then write(*,*) 'Error',ierr,' opening file ',fname stop endif c Initialize the record counter. irec = 1 c Perform the following steps: c - Read the data records; c - Convert the time to integer values; c - Verify that all flag values are consistent; c - Write out the datato the ASCII output file. do while (ierr.eq.0) read (30,rec=irec,iostat=ierr) record if(ierr.eq.0) then call tconi(time,itime) do i = 3, 98 if (record(i) .gt. 1.0e30 ) record(i) = 1.0e34 enddo write(10,'(I3.2,I4.3,5I3.2,I4.3,/,16(6G13.5,/))') > (itime(i),i=1,8), (record(i),i=3,98) irec = irec + 1 endif end do c Close the binary data portion of the flat file pair. close(30) c Finish up. return end c ----------------------------------------------------------------------------- c This function returns the length of a FORTRAN character string with c trailing blanks removed. integer function trimlen (string) character string*(*),c*1 c Get the full length of the character string. i = len(string) c Start with the last character of the string and search forward until c a non-blank (or non-null) character is located. 10 if (i.eq.0) go to 20 c = string(i:i) if (c.ne.' '.and.c.ne.char(0)) go to 20 i = i - 1 go to 10 c Set the function equal to the length of the string excluding trailing c blanks. 20 trimlen = i c Finish up. return end c ----------------------------------------------------------------------------- c The following is a brief description of the contents of each of the data c columns in the 60-second flat file. c ----------------------------------------------------------------------------- c COL DATA DATA DATA FIELD DESCRIPTION c NUM NAME UNITS (COLUMN 1 IS REAL*8, COLUMNS 2-97 ARE REAL*4) c --- --------- --------- ----------------------------------------------------- c 001 TIME SECONDS Seconds since Jan. 1, 1966 at 00:00:00.000 c 002 BT NT 60 second average of total field c 003 BX SC NT 60 second average of Bx in spacecraft coordinates c 004 BY SC NT 60 second average of By in spacecraft coordinates c 005 BZ SC NT 60 second average of Bz in spacecraft coordinates c 006 SDX NT Standard deviation of Bx values c 007 SDY NT Standard deviation of By values c 008 SDZ NT Standard deviation of Bz values c 009 SDT NT Standard deviation of total field c 010 SDC NT SQRT(SDx**2 + SDy**2 + SDz**2 - SDt**2) c 011 BX GSM NT Bx in GSM coordinates c 012 BY GSM NT By in GSM coordinates c 013 BZ GSM NT Bz in GSM coordinates c 014 BX DIP NT Bx minus model(IGRF 75+OP 77) in dipole coord. c 015 BY DIP NT By minus model(IGRF 75+OP 77) in dipole coord. c 016 BZ DIP NT Bz minus model(IGRF 75+OP 77) in dipole coord. c 017 B NT Total field (model) c 018 B/BO NT Ratio of local total field to model field at equator c 019 BINT NT Model internal field - total c 020 BXIM GSM NT Model internal field - Bx in GSM coordinates c 021 BYIM GSM NT Model internal field - By in GSM coordinates c 022 BZIM GSM NT Model internal field - Bz in GSM coordinates c 023 BINTEXT NT Model internal+external field - total c 024 BXIE GSM NT Model internal+external field - Bx in GSM coord. c 025 BYIE GSM NT Model internal+external field - By in GSM coord. c 026 BZIE GSM NT Model internal+external field - Bz in GSM coord. c 027 NLAT GEO DEGREES North geographic latitude of field intercept c 028 NLON GEO DEGREES North geographic longitude of field intercept c 029 SLAT GEO DEGREES South geographic latitude of field intercept c 030 SLON GEO DEGREES South geographic longitude of field intercept c 031 LONG GEO DEGREES Sub-spacecraft geographic longitude c 032 LAT GEO DEGREES Sub-spacecraft geographic latitude c 033 R RE Radial distance to spacecraft (geocentric) c 034 X GSE RE GSE X position (Re) c 035 Y GSE RE GSE Y position (Re) c 036 Z GSE RE GSE Z position (Re) c 037 X GSM RE GSM X position (Re) c 038 Y GSM RE GSM Y position (Re) c 039 Z GSM RE GSM Z position (Re) c 040 ZNS GSM RE Z position of nominal Russell/Brody neutral sheet c 041 TILT DEGREES Dipole tilt angle c 042 L L parameter c 043 LT HR Local time of spacecraft c 044 MLAT DEGREES Latitude of spacecraft from magnetic equator c 045 SES DEGREES Sun-Earth-Satellite angle c 046 PHI DEGREES Clock angle from Y GSM axis (positive toward +Z GSM) c 047 SPIN SECONDS Spin period of spacecraft c 048 SLNG GSM DEGREES Longitude of spinaxis of spacecraft in GSM c 049 SLT GSM DEGREES Latitude of spinaxis of spacecraft in GSM c 050 SLNG GSE DEGREES Longitude of spinaxis of spacecraft in GSE c 051 SLT GSE DEGREES Latitude of spinaxis of spacecraft in GSE c 052 VX GSM KM/SEC X component of velocity in GSM (km/s) c 053 VY GSM KM/SEC Y component of velocity in GSM (km/s) c 054 VZ GSM KM/SEC Z component of velocity in GSM (km/s) c 055 V KM/SEC Total velocity c 056 DVX GSM KM/SEC X component of vel. in GSM relative to other craft c 057 DVY GSM KM/SEC Y component of vel. in GSM relative to other craft c 058 DVZ GSM KM/SEC Z component of vel. in GSM relative to other craft c 059 DV KM/SEC Total relative velocity c 060 DX GSM KM Separation of craft in X GSM (ISEE-2 to ISEE-1) c 061 DY GSM KM Separation of craft in Y GSM (ISEE-2 to ISEE-1) c 062 DZ GSM KM Separation of craft in Z GSM (ISEE-2 to ISEE-1) c 063 DX GSE KM Separation of craft in X GSE (ISEE-2 to ISEE-1) c 064 DY GSE KM Separation of craft in Y GSE (ISEE-2 to ISEE-1) c 065 DZ GSE KM Separation of craft in Z GSE (ISEE-2 to ISEE-1) c 066 DR KM Total separation of spacecraft c 067 NMPX GSE X component GSE of model normal to magnetopause c 068 NMPY GSE Y component GSE of model normal to magnetopause c 069 NMPZ GSE Z component GSE of model normal to magnetopause c 070 MPS KM Component of separation vector along this normal c 071 NSX GSE X component GSE of model normal to bow shock c 072 NSY GSE Y component GSE of model normal to bow shock c 073 NSZ GSE Z component GSE of model normal to bow shock c 074 SS KM Component of separation vector along this normal c 075 EM22 Rotation matrix from GSE to GSM c 076 EM23 ( 1 0 0 ) c 077 EM32 ( 0 EM22 EM23 ) c 078 EM33 ( 0 EM32 EM33 ) c 079 IE11 c 080 IE12 Rotation matrix from geocentric inertial (GEI) c 081 IE13 to geocentric solar ecliptic (GSE) c 082 IE21 c 083 IE22 ( IE11 IE12 IE13 ) c 084 IE23 ( IE21 IE22 IE23 ) c 085 IE31 ( IE31 IE32 IE33 ) c 086 IE32 c 087 IE33 c 088 SE11 c 089 SE12 Rotation matrix from spacecraft coordinates to GSE c 090 SE13 c 091 SE21 ( SE11 SE12 SE13 ) c 092 SE22 ( SE21 SE22 SE23 ) c 093 SE23 ( SE31 SE32 SE33 ) c 094 SE31 c 095 SE32 c 096 SE33 c 097 QUAL Quality flag c c NOTE: c The 4-byte fields of a 60-SECOND data record are initialized with a fill value c greater than 1.0E30, usually 1.0E34, and subsequently the geophysical values c are inserted. Thus if there is no data available for a given parameter that c particular field will contain the fill data value. c -----------------------------------------------------------------------------