Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining the Min and Max temps in a file

Status
Not open for further replies.

Sam032789

Programmer
Jul 25, 2011
3
US
Hello. My file looks like this:

2447893 0 27 16
2447893 3600 25 15
2447893 7200 24 16
2447893 10800 24 16
2447893 14400 22 15
2447893 18000 21 13
2447893 21600 20 13
2447893 25200 17 12
2447893 28800 16 12
2447893 32400 13 9
2447893 36000 12 8
2447893 39600 12 8
2447893 43200 12 8
2447893 46800 11 7
2447893 50400 9 5
2447893 54000 14 9
2447893 57600 21 16
2447893 61200 27 17
2447893 64800 30 17
2447893 68400 34 17
2447893 72000 37 17
2447893 75600 39 18
2447893 79200 38 18
2447893 82800 37 18
2447894 0 34 19
2447894 3600 32 19
2447894 7200 33 20
2447894 10800 32 19
2447894 14400 32 19
2447894 18000 30 18
2447894 21600 25 18
2447894 25200 26 18
2447894 28800 30 20
2447894 32400 29 20
2447894 36000 30 21
2447894 39600 31 22
2447894 43200 27 20
2447894 46800 25 19
2447894 50400 27 21
2447894 54000 32 22
2447894 57600 38 24
2447894 61200 42 25
2447894 64800 45 26
2447894 68400 49 27
2447894 72000 50 28
2447894 75600 51 28
2447894 79200 51 28
2447894 82800 48 28

Where the first column is the Julian Day, the second is the time the temperature was recorded (in seconds), and the last two columns are the temperature and dew point, respectively. I need a program that can read in the temperature values for each day and determine the high and low. I cannot assume the number of observations per day. This is also quite a large file, consisting of 200,000 lines looking exactly like this.

I've tried a number of ways, but there is always something wrong with the high and low. I have already read the values using a two dimensional array, I just can't determine the high and low.
 
This is what I have:

Code:
day = first
DO 20 x = 1, lines
	hiTemp = -100
	loTemp = 200

	IF ( JD(x).eq.day ) THEN

		IF (a(5,x).gt.HiTemp) THEN !change the hiTemp value
			hiTemp = a(5,x)
			hiTempTime = a(4,x)
		ELSE IF (a(5,x).lt.LoTemp) THEN !change the loTemp value
			loTemp = a(5,x)
			loTempTime = a(4,x)
		ENDIF

	ELSE
	
	!highs
	tempHi(day) = hiTemp
	timeTempHi(day) = hiTempTime

	!lows
	tempLo(day) = loTemp
	timeTempLo(day) = loTempTime

	write(*,200) a(2,x), a(3,x), a(1,x), hiTemp, hiTempTime, loTemp, loTempTime

	day= day+1 !count to get the values in the right place
	ENDIF

20 CONTINUE
 
What yu posted could not standalone work.
[ul]
[li]I don't see how you read the file.[/li]
[li]You don't use type declarations, so implicitly your X is real and I don't see what value has LINES[/li]
[/ul]
 
As I wrote in the thread above - you don't need arrays.
Here is an example, how to do it with Control Break Processing:
temperatures.f95
Code:
[COLOR=#a020f0]module[/color] glob_vars
  [COLOR=#0000ff]! declaration of global variables[/color]
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#2e8b57][b]integer[/b][/color] :: nr_records, [COLOR=#804040][b]&[/b][/color]
             [COLOR=#0000ff]! file record fields[/color]
             date, time, temp, point, [COLOR=#804040][b]&[/b][/color]
             [COLOR=#0000ff]! save fields[/color]
             date_save, time_save, temp_save, point_save, [COLOR=#804040][b]&[/b][/color]
             [COLOR=#0000ff]! daily result fields[/color]
             min_time, min_temp, min_point, [COLOR=#804040][b]&[/b][/color]
             max_time, max_temp, max_point, [COLOR=#804040][b]&[/b][/color]
             [COLOR=#0000ff]! total result fields[/color]
             tmin_date, tmin_time, tmin_temp, tmin_point, [COLOR=#804040][b]&[/b][/color]
             tmax_date, tmax_time, tmax_temp, tmax_point
[COLOR=#a020f0]end module[/color] glob_vars

[COLOR=#a020f0]program[/color] temperatures
  [COLOR=#0000ff]! Single-Level Control Break Processing[/color]

  [COLOR=#a020f0]use[/color] glob_vars

  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  
  [COLOR=#2e8b57][b]integer[/b][/color] :: stat [COLOR=#0000ff]! file status[/color]

  [COLOR=#0000ff]! open file[/color]
  [COLOR=#804040][b]open[/b][/color] ([COLOR=#ff00ff]1[/color], [COLOR=#804040][b]file[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'temperatures.dat'[/color], [COLOR=#804040][b]status[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'old'[/color], [COLOR=#804040][b]iostat[/b][/color][COLOR=#804040][b]=[/b][/color]stat)
  [COLOR=#804040][b]if[/b][/color] (stat [COLOR=#804040][b].ne.[/b][/color] [COLOR=#ff00ff]0[/color]) [COLOR=#804040][b]then[/b][/color]
    [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'File cannot be opened !'[/color]
    [COLOR=#804040][b]go to[/b][/color] [COLOR=#ff00ff]99[/color]
  [COLOR=#804040][b]end if[/b][/color]

  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]'(80A)'[/color]) [COLOR=#ff00ff]'*******************************************************'[/color]
  [COLOR=#0000ff]! process file[/color]
  nr_records [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]0[/color]
  date_save [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]0[/color]

  [COLOR=#804040][b]do[/b][/color] [COLOR=#804040][b]while[/b][/color] ([COLOR=#ff00ff].true.[/color])
    [COLOR=#0000ff]! read record[/color]
    [COLOR=#804040][b]read[/b][/color]([COLOR=#ff00ff]1[/color], [COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]end[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#804040][b]99[/b][/color]) date, time, temp, point
    nr_records [COLOR=#804040][b]=[/b][/color] nr_records [COLOR=#804040][b]+[/b][/color] [COLOR=#ff00ff]1[/color]
    [COLOR=#008080]call[/color] process_record
    [COLOR=#008080]call[/color] save_keys
  [COLOR=#804040][b]enddo[/b][/color]

[COLOR=#804040][b]  99 continue[/b][/color]
  [COLOR=#0000ff]! at end print totals[/color]
  [COLOR=#008080]call[/color] print_daily_summary
  [COLOR=#008080]call[/color] print_total_summary  
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]10[/color]) nr_records 
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]'(80A)'[/color]) [COLOR=#ff00ff]'*******************************************************'[/color]
  [COLOR=#0000ff]! close file[/color]
  [COLOR=#804040][b]close[/b][/color]([COLOR=#ff00ff]1[/color])

  [COLOR=#6a5acd]10[/color] [COLOR=#804040][b]format[/b][/color]([COLOR=#ff00ff]'Processing of'[/color],[COLOR=#008080]1X[/color], I0, [COLOR=#008080]1X[/color], [COLOR=#ff00ff]'lines finished.'[/color])
[COLOR=#a020f0]end program[/color] temperatures

[COLOR=#a020f0]subroutine[/color] process_record
  [COLOR=#a020f0]use[/color] glob_vars
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]

  [COLOR=#0000ff]! on 1.record initialize min and max values[/color]
  [COLOR=#804040][b]if[/b][/color] (nr_records [COLOR=#804040][b].eq.[/b][/color] [COLOR=#ff00ff]1[/color]) [COLOR=#804040][b]then[/b][/color]
    [COLOR=#0000ff]! daily values[/color]
    min_time [COLOR=#804040][b]=[/b][/color] time
    min_temp [COLOR=#804040][b]=[/b][/color] temp
    min_point [COLOR=#804040][b]=[/b][/color] point
    max_time [COLOR=#804040][b]=[/b][/color] time
    max_temp [COLOR=#804040][b]=[/b][/color] temp 
    max_point [COLOR=#804040][b]=[/b][/color] point
    [COLOR=#0000ff]! total values[/color]
    tmin_date [COLOR=#804040][b]=[/b][/color] date
    tmin_time [COLOR=#804040][b]=[/b][/color] time
    tmin_temp [COLOR=#804040][b]=[/b][/color] temp
    tmin_point [COLOR=#804040][b]=[/b][/color] point
    tmax_date [COLOR=#804040][b]=[/b][/color] date
    tmax_time [COLOR=#804040][b]=[/b][/color] time
    tmax_temp [COLOR=#804040][b]=[/b][/color] temp 
    tmax_point [COLOR=#804040][b]=[/b][/color] point      
  [COLOR=#804040][b]end if[/b][/color]

  [COLOR=#0000ff]! if not on 1.record[/color]
  [COLOR=#804040][b]if[/b][/color] (date_save [COLOR=#804040][b].ne.[/b][/color] [COLOR=#ff00ff]0[/color]) [COLOR=#804040][b]then[/b][/color]
    [COLOR=#0000ff]! process control break[/color]
    [COLOR=#008080]call[/color] process_control_break
  [COLOR=#804040][b]end if[/b][/color]

  [COLOR=#0000ff]! print line[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]10[/color]) nr_records, date, time, temp, point

  [COLOR=#0000ff]! compute minimum[/color]
  [COLOR=#804040][b]if[/b][/color] (temp [COLOR=#804040][b].lt.[/b][/color] min_temp) [COLOR=#804040][b]then[/b][/color]
    [COLOR=#0000ff]! daily values[/color]
    min_time [COLOR=#804040][b]=[/b][/color] time
    min_temp [COLOR=#804040][b]=[/b][/color] temp
    min_point [COLOR=#804040][b]=[/b][/color] point
  [COLOR=#804040][b]end if[/b][/color]
  [COLOR=#804040][b]if[/b][/color] (temp [COLOR=#804040][b].lt.[/b][/color] tmin_temp) [COLOR=#804040][b]then[/b][/color]
    [COLOR=#0000ff]! total values[/color]
    tmin_date [COLOR=#804040][b]=[/b][/color] date
    tmin_time [COLOR=#804040][b]=[/b][/color] time
    tmin_temp [COLOR=#804040][b]=[/b][/color] temp
    tmin_point [COLOR=#804040][b]=[/b][/color] point
  [COLOR=#804040][b]end if[/b][/color]

  [COLOR=#0000ff]! compute maximum[/color]
  [COLOR=#804040][b]if[/b][/color] (temp [COLOR=#804040][b].gt.[/b][/color] max_temp) [COLOR=#804040][b]then[/b][/color] 
    [COLOR=#0000ff]! daily values[/color]
    max_time [COLOR=#804040][b]=[/b][/color] time
    max_temp [COLOR=#804040][b]=[/b][/color] temp 
    max_point [COLOR=#804040][b]=[/b][/color] point
  [COLOR=#804040][b]end if[/b][/color]
  [COLOR=#804040][b]if[/b][/color] (temp [COLOR=#804040][b].gt.[/b][/color] tmax_temp) [COLOR=#804040][b]then[/b][/color] 
    [COLOR=#0000ff]! total values[/color]
    tmax_date [COLOR=#804040][b]=[/b][/color] date
    tmax_time [COLOR=#804040][b]=[/b][/color] time
    tmax_temp [COLOR=#804040][b]=[/b][/color] temp 
    tmax_point [COLOR=#804040][b]=[/b][/color] point      
  [COLOR=#804040][b]end if[/b][/color]

  [COLOR=#6a5acd]10[/color] [COLOR=#804040][b]format[/b][/color]([COLOR=#008080]5X[/color], i3, [COLOR=#008080]1x[/color], i7, [COLOR=#008080]1X[/color], i5, [COLOR=#008080]1x[/color], i2, [COLOR=#008080]1x[/color], i2)  
[COLOR=#a020f0]end subroutine[/color] process_record

[COLOR=#a020f0]subroutine[/color] process_control_break
  [COLOR=#a020f0]use[/color] glob_vars
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#0000ff]![/color]
  [COLOR=#804040][b]if[/b][/color] (date [COLOR=#804040][b].ne.[/b][/color] date_save) [COLOR=#804040][b]then[/b][/color]
     [COLOR=#008080]call[/color] print_daily_summary
  [COLOR=#804040][b]end if[/b][/color]  
[COLOR=#a020f0]end subroutine[/color] process_control_break

[COLOR=#a020f0]subroutine[/color] print_daily_summary
  [COLOR=#a020f0]use[/color] glob_vars
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#0000ff]![/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]*[/b][/color])
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]10[/color]) date_save
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]20[/color]) [COLOR=#ff00ff]'*  min:'[/color], min_time, min_temp, min_point 
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]20[/color]) [COLOR=#ff00ff]'*  max:'[/color], max_time, max_temp, max_point 
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]*[/b][/color])

  [COLOR=#6a5acd]10[/color] [COLOR=#804040][b]format[/b][/color]([COLOR=#ff00ff]'*  Summary for date'[/color],[COLOR=#008080]1x[/color],i7,[COLOR=#ff00ff]':'[/color])
  [COLOR=#6a5acd]20[/color] [COLOR=#804040][b]format[/b][/color](a7, [COLOR=#008080]10x[/color], i5, [COLOR=#008080]1x[/color], i2, [COLOR=#008080]1x[/color], i2)

  [COLOR=#0000ff]! initialize gloabal variables[/color]
  min_time [COLOR=#804040][b]=[/b][/color] time
  min_temp [COLOR=#804040][b]=[/b][/color] temp
  min_point [COLOR=#804040][b]=[/b][/color] point
  max_time [COLOR=#804040][b]=[/b][/color] time
  max_temp [COLOR=#804040][b]=[/b][/color] temp
  max_point [COLOR=#804040][b]=[/b][/color] point  
[COLOR=#a020f0]end subroutine[/color] print_daily_summary

[COLOR=#a020f0]subroutine[/color] print_total_summary
  [COLOR=#a020f0]use[/color] glob_vars
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#0000ff]![/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]*[/b][/color])
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]10[/color])
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]20[/color]) [COLOR=#ff00ff]'** min:'[/color], tmin_date, tmin_time, tmin_temp, tmin_point 
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#ff00ff]20[/color]) [COLOR=#ff00ff]'** max:'[/color], tmax_date, tmax_time, tmax_temp, tmax_point 
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]*[/b][/color])

  [COLOR=#6a5acd]10[/color] [COLOR=#804040][b]format[/b][/color]([COLOR=#ff00ff]'** Summary for all dates:'[/color])
  [COLOR=#6a5acd]20[/color] [COLOR=#804040][b]format[/b][/color](a7, [COLOR=#008080]2x[/color], i7, [COLOR=#008080]1x[/color], i5, [COLOR=#008080]1x[/color], i2, [COLOR=#008080]1x[/color], i2)
[COLOR=#a020f0]end subroutine[/color] print_total_summary

[COLOR=#a020f0]subroutine[/color] save_keys
  [COLOR=#a020f0]use[/color] glob_vars
  [COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
  [COLOR=#0000ff]![/color]
  date_save [COLOR=#804040][b]=[/b][/color] date
[COLOR=#a020f0]end subroutine[/color] save_keys
Compling and running the example above I get these results:
Code:
$ g95 temperatures.f95 -o temperatures

$ temperatures
*******************************************************
       1 2447893     0 27 16
       2 2447893  3600 25 15
       3 2447893  7200 24 16
       4 2447893 10800 24 16
       5 2447893 14400 22 15
       6 2447893 18000 21 13
       7 2447893 21600 20 13
       8 2447893 25200 17 12
       9 2447893 28800 16 12
      10 2447893 32400 13  9
      11 2447893 36000 12  8
      12 2447893 39600 12  8
      13 2447893 43200 12  8
      14 2447893 46800 11  7
      15 2447893 50400  9  5
      16 2447893 54000 14  9
      17 2447893 57600 21 16
      18 2447893 61200 27 17
      19 2447893 64800 30 17
      20 2447893 68400 34 17
      21 2447893 72000 37 17
      22 2447893 75600 39 18
      23 2447893 79200 38 18
      24 2447893 82800 37 18

*  Summary for date 2447893:
*  min:          50400  9  5
*  max:          75600 39 18

      25 2447894     0 34 19
      26 2447894  3600 32 19
      27 2447894  7200 33 20
      28 2447894 10800 32 19
      29 2447894 14400 32 19
      30 2447894 18000 30 18
      31 2447894 21600 25 18
      32 2447894 25200 26 18
      33 2447894 28800 30 20
      34 2447894 32400 29 20
      35 2447894 36000 30 21
      36 2447894 39600 31 22
      37 2447894 43200 27 20
      38 2447894 46800 25 19
      39 2447894 50400 27 21
      40 2447894 54000 32 22
      41 2447894 57600 38 24
      42 2447894 61200 42 25
      43 2447894 64800 45 26
      44 2447894 68400 49 27
      45 2447894 72000 50 28
      46 2447894 75600 51 28
      47 2447894 79200 51 28
      48 2447894 82800 48 28

*  Summary for date 2447894:
*  min:          21600 25 18
*  max:          75600 51 28


** Summary for all dates:
** min:  2447893 50400  9  5
** max:  2447894 75600 51 28

Processing of 48 lines finished.
*******************************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top