wiki:Documentation/UserGuide/VariableHistory

Version 4 (modified by mmcgrath, 7 years ago) (diff)

--

How to add a variable to history.nc

Define the variable in intersurf.f90, check whether the correct operators (i.e. ave) and history level i.e. (4) are defined more information on 'histdef' and 'histwrite' can be found on the documentation page of this wiki ( or another HowTo, http://forge.ipsl.jussieu.fr/orchidee/wiki/HowTo/HistoryOperators)

The first big question is where to put the histdef. It goes in intersurf, but there are five possible places for it. The questions you need to ask yourself are: 1) Is this a stomate or sechiba variable? 2) If it is sechiba, do I want to write it to the high frequency file or just the regular file (only a few variables should, in theory, be written to the HF file)? 3) Is this variable part of the ALMA convention or not (if you're not sure, the answer is probably "no")?

The basic structure of intersurf for defining variables is

  SUBROUTINE intsurf_history

  ! Writing to the main history file, file id hist_id
         IF ( .NOT. almaoutput ) THEN

              ... a few hundred lines of histdefs

          ELSE

              ... a few hundred lines of histdefs

          ENDIF

    ! Writing to the HF file, file ID hist2_id
        IF ( .NOT. almaoutput ) THEN

              ... a few hundred lines of histdefs

          ELSE

              ... a few hundred lines of histdefs

          ENDIF

! Writing to the STOMATE history file
      CALL stom_define_history

  END SUBROUTINE

  SUBROUTINE stom_define_history

    ... a few hundred lines of histdefs

  END SUBROUTINE

Your histdef should go in one of those five places based on how you answered the three questions above, and will look something like this.

! total living biomass
    CALL histdef (hist_id_stom, &
         &               TRIM("Fruit_M             "), &
         &               TRIM("Fruit biomass                                       "), &
         &               TRIM("gC/m^2/pft          "), iim,jjm, hist_hori_id, &
         &               nvm,1,nvm, hist_PFTaxis_id,32, ave(4), dt, hist_dt)

Once you have done that (making sure to use the correct file ID for the section, as well as the correct axes IDs, write frequency (dw, dw2, or hist_dt), and operation array (for the HF file, the operation arrays are followed by 2), you have to write out the variable with a histwrite somewhere in the other routines. Make sure that the histwrite and histdef have the same file ID (you will get an error if you try to write a variable to a file for which it has not been defined), and also make sure that it appears either in the same almaoutput branch that you defined it in (if you define it in the IF statement where almaoutput is TRUE but write it surrounded by an IF statement that checks if almaoutput is FALSE, you will not see it in the history file).

CALL histwrite (hist_id_stomate, 'FRUIT_M', itime, &
         biomass(:,:,ifruit), npts*nvm, horipft_index)

There also seems to be a convention that if you are defining a variable for ALMA output, the first letter is a capital letter, and otherwise it is lowercase. I do not know this for a fact, but it seems to be that way in the code.